From ff4b025c2c80b399ef124ccbcb4d44445e0d457f Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Sun, 1 Mar 2020 10:47:25 -0600 Subject: [PATCH 1/3] 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. --- Engine/source/lighting/shadowMap/shadowMapPass.cpp | 2 +- Engine/source/lighting/shadowMap/shadowMatHook.cpp | 2 ++ Engine/source/materials/baseMaterialDefinition.h | 1 + Engine/source/materials/materialDefinition.h | 3 ++- Engine/source/ts/tsMesh.cpp | 2 +- 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Engine/source/lighting/shadowMap/shadowMapPass.cpp b/Engine/source/lighting/shadowMap/shadowMapPass.cpp index 58fbf9828..74f026f70 100644 --- a/Engine/source/lighting/shadowMap/shadowMapPass.cpp +++ b/Engine/source/lighting/shadowMap/shadowMapPass.cpp @@ -260,7 +260,7 @@ void ShadowRenderPassManager::addInst( RenderInst *inst ) return; 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 // of calling up to Parent::addInst() diff --git a/Engine/source/lighting/shadowMap/shadowMatHook.cpp b/Engine/source/lighting/shadowMap/shadowMatHook.cpp index 11a82ec1e..93850ba97 100644 --- a/Engine/source/lighting/shadowMap/shadowMatHook.cpp +++ b/Engine/source/lighting/shadowMap/shadowMatHook.cpp @@ -190,6 +190,8 @@ void ShadowMaterialHook::_overrideFeatures( ProcessedMaterial *mat, fd.features.removeFeature( MFT_TexAnim ); fd.features.removeFeature( MFT_DiffuseMap ); } + else + fd.features.removeFeature(MFT_IsTranslucent); // HACK: Need to figure out how to enable these // suckers without this override call! diff --git a/Engine/source/materials/baseMaterialDefinition.h b/Engine/source/materials/baseMaterialDefinition.h index c1c033015..6fb40ae80 100644 --- a/Engine/source/materials/baseMaterialDefinition.h +++ b/Engine/source/materials/baseMaterialDefinition.h @@ -37,6 +37,7 @@ public: virtual bool isDoubleSided() const = 0; virtual bool isLightmapped() const = 0; virtual bool castsShadows() const = 0; + virtual bool isAlphatest() const = 0; }; #endif // _BASEMATERIALDEFINITION_H_ diff --git a/Engine/source/materials/materialDefinition.h b/Engine/source/materials/materialDefinition.h index 9a4c31b26..481176a4b 100644 --- a/Engine/source/materials/materialDefinition.h +++ b/Engine/source/materials/materialDefinition.h @@ -395,7 +395,8 @@ public: /// Allocates and returns a BaseMatInstance for this material. Caller is responsible /// for freeing the instance 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 isAutoGenerated() const { return mAutoGenerated; } virtual void setAutoGenerated(bool isAutoGenerated) { mAutoGenerated = isAutoGenerated; } diff --git a/Engine/source/ts/tsMesh.cpp b/Engine/source/ts/tsMesh.cpp index 9053a1184..5800e7e7c 100644 --- a/Engine/source/ts/tsMesh.cpp +++ b/Engine/source/ts/tsMesh.cpp @@ -280,7 +280,7 @@ void TSMesh::innerRender( TSMaterialList *materials, const TSRenderState &rdata, ri->primBuffIndex = mPrimBufferOffset + i; // 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->translucentSort = true; From f956c17f3be3e0ca4fbdfc00a64cd693720550dc Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Sun, 1 Mar 2020 11:51:50 -0600 Subject: [PATCH 2/3] for normal rendering, if we're translucent, don't use alphatesting. (as a remindernote, the shadowmathook removes MFT_IsTranslucent]) --- Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp | 5 +++-- Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp index 2ed6c5061..6b9ff016f 100644 --- a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp +++ b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp @@ -2496,9 +2496,10 @@ void AlphaTestGLSL::processPix( Vector &componentList, { // If we're below SM3 and don't have a depth output // feature then don't waste an instruction here. - if ( GFX->getPixelShaderVersion() < 3.0 && + if (( GFX->getPixelShaderVersion() < 3.0 && !fd.features[ MFT_EyeSpaceDepthOut ] && - !fd.features[ MFT_DepthOut ] ) + !fd.features[ MFT_DepthOut ] ) || + fd.features[MFT_IsTranslucent]) { output = NULL; return; diff --git a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp index 6ba1f6f10..3159c0ff8 100644 --- a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp +++ b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp @@ -2565,9 +2565,10 @@ void AlphaTestHLSL::processPix( Vector &componentList, { // If we're below SM3 and don't have a depth output // feature then don't waste an instruction here. - if ( GFX->getPixelShaderVersion() < 3.0 && + if (( GFX->getPixelShaderVersion() < 3.0 && !fd.features[ MFT_EyeSpaceDepthOut ] && - !fd.features[ MFT_DepthOut ] ) + !fd.features[ MFT_DepthOut ] ) || + fd.features[MFT_IsTranslucent]) { output = NULL; return; From a308261886eded32702300685442edc455b6e346 Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Tue, 10 Mar 2020 16:11:41 -0500 Subject: [PATCH 3/3] followup: convex shape translucent with alphatested shadow support --- Engine/source/T3D/convexShape.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Engine/source/T3D/convexShape.cpp b/Engine/source/T3D/convexShape.cpp index 2b6fa2448..12deb300d 100644 --- a/Engine/source/T3D/convexShape.cpp +++ b/Engine/source/T3D/convexShape.cpp @@ -704,7 +704,7 @@ void ConvexShape::prepRenderImage( SceneRenderState *state ) // Set our Material ri->matInst = matInst; - if (matInst->getMaterial()->isTranslucent()) + if (matInst->getMaterial()->isTranslucent() && (!(matInst->getMaterial()->isAlphatest() && state->isShadowPass()))) { ri->translucentSort = true; ri->type = RenderPassManager::RIT_Translucent;