cleans up a few more spots of various variables that ammount to the "PBRConfig" in the end, as well as a MFT_isDeferred test for determining if that's stored off as a temp-val or in the gbuffer. though seem to have forgotten a catch, as it's not finding the MFT_PBRConfigMap feature and falling back to recreation come time to process MFT_ReflectionProbes

This commit is contained in:
AzaezelX 2019-10-23 14:59:29 -05:00
parent fe335128c1
commit 92efdb0d86
5 changed files with 96 additions and 63 deletions

View file

@ -35,22 +35,38 @@
//**************************************************************************** //****************************************************************************
// Deferred Shading Features // Deferred Shading Features
//**************************************************************************** //****************************************************************************
U32 PBRConfigMapHLSL::getOutputTargets(const MaterialFeatureData& fd) const
{
return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget2 : ShaderFeature::DefaultTarget;
}
void PBRConfigMapHLSL::processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd ) void PBRConfigMapHLSL::processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd )
{ {
// Get the texture coord. // Get the texture coord.
Var *texCoord = getInTexCoord( "texCoord", "float2", componentList ); Var *texCoord = getInTexCoord( "texCoord", "float2", componentList );
// search for color var MultiLine* meta = new MultiLine;
Var *material = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget2) ); Var* pbrConfig;
MultiLine * meta = new MultiLine; if (fd.features[MFT_isDeferred])
if ( !material )
{ {
// create color var pbrConfig = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget2));
material = new Var; if (!pbrConfig)
material->setType( "fragout" ); {
material->setName( getOutputTargetVarName(ShaderFeature::RenderTarget2) ); // create material var
material->setStructName( "OUT" ); pbrConfig = new Var;
pbrConfig->setType("fragout");
pbrConfig->setName(getOutputTargetVarName(ShaderFeature::RenderTarget2));
pbrConfig->setStructName("OUT");
}
}
else
{
pbrConfig = (Var*)LangElement::find("PBRConfig");
if (!pbrConfig)
{
pbrConfig = new Var("PBRConfig", "float4");
meta->addStatement(new GenOp(" @;\r\n", new DecOp(pbrConfig)));
}
} }
// create texture var // create texture var
@ -69,8 +85,6 @@ void PBRConfigMapHLSL::processPix( Vector<ShaderComponent*> &componentList, cons
pbrConfigMapTex->constNum = pbrConfigMap->constNum; pbrConfigMapTex->constNum = pbrConfigMap->constNum;
LangElement *texOp = new GenOp(" @.Sample(@, @)", pbrConfigMapTex, pbrConfigMap, texCoord); LangElement *texOp = new GenOp(" @.Sample(@, @)", pbrConfigMapTex, pbrConfigMap, texCoord);
Var * pbrConfig = (Var*)LangElement::find("PBRConfig");
if (!pbrConfig) pbrConfig = new Var("PBRConfig", "float4");
Var *metalness = (Var*)LangElement::find("metalness"); Var *metalness = (Var*)LangElement::find("metalness");
if (!metalness) metalness = new Var("metalness", "float"); if (!metalness) metalness = new Var("metalness", "float");
Var *smoothness = (Var*)LangElement::find("smoothness"); Var *smoothness = (Var*)LangElement::find("smoothness");
@ -82,8 +96,9 @@ void PBRConfigMapHLSL::processPix( Vector<ShaderComponent*> &componentList, cons
if (fd.features[MFT_InvertSmoothness]) if (fd.features[MFT_InvertSmoothness])
meta->addStatement(new GenOp(" @ = 1.0-@;\r\n", smoothness, smoothness)); meta->addStatement(new GenOp(" @ = 1.0-@;\r\n", smoothness, smoothness));
meta->addStatement(new GenOp(" @ = @.ggga;\r\n", new DecOp(pbrConfig), texOp)); if (!fd.features[MFT_isDeferred])
meta->addStatement(new GenOp(" @.bga = float3(@,@.g,@);\r\n", material, smoothness, pbrConfig, metalness)); meta->addStatement(new GenOp(" @ = @.ggga;\r\n", pbrConfig, texOp));
meta->addStatement(new GenOp(" @.bga = float3(@,@.g,@);\r\n", pbrConfig, smoothness, pbrConfig, metalness));
output = meta; output = meta;
} }
@ -126,14 +141,23 @@ void PBRConfigMapHLSL::processVert( Vector<ShaderComponent*> &componentList,
void DeferredMatInfoFlagsHLSL::processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd ) void DeferredMatInfoFlagsHLSL::processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd )
{ {
// search for material var // search for material var
Var *material = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget2) ); Var* pbrConfig;
if ( !material ) if (fd.features[MFT_isDeferred])
{ {
// create material var pbrConfig = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget2));
material = new Var; if (!pbrConfig)
material->setType( "fragout" ); {
material->setName( getOutputTargetVarName(ShaderFeature::RenderTarget2) ); // create material var
material->setStructName( "OUT" ); pbrConfig = new Var;
pbrConfig->setType("fragout");
pbrConfig->setName(getOutputTargetVarName(ShaderFeature::RenderTarget2));
pbrConfig->setStructName("OUT");
}
}
else
{
pbrConfig = (Var*)LangElement::find("PBRConfig");
if (!pbrConfig) pbrConfig = new Var("PBRConfig", "float4");
} }
Var *matInfoFlags = new Var; Var *matInfoFlags = new Var;
@ -142,24 +166,36 @@ void DeferredMatInfoFlagsHLSL::processPix( Vector<ShaderComponent*> &componentLi
matInfoFlags->uniform = true; matInfoFlags->uniform = true;
matInfoFlags->constSortPos = cspPotentialPrimitive; matInfoFlags->constSortPos = cspPotentialPrimitive;
output = new GenOp( " @.r = @;\r\n", material, matInfoFlags ); output = new GenOp( " @.r = @;\r\n", pbrConfig, matInfoFlags );
}
U32 PBRConfigVarsHLSL::getOutputTargets(const MaterialFeatureData& fd) const
{
return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget2 : ShaderFeature::DefaultTarget;
} }
// Spec Strength -> Blue Channel of Material Info Buffer.
// Spec Power -> Alpha Channel ( of Material Info Buffer.
void PBRConfigVarsHLSL::processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd ) void PBRConfigVarsHLSL::processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd )
{ {
// search for material var MultiLine* meta = new MultiLine;
Var *material = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget2) ); Var* pbrConfig;
if ( !material ) if (fd.features[MFT_isDeferred])
{ {
// create material var pbrConfig = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget2));
material = new Var; if (!pbrConfig)
material->setType( "fragout" ); {
material->setName( getOutputTargetVarName(ShaderFeature::RenderTarget2) ); // create material var
material->setStructName( "OUT" ); pbrConfig = new Var;
pbrConfig->setType("fragout");
pbrConfig->setName(getOutputTargetVarName(ShaderFeature::RenderTarget2));
pbrConfig->setStructName("OUT");
}
}
else
{
pbrConfig = (Var*)LangElement::find("PBRConfig");
if (!pbrConfig) pbrConfig = new Var("PBRConfig", "float4");
meta->addStatement(new GenOp(" @;\r\n", new DecOp(pbrConfig)));
} }
Var *metalness = new Var("metalness", "float"); Var *metalness = new Var("metalness", "float");
metalness->uniform = true; metalness->uniform = true;
metalness->constSortPos = cspPotentialPrimitive; metalness->constSortPos = cspPotentialPrimitive;
@ -168,13 +204,12 @@ void PBRConfigVarsHLSL::processPix( Vector<ShaderComponent*> &componentList, con
smoothness->uniform = true; smoothness->uniform = true;
smoothness->constSortPos = cspPotentialPrimitive; smoothness->constSortPos = cspPotentialPrimitive;
MultiLine * meta = new MultiLine;
//matinfo.g slot reserved for AO later //matinfo.g slot reserved for AO later
meta->addStatement(new GenOp(" @.g = 1.0;\r\n", material)); meta->addStatement(new GenOp(" @.g = 1.0;\r\n", pbrConfig));
meta->addStatement(new GenOp(" @.b = @;\r\n", material, smoothness)); meta->addStatement(new GenOp(" @.b = @;\r\n", pbrConfig, smoothness));
if (fd.features[MFT_InvertSmoothness]) if (fd.features[MFT_InvertSmoothness])
meta->addStatement(new GenOp(" @ = 1.0-@;\r\n", smoothness, smoothness)); meta->addStatement(new GenOp(" @ = 1.0-@;\r\n", smoothness, smoothness));
meta->addStatement(new GenOp(" @.a = @;\r\n", material, metalness)); meta->addStatement(new GenOp(" @.a = @;\r\n", pbrConfig, metalness));
output = meta; output = meta;
} }

View file

@ -31,6 +31,8 @@ class PBRConfigMapHLSL : public ShaderFeatureHLSL
public: public:
virtual String getName() { return "Deferred Shading: PBR Config Map"; } virtual String getName() { return "Deferred Shading: PBR Config Map"; }
virtual U32 getOutputTargets(const MaterialFeatureData& fd) const;
virtual void processPix( Vector<ShaderComponent*> &componentList, virtual void processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd ); const MaterialFeatureData &fd );
@ -62,10 +64,10 @@ class PBRConfigVarsHLSL : public ShaderFeatureHLSL
public: public:
virtual String getName() { return "Deferred Shading: PBR Config Explicit Numbers"; } virtual String getName() { return "Deferred Shading: PBR Config Explicit Numbers"; }
virtual U32 getOutputTargets(const MaterialFeatureData& fd) const;
virtual void processPix( Vector<ShaderComponent*> &componentList, virtual void processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd ); const MaterialFeatureData &fd );
virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const { return ShaderFeature::RenderTarget2; }
}; };
class DeferredEmissiveHLSL : public ShaderFeatureHLSL class DeferredEmissiveHLSL : public ShaderFeatureHLSL

View file

@ -439,7 +439,15 @@ void ProcessedShaderMaterial::_determineFeatures( U32 stageNum,
fd.features[ MFT_NormalMap ] ) fd.features[ MFT_NormalMap ] )
fd.features.addFeature( MFT_Parallax ); fd.features.addFeature( MFT_Parallax );
} }
// Deferred Shading : PBR Config
if (mStages[stageNum].getTex(MFT_PBRConfigMap))
{
fd.features.addFeature(MFT_PBRConfigMap);
}
else
fd.features.addFeature(MFT_PBRConfigVars);
if( fd.features[ MFT_PBRConfigMap ] ) if( fd.features[ MFT_PBRConfigMap ] )
{ {
// Check for an alpha channel on the PBR Config map. If it has one (and it // Check for an alpha channel on the PBR Config map. If it has one (and it

View file

@ -837,8 +837,8 @@ Var* ShaderFeatureGLSL::getSurface(Vector<ShaderComponent*>& componentList, Mult
Var* diffuseColor = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget)); Var* diffuseColor = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget));
Var* matinfo = (Var*)LangElement::find("PBRConfig"); Var* pbrConfig = (Var*)LangElement::find("PBRConfig");
if (!matinfo) if (!pbrConfig)
{ {
Var* metalness = (Var*)LangElement::find("metalness"); Var* metalness = (Var*)LangElement::find("metalness");
if (!metalness) if (!metalness)
@ -856,9 +856,9 @@ Var* ShaderFeatureGLSL::getSurface(Vector<ShaderComponent*>& componentList, Mult
smoothness->constSortPos = cspPotentialPrimitive; smoothness->constSortPos = cspPotentialPrimitive;
} }
matinfo = new Var("PBRConfig", "vec4"); pbrConfig = new Var("PBRConfig", "vec4");
LangElement* colorDecl = new DecOp(matinfo); LangElement* colorDecl = new DecOp(pbrConfig);
meta->addStatement(new GenOp(" @ = vec4(0.0,1.0,@,@);\r\n", colorDecl, smoothness, metalness)); //reconstruct matinfo, no ao darkening meta->addStatement(new GenOp(" @ = vec4(0.0,1.0,@,@);\r\n", colorDecl, smoothness, metalness)); //reconstruct pbrConfig, no ao darkening
} }
Var* wsNormal = (Var*)LangElement::find("wsNormal"); Var* wsNormal = (Var*)LangElement::find("wsNormal");
@ -895,7 +895,7 @@ Var* ShaderFeatureGLSL::getSurface(Vector<ShaderComponent*>& componentList, Mult
if (!surface) if (!surface)
{ {
surface = new Var("surface", "Surface"); surface = new Var("surface", "Surface");
meta->addStatement(new GenOp(" @ = createForwardSurface(@,@,@,@,@,@);\r\n\n", new DecOp(surface), diffuseColor, normal, matinfo, meta->addStatement(new GenOp(" @ = createForwardSurface(@,@,@,@,@,@);\r\n\n", new DecOp(surface), diffuseColor, normal, pbrConfig,
wsPosition, wsEyePos, wsView)); wsPosition, wsEyePos, wsView));
} }
@ -3046,13 +3046,7 @@ void ReflectionProbeFeatGLSL::processPix(Vector<ShaderComponent*>& componentList
} }
Var *curColor = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget)); Var *curColor = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget));
Var *matinfo = (Var*)LangElement::find("PBRConfig");
Var* metalness = (Var*)LangElement::find("metalness");
Var* smoothness = (Var*)LangElement::find("smoothness");
Var* wsEyePos = (Var*)LangElement::find("eyePosWorld");
//Reflection vec //Reflection vec
String computeForwardProbes = String(" @.rgb = computeForwardProbes(@,@,@,@,@,@,@,@,@,\r\n\t\t"); String computeForwardProbes = String(" @.rgb = computeForwardProbes(@,@,@,@,@,@,@,@,@,\r\n\t\t");
computeForwardProbes += String("@,@,\r\n\t\t"); computeForwardProbes += String("@,@,\r\n\t\t");

View file

@ -829,8 +829,8 @@ Var* ShaderFeatureHLSL::getSurface(Vector<ShaderComponent*>& componentList, Mult
Var* diffuseColor = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget)); Var* diffuseColor = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget));
Var* matinfo = (Var*)LangElement::find("PBRConfig"); Var* pbrConfig = (Var*)LangElement::find("PBRConfig");
if (!matinfo) if (!pbrConfig)
{ {
Var* metalness = (Var*)LangElement::find("metalness"); Var* metalness = (Var*)LangElement::find("metalness");
if (!metalness) if (!metalness)
@ -848,8 +848,8 @@ Var* ShaderFeatureHLSL::getSurface(Vector<ShaderComponent*>& componentList, Mult
smoothness->constSortPos = cspPotentialPrimitive; smoothness->constSortPos = cspPotentialPrimitive;
} }
matinfo = new Var("PBRConfig", "float4"); pbrConfig = new Var("PBRConfig", "float4");
LangElement* colorDecl = new DecOp(matinfo); LangElement* colorDecl = new DecOp(pbrConfig);
meta->addStatement(new GenOp(" @ = float4(0.0,1.0,@,@);\r\n", colorDecl, smoothness, metalness)); //reconstruct matinfo, no ao darkening meta->addStatement(new GenOp(" @ = float4(0.0,1.0,@,@);\r\n", colorDecl, smoothness, metalness)); //reconstruct matinfo, no ao darkening
} }
@ -879,7 +879,7 @@ Var* ShaderFeatureHLSL::getSurface(Vector<ShaderComponent*>& componentList, Mult
if (!surface) if (!surface)
{ {
surface = new Var("surface", "Surface"); surface = new Var("surface", "Surface");
meta->addStatement(new GenOp(" @ = createForwardSurface(@,@,@,@,@,@);\r\n\n", new DecOp(surface), diffuseColor, normal, matinfo, meta->addStatement(new GenOp(" @ = createForwardSurface(@,@,@,@,@,@);\r\n\n", new DecOp(surface), diffuseColor, normal, pbrConfig,
wsPosition, wsEyePos, wsView)); wsPosition, wsEyePos, wsView));
} }
@ -3106,12 +3106,6 @@ void ReflectionProbeFeatHLSL::processPix(Vector<ShaderComponent*> &componentList
Var *curColor = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget)); Var *curColor = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget));
Var *matinfo = (Var*)LangElement::find("PBRConfig");
Var* metalness = (Var*)LangElement::find("metalness");
Var* smoothness = (Var*)LangElement::find("smoothness");
Var* wsEyePos = (Var*)LangElement::find("eyePosWorld");
//Reflection vec //Reflection vec
String computeForwardProbes = String::String(" @.rgb = computeForwardProbes(@,@,@,@,@,@,@,@,@,\r\n\t\t"); String computeForwardProbes = String::String(" @.rgb = computeForwardProbes(@,@,@,@,@,@,@,@,@,\r\n\t\t");
computeForwardProbes += String::String("@,TORQUE_SAMPLER2D_MAKEARG(@),\r\n\t\t"); computeForwardProbes += String::String("@,TORQUE_SAMPLER2D_MAKEARG(@),\r\n\t\t");