mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-12 07:04:36 +00:00
Merge branch 'alph40_pbrConfig_BREAKINGWip' of https://github.com/Azaezel/Torque3D into Preview4_0
This commit is contained in:
commit
b01d53a825
36 changed files with 1157 additions and 763 deletions
|
|
@ -390,7 +390,7 @@ void DeferredBumpFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
|
|||
Parent::processPix( componentList, fd );
|
||||
return;
|
||||
}
|
||||
else if (!fd.features[MFT_SpecularMap] )
|
||||
else if (!fd.features[MFT_PBRConfigMap] )
|
||||
{
|
||||
Var *bumpSample = (Var *)LangElement::find( "bumpSample" );
|
||||
if( bumpSample == NULL )
|
||||
|
|
@ -421,7 +421,7 @@ ShaderFeature::Resources DeferredBumpFeatGLSL::getResources( const MaterialFeatu
|
|||
return Parent::getResources( fd );
|
||||
|
||||
Resources res;
|
||||
if(!fd.features[MFT_SpecularMap])
|
||||
if(!fd.features[MFT_PBRConfigMap])
|
||||
{
|
||||
res.numTex = 1;
|
||||
res.numTexReg = 1;
|
||||
|
|
@ -464,7 +464,7 @@ void DeferredBumpFeatGLSL::setTexData( Material::StageData &stageDat,
|
|||
passData.mTexSlot[texIndex++].texObject = stageDat.getTex(MFT_DetailNormalMap);
|
||||
}
|
||||
}
|
||||
else if (!fd.features[MFT_Parallax] && !fd.features[MFT_SpecularMap] &&
|
||||
else if (!fd.features[MFT_Parallax] && !fd.features[MFT_PBRConfigMap] &&
|
||||
( fd.features[MFT_DeferredConditioner]) )
|
||||
{
|
||||
passData.mTexType[ texIndex ] = Material::Bump;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@
|
|||
|
||||
#include "shaderGen/GLSL/shaderFeatureGLSL.h"
|
||||
#include "shaderGen/GLSL/bumpGLSL.h"
|
||||
#include "shaderGen/GLSL/pixSpecularGLSL.h"
|
||||
|
||||
class ConditionerMethodDependency;
|
||||
|
||||
|
|
|
|||
|
|
@ -35,55 +35,72 @@
|
|||
//****************************************************************************
|
||||
// Deferred Shading Features
|
||||
//****************************************************************************
|
||||
U32 PBRConfigMapGLSL::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 DeferredSpecMapGLSL::processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd )
|
||||
void PBRConfigMapGLSL::processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd )
|
||||
{
|
||||
// Get the texture coord.
|
||||
Var *texCoord = getInTexCoord( "texCoord", "vec2", 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])
|
||||
{
|
||||
// create color var
|
||||
material = new Var;
|
||||
material->setType( "vec4" );
|
||||
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("vec4");
|
||||
pbrConfig->setName(getOutputTargetVarName(ShaderFeature::RenderTarget2));
|
||||
pbrConfig->setStructName("OUT");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pbrConfig = (Var*)LangElement::find("PBRConfig");
|
||||
if (!pbrConfig)
|
||||
{
|
||||
pbrConfig = new Var("PBRConfig", "vec4");
|
||||
meta->addStatement(new GenOp(" @;\r\n", new DecOp(pbrConfig)));
|
||||
}
|
||||
}
|
||||
|
||||
// create texture var
|
||||
Var *specularMap = new Var;
|
||||
specularMap->setType( "sampler2D" );
|
||||
specularMap->setName( "specularMap" );
|
||||
specularMap->uniform = true;
|
||||
specularMap->sampler = true;
|
||||
specularMap->constNum = Var::getTexUnitNum();
|
||||
LangElement *texOp = new GenOp( "tex2D(@, @)", specularMap, texCoord );
|
||||
Var *pbrConfigMap = new Var;
|
||||
pbrConfigMap->setType( "sampler2D" );
|
||||
pbrConfigMap->setName( "pbrConfigMap" );
|
||||
pbrConfigMap->uniform = true;
|
||||
pbrConfigMap->sampler = true;
|
||||
pbrConfigMap->constNum = Var::getTexUnitNum();
|
||||
LangElement *texOp = new GenOp( "tex2D(@, @)", pbrConfigMap, texCoord );
|
||||
|
||||
Var *pbrConfig = (Var*)LangElement::find("PBRConfig");
|
||||
if (!pbrConfig) pbrConfig = new Var("PBRConfig", "vec4");
|
||||
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 = 1.0-@.b;\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 = vec3(@,@.g,@);\r\n", material, smoothness, pbrConfig, metalness));
|
||||
output = meta;
|
||||
}
|
||||
|
||||
ShaderFeature::Resources DeferredSpecMapGLSL::getResources( const MaterialFeatureData &fd )
|
||||
ShaderFeature::Resources PBRConfigMapGLSL::getResources( const MaterialFeatureData &fd )
|
||||
{
|
||||
Resources res;
|
||||
res.numTex = 1;
|
||||
|
|
@ -92,21 +109,21 @@ ShaderFeature::Resources DeferredSpecMapGLSL::getResources( const MaterialFeatur
|
|||
return res;
|
||||
}
|
||||
|
||||
void DeferredSpecMapGLSL::setTexData( Material::StageData &stageDat,
|
||||
void PBRConfigMapGLSL::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 DeferredSpecMapGLSL::processVert( Vector<ShaderComponent*> &componentList,
|
||||
void PBRConfigMapGLSL::processVert( Vector<ShaderComponent*> &componentList,
|
||||
const MaterialFeatureData &fd )
|
||||
{
|
||||
MultiLine *meta = new MultiLine;
|
||||
|
|
@ -118,20 +135,37 @@ void DeferredSpecMapGLSL::processVert( Vector<ShaderComponent*> &componentList,
|
|||
output = meta;
|
||||
}
|
||||
|
||||
U32 MatInfoFlagsGLSL::getOutputTargets(const MaterialFeatureData& fd) const
|
||||
{
|
||||
return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget2 : ShaderFeature::DefaultTarget;
|
||||
}
|
||||
|
||||
// Material Info Flags -> Red ( Flags ) of Material Info Buffer.
|
||||
void DeferredMatInfoFlagsGLSL::processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd )
|
||||
void MatInfoFlagsGLSL::processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd )
|
||||
{
|
||||
MultiLine *meta = new MultiLine;
|
||||
|
||||
// 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( "vec4" );
|
||||
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("vec4");
|
||||
pbrConfig->setName(getOutputTargetVarName(ShaderFeature::RenderTarget2));
|
||||
pbrConfig->setStructName("OUT");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pbrConfig = (Var*)LangElement::find("PBRConfig");
|
||||
if (!pbrConfig)
|
||||
{
|
||||
pbrConfig = new Var("PBRConfig", "vec4");
|
||||
meta->addStatement(new GenOp(" @;\r\n", new DecOp(pbrConfig)));
|
||||
}
|
||||
}
|
||||
|
||||
Var *matInfoFlags = new Var;
|
||||
|
|
@ -140,39 +174,126 @@ void DeferredMatInfoFlagsGLSL::processPix( Vector<ShaderComponent*> &componentLi
|
|||
matInfoFlags->uniform = true;
|
||||
matInfoFlags->constSortPos = cspPotentialPrimitive;
|
||||
|
||||
meta->addStatement(output = new GenOp(" @.r = @;\r\n", material, matInfoFlags));
|
||||
meta->addStatement(output = new GenOp(" @.r = @;\r\n", pbrConfig, matInfoFlags));
|
||||
output = meta;
|
||||
}
|
||||
|
||||
U32 PBRConfigVarsGLSL::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 DeferredSpecVarsGLSL::processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd )
|
||||
void PBRConfigVarsGLSL::processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd )
|
||||
{
|
||||
MultiLine* meta = new MultiLine;
|
||||
|
||||
// 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( "vec4" );
|
||||
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("vec4");
|
||||
pbrConfig->setName(getOutputTargetVarName(ShaderFeature::RenderTarget2));
|
||||
pbrConfig->setStructName("OUT");
|
||||
}
|
||||
}
|
||||
|
||||
Var *metalness = new Var("metalness", "float");
|
||||
else
|
||||
{
|
||||
pbrConfig = (Var*)LangElement::find("PBRConfig");
|
||||
if (!pbrConfig)
|
||||
{
|
||||
pbrConfig = new Var("PBRConfig", "vec4");
|
||||
meta->addStatement(new GenOp(" @;\r\n", new DecOp(pbrConfig)));
|
||||
}
|
||||
}
|
||||
Var* metalness = new Var("metalness", "float");
|
||||
metalness->uniform = true;
|
||||
metalness->constSortPos = cspPotentialPrimitive;
|
||||
|
||||
Var *smoothness = new Var("smoothness", "float");
|
||||
Var* smoothness = new Var("smoothness", "float");
|
||||
smoothness->uniform = true;
|
||||
smoothness->constSortPos = cspPotentialPrimitive;
|
||||
|
||||
MultiLine *meta = new MultiLine;
|
||||
meta->addStatement(new GenOp(" @.g = 1.0;\r\n", material));
|
||||
meta->addStatement(new GenOp(" @.b = @;\r\n", material, 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));
|
||||
//matinfo.g slot reserved for AO later
|
||||
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", pbrConfig, metalness));
|
||||
output = meta;
|
||||
}
|
||||
|
||||
U32 GlowMapGLSL::getOutputTargets(const MaterialFeatureData& fd) const
|
||||
{
|
||||
return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget3 : ShaderFeature::DefaultTarget;
|
||||
}
|
||||
|
||||
//deferred emissive
|
||||
void GlowMapGLSL::processPix(Vector<ShaderComponent*>& componentList, const MaterialFeatureData& fd)
|
||||
{
|
||||
Var* texCoord = getInTexCoord("texCoord", "vec2", componentList);
|
||||
|
||||
Var* glowMap = new Var;
|
||||
glowMap->setType("sampler2D");
|
||||
glowMap->setName("glowMap");
|
||||
glowMap->uniform = true;
|
||||
glowMap->sampler = true;
|
||||
glowMap->constNum = Var::getTexUnitNum();
|
||||
LangElement* texOp = new GenOp("tex2D(@, @)", 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])
|
||||
{
|
||||
targ = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget3));
|
||||
if (!targ)
|
||||
{
|
||||
// create scene color target var
|
||||
targ = new Var;
|
||||
targ->setType("vec4");
|
||||
targ->setName(getOutputTargetVarName(ShaderFeature::RenderTarget3));
|
||||
targ->setStructName("OUT");
|
||||
output = new GenOp("@ = vec4(@.rgb*@,0);", targ, texOp, glowMul);
|
||||
}
|
||||
else
|
||||
{
|
||||
output = new GenOp("@ += vec4(@.rgb*@,0);", targ, texOp, glowMul);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
output = new GenOp("@ += vec4(@.rgb*@,@.a);", targ, texOp, glowMul, targ);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ShaderFeature::Resources GlowMapGLSL::getResources(const MaterialFeatureData& fd)
|
||||
{
|
||||
Resources res;
|
||||
res.numTex = 1;
|
||||
res.numTexReg = 1;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void GlowMapGLSL::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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,13 +25,14 @@
|
|||
|
||||
#include "shaderGen/GLSL/shaderFeatureGLSL.h"
|
||||
#include "shaderGen/GLSL/bumpGLSL.h"
|
||||
#include "shaderGen/GLSL/pixSpecularGLSL.h"
|
||||
|
||||
// Specular Outputs
|
||||
class DeferredSpecMapGLSL : public ShaderFeatureGLSL
|
||||
class PBRConfigMapGLSL : public ShaderFeatureGLSL
|
||||
{
|
||||
public:
|
||||
virtual String getName() { return "Deferred Shading: Specular Map"; }
|
||||
virtual String getName() { return "Deferred Shading: PBR Config Map"; }
|
||||
|
||||
virtual U32 getOutputTargets(const MaterialFeatureData& fd) const;
|
||||
|
||||
virtual void processPix( Vector<ShaderComponent*> &componentList,
|
||||
const MaterialFeatureData &fd );
|
||||
|
|
@ -48,26 +49,44 @@ public:
|
|||
const MaterialFeatureData &fd );
|
||||
};
|
||||
|
||||
class DeferredMatInfoFlagsGLSL : public ShaderFeatureGLSL
|
||||
class MatInfoFlagsGLSL : public ShaderFeatureGLSL
|
||||
{
|
||||
public:
|
||||
virtual String getName() { return "Deferred Shading: Mat Info Flags"; }
|
||||
|
||||
virtual void processPix( Vector<ShaderComponent*> &componentList,
|
||||
const MaterialFeatureData &fd );
|
||||
|
||||
virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const { return ShaderFeature::RenderTarget2; }
|
||||
|
||||
virtual U32 getOutputTargets(const MaterialFeatureData& fd) const;
|
||||
};
|
||||
|
||||
class DeferredSpecVarsGLSL : public ShaderFeatureGLSL
|
||||
class PBRConfigVarsGLSL : public ShaderFeatureGLSL
|
||||
{
|
||||
public:
|
||||
virtual String getName() { return "Deferred Shading: Specular 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,
|
||||
const MaterialFeatureData &fd );
|
||||
|
||||
virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const { return ShaderFeature::RenderTarget2; }
|
||||
};
|
||||
|
||||
#endif
|
||||
class GlowMapGLSL : public ShaderFeatureGLSL
|
||||
{
|
||||
public:
|
||||
virtual String getName() { return "Glow Map"; }
|
||||
|
||||
virtual void processPix(Vector<ShaderComponent*>& componentList,
|
||||
const MaterialFeatureData& fd);
|
||||
|
||||
virtual U32 getOutputTargets(const MaterialFeatureData& fd) const;
|
||||
|
||||
virtual Resources getResources(const MaterialFeatureData& fd);
|
||||
|
||||
// Sets textures and texture flags for current pass
|
||||
virtual void setTexData(Material::StageData& stageDat,
|
||||
const MaterialFeatureData& fd,
|
||||
RenderPassData& passData,
|
||||
U32& texIndex);
|
||||
};
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -421,7 +421,7 @@ void DeferredBumpFeatHLSL::processPix( Vector<ShaderComponent*> &componentList,
|
|||
Parent::processPix( componentList, fd );
|
||||
return;
|
||||
}
|
||||
else if (!fd.features[MFT_SpecularMap] )
|
||||
else if (!fd.features[MFT_PBRConfigMap] )
|
||||
{
|
||||
Var *bumpSample = (Var *)LangElement::find( "bumpSample" );
|
||||
if( bumpSample == NULL )
|
||||
|
|
@ -454,7 +454,7 @@ ShaderFeature::Resources DeferredBumpFeatHLSL::getResources( const MaterialFeatu
|
|||
return Parent::getResources( fd );
|
||||
|
||||
Resources res;
|
||||
if(!fd.features[MFT_SpecularMap])
|
||||
if(!fd.features[MFT_PBRConfigMap])
|
||||
{
|
||||
res.numTex = 1;
|
||||
res.numTexReg = 1;
|
||||
|
|
@ -497,7 +497,7 @@ void DeferredBumpFeatHLSL::setTexData( Material::StageData &stageDat,
|
|||
passData.mTexSlot[ texIndex++ ].texObject = stageDat.getTex( MFT_DetailNormalMap );
|
||||
}
|
||||
}
|
||||
else if ( !fd.features[MFT_Parallax] && !fd.features[MFT_SpecularMap] &&
|
||||
else if ( !fd.features[MFT_Parallax] && !fd.features[MFT_PBRConfigMap] &&
|
||||
( fd.features[MFT_DeferredConditioner]) )
|
||||
{
|
||||
passData.mTexType[ texIndex ] = Material::Bump;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@
|
|||
|
||||
#include "shaderGen/HLSL/shaderFeatureHLSL.h"
|
||||
#include "shaderGen/HLSL/bumpHLSL.h"
|
||||
#include "shaderGen/HLSL/pixSpecularHLSL.h"
|
||||
|
||||
class ConditionerMethodDependency;
|
||||
|
||||
|
|
|
|||
|
|
@ -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])
|
||||
{
|
||||
// create color 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)));
|
||||
}
|
||||
}
|
||||
|
||||
// create texture var
|
||||
Var *specularMap = new Var;
|
||||
specularMap->setType( "SamplerState" );
|
||||
specularMap->setName( "specularMap" );
|
||||
specularMap->uniform = true;
|
||||
specularMap->sampler = true;
|
||||
specularMap->constNum = Var::getTexUnitNum();
|
||||
Var * pbrConfigMap = new Var;
|
||||
pbrConfigMap->setType( "SamplerState" );
|
||||
pbrConfigMap->setName( "PBRConfigMap" );
|
||||
pbrConfigMap->uniform = true;
|
||||
pbrConfigMap->sampler = true;
|
||||
pbrConfigMap->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* 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 = 1.0-@.b;\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 )
|
||||
{
|
||||
// create material var
|
||||
material = new Var;
|
||||
material->setType( "fragout" );
|
||||
material->setName( getOutputTargetVarName(ShaderFeature::RenderTarget2) );
|
||||
material->setStructName( "OUT" );
|
||||
}
|
||||
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])
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
//deferred emissive
|
||||
void DeferredEmissiveHLSL::processPix(Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd)
|
||||
U32 GlowMapHLSL::getOutputTargets(const MaterialFeatureData& fd) const
|
||||
{
|
||||
//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
|
||||
return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget3 : ShaderFeature::DefaultTarget;
|
||||
}
|
||||
|
||||
// search for scene color target var
|
||||
Var *sceneColorVar = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget3));
|
||||
if (!sceneColorVar)
|
||||
//deferred emissive
|
||||
void GlowMapHLSL::processPix(Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,13 +25,13 @@
|
|||
|
||||
#include "shaderGen/HLSL/shaderFeatureHLSL.h"
|
||||
#include "shaderGen/HLSL/bumpHLSL.h"
|
||||
#include "shaderGen/HLSL/pixSpecularHLSL.h"
|
||||
|
||||
// Specular Outputs
|
||||
class DeferredSpecMapHLSL : public ShaderFeatureHLSL
|
||||
class PBRConfigMapHLSL : public ShaderFeatureHLSL
|
||||
{
|
||||
public:
|
||||
virtual String getName() { return "Deferred Shading: Specular Map"; }
|
||||
virtual String getName() { return "Deferred Shading: PBR Config Map"; }
|
||||
|
||||
virtual U32 getOutputTargets(const MaterialFeatureData& fd) const;
|
||||
|
||||
virtual void processPix( Vector<ShaderComponent*> &componentList,
|
||||
const MaterialFeatureData &fd );
|
||||
|
|
@ -48,37 +48,45 @@ public:
|
|||
const MaterialFeatureData &fd );
|
||||
};
|
||||
|
||||
class DeferredMatInfoFlagsHLSL : public ShaderFeatureHLSL
|
||||
class MatInfoFlagsHLSL : public ShaderFeatureHLSL
|
||||
{
|
||||
public:
|
||||
virtual String getName() { return "Deferred Shading: Mat Info Flags"; }
|
||||
|
||||
virtual void processPix( Vector<ShaderComponent*> &componentList,
|
||||
const MaterialFeatureData &fd );
|
||||
|
||||
virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const { return ShaderFeature::RenderTarget2; }
|
||||
|
||||
virtual U32 getOutputTargets(const MaterialFeatureData& fd) const;
|
||||
};
|
||||
|
||||
class DeferredSpecVarsHLSL : public ShaderFeatureHLSL
|
||||
class PBRConfigVarsHLSL : public ShaderFeatureHLSL
|
||||
{
|
||||
public:
|
||||
virtual String getName() { return "Deferred Shading: Specular 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,
|
||||
const MaterialFeatureData &fd );
|
||||
|
||||
virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const { return ShaderFeature::RenderTarget2; }
|
||||
};
|
||||
|
||||
class DeferredEmissiveHLSL : public ShaderFeatureHLSL
|
||||
class GlowMapHLSL : public ShaderFeatureHLSL
|
||||
{
|
||||
public:
|
||||
virtual String getName() { return "Deferred Shading: Emissive"; }
|
||||
virtual String getName() { return "Glow Map"; }
|
||||
|
||||
virtual void processPix(Vector<ShaderComponent*> &componentList,
|
||||
const MaterialFeatureData &fd);
|
||||
|
||||
virtual U32 getOutputTargets(const MaterialFeatureData &fd) const { return ShaderFeature::RenderTarget3; }
|
||||
virtual U32 getOutputTargets(const MaterialFeatureData& fd) const;
|
||||
|
||||
virtual Resources getResources(const MaterialFeatureData& fd);
|
||||
|
||||
// Sets textures and texture flags for current pass
|
||||
virtual void setTexData(Material::StageData& stageDat,
|
||||
const MaterialFeatureData& fd,
|
||||
RenderPassData& passData,
|
||||
U32& texIndex);
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -43,14 +43,12 @@
|
|||
#include "shaderGen/featureMgr.h"
|
||||
#include "shaderGen/HLSL/shaderFeatureHLSL.h"
|
||||
#include "shaderGen/HLSL/bumpHLSL.h"
|
||||
#include "shaderGen/HLSL/pixSpecularHLSL.h"
|
||||
#include "lighting/basic/blTerrainSystem.h"
|
||||
#include "lighting/common/projectedShadow.h"
|
||||
|
||||
#if defined( TORQUE_OPENGL )
|
||||
#include "shaderGen/GLSL/shaderFeatureGLSL.h"
|
||||
#include "shaderGen/GLSL/bumpGLSL.h"
|
||||
#include "shaderGen/GLSL/pixSpecularGLSL.h"
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue