mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-29 16:25:42 +00:00
glowmap gl port rev1: debug yells about "ShaderFeatureGLSL::getInTexCoord - Type mismatch!", so will need to hunt that down before calling it final, but otherwise, functions.
This commit is contained in:
parent
13f251e83c
commit
21ea0d94aa
3 changed files with 191 additions and 47 deletions
|
|
@ -35,22 +35,38 @@
|
||||||
//****************************************************************************
|
//****************************************************************************
|
||||||
// Deferred Shading Features
|
// Deferred Shading Features
|
||||||
//****************************************************************************
|
//****************************************************************************
|
||||||
|
U32 PBRConfigMapGLSL::getOutputTargets(const MaterialFeatureData& fd) const
|
||||||
|
{
|
||||||
|
return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget2 : ShaderFeature::DefaultTarget;
|
||||||
|
}
|
||||||
|
|
||||||
void PBRConfigMapGLSL::processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd )
|
void PBRConfigMapGLSL::processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd )
|
||||||
{
|
{
|
||||||
// Get the texture coord.
|
// Get the texture coord.
|
||||||
Var *texCoord = getInTexCoord( "texCoord", "vec2", componentList );
|
Var *texCoord = getInTexCoord( "texCoord", "vec2", 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( "vec4" );
|
{
|
||||||
material->setName( getOutputTargetVarName(ShaderFeature::RenderTarget2) );
|
// create material var
|
||||||
material->setStructName("OUT");
|
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
|
// create texture var
|
||||||
|
|
@ -62,22 +78,25 @@ void PBRConfigMapGLSL::processPix( Vector<ShaderComponent*> &componentList, cons
|
||||||
pbrConfigMap->constNum = Var::getTexUnitNum();
|
pbrConfigMap->constNum = Var::getTexUnitNum();
|
||||||
LangElement *texOp = new GenOp( "tex2D(@, @)", pbrConfigMap, texCoord );
|
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");
|
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");
|
||||||
if (!smoothness) smoothness = new Var("smoothness", "float");
|
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])
|
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(" @ = 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;
|
output = meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -116,20 +135,37 @@ void PBRConfigMapGLSL::processVert( Vector<ShaderComponent*> &componentList,
|
||||||
output = meta;
|
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.
|
// Material Info Flags -> Red ( Flags ) of Material Info Buffer.
|
||||||
void MatInfoFlagsGLSL::processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd )
|
void MatInfoFlagsGLSL::processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd )
|
||||||
{
|
{
|
||||||
MultiLine *meta = new MultiLine;
|
MultiLine *meta = new MultiLine;
|
||||||
|
|
||||||
// search for material var
|
Var* pbrConfig;
|
||||||
Var *material = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget2) );
|
if (fd.features[MFT_isDeferred])
|
||||||
if ( !material )
|
|
||||||
{
|
{
|
||||||
// create material var
|
pbrConfig = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget2));
|
||||||
material = new Var;
|
if (!pbrConfig)
|
||||||
material->setType( "vec4" );
|
{
|
||||||
material->setName( getOutputTargetVarName(ShaderFeature::RenderTarget2) );
|
// create material var
|
||||||
material->setStructName("OUT");
|
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;
|
Var *matInfoFlags = new Var;
|
||||||
|
|
@ -138,39 +174,126 @@ void MatInfoFlagsGLSL::processPix( Vector<ShaderComponent*> &componentList, cons
|
||||||
matInfoFlags->uniform = true;
|
matInfoFlags->uniform = true;
|
||||||
matInfoFlags->constSortPos = cspPotentialPrimitive;
|
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;
|
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 Strength -> Blue Channel of Material Info Buffer.
|
||||||
// Spec Power -> Alpha Channel ( of Material Info Buffer.
|
// Spec Power -> Alpha Channel ( of Material Info Buffer.
|
||||||
void PBRConfigVarsGLSL::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* pbrConfig;
|
||||||
Var *material = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget2) );
|
if (fd.features[MFT_isDeferred])
|
||||||
if ( !material )
|
|
||||||
{
|
{
|
||||||
// create material var
|
pbrConfig = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget2));
|
||||||
material = new Var;
|
if (!pbrConfig)
|
||||||
material->setType( "vec4" );
|
{
|
||||||
material->setName( getOutputTargetVarName(ShaderFeature::RenderTarget2) );
|
// create material var
|
||||||
material->setStructName("OUT");
|
pbrConfig = new Var;
|
||||||
|
pbrConfig->setType("vec4");
|
||||||
|
pbrConfig->setName(getOutputTargetVarName(ShaderFeature::RenderTarget2));
|
||||||
|
pbrConfig->setStructName("OUT");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
Var *metalness = new Var("metalness", "float");
|
{
|
||||||
|
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->uniform = true;
|
||||||
metalness->constSortPos = cspPotentialPrimitive;
|
metalness->constSortPos = cspPotentialPrimitive;
|
||||||
|
|
||||||
Var *smoothness = new Var("smoothness", "float");
|
Var* smoothness = new Var("smoothness", "float");
|
||||||
smoothness->uniform = true;
|
smoothness->uniform = true;
|
||||||
smoothness->constSortPos = cspPotentialPrimitive;
|
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(" @.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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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", "float2", 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,8 @@ class PBRConfigMapGLSL : public ShaderFeatureGLSL
|
||||||
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 );
|
||||||
|
|
||||||
|
|
@ -54,8 +56,8 @@ public:
|
||||||
|
|
||||||
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; }
|
virtual U32 getOutputTargets(const MaterialFeatureData& fd) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PBRConfigVarsGLSL : public ShaderFeatureGLSL
|
class PBRConfigVarsGLSL : public ShaderFeatureGLSL
|
||||||
|
|
@ -63,10 +65,28 @@ class PBRConfigVarsGLSL : public ShaderFeatureGLSL
|
||||||
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 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
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -102,6 +102,7 @@ void _initShaderGenGLSL( ShaderGen *shaderGen )
|
||||||
FEATUREMGR->registerFeature( MFT_PBRConfigMap, new PBRConfigMapGLSL );
|
FEATUREMGR->registerFeature( MFT_PBRConfigMap, new PBRConfigMapGLSL );
|
||||||
FEATUREMGR->registerFeature( MFT_PBRConfigVars, new PBRConfigVarsGLSL );
|
FEATUREMGR->registerFeature( MFT_PBRConfigVars, new PBRConfigVarsGLSL );
|
||||||
FEATUREMGR->registerFeature( MFT_MatInfoFlags, new MatInfoFlagsGLSL );
|
FEATUREMGR->registerFeature( MFT_MatInfoFlags, new MatInfoFlagsGLSL );
|
||||||
|
FEATUREMGR->registerFeature( MFT_GlowMap, new GlowMapGLSL);
|
||||||
FEATUREMGR->registerFeature( MFT_SkyBox, new NamedFeatureGLSL( "skybox" ) );
|
FEATUREMGR->registerFeature( MFT_SkyBox, new NamedFeatureGLSL( "skybox" ) );
|
||||||
FEATUREMGR->registerFeature( MFT_HardwareSkinning, new HardwareSkinningFeatureGLSL );
|
FEATUREMGR->registerFeature( MFT_HardwareSkinning, new HardwareSkinningFeatureGLSL );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue