From 3278b76eefb492bf5df9f54236e973b38db1688b Mon Sep 17 00:00:00 2001 From: samcake Date: Fri, 4 Mar 2016 18:24:36 -0800 Subject: [PATCH 1/5] Starting investigating the text rendering bug --- libraries/render-utils/src/sdf_text3D.slf | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libraries/render-utils/src/sdf_text3D.slf b/libraries/render-utils/src/sdf_text3D.slf index faa4d02bfa..6355c71737 100644 --- a/libraries/render-utils/src/sdf_text3D.slf +++ b/libraries/render-utils/src/sdf_text3D.slf @@ -15,6 +15,7 @@ uniform sampler2D Font; uniform bool Outline; uniform vec4 Color; +uniform vec4 backgroundColor = vec4(1.0, 0.0, 0.0, 1.0); // the interpolated normal in vec3 _normal; @@ -30,6 +31,8 @@ const float smoothing = 256.0; const float interiorCutoff = 0.8; const float outlineExpansion = 0.2; + + void main() { // retrieve signed distance float sdf = texture(Font, _texCoord0).g; @@ -60,8 +63,8 @@ void main() { */ packDeferredFragmentLightmap( normalize(_normal), - Color.a * a, - Color.rgb, + 1.0 // Color.a * a, + mix(Color.rgb, backgroundColor, Color.a * a), DEFAULT_ROUGHNESS, DEFAULT_METALLIC, DEFAULT_SPECULAR, From e3d11560ebe60dfa8f500a02c4a6ca6f845386a2 Mon Sep 17 00:00:00 2001 From: samcake Date: Fri, 4 Mar 2016 19:08:48 -0800 Subject: [PATCH 2/5] With a shader compiling --- libraries/render-utils/src/sdf_text3D.slf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/render-utils/src/sdf_text3D.slf b/libraries/render-utils/src/sdf_text3D.slf index 6355c71737..3d229ef359 100644 --- a/libraries/render-utils/src/sdf_text3D.slf +++ b/libraries/render-utils/src/sdf_text3D.slf @@ -63,10 +63,10 @@ void main() { */ packDeferredFragmentLightmap( normalize(_normal), - 1.0 // Color.a * a, - mix(Color.rgb, backgroundColor, Color.a * a), + step(alphaThreshold, Color.a * a), + mix(Color.rgb, backgroundColor.rgb, Color.a * a), DEFAULT_ROUGHNESS, DEFAULT_METALLIC, DEFAULT_SPECULAR, - Color.rgb); + mix(Color.rgb, backgroundColor.rgb, Color.a * a)); } \ No newline at end of file From 2d3f0b12f56b8d341b576c9383aa2ed39ae7a9e6 Mon Sep 17 00:00:00 2001 From: samcake Date: Sat, 5 Mar 2016 10:18:50 -0800 Subject: [PATCH 3/5] Simple fix to the text bug --- libraries/render-utils/src/sdf_text3D.slf | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/libraries/render-utils/src/sdf_text3D.slf b/libraries/render-utils/src/sdf_text3D.slf index 3d229ef359..55952e1c3d 100644 --- a/libraries/render-utils/src/sdf_text3D.slf +++ b/libraries/render-utils/src/sdf_text3D.slf @@ -15,16 +15,10 @@ uniform sampler2D Font; uniform bool Outline; uniform vec4 Color; -uniform vec4 backgroundColor = vec4(1.0, 0.0, 0.0, 1.0); // the interpolated normal in vec3 _normal; in vec2 _texCoord0; -/* -layout(location = 0) out vec4 _fragColor0; -layout(location = 1) out vec4 _fragColor1; -layout(location = 2) out vec4 _fragColor2; -*/ const float gamma = 2.2; const float smoothing = 256.0; @@ -52,21 +46,17 @@ void main() { // gamma correction for linear attenuation a = pow(a, 1.0 / gamma); + // discard if unvisible if (a < 0.01) { discard; } - // final color - /* _fragColor0 = vec4(Color.rgb, Color.a * a); - _fragColor1 = vec4(normalize(_normal.xyz), 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 0.5); - _fragColor2 = vec4(Color.rgb, 10 / 128.0); - */ packDeferredFragmentLightmap( normalize(_normal), - step(alphaThreshold, Color.a * a), - mix(Color.rgb, backgroundColor.rgb, Color.a * a), + 1.0, + Color.rgb, DEFAULT_ROUGHNESS, DEFAULT_METALLIC, DEFAULT_SPECULAR, - mix(Color.rgb, backgroundColor.rgb, Color.a * a)); + Color.rgb); } \ No newline at end of file From d3b84311c5a55b24a2903103dafd5aff88e2149d Mon Sep 17 00:00:00 2001 From: samcake Date: Sat, 5 Mar 2016 10:36:45 -0800 Subject: [PATCH 4/5] FIxing the color --- libraries/render-utils/src/sdf_text3D.slf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/render-utils/src/sdf_text3D.slf b/libraries/render-utils/src/sdf_text3D.slf index 55952e1c3d..1e11cd984d 100644 --- a/libraries/render-utils/src/sdf_text3D.slf +++ b/libraries/render-utils/src/sdf_text3D.slf @@ -54,7 +54,7 @@ void main() { packDeferredFragmentLightmap( normalize(_normal), 1.0, - Color.rgb, + vec3(1.0), DEFAULT_ROUGHNESS, DEFAULT_METALLIC, DEFAULT_SPECULAR, From 193b98f24fb35580faed499bdcb952712d96ba1a Mon Sep 17 00:00:00 2001 From: samcake Date: Sat, 5 Mar 2016 10:59:03 -0800 Subject: [PATCH 5/5] Gamma correct the text color --- libraries/render-utils/src/text/Font.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libraries/render-utils/src/text/Font.cpp b/libraries/render-utils/src/text/Font.cpp index 2e86d09fe0..762a7fb723 100644 --- a/libraries/render-utils/src/text/Font.cpp +++ b/libraries/render-utils/src/text/Font.cpp @@ -3,6 +3,8 @@ #include #include +#include + #include #include "sdf_text3D_vert.h" @@ -354,7 +356,10 @@ void Font::drawString(gpu::Batch& batch, float x, float y, const QString& str, c batch.setPipeline(layered ? _layeredPipeline : _pipeline); batch.setResourceTexture(_fontLoc, _texture); batch._glUniform1i(_outlineLoc, (effectType == OUTLINE_EFFECT)); - batch._glUniform4fv(_colorLoc, 1, (const float*)color); + + // need the gamma corrected color here + glm::vec4 lrgba = glm::vec4(ColorUtils::toLinearVec3(glm::vec3(*color)), color->a); + batch._glUniform4fv(_colorLoc, 1, (const float*)&lrgba); batch.setInputFormat(_format); batch.setInputBuffer(0, _verticesBuffer, 0, _format->getChannels().at(0)._stride);