From 454192ed02d9d0e4d8b82d2af1467479664882fd Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Tue, 14 Jul 2020 14:08:12 -0500 Subject: [PATCH] from @rextimmy new isbackground shader feature. used the same z=w trick we've done before to force things to render behind everything else. applied to fog --- Engine/source/environment/skyBox.cpp | 5 ++++- Engine/source/materials/materialFeatureTypes.cpp | 3 ++- Engine/source/materials/materialFeatureTypes.h | 1 + Engine/source/materials/processedShaderMaterial.cpp | 4 ++++ Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp | 2 +- Engine/source/shaderGen/GLSL/shaderGenGLSLInit.cpp | 1 + Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp | 2 +- Engine/source/shaderGen/HLSL/shaderGenHLSLInit.cpp | 1 + 8 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Engine/source/environment/skyBox.cpp b/Engine/source/environment/skyBox.cpp index 23ceaf722..492265d20 100644 --- a/Engine/source/environment/skyBox.cpp +++ b/Engine/source/environment/skyBox.cpp @@ -575,8 +575,10 @@ void SkyBox::_initRender() mFogBandMat->mDoubleSided = true; mFogBandMat->mEmissive[0] = true; + FeatureSet features = MATMGR->getDefaultFeatures(); + features.addFeature(MFT_isBackground); mFogBandMatInst = mFogBandMat->createMatInstance(); - mFogBandMatInst->init( MATMGR->getDefaultFeatures(), getGFXVertexFormat() ); + mFogBandMatInst->init(features, getGFXVertexFormat() ); } void SkyBox::onStaticModified( const char *slotName, const char *newValue ) @@ -609,6 +611,7 @@ void SkyBox::_initMaterial() FeatureSet features = MATMGR->getDefaultFeatures(); features.removeFeature( MFT_RTLighting ); features.removeFeature( MFT_Visibility ); + features.addFeature(MFT_isBackground); features.addFeature(MFT_SkyBox); // Now initialize the material. diff --git a/Engine/source/materials/materialFeatureTypes.cpp b/Engine/source/materials/materialFeatureTypes.cpp index 574e388cf..9abee92b5 100644 --- a/Engine/source/materials/materialFeatureTypes.cpp +++ b/Engine/source/materials/materialFeatureTypes.cpp @@ -105,6 +105,7 @@ ImplementFeatureType( MFT_ImposterVert, MFG_PreTransform, 1.0, false ); // Deferred Shading ImplementFeatureType( MFT_isDeferred, U32(-1), -1, true ); -ImplementFeatureType( MFT_SkyBox, MFG_Transform, 1.0f, false ); +ImplementFeatureType( MFT_isBackground, MFG_Transform, 1.0f, false ); +ImplementFeatureType( MFT_SkyBox, MFG_Transform, 2.0f, false ); ImplementFeatureType( MFT_HardwareSkinning, MFG_Transform,-2.0, false ); diff --git a/Engine/source/materials/materialFeatureTypes.h b/Engine/source/materials/materialFeatureTypes.h index fb3d360b8..6ab6ba418 100644 --- a/Engine/source/materials/materialFeatureTypes.h +++ b/Engine/source/materials/materialFeatureTypes.h @@ -192,6 +192,7 @@ DeclareFeatureType( MFT_HardwareSkinning ); // Deferred Shading DeclareFeatureType( MFT_isDeferred ); +DeclareFeatureType( MFT_isBackground ); DeclareFeatureType( MFT_SkyBox ); DeclareFeatureType( MFT_MatInfoFlags ); #endif // _MATERIALFEATURETYPES_H_ diff --git a/Engine/source/materials/processedShaderMaterial.cpp b/Engine/source/materials/processedShaderMaterial.cpp index 76338b23f..5a89d27c3 100644 --- a/Engine/source/materials/processedShaderMaterial.cpp +++ b/Engine/source/materials/processedShaderMaterial.cpp @@ -452,6 +452,10 @@ void ProcessedShaderMaterial::_determineFeatures( U32 stageNum, // Deferred Shading : Material Info Flags fd.features.addFeature(MFT_MatInfoFlags); + if (features.hasFeature(MFT_isBackground)) + { + fd.features.addFeature(MFT_isBackground); + } if (features.hasFeature(MFT_SkyBox)) { fd.features.addFeature(MFT_StaticCubemap); diff --git a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp index 23c3fe8a9..62874f22d 100644 --- a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp +++ b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp @@ -1743,7 +1743,7 @@ void VertPositionGLSL::processVert( Vector &componentList, meta->addStatement( new GenOp( " @ = tMul(@, vec4(@.xyz,1));\r\n", outPosition, modelview, inPosition ) ); - if (fd.materialFeatures[MFT_SkyBox]) + if (fd.materialFeatures[MFT_isBackground]) { meta->addStatement(new GenOp(" @ = @.xyww;\r\n", outPosition, outPosition)); } diff --git a/Engine/source/shaderGen/GLSL/shaderGenGLSLInit.cpp b/Engine/source/shaderGen/GLSL/shaderGenGLSLInit.cpp index 8630a6918..e1f684280 100644 --- a/Engine/source/shaderGen/GLSL/shaderGenGLSLInit.cpp +++ b/Engine/source/shaderGen/GLSL/shaderGenGLSLInit.cpp @@ -103,6 +103,7 @@ void _initShaderGenGLSL( ShaderGen *shaderGen ) FEATUREMGR->registerFeature( MFT_PBRConfigVars, new PBRConfigVarsGLSL ); FEATUREMGR->registerFeature( MFT_MatInfoFlags, new MatInfoFlagsGLSL ); FEATUREMGR->registerFeature( MFT_GlowMap, new GlowMapGLSL); + FEATUREMGR->registerFeature( MFT_isBackground, new NamedFeatureGLSL("Background Object")); FEATUREMGR->registerFeature( MFT_SkyBox, new NamedFeatureGLSL( "skybox" ) ); FEATUREMGR->registerFeature( MFT_HardwareSkinning, new HardwareSkinningFeatureGLSL ); } diff --git a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp index ef16f6492..4ebd53024 100644 --- a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp +++ b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp @@ -1781,7 +1781,7 @@ void VertPositionHLSL::processVert( Vector &componentList, meta->addStatement( new GenOp( " @ = mul(@, float4(@.xyz,1));\r\n", outPosition, modelview, inPosition ) ); - if (fd.materialFeatures[MFT_SkyBox]) + if (fd.materialFeatures[MFT_isBackground]) { meta->addStatement(new GenOp(" @ = @.xyww;\r\n", outPosition, outPosition)); } diff --git a/Engine/source/shaderGen/HLSL/shaderGenHLSLInit.cpp b/Engine/source/shaderGen/HLSL/shaderGenHLSLInit.cpp index 8afc512ab..8d7856498 100644 --- a/Engine/source/shaderGen/HLSL/shaderGenHLSLInit.cpp +++ b/Engine/source/shaderGen/HLSL/shaderGenHLSLInit.cpp @@ -108,6 +108,7 @@ void _initShaderGenHLSL( ShaderGen *shaderGen ) FEATUREMGR->registerFeature( MFT_PBRConfigVars, new PBRConfigVarsHLSL); FEATUREMGR->registerFeature( MFT_MatInfoFlags, new MatInfoFlagsHLSL ); FEATUREMGR->registerFeature( MFT_GlowMap, new GlowMapHLSL); + FEATUREMGR->registerFeature( MFT_isBackground, new NamedFeatureHLSL("Background Object")); FEATUREMGR->registerFeature( MFT_SkyBox, new NamedFeatureHLSL( "skybox" ) ); FEATUREMGR->registerFeature( MFT_HardwareSkinning, new HardwareSkinningFeatureHLSL ); }