2
0
Эх сурвалжийг харах

AlphaDiscardTreshold is now supported by the Unshaded material.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10588 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
rem..om 12 жил өмнө
parent
commit
706cd410b6

+ 11 - 1
engine/src/core-data/Common/MatDefs/Misc/Unshaded.frag

@@ -2,6 +2,10 @@
     #define NEED_TEXCOORD1
 #endif
 
+#if defined(DISCARD_ALPHA)
+    uniform float m_AlphaDiscardThreshold;
+#endif
+
 uniform vec4 m_Color;
 uniform sampler2D m_ColorMap;
 uniform sampler2D m_LightMap;
@@ -15,7 +19,7 @@ void main(){
     vec4 color = vec4(1.0);
 
     #ifdef HAS_COLORMAP
-        color *= texture2D(m_ColorMap, texCoord1);
+        color *= texture2D(m_ColorMap, texCoord1);     
     #endif
 
     #ifdef HAS_VERTEXCOLOR
@@ -34,5 +38,11 @@ void main(){
         #endif
     #endif
 
+    #if defined(DISCARD_ALPHA)
+        if(color.a < m_AlphaDiscardThreshold){
+           discard;
+        }
+    #endif
+
     gl_FragColor = color;
 }

+ 4 - 0
engine/src/core-data/Common/MatDefs/Misc/Unshaded.j3md

@@ -16,6 +16,9 @@ MaterialDef Unshaded {
         Int NumberOfBones
         Matrix4Array BoneMatrices
 
+        // Apha threshold for fragment discarding
+        Float AlphaDiscardThreshold (AlphaTestFallOff)
+
         //Shadows
         Int FilterMode
         Boolean HardwareShadows
@@ -61,6 +64,7 @@ MaterialDef Unshaded {
             HAS_VERTEXCOLOR : VertexColor
             HAS_COLOR : Color
             NUM_BONES : NumberOfBones
+            DISCARD_ALPHA : AlphaDiscardThreshold
         }
     }