Bläddra i källkod

Use ALPHAMAP shader define in Text shader to differentiate between alpha texture (TTF) and RGBA (bitmap fonts). Closes #1750.

Lasse Öörni 9 år sedan
förälder
incheckning
8b4ddd5289

+ 17 - 0
Source/Urho3D/UI/Text3D.cpp

@@ -25,6 +25,7 @@
 #include "../Core/Context.h"
 #include "../Core/Context.h"
 #include "../Graphics/Camera.h"
 #include "../Graphics/Camera.h"
 #include "../Graphics/Geometry.h"
 #include "../Graphics/Geometry.h"
+#include "../Graphics/Graphics.h"
 #include "../Graphics/Material.h"
 #include "../Graphics/Material.h"
 #include "../Graphics/Technique.h"
 #include "../Graphics/Technique.h"
 #include "../Graphics/VertexBuffer.h"
 #include "../Graphics/VertexBuffer.h"
@@ -714,6 +715,22 @@ void Text3D::UpdateTextMaterials(bool forceUpdate)
                 break;
                 break;
             }
             }
         }
         }
+        else
+        {
+            // If not SDF, set shader defines based on whether font texture is full RGB or just alpha
+            if (!material_)
+            {
+                Technique* tech = material->GetTechnique(0);
+                Pass* pass = tech ? tech->GetPass("alpha") : (Pass*)0;
+                if (pass)
+                {
+                    if (texture && texture->GetFormat() == Graphics::GetAlphaFormat())
+                        pass->SetPixelShaderDefines("ALPHAMAP");
+                    else
+                        pass->SetPixelShaderDefines("");
+                }
+            }
+        }
     }
     }
 }
 }
 
 

+ 9 - 5
bin/CoreData/Shaders/GLSL/Text.glsl

@@ -26,9 +26,9 @@ void VS()
 
 
 void PS()
 void PS()
 {
 {
+#ifdef SIGNED_DISTANCE_FIELD
     gl_FragColor.rgb = vColor.rgb;
     gl_FragColor.rgb = vColor.rgb;
 
 
-#ifdef SIGNED_DISTANCE_FIELD
     float distance = texture2D(sDiffMap, vTexCoord).a;
     float distance = texture2D(sDiffMap, vTexCoord).a;
     if (distance < 0.5)
     if (distance < 0.5)
     {
     {
@@ -54,11 +54,15 @@ void PS()
         gl_FragColor.a = vColor.a * smoothstep(0.5, 0.505, distance);
         gl_FragColor.a = vColor.a * smoothstep(0.5, 0.505, distance);
     }
     }
 #else
 #else
-    // Non-SDF font will likely be monochrome, in which case the alpha channel will be on the R channel on OpenGL 3
-    #ifdef GL3
-        gl_FragColor.a = vColor.a * texture2D(sDiffMap, vTexCoord).r;
+    #ifdef ALPHAMAP
+        gl_FragColor.rgb = vColor.rgb;
+        #ifdef GL3
+            gl_FragColor.a = vColor.a * texture2D(sDiffMap, vTexCoord).r;
+        #else
+            gl_FragColor.a = vColor.a * texture2D(sDiffMap, vTexCoord).a;
+        #endif
     #else
     #else
-        gl_FragColor.a = vColor.a * texture2D(sDiffMap, vTexCoord).a;
+        gl_FragColor = vColor * texture2D(sDiffMap, vTexCoord);
     #endif
     #endif
 #endif
 #endif
 }
 }

+ 8 - 3
bin/CoreData/Shaders/HLSL/Text.hlsl

@@ -41,9 +41,9 @@ void PS(float2 iTexCoord : TEXCOORD0,
     float4 iColor : COLOR0,
     float4 iColor : COLOR0,
     out float4 oColor : OUTCOLOR0)
     out float4 oColor : OUTCOLOR0)
 {
 {
-    oColor.rgb = iColor.rgb;
-
 #ifdef SIGNED_DISTANCE_FIELD
 #ifdef SIGNED_DISTANCE_FIELD
+    oColor.rgb = iColor.rgb;
+    
     float distance = Sample2D(DiffMap, iTexCoord).a;
     float distance = Sample2D(DiffMap, iTexCoord).a;
     if (distance < 0.5f)
     if (distance < 0.5f)
     {
     {
@@ -69,6 +69,11 @@ void PS(float2 iTexCoord : TEXCOORD0,
         oColor.a = iColor.a * smoothstep(0.5f, 0.505f, distance);
         oColor.a = iColor.a * smoothstep(0.5f, 0.505f, distance);
     }
     }
 #else
 #else
-    oColor.a = iColor.a * Sample2D(DiffMap, iTexCoord).a;
+    #ifdef ALPHAMAP
+        oColor.rgb = iColor.rgb;
+        oColor.a = iColor.a * Sample2D(DiffMap, iTexCoord).a;
+    #else
+        oColor = iColor* Sample2D(DiffMap, iTexCoord);
+    #endif
 #endif
 #endif
 }
 }