|
@@ -35,61 +35,79 @@
|
|
|
//****************************************************************************
|
|
|
// Deferred Shading Features
|
|
|
//****************************************************************************
|
|
|
+U32 PBRConfigMapHLSL::getOutputTargets(const MaterialFeatureData& fd) const
|
|
|
+{
|
|
|
+ return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget2 : ShaderFeature::DefaultTarget;
|
|
|
+}
|
|
|
|
|
|
-// Specular Map -> Blue of Material Buffer ( greyscaled )
|
|
|
-// Gloss Map (Alpha Channel of Specular Map) -> Alpha ( Spec Power ) of Material Info Buffer.
|
|
|
-void DeferredSpecMapHLSL::processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd )
|
|
|
+void PBRConfigMapHLSL::processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd )
|
|
|
{
|
|
|
// Get the texture coord.
|
|
|
Var *texCoord = getInTexCoord( "texCoord", "float2", componentList );
|
|
|
|
|
|
- // search for color var
|
|
|
- Var *material = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget2) );
|
|
|
- MultiLine * meta = new MultiLine;
|
|
|
- if ( !material )
|
|
|
+ MultiLine* meta = new MultiLine;
|
|
|
+ Var* pbrConfig;
|
|
|
+ if (fd.features[MFT_isDeferred])
|
|
|
+ {
|
|
|
+ pbrConfig = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget2));
|
|
|
+ if (!pbrConfig)
|
|
|
+ {
|
|
|
+ // create material var
|
|
|
+ pbrConfig = new Var;
|
|
|
+ pbrConfig->setType("fragout");
|
|
|
+ pbrConfig->setName(getOutputTargetVarName(ShaderFeature::RenderTarget2));
|
|
|
+ pbrConfig->setStructName("OUT");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- // create color var
|
|
|
- material = new Var;
|
|
|
- material->setType( "fragout" );
|
|
|
- material->setName( getOutputTargetVarName(ShaderFeature::RenderTarget2) );
|
|
|
- material->setStructName( "OUT" );
|
|
|
+ pbrConfig = (Var*)LangElement::find("PBRConfig");
|
|
|
+ if (!pbrConfig)
|
|
|
+ {
|
|
|
+ pbrConfig = new Var("PBRConfig", "float4");
|
|
|
+ meta->addStatement(new GenOp(" @;\r\n", new DecOp(pbrConfig)));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// create texture var
|
|
|
- Var *specularMap = new Var;
|
|
|
- specularMap->setType( "SamplerState" );
|
|
|
- specularMap->setName( "specularMap" );
|
|
|
- specularMap->uniform = true;
|
|
|
- specularMap->sampler = true;
|
|
|
- specularMap->constNum = Var::getTexUnitNum();
|
|
|
-
|
|
|
- Var* specularMapTex = new Var;
|
|
|
- specularMapTex->setName("specularMapTex");
|
|
|
- specularMapTex->setType("Texture2D");
|
|
|
- specularMapTex->uniform = true;
|
|
|
- specularMapTex->texture = true;
|
|
|
- specularMapTex->constNum = specularMap->constNum;
|
|
|
- LangElement *texOp = new GenOp(" @.Sample(@, @)", specularMapTex, specularMap, texCoord);
|
|
|
+ Var * pbrConfigMap = new Var;
|
|
|
+ pbrConfigMap->setType( "SamplerState" );
|
|
|
+ pbrConfigMap->setName( "PBRConfigMap" );
|
|
|
+ pbrConfigMap->uniform = true;
|
|
|
+ pbrConfigMap->sampler = true;
|
|
|
+ pbrConfigMap->constNum = Var::getTexUnitNum();
|
|
|
+
|
|
|
+ Var* pbrConfigMapTex = new Var;
|
|
|
+ pbrConfigMapTex->setName("PBRConfigMapTex");
|
|
|
+ pbrConfigMapTex->setType("Texture2D");
|
|
|
+ pbrConfigMapTex->uniform = true;
|
|
|
+ pbrConfigMapTex->texture = true;
|
|
|
+ pbrConfigMapTex->constNum = pbrConfigMap->constNum;
|
|
|
+ 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");
|
|
|
if (!metalness) metalness = new Var("metalness", "float");
|
|
|
Var *smoothness = (Var*)LangElement::find("smoothness");
|
|
|
if (!smoothness) smoothness = new Var("smoothness", "float");
|
|
|
+ Var* ao = (Var*)LangElement::find("ao");
|
|
|
+ if (!ao) ao = new Var("ao", "float");
|
|
|
+
|
|
|
|
|
|
- meta->addStatement(new GenOp(" @ = @.r;\r\n", new DecOp(smoothness), texOp));
|
|
|
- meta->addStatement(new GenOp(" @ = @.b;\r\n", new DecOp(metalness), texOp));
|
|
|
+ meta->addStatement(new GenOp(" @.bga = @.rgb;\r\n", pbrConfig, texOp));
|
|
|
|
|
|
+ meta->addStatement(new GenOp(" @ = @.b;\r\n", new DecOp(smoothness), pbrConfig));
|
|
|
if (fd.features[MFT_InvertSmoothness])
|
|
|
+ {
|
|
|
+ meta->addStatement(new GenOp(" @.b = [email protected];\r\n", pbrConfig, pbrConfig));
|
|
|
meta->addStatement(new GenOp(" @ = 1.0-@;\r\n", smoothness, smoothness));
|
|
|
+ }
|
|
|
+ meta->addStatement(new GenOp(" @ = @.g;\r\n", new DecOp(ao), pbrConfig));
|
|
|
+ meta->addStatement(new GenOp(" @ = @.a;\r\n", new DecOp(metalness), pbrConfig));
|
|
|
|
|
|
- meta->addStatement(new GenOp(" @ = @.ggga;\r\n", new DecOp(pbrConfig), texOp));
|
|
|
- meta->addStatement(new GenOp(" @.bga = float3(@,@.g,@);\r\n", material, smoothness, pbrConfig, metalness));
|
|
|
output = meta;
|
|
|
}
|
|
|
|
|
|
-ShaderFeature::Resources DeferredSpecMapHLSL::getResources( const MaterialFeatureData &fd )
|
|
|
+ShaderFeature::Resources PBRConfigMapHLSL::getResources( const MaterialFeatureData &fd )
|
|
|
{
|
|
|
Resources res;
|
|
|
res.numTex = 1;
|
|
@@ -98,21 +116,21 @@ ShaderFeature::Resources DeferredSpecMapHLSL::getResources( const MaterialFeatur
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
-void DeferredSpecMapHLSL::setTexData( Material::StageData &stageDat,
|
|
|
+void PBRConfigMapHLSL::setTexData( Material::StageData &stageDat,
|
|
|
const MaterialFeatureData &fd,
|
|
|
RenderPassData &passData,
|
|
|
U32 &texIndex )
|
|
|
{
|
|
|
- GFXTextureObject *tex = stageDat.getTex( MFT_SpecularMap );
|
|
|
+ GFXTextureObject *tex = stageDat.getTex(MFT_PBRConfigMap);
|
|
|
if ( tex )
|
|
|
{
|
|
|
passData.mTexType[ texIndex ] = Material::Standard;
|
|
|
- passData.mSamplerNames[ texIndex ] = "specularMap";
|
|
|
+ passData.mSamplerNames[ texIndex ] = "PBRConfigMap";
|
|
|
passData.mTexSlot[ texIndex++ ].texObject = tex;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void DeferredSpecMapHLSL::processVert( Vector<ShaderComponent*> &componentList,
|
|
|
+void PBRConfigMapHLSL::processVert( Vector<ShaderComponent*> &componentList,
|
|
|
const MaterialFeatureData &fd )
|
|
|
{
|
|
|
MultiLine *meta = new MultiLine;
|
|
@@ -124,18 +142,32 @@ void DeferredSpecMapHLSL::processVert( Vector<ShaderComponent*> &componentList,
|
|
|
output = meta;
|
|
|
}
|
|
|
|
|
|
+U32 MatInfoFlagsHLSL::getOutputTargets(const MaterialFeatureData& fd) const
|
|
|
+{
|
|
|
+ return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget2 : ShaderFeature::DefaultTarget;
|
|
|
+}
|
|
|
+
|
|
|
// Material Info Flags -> Red ( Flags ) of Material Info Buffer.
|
|
|
-void DeferredMatInfoFlagsHLSL::processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd )
|
|
|
+void MatInfoFlagsHLSL::processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd )
|
|
|
{
|
|
|
// search for material var
|
|
|
- Var *material = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget2) );
|
|
|
- if ( !material )
|
|
|
+ Var* pbrConfig;
|
|
|
+ if (fd.features[MFT_isDeferred])
|
|
|
{
|
|
|
- // create material var
|
|
|
- material = new Var;
|
|
|
- material->setType( "fragout" );
|
|
|
- material->setName( getOutputTargetVarName(ShaderFeature::RenderTarget2) );
|
|
|
- material->setStructName( "OUT" );
|
|
|
+ pbrConfig = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget2));
|
|
|
+ if (!pbrConfig)
|
|
|
+ {
|
|
|
+ // create material var
|
|
|
+ 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;
|
|
@@ -144,24 +176,36 @@ void DeferredMatInfoFlagsHLSL::processPix( Vector<ShaderComponent*> &componentLi
|
|
|
matInfoFlags->uniform = true;
|
|
|
matInfoFlags->constSortPos = cspPotentialPrimitive;
|
|
|
|
|
|
- output = new GenOp( " @.r = @;\r\n", material, matInfoFlags );
|
|
|
+ output = new GenOp( " @.r = @;\r\n", pbrConfig, matInfoFlags );
|
|
|
}
|
|
|
|
|
|
-// Spec Strength -> Blue Channel of Material Info Buffer.
|
|
|
-// Spec Power -> Alpha Channel ( of Material Info Buffer.
|
|
|
-void DeferredSpecVarsHLSL::processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd )
|
|
|
+U32 PBRConfigVarsHLSL::getOutputTargets(const MaterialFeatureData& fd) const
|
|
|
{
|
|
|
- // search for material var
|
|
|
- Var *material = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget2) );
|
|
|
- if ( !material )
|
|
|
+ return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget2 : ShaderFeature::DefaultTarget;
|
|
|
+}
|
|
|
+
|
|
|
+void PBRConfigVarsHLSL::processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd )
|
|
|
+{
|
|
|
+ MultiLine* meta = new MultiLine;
|
|
|
+ Var* pbrConfig;
|
|
|
+ if (fd.features[MFT_isDeferred])
|
|
|
{
|
|
|
- // create material var
|
|
|
- material = new Var;
|
|
|
- material->setType( "fragout" );
|
|
|
- material->setName( getOutputTargetVarName(ShaderFeature::RenderTarget2) );
|
|
|
- material->setStructName( "OUT" );
|
|
|
+ pbrConfig = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget2));
|
|
|
+ if (!pbrConfig)
|
|
|
+ {
|
|
|
+ // create material var
|
|
|
+ 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");
|
|
|
metalness->uniform = true;
|
|
|
metalness->constSortPos = cspPotentialPrimitive;
|
|
@@ -170,34 +214,89 @@ void DeferredSpecVarsHLSL::processPix( Vector<ShaderComponent*> &componentList,
|
|
|
smoothness->uniform = true;
|
|
|
smoothness->constSortPos = cspPotentialPrimitive;
|
|
|
|
|
|
- MultiLine * meta = new MultiLine;
|
|
|
//matinfo.g slot reserved for AO later
|
|
|
- meta->addStatement(new GenOp(" @.g = 1.0;\r\n", material));
|
|
|
- meta->addStatement(new GenOp(" @.b = @;\r\n", material, smoothness));
|
|
|
+ meta->addStatement(new GenOp(" @.g = 1.0;\r\n", pbrConfig));
|
|
|
+ meta->addStatement(new GenOp(" @.b = @;\r\n", pbrConfig, smoothness));
|
|
|
if (fd.features[MFT_InvertSmoothness])
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
+U32 GlowMapHLSL::getOutputTargets(const MaterialFeatureData& fd) const
|
|
|
+{
|
|
|
+ return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget3 : ShaderFeature::DefaultTarget;
|
|
|
+}
|
|
|
+
|
|
|
//deferred emissive
|
|
|
-void DeferredEmissiveHLSL::processPix(Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd)
|
|
|
+void GlowMapHLSL::processPix(Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd)
|
|
|
{
|
|
|
- //for now emission just uses the diffuse color, we could plug in a separate texture for emission at some stage
|
|
|
- Var *diffuseTargetVar = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget1));
|
|
|
- if (!diffuseTargetVar)
|
|
|
- return; //oh dear something is not right, maybe we should just write 0's instead
|
|
|
-
|
|
|
- // search for scene color target var
|
|
|
- Var *sceneColorVar = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget3));
|
|
|
- if (!sceneColorVar)
|
|
|
+ Var* texCoord = getInTexCoord("texCoord", "float2", componentList);
|
|
|
+
|
|
|
+ // create texture var
|
|
|
+ Var* glowMap = new Var;
|
|
|
+ glowMap->setType("SamplerState");
|
|
|
+ glowMap->setName("glowMap");
|
|
|
+ glowMap->uniform = true;
|
|
|
+ glowMap->sampler = true;
|
|
|
+ glowMap->constNum = Var::getTexUnitNum();
|
|
|
+
|
|
|
+ Var* glowMapTex = new Var;
|
|
|
+ glowMapTex->setName("glowMapTex");
|
|
|
+ glowMapTex->setType("Texture2D");
|
|
|
+ glowMapTex->uniform = true;
|
|
|
+ glowMapTex->texture = true;
|
|
|
+ glowMapTex->constNum = glowMap->constNum;
|
|
|
+ LangElement* texOp = new GenOp("@.Sample(@, @)", glowMapTex, glowMap, texCoord);
|
|
|
+
|
|
|
+ Var* glowMul = new Var("glowMul", "float");
|
|
|
+ glowMul->uniform = true;
|
|
|
+ glowMul->constSortPos = cspPotentialPrimitive;
|
|
|
+
|
|
|
+ Var *targ = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget));
|
|
|
+ if (fd.features[MFT_isDeferred])
|
|
|
{
|
|
|
- // create scene color target var
|
|
|
- sceneColorVar = new Var;
|
|
|
- sceneColorVar->setType("fragout");
|
|
|
- sceneColorVar->setName(getOutputTargetVarName(ShaderFeature::RenderTarget3));
|
|
|
- sceneColorVar->setStructName("OUT");
|
|
|
+ targ = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget3));
|
|
|
+ if (!targ)
|
|
|
+ {
|
|
|
+ // create scene color target var
|
|
|
+ targ = new Var;
|
|
|
+ targ->setType("fragout");
|
|
|
+ targ->setName(getOutputTargetVarName(ShaderFeature::RenderTarget3));
|
|
|
+ targ->setStructName("OUT");
|
|
|
+ output = new GenOp("@ = float4(@.rgb*@,0);", targ, texOp, glowMul);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ output = new GenOp("@ += float4(@.rgb*@,0);", targ, texOp, glowMul);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ output = new GenOp("@ += float4(@.rgb*@,@.a);", targ, texOp, glowMul, targ);
|
|
|
}
|
|
|
|
|
|
- output = new GenOp("@ = float4(@.rgb,0);", sceneColorVar, diffuseTargetVar);
|
|
|
-}
|
|
|
+}
|
|
|
+
|
|
|
+ShaderFeature::Resources GlowMapHLSL::getResources(const MaterialFeatureData& fd)
|
|
|
+{
|
|
|
+ Resources res;
|
|
|
+ res.numTex = 1;
|
|
|
+ res.numTexReg = 1;
|
|
|
+
|
|
|
+ return res;
|
|
|
+}
|
|
|
+
|
|
|
+void GlowMapHLSL::setTexData(Material::StageData& stageDat,
|
|
|
+ const MaterialFeatureData& fd,
|
|
|
+ RenderPassData& passData,
|
|
|
+ U32& texIndex)
|
|
|
+{
|
|
|
+ GFXTextureObject* tex = stageDat.getTex(MFT_GlowMap);
|
|
|
+ if (tex)
|
|
|
+ {
|
|
|
+ passData.mTexType[texIndex] = Material::Standard;
|
|
|
+ passData.mSamplerNames[texIndex] = "glowMap";
|
|
|
+ passData.mTexSlot[texIndex++].texObject = tex;
|
|
|
+ }
|
|
|
+}
|