From 2221c839c3a1e39d7baccdb9482c76605f5a6e2f Mon Sep 17 00:00:00 2001 From: Bradley Austin Davis Date: Tue, 4 Aug 2015 15:06:18 -0700 Subject: [PATCH] Fix star point smoothing... sort of --- libraries/render-utils/src/stars.slf | 18 +++++++++++++++++- libraries/render-utils/src/stars.slv | 11 +++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/libraries/render-utils/src/stars.slf b/libraries/render-utils/src/stars.slf index 8d1ba0da51..14191f2a6a 100644 --- a/libraries/render-utils/src/stars.slf +++ b/libraries/render-utils/src/stars.slf @@ -11,8 +11,24 @@ // in vec4 varColor; +in float varSize; + out vec4 outFragColor; +const float EDGE_SIZE = 0.25; +const float ALPHA_BOUNDARY = 1.0 - EDGE_SIZE; + void main(void) { - outFragColor = varColor; //vec4(varColor, 1.0); + vec2 coord = gl_PointCoord * vec2(2.0) - vec2(1.0); + coord = coord * coord; + + float l = coord.x + coord.y; + if (l > 1.0) { + discard; + } + + outFragColor = varColor; + if (l >= ALPHA_BOUNDARY) { + outFragColor.a = smoothstep(1.0, ALPHA_BOUNDARY, l); + } } diff --git a/libraries/render-utils/src/stars.slv b/libraries/render-utils/src/stars.slv index f9be6d0139..b9ad736d5e 100644 --- a/libraries/render-utils/src/stars.slv +++ b/libraries/render-utils/src/stars.slv @@ -18,9 +18,12 @@ <$declareStandardTransform()$> -out vec3 varPosition; -out vec4 varColor; +// TODO we need to get the viewport resolution and FOV passed to us so we can modify the point size +// and effectively producing a points that take up a constant angular size regardless of the display resolution +// or projection matrix +out vec4 varColor; +out float varSize; void main(void) { varColor = inColor.rgba; @@ -29,6 +32,6 @@ void main(void) { TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); <$transformModelToClipPos(cam, obj, inPosition, gl_Position)$> - varPosition = inPosition.xyz; - gl_PointSize = inColor.a; + varSize = inColor.a; + gl_PointSize = varSize; } \ No newline at end of file