Bläddra i källkod

Fix artifacts in SDF text effects when supersampling is off.

Lasse Öörni 9 år sedan
förälder
incheckning
314a3af082
2 ändrade filer med 25 tillägg och 7 borttagningar
  1. 12 3
      bin/CoreData/Shaders/GLSL/Text.glsl
  2. 13 4
      bin/CoreData/Shaders/HLSL/Text.hlsl

+ 12 - 3
bin/CoreData/Shaders/GLSL/Text.glsl

@@ -53,7 +53,7 @@ void VS()
         return smoothstep(0.5 - width, 0.5 + width, distance);
     }
 
-    // Comment for turn off supersampling
+    // Comment this define to turn off supersampling
     #define SUPERSAMPLING
 #endif
 
@@ -64,13 +64,22 @@ void PS()
     float distance = texture2D(sDiffMap, vTexCoord).a;
 
     #ifdef TEXT_EFFECT_STROKE
-        float outlineFactor = smoothstep(0.5, 0.52, distance); // Border of glyph
-        gl_FragColor.rgb = mix(cStrokeColor.rgb, vColor.rgb, outlineFactor);
+        #ifdef SUPERSAMPLING
+            float outlineFactor = smoothstep(0.5, 0.525, distance); // Border of glyph
+            gl_FragColor.rgb = mix(cStrokeColor.rgb, vColor.rgb, outlineFactor);
+        #else
+            if (distance < 0.525)
+               gl_FragColor.rgb = cStrokeColor.rgb;
+        #endif
     #endif
 
     #ifdef TEXT_EFFECT_SHADOW
         if (texture2D(sDiffMap, vTexCoord - cShadowOffset).a > 0.5 && distance <= 0.5)
             gl_FragColor = cShadowColor;
+        #ifndef SUPERSAMPLING
+        else if (distance <= 0.5)
+            gl_FragColor.a = 0;
+        #endif
         else
     #endif
         {

+ 13 - 4
bin/CoreData/Shaders/HLSL/Text.hlsl

@@ -44,7 +44,7 @@ void VS(float4 iPos : POSITION,
         return smoothstep(0.5 - width, 0.5 + width, distance);
     }
 
-    // Comment for turn off supersampling
+    // Comment this define to turn off supersampling
     #define SUPERSAMPLING
 #endif
 
@@ -58,20 +58,29 @@ void PS(float2 iTexCoord : TEXCOORD0,
     float distance = Sample2D(DiffMap, iTexCoord).a;
 
     #ifdef TEXT_EFFECT_STROKE
-        float outlineFactor = smoothstep(0.5, 0.52, distance); // Border of glyph
-        oColor.rgb = lerp(cStrokeColor.rgb, iColor.rgb, outlineFactor);
+        #ifdef SUPERSAMPLING
+            float outlineFactor = smoothstep(0.5, 0.525, distance); // Border of glyph
+            oColor.rgb = lerp(cStrokeColor.rgb, iColor.rgb, outlineFactor);
+        #else
+            if (distance < 0.525)
+                oColor.rgb = cStrokeColor.rgb;
+        #endif
     #endif
 
     #ifdef TEXT_EFFECT_SHADOW
         if (Sample2D(DiffMap, iTexCoord - cShadowOffset).a > 0.5 && distance <= 0.5)
             oColor = cShadowColor;
+        #ifndef SUPERSAMPLING
+        else if (distance <= 0.5)
+            oColor.a = 0.0;
+        #endif
         else
     #endif
         {
             float width = fwidth(distance);
             float alpha = GetAlpha(distance, width);
 
-            #ifdef SUPERSAMPLING  
+            #ifdef SUPERSAMPLING
                 float2 deltaUV = 0.354 * fwidth(iTexCoord); // (1.0 / sqrt(2.0)) / 2.0 = 0.354
                 float4 square = float4(iTexCoord - deltaUV, iTexCoord + deltaUV);