From 01f562b9e524eb4ae247260973c54b3eb83eaa59 Mon Sep 17 00:00:00 2001 From: Areloch Date: Thu, 3 Oct 2019 23:46:53 -0500 Subject: [PATCH] Added check for when getting the Detail feature's output, to validate if we have the foliage feature, which was causing a stomp on the required float4 texCoord for the foliage featuer to work right Temporarily disabled wsNormal addition when we have no defined normal map until it's finished being integrated Fixed the structure for the lighting/probe shadergen logic in GL so it generates correctly, resolving a crash on unix machines. --- .../glsl/advancedLightingFeaturesGLSL.cpp | 4 +- .../hlsl/advancedLightingFeaturesHLSL.cpp | 4 +- Engine/source/shaderGen/GLSL/bumpGLSL.cpp | 4 +- .../shaderGen/GLSL/shaderFeatureGLSL.cpp | 47 +++++++++++++------ .../source/shaderGen/GLSL/shaderFeatureGLSL.h | 3 +- Engine/source/shaderGen/HLSL/bumpHLSL.cpp | 4 +- .../shaderGen/HLSL/shaderFeatureHLSL.cpp | 28 +++++++---- .../source/shaderGen/HLSL/shaderFeatureHLSL.h | 3 +- 8 files changed, 66 insertions(+), 31 deletions(-) diff --git a/Engine/source/lighting/advanced/glsl/advancedLightingFeaturesGLSL.cpp b/Engine/source/lighting/advanced/glsl/advancedLightingFeaturesGLSL.cpp index ae36fe6d1..c0c769645 100644 --- a/Engine/source/lighting/advanced/glsl/advancedLightingFeaturesGLSL.cpp +++ b/Engine/source/lighting/advanced/glsl/advancedLightingFeaturesGLSL.cpp @@ -237,10 +237,12 @@ void DeferredBumpFeatGLSL::processVert( Vector &componentLis componentList ); } + const bool useFoliageTexCoord = fd.features[MFT_Foliage]; + if ( fd.features.hasFeature( MFT_DetailNormalMap ) ) addOutDetailTexCoord( componentList, meta, - useTexAnim ); + useTexAnim, useFoliageTexCoord); output = meta; } diff --git a/Engine/source/lighting/advanced/hlsl/advancedLightingFeaturesHLSL.cpp b/Engine/source/lighting/advanced/hlsl/advancedLightingFeaturesHLSL.cpp index cd963f32f..9b495e0ff 100644 --- a/Engine/source/lighting/advanced/hlsl/advancedLightingFeaturesHLSL.cpp +++ b/Engine/source/lighting/advanced/hlsl/advancedLightingFeaturesHLSL.cpp @@ -245,10 +245,12 @@ void DeferredBumpFeatHLSL::processVert( Vector &componentLis componentList ); } + const bool useFoliageTexCoord = fd.features[MFT_Foliage]; + if ( fd.features.hasFeature( MFT_DetailNormalMap ) ) addOutDetailTexCoord( componentList, meta, - useTexAnim ); + useTexAnim, useFoliageTexCoord); output = meta; } diff --git a/Engine/source/shaderGen/GLSL/bumpGLSL.cpp b/Engine/source/shaderGen/GLSL/bumpGLSL.cpp index ec9d999ef..ab034bc2d 100644 --- a/Engine/source/shaderGen/GLSL/bumpGLSL.cpp +++ b/Engine/source/shaderGen/GLSL/bumpGLSL.cpp @@ -46,10 +46,12 @@ void BumpFeatGLSL::processVert( Vector &componentList, meta, componentList ); + const bool useFoliageTexCoord = fd.features[MFT_Foliage]; + if ( fd.features.hasFeature( MFT_DetailNormalMap ) ) addOutDetailTexCoord( componentList, meta, - useTexAnim ); + useTexAnim, useFoliageTexCoord); // Also output the worldToTanget transform which // we use to create the world space normal. diff --git a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp index c98487e91..09c3e6c1f 100644 --- a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp +++ b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp @@ -777,7 +777,8 @@ Var* ShaderFeatureGLSL::getWsView( Var *wsPosition, MultiLine *meta ) Var* ShaderFeatureGLSL::addOutDetailTexCoord( Vector &componentList, MultiLine *meta, - bool useTexAnim ) + bool useTexAnim, + bool useFoliageTexCoord) { // Check if its already added. Var *outTex = (Var*)LangElement::find( "detCoord" ); @@ -786,6 +787,9 @@ Var* ShaderFeatureGLSL::addOutDetailTexCoord( Vector &compon // Grab incoming texture coords. Var *inTex = getVertTexCoord( "texCoord" ); + + if(useFoliageTexCoord) + inTex->setType("float4"); // create detail variable Var *detScale = new Var; @@ -816,12 +820,12 @@ Var* ShaderFeatureGLSL::addOutDetailTexCoord( Vector &compon texMat->constSortPos = cspPass; } - meta->addStatement( new GenOp( " @ = tMul(@, @).xy * @;\r\n", outTex, texMat, inTex, detScale ) ); + meta->addStatement( new GenOp( " @ = tMul(@.xy, @).xy * @;\r\n", outTex, texMat, inTex, detScale ) ); } else { // setup output to mul texCoord by detail scale - meta->addStatement( new GenOp( " @ = @ * @;\r\n", outTex, inTex, detScale ) ); + meta->addStatement( new GenOp( " @ = @.xy * @;\r\n", outTex, inTex, detScale ) ); } return outTex; @@ -831,7 +835,7 @@ Var* ShaderFeatureGLSL::getSurface(Vector& componentList, Mult { ShaderConnector* connectComp = dynamic_cast(componentList[C_CONNECTOR]); - /*Var* diffuseColor = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget)); + Var* diffuseColor = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget)); Var* matinfo = (Var*)LangElement::find("PBRConfig"); if (!matinfo) @@ -875,6 +879,14 @@ Var* ShaderFeatureGLSL::getSurface(Vector& componentList, Mult } Var* wsEyePos = (Var*)LangElement::find("eyePosWorld"); + + if (!wsEyePos) + { + wsEyePos = new Var("eyePosWorld", "vec3"); + wsEyePos->uniform = true; + wsEyePos->constSortPos = cspPass; + } + Var* wsPosition = getInWsPosition(componentList); Var* wsView = getWsView(wsPosition, meta); @@ -885,13 +897,13 @@ Var* ShaderFeatureGLSL::getSurface(Vector& componentList, Mult surface = new Var("surface", "Surface"); meta->addStatement(new GenOp(" @ = createForwardSurface(@,@,@,@,@,@);\r\n\n", new DecOp(surface), diffuseColor, normal, matinfo, wsPosition, wsEyePos, wsView)); - }*/ + } - Var* surface = (Var*)LangElement::find("surface"); + /*Var* surface = (Var*)LangElement::find("surface"); if (!surface) { surface = new Var("surface", "float"); - } + }*/ return surface; } //**************************************************************************** @@ -1634,9 +1646,10 @@ void DetailFeatGLSL::processVert( Vector &componentList, const MaterialFeatureData &fd ) { MultiLine *meta = new MultiLine; + addOutDetailTexCoord( componentList, meta, - fd.features[MFT_TexAnim] ); + fd.features[MFT_TexAnim], fd.features[MFT_Foliage]); output = meta; } @@ -2067,8 +2080,9 @@ void RTLightingFeatGLSL::processVert( Vector &componentList, eyePos->uniform = true; eyePos->constSortPos = cspPass; } - - Var *inPosition = (Var*)LangElement::find( "position" ); + + //Temporarily disabled while we figure out how to better handle normals without a normal map + /*Var *inPosition = (Var*)LangElement::find( "position" ); Var *outNormal = connectComp->getElement( RT_TEXCOORD ); outNormal->setName( "wsNormal" ); @@ -2076,7 +2090,7 @@ void RTLightingFeatGLSL::processVert( Vector &componentList, outNormal->setType( "vec3" ); // Transform the normal to world space. - meta->addStatement( new GenOp( " @ = normalize( @ - @.xyz );\r\n", outNormal, eyePos, inPosition ) ); + meta->addStatement( new GenOp( " @ = normalize( @ - @.xyz );\r\n", outNormal, eyePos, inPosition ) );*/ } addOutWsPosition( componentList, fd.features[MFT_UseInstancing], meta ); @@ -2099,7 +2113,8 @@ void RTLightingFeatGLSL::processVert( Vector &componentList, // If there isn't a normal map then we need to pass // the world space normal to the pixel shader ourselves. - if ( !fd.features[MFT_NormalMap] ) + //Temporarily disabled while we figure out how to better handle normals without a normal map + /*if ( !fd.features[MFT_NormalMap] ) { Var *outNormal = connectComp->getElement( RT_TEXCOORD ); outNormal->setName( "wsNormal" ); @@ -2111,9 +2126,11 @@ void RTLightingFeatGLSL::processVert( Vector &componentList, // Transform the normal to world space. meta->addStatement( new GenOp( " @ = tMul( @, vec4( normalize( @ ), 0.0 ) ).xyz;\r\n", outNormal, objTrans, inNormal ) ); - } + }*/ addOutWsPosition( componentList, fd.features[MFT_UseInstancing], meta ); + + getOutWorldToTangent(componentList, meta, fd); output = meta; } @@ -2127,7 +2144,7 @@ void RTLightingFeatGLSL::processPix( Vector &componentList, // TODO: We can totally detect for this in the material // feature setup... we should move it out of here! // - //if ( fd.features[MFT_LightMap] || fd.features[MFT_ToneMap] || fd.features[MFT_VertLit] ) + if ( fd.features[MFT_LightMap] || fd.features[MFT_ToneMap] || fd.features[MFT_VertLit] ) return; ShaderConnector *connectComp = dynamic_cast( componentList[C_CONNECTOR] ); @@ -2946,7 +2963,7 @@ void ReflectionProbeFeatGLSL::processPix(Vector& componentList // TODO: We can totally detect for this in the material // feature setup... we should move it out of here! // - //if (fd.features[MFT_LightMap] || fd.features[MFT_ToneMap] || fd.features[MFT_VertLit]) + if (fd.features[MFT_LightMap] || fd.features[MFT_ToneMap] || fd.features[MFT_VertLit]) return; ShaderConnector * connectComp = dynamic_cast(componentList[C_CONNECTOR]); diff --git a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.h b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.h index 96b7be731..24a2a8115 100644 --- a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.h +++ b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.h @@ -113,7 +113,8 @@ public: /// Var* addOutDetailTexCoord( Vector &componentList, MultiLine *meta, - bool useTexAnim ); + bool useTexAnim, + bool useFoliageTexCoord); /// Var* getObjTrans( Vector &componentList, diff --git a/Engine/source/shaderGen/HLSL/bumpHLSL.cpp b/Engine/source/shaderGen/HLSL/bumpHLSL.cpp index 17769b412..b495da61e 100644 --- a/Engine/source/shaderGen/HLSL/bumpHLSL.cpp +++ b/Engine/source/shaderGen/HLSL/bumpHLSL.cpp @@ -46,10 +46,12 @@ void BumpFeatHLSL::processVert( Vector &componentList, meta, componentList ); + const bool useFoliageTexCoord = fd.features[MFT_Foliage]; + if ( fd.features.hasFeature( MFT_DetailNormalMap ) ) addOutDetailTexCoord( componentList, meta, - useTexAnim ); + useTexAnim, useFoliageTexCoord); // Also output the worldToTanget transform which // we use to create the world space normal. diff --git a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp index 382f1f669..070096097 100644 --- a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp +++ b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp @@ -769,7 +769,8 @@ Var* ShaderFeatureHLSL::getWsView( Var *wsPosition, MultiLine *meta ) Var* ShaderFeatureHLSL::addOutDetailTexCoord( Vector &componentList, MultiLine *meta, - bool useTexAnim ) + bool useTexAnim, + bool useFoliageTexCoord) { // Check if its already added. Var *outTex = (Var*)LangElement::find( "detCoord" ); @@ -778,7 +779,11 @@ Var* ShaderFeatureHLSL::addOutDetailTexCoord( Vector &compon // Grab incoming texture coords. Var *inTex = getVertTexCoord( "texCoord" ); - inTex->setType("float2"); + + if (useFoliageTexCoord) + inTex->setType("float4"); + else + inTex->setType("float2"); // create detail variable Var *detScale = new Var; @@ -807,12 +812,12 @@ Var* ShaderFeatureHLSL::addOutDetailTexCoord( Vector &compon texMat->constSortPos = cspPass; } - meta->addStatement(new GenOp(" @ = mul(@, float4(@,1,1)).xy * @;\r\n", outTex, texMat, inTex, detScale)); + meta->addStatement(new GenOp(" @ = mul(@, float4(@.xy,1,1)).xy * @;\r\n", outTex, texMat, inTex, detScale)); } else { // setup output to mul texCoord by detail scale - meta->addStatement( new GenOp( " @ = @ * @;\r\n", outTex, inTex, detScale ) ); + meta->addStatement( new GenOp( " @ = @.xy * @;\r\n", outTex, inTex, detScale ) ); } return outTex; @@ -1652,7 +1657,7 @@ void DetailFeatHLSL::processVert( Vector &componentList, MultiLine *meta = new MultiLine; addOutDetailTexCoord( componentList, meta, - fd.features[MFT_TexAnim] ); + fd.features[MFT_TexAnim], fd.features[MFT_Foliage] ); output = meta; } @@ -2119,6 +2124,7 @@ void RTLightingFeatHLSL::processVert( Vector &componentList, // have a normal map. Generate and pass the normal data the pixel shader needs. if ( fd.features[MFT_ImposterVert] ) { + if ( !fd.features[MFT_NormalMap] ) { Var *eyePos = (Var*)LangElement::find( "eyePosWorld" ); @@ -2128,8 +2134,9 @@ void RTLightingFeatHLSL::processVert( Vector &componentList, eyePos->uniform = true; eyePos->constSortPos = cspPass; } - - Var *inPosition = (Var*)LangElement::find( "position" ); + + //Temporarily disabled while we figure out how to better handle normals without a normal map + /*Var *inPosition = (Var*)LangElement::find( "position" ); Var *outNormal = connectComp->getElement( RT_TEXCOORD ); outNormal->setName( "wsNormal" ); @@ -2137,7 +2144,7 @@ void RTLightingFeatHLSL::processVert( Vector &componentList, outNormal->setType( "float3" ); // Transform the normal to world space. - meta->addStatement( new GenOp( " @ = normalize( @ - @.xyz );\r\n", outNormal, eyePos, inPosition ) ); + meta->addStatement( new GenOp( " @ = normalize( @ - @.xyz );\r\n", outNormal, eyePos, inPosition ) );*/ } addOutWsPosition( componentList, fd.features[MFT_UseInstancing], meta ); @@ -2160,7 +2167,8 @@ void RTLightingFeatHLSL::processVert( Vector &componentList, // If there isn't a normal map then we need to pass // the world space normal to the pixel shader ourselves. - if ( !fd.features[MFT_NormalMap] ) + //Temporarily disabled while we figure out how to better handle normals without a normal map + /* if ( !fd.features[MFT_NormalMap] ) { Var *outNormal = connectComp->getElement( RT_TEXCOORD ); outNormal->setName( "wsNormal" ); @@ -2172,7 +2180,7 @@ void RTLightingFeatHLSL::processVert( Vector &componentList, // Transform the normal to world space. meta->addStatement( new GenOp( " @ = mul( @, float4( normalize( @ ), 0.0 ) ).xyz;\r\n", outNormal, objTrans, inNormal ) ); - } + }*/ addOutWsPosition( componentList, fd.features[MFT_UseInstancing], meta ); diff --git a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.h b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.h index 0c8f7806b..a2c765ffb 100644 --- a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.h +++ b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.h @@ -113,7 +113,8 @@ public: /// Var* addOutDetailTexCoord( Vector &componentList, MultiLine *meta, - bool useTexAnim ); + bool useTexAnim, + bool useFoliageTexCoord); /// Var* getObjTrans( Vector &componentList,