Browse Source

adds alphatest shadows for translucent objects
leverage the fact shadergen spits out a modified material per pass, in this instance the shadow pass, to basically flip the translucent aspect off if you've got both translucency and alphatesting flipped on.

AzaezelX 5 years ago
parent
commit
ff4b025c2c

+ 1 - 1
Engine/source/lighting/shadowMap/shadowMapPass.cpp

@@ -260,7 +260,7 @@ void ShadowRenderPassManager::addInst( RenderInst *inst )
          return;
          return;
 
 
       const BaseMaterialDefinition *mat = meshRI->matInst->getMaterial();
       const BaseMaterialDefinition *mat = meshRI->matInst->getMaterial();
-      if ( !mat->castsShadows() || mat->isTranslucent() )
+      if ( !mat->castsShadows() || (mat->isTranslucent() && !mat->isAlphatest()))
       {
       {
          // Do not add this instance, return here and avoid the default behavior
          // Do not add this instance, return here and avoid the default behavior
          // of calling up to Parent::addInst()
          // of calling up to Parent::addInst()

+ 2 - 0
Engine/source/lighting/shadowMap/shadowMatHook.cpp

@@ -190,6 +190,8 @@ void ShadowMaterialHook::_overrideFeatures(  ProcessedMaterial *mat,
       fd.features.removeFeature( MFT_TexAnim );
       fd.features.removeFeature( MFT_TexAnim );
       fd.features.removeFeature( MFT_DiffuseMap );
       fd.features.removeFeature( MFT_DiffuseMap );
    }
    }
+   else
+      fd.features.removeFeature(MFT_IsTranslucent);
 
 
    // HACK: Need to figure out how to enable these 
    // HACK: Need to figure out how to enable these 
    // suckers without this override call!
    // suckers without this override call!

+ 1 - 0
Engine/source/materials/baseMaterialDefinition.h

@@ -37,6 +37,7 @@ public:
    virtual bool isDoubleSided() const = 0;
    virtual bool isDoubleSided() const = 0;
    virtual bool isLightmapped() const = 0;
    virtual bool isLightmapped() const = 0;
    virtual bool castsShadows() const = 0;
    virtual bool castsShadows() const = 0;
+   virtual bool isAlphatest() const = 0;
 };
 };
 
 
 #endif // _BASEMATERIALDEFINITION_H_
 #endif // _BASEMATERIALDEFINITION_H_

+ 2 - 1
Engine/source/materials/materialDefinition.h

@@ -395,7 +395,8 @@ public:
    /// Allocates and returns a BaseMatInstance for this material.  Caller is responsible
    /// Allocates and returns a BaseMatInstance for this material.  Caller is responsible
    /// for freeing the instance
    /// for freeing the instance
    virtual BaseMatInstance* createMatInstance();      
    virtual BaseMatInstance* createMatInstance();      
-   virtual bool isTranslucent() const { return mTranslucent && mTranslucentBlendOp != Material::None; }   
+   virtual bool isTranslucent() const { return mTranslucent && mTranslucentBlendOp != Material::None; }
+   virtual bool isAlphatest() const { return mAlphaTest; }
    virtual bool isDoubleSided() const { return mDoubleSided; }
    virtual bool isDoubleSided() const { return mDoubleSided; }
    virtual bool isAutoGenerated() const { return mAutoGenerated; }
    virtual bool isAutoGenerated() const { return mAutoGenerated; }
    virtual void setAutoGenerated(bool isAutoGenerated) { mAutoGenerated = isAutoGenerated; }
    virtual void setAutoGenerated(bool isAutoGenerated) { mAutoGenerated = isAutoGenerated; }

+ 1 - 1
Engine/source/ts/tsMesh.cpp

@@ -280,7 +280,7 @@ void TSMesh::innerRender( TSMaterialList *materials, const TSRenderState &rdata,
       ri->primBuffIndex = mPrimBufferOffset + i;
       ri->primBuffIndex = mPrimBufferOffset + i;
 
 
       // Translucent materials need the translucent type.
       // Translucent materials need the translucent type.
-      if ( matInst->getMaterial()->isTranslucent() )
+      if ( matInst->getMaterial()->isTranslucent() && (!(matInst->getMaterial()->isAlphatest() && state->isShadowPass())))
       {
       {
          ri->type = RenderPassManager::RIT_Translucent;
          ri->type = RenderPassManager::RIT_Translucent;
          ri->translucentSort = true;
          ri->translucentSort = true;