瀏覽代碼

Removed alpha test, as it is deprecated in modern graphics API's. Instead implemented in the pixel shader.

Lasse Öörni 13 年之前
父節點
當前提交
c3f75ee181
共有 37 個文件被更改,包括 76 次插入154 次删除
  1. 7 7
      Bin/CoreData/Techniques/DiffAlphaMask.xml
  2. 7 7
      Bin/CoreData/Techniques/DiffNormalAlphaMask.xml
  3. 0 2
      Engine/Engine/GraphicsAPI.cpp
  4. 0 5
      Engine/Graphics/Batch.cpp
  5. 0 1
      Engine/Graphics/DebugRenderer.cpp
  6. 0 25
      Engine/Graphics/Direct3D9/D3D9Graphics.cpp
  7. 0 14
      Engine/Graphics/Direct3D9/D3D9Graphics.h
  8. 1 31
      Engine/Graphics/OpenGL/OGLGraphics.cpp
  9. 0 14
      Engine/Graphics/OpenGL/OGLGraphics.h
  10. 0 1
      Engine/Graphics/Renderer.cpp
  11. 0 9
      Engine/Graphics/Technique.cpp
  12. 0 6
      Engine/Graphics/Technique.h
  13. 0 5
      Engine/Graphics/View.cpp
  14. 3 7
      Engine/UI/UI.cpp
  15. 2 0
      Engine/UI/UI.h
  16. 6 1
      SourceAssets/GLSLShaders/Basic.frag
  17. 1 0
      SourceAssets/GLSLShaders/Basic.xml
  18. 1 1
      SourceAssets/GLSLShaders/Deferred.xml
  19. 6 1
      SourceAssets/GLSLShaders/ForwardLit.frag
  20. 1 0
      SourceAssets/GLSLShaders/ForwardLit.xml
  21. 6 1
      SourceAssets/GLSLShaders/LitParticle.frag
  22. 1 0
      SourceAssets/GLSLShaders/LitParticle.xml
  23. 1 1
      SourceAssets/GLSLShaders/Material.xml
  24. 1 1
      SourceAssets/GLSLShaders/Prepass.xml
  25. 3 3
      SourceAssets/GLSLShaders/Shadow.frag
  26. 1 1
      SourceAssets/GLSLShaders/Shadow.xml
  27. 6 1
      SourceAssets/HLSLShaders/Basic.hlsl
  28. 1 0
      SourceAssets/HLSLShaders/Basic.xml
  29. 1 1
      SourceAssets/HLSLShaders/Deferred.xml
  30. 6 1
      SourceAssets/HLSLShaders/ForwardLit.hlsl
  31. 1 0
      SourceAssets/HLSLShaders/ForwardLit.xml
  32. 6 1
      SourceAssets/HLSLShaders/LitParticle.hlsl
  33. 1 0
      SourceAssets/HLSLShaders/LitParticle.xml
  34. 1 1
      SourceAssets/HLSLShaders/Material.xml
  35. 1 1
      SourceAssets/HLSLShaders/Prepass.xml
  36. 3 3
      SourceAssets/HLSLShaders/Shadow.hlsl
  37. 1 1
      SourceAssets/HLSLShaders/Shadow.xml

+ 7 - 7
Bin/CoreData/Techniques/DiffAlphaMask.xml

@@ -1,9 +1,9 @@
 <technique>
-    <pass name="base" vs="Ambient" ps="Ambient_Diff" alphatest="true" />
-    <pass name="litbase" vs="ForwardLit" ps="ForwardLit_DiffAmbient"  alphatest="true" />
-    <pass name="light" vs="ForwardLit" ps="ForwardLit_Diff"  alphatest="true" depthtest="equal" depthwrite="false" blend="add" />
-    <pass name="shadow" vs="Shadow_Mask" ps="Shadow_Mask" alphatest="true" />
-    <pass name="prepass" vs="Prepass" ps="Prepass_Mask" />
-    <pass name="material" vs="Material" ps="Material_DiffMask" depthtest="equal" depthwrite="false" />
-    <pass name="deferred" vs="Deferred" ps="Deferred_DiffMask" />
+    <pass name="base" vs="Ambient" ps="Ambient_DiffAlphaMask" />
+    <pass name="litbase" vs="ForwardLit" ps="ForwardLit_DiffAlphaMaskAmbient" />
+    <pass name="light" vs="ForwardLit" ps="ForwardLit_DiffAlphaMask"  depthtest="equal" depthwrite="false" blend="add" />
+    <pass name="shadow" vs="Shadow_Mask" ps="Shadow_AlphaMask" />
+    <pass name="prepass" vs="Prepass" ps="Prepass_AlphaMask" />
+    <pass name="material" vs="Material" ps="Material_DiffAlphaMask" depthtest="equal" depthwrite="false" />
+    <pass name="deferred" vs="Deferred" ps="Deferred_DiffAlphaMask" />
 </technique>

+ 7 - 7
Bin/CoreData/Techniques/DiffNormalAlphaMask.xml

@@ -1,9 +1,9 @@
 <technique>
-    <pass name="base" vs="Ambient" ps="Ambient_Diff" alphatest="true" />
-    <pass name="litbase" vs="ForwardLit_Normal" ps="ForwardLit_DiffNormalAmbient" alphatest="true" />
-    <pass name="light" vs="ForwardLit_Normal" ps="ForwardLit_DiffNormal" alphatest="true" depthtest="equal" depthwrite="false" blend="add" />
-    <pass name="shadow" vs="Shadow_Mask" ps="Shadow_Mask" alphatest="true" />
-    <pass name="prepass" vs="Prepass_Normal" ps="Prepass_NormalMask" />
-    <pass name="material" vs="Material" ps="Material_DiffMask" depthtest="equal" depthwrite="false" />
-    <pass name="deferred" vs="Deferred_Normal" ps="Deferred_DiffNormalMask" />
+    <pass name="base" vs="Ambient" ps="Ambient_DiffAlphaMask" />
+    <pass name="litbase" vs="ForwardLit_Normal" ps="ForwardLit_DiffNormalAlphaMaskAmbient" />
+    <pass name="light" vs="ForwardLit_Normal" ps="ForwardLit_DiffNormalAlphaMask" depthtest="equal" depthwrite="false" blend="add" />
+    <pass name="shadow" vs="Shadow_Mask" ps="Shadow_AlphaMask" />
+    <pass name="prepass" vs="Prepass_Normal" ps="Prepass_NormalAlphaMask" />
+    <pass name="material" vs="Material" ps="Material_DiffAlphaMask" depthtest="equal" depthwrite="false" />
+    <pass name="deferred" vs="Deferred_Normal" ps="Deferred_DiffNormalAlphaMask" />
 </technique>

+ 0 - 2
Engine/Engine/GraphicsAPI.cpp

@@ -327,8 +327,6 @@ static void RegisterMaterial(asIScriptEngine* engine)
     engine->RegisterEnumValue("CullMode", "CULL_CW", CULL_CW);
     
     RegisterRefCounted<Pass>(engine, "Pass");
-    engine->RegisterObjectMethod("Pass", "void set_alphaTest(bool)", asMETHOD(Pass, SetAlphaTest), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Pass", "bool get_alphaTest() const", asMETHOD(Pass, GetAlphaTest), asCALL_THISCALL);
     engine->RegisterObjectMethod("Pass", "void set_blendMode(BlendMode)", asMETHOD(Pass, SetBlendMode), asCALL_THISCALL);
     engine->RegisterObjectMethod("Pass", "BlendMode get_blendMode() const", asMETHOD(Pass, GetBlendMode), asCALL_THISCALL);
     engine->RegisterObjectMethod("Pass", "void set_depthTestMode(CompareMode)", asMETHOD(Pass, SetDepthTestMode), asCALL_THISCALL);

+ 0 - 5
Engine/Graphics/Batch.cpp

@@ -172,11 +172,6 @@ void Batch::Prepare(Graphics* graphics, Renderer* renderer, bool setModelTransfo
     // Set pass / material-specific renderstates
     if (pass_ && material_)
     {
-        if (pass_->GetAlphaTest())
-            graphics->SetAlphaTest(true, CMP_GREATEREQUAL, 0.5f);
-        else
-            graphics->SetAlphaTest(false);
-        
         graphics->SetBlendMode(pass_->GetBlendMode());
         renderer->SetCullMode(pass_->GetType() != PASS_SHADOW ? material_->GetCullMode() : material_->GetShadowCullMode(),
             camera_);

+ 0 - 1
Engine/Graphics/DebugRenderer.cpp

@@ -398,7 +398,6 @@ void DebugRenderer::Render()
     
     vertexBuffer_->Unlock();
     
-    graphics->SetAlphaTest(false);
     graphics->SetBlendMode(BLEND_REPLACE);
     graphics->SetColorWrite(true);
     graphics->SetCullMode(CULL_NONE);

+ 0 - 25
Engine/Graphics/Direct3D9/D3D9Graphics.cpp

@@ -1377,31 +1377,6 @@ void Graphics::SetViewport(const IntRect& rect)
     SetScissorTest(false);
 }
 
-void Graphics::SetAlphaTest(bool enable, CompareMode mode, float alphaRef)
-{
-    if (enable != alphaTest_)
-    {
-        impl_->device_->SetRenderState(D3DRS_ALPHATESTENABLE, enable ? TRUE : FALSE);
-        alphaTest_ = enable;
-    }
-    
-    if (enable)
-    {
-        if (mode != alphaTestMode_)
-        {
-            impl_->device_->SetRenderState(D3DRS_ALPHAFUNC, d3dCmpFunc[mode]);
-            alphaTestMode_ = mode;
-        }
-        
-        alphaRef = Clamp(alphaRef, 0.0f, 1.0f);
-        if (alphaRef != alphaRef_)
-        {
-            impl_->device_->SetRenderState(D3DRS_ALPHAREF, (DWORD)(alphaRef * 255.0f));
-            alphaRef_ = alphaRef;
-        }
-    }
-}
-
 void Graphics::SetTextureAnisotropy(unsigned level)
 {
     if (level < 1)

+ 0 - 14
Engine/Graphics/Direct3D9/D3D9Graphics.h

@@ -149,8 +149,6 @@ public:
     void SetViewTexture(Texture* texture);
     /// %Set viewport.
     void SetViewport(const IntRect& rect);
-    /// %Set alpha test.
-    void SetAlphaTest(bool enable, CompareMode mode = CMP_ALWAYS, float alphaRef = 0.5f);
     /// %Set blending mode.
     void SetBlendMode(BlendMode mode);
     /// %Set color write on/off.
@@ -254,14 +252,8 @@ public:
     Texture2D* GetDepthTexture() const;
     /// Return the viewport coordinates.
     IntRect GetViewport() const { return viewport_; }
-    /// Return whether alpha testing is enabled.
-    bool GetAlphaTest() const { return alphaTest_; }
-    /// Return alpha test compare mode.
-    CompareMode GetAlphaTestMode() const { return alphaTestMode_; }
     /// Return texture anisotropy.
     unsigned GetTextureAnisotropy() const { return textureAnisotropy_; }
-    /// Return alpha test reference value.
-    float GetAlphaRef() const { return alphaRef_; }
     /// Return blending mode.
     BlendMode GetBlendMode() const { return blendMode_; }
     /// Return whether color write is enabled.
@@ -435,12 +427,6 @@ private:
     Texture* viewTexture_;
     /// Viewport coordinates.
     IntRect viewport_;
-    /// Alpha test enable flag.
-    bool alphaTest_;
-    /// Alpha test compare mode.
-    CompareMode alphaTestMode_;
-    /// Alpha test reference value.
-    float alphaRef_;
     /// Texture anisotropy level.
     unsigned textureAnisotropy_;
     /// Blending mode.

+ 1 - 31
Engine/Graphics/OpenGL/OGLGraphics.cpp

@@ -64,6 +64,7 @@
 #define GL_DEPTH_ATTACHMENT_EXT GL_DEPTH_ATTACHMENT
 #define GL_STENCIL_ATTACHMENT_EXT GL_STENCIL_ATTACHMENT
 #define GL_FRAMEBUFFER_COMPLETE_EXT GL_FRAMEBUFFER_COMPLETE
+#define glClearDepth glClearDepthf
 #define glBindFramebufferEXT glBindFramebuffer
 #define glFramebufferTexture2DEXT glFramebufferTexture2D
 #define glFramebufferRenderbufferEXT glFramebufferRenderbuffer
@@ -439,11 +440,7 @@ void Graphics::Clear(unsigned flags, const Color& color, float depth, unsigned s
     if (flags & CLEAR_DEPTH)
     {
         glFlags |= GL_DEPTH_BUFFER_BIT;
-        #ifndef GL_ES_VERSION_2_0
         glClearDepth(depth);
-        #else
-        glClearDepthf(depth);
-        #endif
     }
     if (flags & CLEAR_STENCIL)
     {
@@ -1329,33 +1326,6 @@ void Graphics::SetViewport(const IntRect& rect)
     SetScissorTest(false);
 }
 
-void Graphics::SetAlphaTest(bool enable, CompareMode mode, float alphaRef)
-{
-    if (enable != alphaTest_)
-    {
-        #ifndef GL_ES_VERSION_2_0
-        if (enable)
-            glEnable(GL_ALPHA_TEST);
-        else
-            glDisable(GL_ALPHA_TEST);
-        #endif
-        alphaTest_ = enable;
-    }
-
-    #ifndef GL_ES_VERSION_2_0
-    if (enable)
-    {
-        alphaRef = Clamp(alphaRef, 0.0f, 1.0f);
-        if (mode != alphaTestMode_ || alphaRef != alphaRef_)
-        {
-            glAlphaFunc(glCmpFunc[mode], alphaRef);
-            alphaTestMode_ = mode;
-            alphaRef_ = alphaRef;
-        }
-    }
-    #endif
-}
-
 void Graphics::SetBlendMode(BlendMode mode)
 {
     if (mode != blendMode_)

+ 0 - 14
Engine/Graphics/OpenGL/OGLGraphics.h

@@ -174,8 +174,6 @@ public:
     void SetViewTexture(Texture* texture);
     /// Set viewport.
     void SetViewport(const IntRect& rect);
-    /// Set alpha test.
-    void SetAlphaTest(bool enable, CompareMode mode = CMP_ALWAYS, float alphaRef = 0.5f);
     /// Set blending mode.
     void SetBlendMode(BlendMode mode);
     /// Set color write on/off.
@@ -281,14 +279,8 @@ public:
     Texture2D* GetDepthTexture() const { return 0; }
     /// Return the viewport coordinates.
     IntRect GetViewport() const { return viewport_; }
-    /// Return whether alpha testing is enabled.
-    bool GetAlphaTest() const { return alphaTest_; }
-    /// Return alpha test compare mode.
-    CompareMode GetAlphaTestMode() const { return alphaTestMode_; }
     /// Return texture anisotropy.
     unsigned GetTextureAnisotropy() const { return textureAnisotropy_; }
-    /// Return alpha test reference value.
-    float GetAlphaRef() const { return alphaRef_; }
     /// Return blending mode.
     BlendMode GetBlendMode() const { return blendMode_; }
     /// Return whether color write is enabled.
@@ -442,12 +434,6 @@ private:
     Texture* viewTexture_;
     /// Viewport coordinates.
     IntRect viewport_;
-    /// Alpha test enable flag.
-    bool alphaTest_;
-    /// Alpha test compare mode.
-    CompareMode alphaTestMode_;
-    /// Alpha test reference value.
-    float alphaRef_;
     /// Texture anisotropy level.
     unsigned textureAnisotropy_;
     /// Blending mode.

+ 0 - 1
Engine/Graphics/Renderer.cpp

@@ -648,7 +648,6 @@ void Renderer::Render()
     // If no views, just clear the screen
     if (!numViews_)
     {
-        graphics_->SetAlphaTest(false);
         graphics_->SetBlendMode(BLEND_REPLACE);
         graphics_->SetColorWrite(true);
         graphics_->SetDepthWrite(true);

+ 0 - 9
Engine/Graphics/Technique.cpp

@@ -73,7 +73,6 @@ static const String CompareModeNames[] =
 
 Pass::Pass(PassType type) :
     type_(type),
-    alphaTest_(false),
     blendMode_(BLEND_REPLACE),
     depthTestMode_(CMP_LESSEQUAL),
     depthWrite_(true)
@@ -84,11 +83,6 @@ Pass::~Pass()
 {
 }
 
-void Pass::SetAlphaTest(bool enable)
-{
-    alphaTest_ = enable;
-}
-
 void Pass::SetBlendMode(BlendMode mode)
 {
     blendMode_ = mode;
@@ -176,9 +170,6 @@ bool Technique::Load(Deserializer& source)
             if (passElem.HasAttribute("ps"))
                 newPass->SetPixelShader(passElem.GetAttribute("ps"));
             
-            if (passElem.HasAttribute("alphatest"))
-                newPass->SetAlphaTest(passElem.GetBool("alphatest"));
-            
             if (passElem.HasAttribute("blend"))
             {
                 String blend = passElem.GetAttributeLower("blend");

+ 0 - 6
Engine/Graphics/Technique.h

@@ -37,8 +37,6 @@ public:
     /// Destruct.
     ~Pass();
     
-    /// %Set alpha test on/off.
-    void SetAlphaTest(bool enable);
     /// %Set blend mode.
     void SetBlendMode(BlendMode mode);
     /// %Set depth compare mode.
@@ -54,8 +52,6 @@ public:
     
     /// Return pass type.
     PassType GetType() const { return type_; }
-    /// Return alpha test mode.
-    bool GetAlphaTest() const { return alphaTest_; }
     /// Return blend mode.
     BlendMode GetBlendMode() const { return blendMode_; }
     /// Return depth compare mode.
@@ -74,8 +70,6 @@ public:
 private:
     /// Pass type.
     PassType type_;
-    /// Alpha test mode.
-    bool alphaTest_;
     /// Blend mode.
     BlendMode blendMode_;
     /// Depth compare mode.

+ 0 - 5
Engine/Graphics/View.cpp

@@ -1210,7 +1210,6 @@ void View::RenderBatchesForward()
     graphics_->SetStencilTest(false);
     
     // At this point clear the parts of viewport not occupied by opaque geometry with fog color
-    graphics_->SetAlphaTest(false);
     graphics_->SetBlendMode(BLEND_REPLACE);
     graphics_->SetColorWrite(true);
     graphics_->SetDepthTest(CMP_LESSEQUAL);
@@ -1361,7 +1360,6 @@ void View::RenderBatchesDeferred()
     }
     
     // At this point clear the parts of viewport not occupied by opaque geometry with fog color
-    graphics_->SetAlphaTest(false);
     graphics_->SetBlendMode(BLEND_REPLACE);
     graphics_->SetColorWrite(true);
     graphics_->SetDepthTest(CMP_ALWAYS);
@@ -1439,7 +1437,6 @@ void View::BlitFramebuffer()
 {
     // Blit the final image to destination rendertarget
     /// \todo Depth is reset to far plane, so geometry drawn after the view can not be depth tested
-    graphics_->SetAlphaTest(false);
     graphics_->SetBlendMode(BLEND_REPLACE);
     graphics_->SetDepthTest(CMP_ALWAYS);
     graphics_->SetDepthWrite(true);
@@ -1478,7 +1475,6 @@ void View::RunPostProcesses()
     unsigned readRtIndex = 0;
     unsigned writeRtIndex = screenBuffers_.Size() - 1;
     
-    graphics_->SetAlphaTest(false);
     graphics_->SetBlendMode(BLEND_REPLACE);
     graphics_->SetDepthTest(CMP_ALWAYS);
     graphics_->SetScissorTest(false);
@@ -2420,7 +2416,6 @@ void View::SetupLightVolumeBatch(Batch& batch)
     float lightDist;
     
     // Use replace blend mode for the first pre-pass light volume, and additive for the rest
-    graphics_->SetAlphaTest(false);
     graphics_->SetBlendMode(renderMode_ == RENDER_PREPASS && light == lightQueues_.Front().light_ ? BLEND_REPLACE : BLEND_ADD);
     graphics_->SetDepthWrite(false);
     

+ 3 - 7
Engine/UI/UI.cpp

@@ -263,7 +263,6 @@ void UI::Render()
     projection.m33_ = 1.0f;
     
     graphics_->ClearParameterSources();
-    graphics_->SetAlphaTest(false);
     graphics_->SetCullMode(CULL_CCW);
     graphics_->SetDepthTest(CMP_ALWAYS);
     graphics_->SetDepthWrite(false);
@@ -294,6 +293,8 @@ void UI::Render()
             
             if (batch.texture_->GetFormat() == alphaFormat)
                 ps = alphaTexturePS_;
+            else if (batch.blendMode_ != BLEND_ALPHA && batch.blendMode_ != BLEND_ADDALPHA && batch.blendMode_ != BLEND_PREMULALPHA)
+                ps = diffMaskTexturePS_;
             else
                 ps = diffTexturePS_;
         }
@@ -306,12 +307,6 @@ void UI::Render()
         if (graphics_->NeedParameterUpdate(SP_MATERIAL, this))
             graphics_->SetShaderParameter(PSP_MATDIFFCOLOR, Color(1.0f, 1.0f, 1.0f, 1.0f));
         
-        // Use alpha test if not alpha blending
-        if (batch.blendMode_ != BLEND_ALPHA && batch.blendMode_ != BLEND_ADDALPHA && batch.blendMode_ != BLEND_PREMULALPHA)
-            graphics_->SetAlphaTest(true, CMP_GREATEREQUAL, 0.5f);
-        else
-            graphics_->SetAlphaTest(false);
-        
         graphics_->SetBlendMode(batch.blendMode_);
         graphics_->SetScissorTest(true, batch.scissor_);
         graphics_->SetTexture(0, batch.texture_);
@@ -454,6 +449,7 @@ void UI::Initialize()
         diffTextureVS_ = basicVS->GetVariation("DiffVCol");
         noTexturePS_ = basicPS->GetVariation("VCol");
         diffTexturePS_ = basicPS->GetVariation("DiffVCol");
+        diffMaskTexturePS_ = basicPS->GetVariation("DiffAlphaMaskVCol");
         alphaTexturePS_ = basicPS->GetVariation("AlphaVCol");
     }
     

+ 2 - 0
Engine/UI/UI.h

@@ -126,6 +126,8 @@ private:
     SharedPtr<ShaderVariation> noTexturePS_;
     /// Pixel shader for diffuse texture.
     SharedPtr<ShaderVariation> diffTexturePS_;
+    /// Pixel shader for diffuse texture masking.
+    SharedPtr<ShaderVariation> diffMaskTexturePS_;
     /// Pixel shader for alpha texture.
     SharedPtr<ShaderVariation> alphaTexturePS_;
     /// UI root element.

+ 6 - 1
SourceAssets/GLSLShaders/Basic.frag

@@ -20,7 +20,12 @@ void main()
         gl_FragColor = diffColor;
     #endif
     #ifdef DIFFMAP
-        gl_FragColor = diffColor * texture2D(sDiffMap, vTexCoord);
+        vec4 diffInput = texture2D(sDiffMap, vTexCoord);
+        #ifdef ALPHAMASK
+            if (diffInput.a < 0.5)
+                discard;
+        #endif
+        gl_FragColor = diffColor * diffInput;
     #endif
     #ifdef ALPHAMAP
         float alphaInput = texture2D(sDiffMap, vTexCoord).a;

+ 1 - 0
SourceAssets/GLSLShaders/Basic.xml

@@ -6,6 +6,7 @@
     <shader name="Basic" type="ps">
         <option name="Diff" define="DIFFMAP" exclude="Alpha" />
         <option name="Alpha" define="ALPHAMAP" exclude="Diff" />
+        <option name="AlphaMask" define="ALPHAMASK" require="DIFFMAP" />        
         <option name="VCol" define="VERTEXCOLOR" />
     </shader>
     <shader name="Skybox" />

+ 1 - 1
SourceAssets/GLSLShaders/Deferred.xml

@@ -17,7 +17,7 @@
         <option name="Diff" define="DIFFMAP" />
         <option name="Normal" define="NORMALMAP" require="DIFFMAP" />
         <option name="SpecMap" define="SPECMAP" require="DIFFMAP" />
-        <option name="Mask" define="ALPHAMASK" require="DIFFMAP" />
+        <option name="AlphaMask" define="ALPHAMASK" require="DIFFMAP" />
         <option name="HW" define="HWDEPTH" />
     </shader>
 </shaders>

+ 6 - 1
SourceAssets/GLSLShaders/ForwardLit.frag

@@ -33,7 +33,12 @@ varying vec4 vLightVec;
 void main()
 {
     #ifdef DIFFMAP
-        vec4 diffColor = cMatDiffColor * texture2D(sDiffMap, vTexCoord);
+        vec4 diffInput = texture2D(sDiffMap, vTexCoord);
+        #ifdef ALPHAMASK
+            if (diffInput.a < 0.5)
+                discard;
+        #endif
+        vec4 diffColor = cMatDiffColor * diffInput;
     #else
         vec4 diffColor = cMatDiffColor;
     #endif

+ 1 - 0
SourceAssets/GLSLShaders/ForwardLit.xml

@@ -15,6 +15,7 @@
         <option name="Diff" define="DIFFMAP" />
         <option name="Normal" define="NORMALMAP" require="DIFFMAP" />
         <option name="SpecMap" define="SPECMAP" require="DIFFMAP" />
+        <option name="AlphaMask" define="ALPHAMASK" require="DIFFMAP" />           
         <option name="VCol" define="VERTEXCOLOR" />
         <option name="Ambient" define="AMBIENT" />
         <variation name="Dir" define="DIRLIGHT" />

+ 6 - 1
SourceAssets/GLSLShaders/LitParticle.frag

@@ -18,7 +18,12 @@ varying vec4 vLightVec;
 void main()
 {
     #ifdef DIFFMAP
-        vec4 diffColor = cMatDiffColor * texture2D(sDiffMap, vTexCoord);
+        vec4 diffInput = texture2D(sDiffMap, vTexCoord);
+        #ifdef ALPHAMASK
+            if (diffInput.a < 0.5)
+                discard;
+        #endif
+        vec4 diffColor = cMatDiffColor * diffInput;
     #else
         vec4 diffColor = cMatDiffColor;
     #endif

+ 1 - 0
SourceAssets/GLSLShaders/LitParticle.xml

@@ -11,6 +11,7 @@
     </shader>
     <shader name="LitParticle" type="ps">
         <option name="Diff" define="DIFFMAP" />
+        <option name="AlphaMask" define="ALPHAMASK" require="DIFFMAP" />           
         <option name="VCol" define="VERTEXCOLOR" />
         <option name="Ambient" define="AMBIENT" />
         <variation name="Dir" define="DIRLIGHT" />

+ 1 - 1
SourceAssets/GLSLShaders/Material.xml

@@ -15,7 +15,7 @@
     <shader name="Material" type="ps">
         <option name="Diff" define="DIFFMAP" />
         <option name="SpecMap" define="SPECMAP" />
-        <option name="Mask" define="ALPHAMASK" include="Diff" />
+        <option name="AlphaMask" define="ALPHAMASK" require="DIFFMAP" />
         <option name="VCol" define="VERTEXCOLOR" /> 
     </shader>
 </shaders>

+ 1 - 1
SourceAssets/GLSLShaders/Prepass.xml

@@ -7,7 +7,7 @@
     </shader>
     <shader name="Prepass" type="ps">
         <option name="Normal" define="NORMALMAP" />
-        <option name="Mask" define="ALPHAMASK" />
+        <option name="AlphaMask" define="ALPHAMASK" />
         <option name="HW" define="HWDEPTH" />
     </shader>
 </shaders>

+ 3 - 3
SourceAssets/GLSLShaders/Shadow.frag

@@ -9,9 +9,9 @@ void main()
 {
     #ifdef ALPHAMASK
         float alpha = texture2D(sDiffMap, vTexCoord).a;
-    #else
-        const float alpha = 1.0;
+        if (alpha < 0.5)
+            discard;
     #endif
 
-    gl_FragColor = vec4(alpha);
+    gl_FragColor = vec4(1.0);
 }

+ 1 - 1
SourceAssets/GLSLShaders/Shadow.xml

@@ -5,6 +5,6 @@
         <variation name="Skinned" define="SKINNED" />
     </shader>
     <shader name="Shadow" type="ps">
-        <option name="Mask" define="ALPHAMASK" />
+        <option name="AlphaMask" define="ALPHAMASK" />
     </shader>
 </shaders>

+ 6 - 1
SourceAssets/HLSLShaders/Basic.hlsl

@@ -46,7 +46,12 @@ void PS(
         oColor = diffColor;
     #endif
     #ifdef DIFFMAP
-        oColor = diffColor * tex2D(sDiffMap, iTexCoord);
+        float4 diffInput = tex2D(sDiffMap, iTexCoord);
+        #ifdef ALPHAMASK
+            if (diffInput.a < 0.5)
+                discard;
+        #endif
+        oColor = diffColor * diffInput;
     #endif
     #ifdef ALPHAMAP
         float alphaInput = tex2D(sDiffMap, iTexCoord).a;

+ 1 - 0
SourceAssets/HLSLShaders/Basic.xml

@@ -6,6 +6,7 @@
     <shader name="Basic" type="ps">
         <option name="Diff" define="DIFFMAP" exclude="Alpha" />
         <option name="Alpha" define="ALPHAMAP" exclude="Diff" />
+        <option name="AlphaMask" define="ALPHAMASK" require="DIFFMAP" />
         <option name="VCol" define="VERTEXCOLOR" />
     </shader>
     <shader name="Skybox" />

+ 1 - 1
SourceAssets/HLSLShaders/Deferred.xml

@@ -19,7 +19,7 @@
         <option name="Diff" define="DIFFMAP" />
         <option name="Normal" define="NORMALMAP" require="DIFFMAP" />
         <option name="SpecMap" define="SPECMAP" require="DIFFMAP" />
-        <option name="Mask" define="ALPHAMASK" require="DIFFMAP" />
+        <option name="AlphaMask" define="ALPHAMASK" require="DIFFMAP" />
         <option name="VCol" define="VERTEXCOLOR" />
         <option name="HW" define="HWDEPTH" />
     </shader>

+ 6 - 1
SourceAssets/HLSLShaders/ForwardLit.hlsl

@@ -140,7 +140,12 @@ void PS(float2 iTexCoord : TEXCOORD0,
     out float4 oColor : COLOR0)
 {
     #ifdef DIFFMAP
-        float4 diffColor = cMatDiffColor * tex2D(sDiffMap, iTexCoord);
+        float4 diffInput = tex2D(sDiffMap, iTexCoord);
+        #ifdef ALPHAMASK
+            if (diffInput.a < 0.5)
+                discard;
+        #endif
+        float4 diffColor = cMatDiffColor * diffInput;
     #else
         float4 diffColor = cMatDiffColor;
     #endif

+ 1 - 0
SourceAssets/HLSLShaders/ForwardLit.xml

@@ -16,6 +16,7 @@
         <option name="Diff" define="DIFFMAP" />
         <option name="Normal" define="NORMALMAP" require="DIFFMAP" />
         <option name="SpecMap" define="SPECMAP" require="DIFFMAP" />
+        <option name="AlphaMask" define="ALPHAMASK" require="DIFFMAP" />        
         <option name="VCol" define="VERTEXCOLOR" />
         <option name="Ambient" define="AMBIENT" />
         <variation name="Dir" define="DIRLIGHT" />

+ 6 - 1
SourceAssets/HLSLShaders/LitParticle.hlsl

@@ -74,7 +74,12 @@ void PS(float2 iTexCoord : TEXCOORD0,
     out float4 oColor : COLOR0)
 {
     #ifdef DIFFMAP
-        float4 diffColor = cMatDiffColor * tex2D(sDiffMap, iTexCoord);
+        float4 diffInput = tex2D(sDiffMap, iTexCoord);
+        #ifdef ALPHAMASK
+            if (diffInput.a < 0.5)
+                discard;
+        #endif
+        float4 diffColor = cMatDiffColor * diffInput;
     #else
         float4 diffColor = cMatDiffColor;
     #endif

+ 1 - 0
SourceAssets/HLSLShaders/LitParticle.xml

@@ -12,6 +12,7 @@
     </shader>
     <shader name="LitParticle" type="ps">
         <option name="Diff" define="DIFFMAP" />
+        <option name="AlphaMask" define="ALPHAMASK" require="DIFFMAP" />        
         <option name="VCol" define="VERTEXCOLOR" />
         <option name="Ambient" define="AMBIENT" />
         <variation name="Dir" define="DIRLIGHT" />

+ 1 - 1
SourceAssets/HLSLShaders/Material.xml

@@ -16,7 +16,7 @@
     <shader name="Material" type="ps">
         <option name="Diff" define="DIFFMAP" />
         <option name="SpecMap" define="SPECMAP" />
-        <option name="Mask" define="ALPHAMASK" include="Diff" />
+        <option name="AlphaMask" define="ALPHAMASK" include="Diff" />
         <option name="VCol" define="VERTEXCOLOR" />
     </shader>
 </shaders>

+ 1 - 1
SourceAssets/HLSLShaders/Prepass.xml

@@ -8,7 +8,7 @@
     </shader>
     <shader name="Prepass" type="ps">
         <option name="Normal" define="NORMALMAP" />
-        <option name="Mask" define="ALPHAMASK" />
+        <option name="AlphaMask" define="ALPHAMASK" />
         <option name="HW" define="HWDEPTH" />
     </shader>
 </shaders>

+ 3 - 3
SourceAssets/HLSLShaders/Shadow.hlsl

@@ -33,9 +33,9 @@ void PS(
 {
     #ifdef ALPHAMASK
         float alpha = tex2D(sDiffMap, iTexCoord).a;
-    #else
-        const float alpha = 1.0;
+        if (alpha < 0.5)
+            discard;
     #endif
 
-    oColor = alpha;
+    oColor = 1.0;
 }

+ 1 - 1
SourceAssets/HLSLShaders/Shadow.xml

@@ -6,6 +6,6 @@
         <variation name="Instanced" define="INSTANCED" require="SM3" />
     </shader>
     <shader name="Shadow" type="ps">
-        <option name="Mask" define="ALPHAMASK" />
+        <option name="AlphaMask" define="ALPHAMASK" />
     </shader>
 </shaders>