Core implementation of Physical Based Rendering.

This commit is contained in:
Areloch 2018-09-15 20:19:57 -05:00
parent d2a78b0a82
commit ef5e3a5271
148 changed files with 4464 additions and 1016 deletions

View file

@ -41,8 +41,8 @@
#include "math/util/matrixSet.h"
#include "console/consoleTypes.h"
const RenderInstType AdvancedLightBinManager::RIT_LightInfo( "LightInfo" );
const String AdvancedLightBinManager::smBufferName( "lightinfo" );
const RenderInstType AdvancedLightBinManager::RIT_LightInfo( "directLighting" );
const String AdvancedLightBinManager::smBufferName( "directLighting" );
ShadowFilterMode AdvancedLightBinManager::smShadowFilterMode = ShadowFilterMode_SoftShadowHighQuality;
bool AdvancedLightBinManager::smPSSMDebugRender = false;
@ -130,7 +130,7 @@ AdvancedLightBinManager::AdvancedLightBinManager( AdvancedLightManager *lm /* =
// We want a full-resolution buffer
mTargetSizeType = RenderTexTargetBinManager::WindowSize;
mMRTLightmapsDuringDeferred = false;
mMRTLightmapsDuringDeferred = true;
Con::NotifyDelegate callback( this, &AdvancedLightBinManager::_deleteLightMaterials );
Con::addVariableNotify( "$pref::Shadows::filterMode", callback );
@ -252,9 +252,7 @@ void AdvancedLightBinManager::render( SceneRenderState *state )
if ( !_onPreRender( state ) )
return;
// Clear as long as there isn't MRT population of light buffer with lightmap data
if ( !MRTLightmapsDuringDeferred() )
GFX->clear(GFXClearTarget, ColorI(0, 0, 0, 0), 1.0f, 0);
GFX->clear(GFXClearTarget, ColorI(0, 0, 0, 0), 1.0f, 0);
// Restore transforms
MatrixSet &matrixSet = getRenderPass()->getMatrixSet();

View file

@ -36,7 +36,7 @@ void DeferredRTLightingFeatGLSL::processPixMacros( Vector<GFXShaderMacro> &macro
const MaterialFeatureData &fd )
{
// Skip deferred features, and use forward shading instead
if ( fd.features[MFT_ForwardShading] )
if ( !fd.features[MFT_isDeferred] )
{
Parent::processPixMacros( macros, fd );
return;
@ -56,7 +56,7 @@ void DeferredRTLightingFeatGLSL::processVert( Vector<ShaderComponent*> &compon
const MaterialFeatureData &fd )
{
// Skip deferred features, and use forward shading instead
if ( fd.features[MFT_ForwardShading] )
if ( !fd.features[MFT_isDeferred] )
{
Parent::processVert( componentList, fd );
return;
@ -79,7 +79,7 @@ void DeferredRTLightingFeatGLSL::processPix( Vector<ShaderComponent*> &component
const MaterialFeatureData &fd )
{
// Skip deferred features, and use forward shading instead
if ( fd.features[MFT_ForwardShading] )
if ( !fd.features[MFT_isDeferred] )
{
Parent::processPix( componentList, fd );
return;
@ -98,7 +98,7 @@ void DeferredRTLightingFeatGLSL::processPix( Vector<ShaderComponent*> &component
uvScene->setName( "uvScene" );
LangElement *uvSceneDecl = new DecOp( uvScene );
String rtParamName = String::ToString( "rtParams%s", "lightInfoBuffer" );
String rtParamName = String::ToString( "rtParams%s", "directLightingBuffer" );
Var *rtParams = (Var*) LangElement::find( rtParamName );
if( !rtParams )
{
@ -121,7 +121,7 @@ void DeferredRTLightingFeatGLSL::processPix( Vector<ShaderComponent*> &component
// create texture var
Var *lightInfoBuffer = new Var;
lightInfoBuffer->setType( "sampler2D" );
lightInfoBuffer->setName( "lightInfoBuffer" );
lightInfoBuffer->setName( "directLightingBuffer" );
lightInfoBuffer->uniform = true;
lightInfoBuffer->sampler = true;
lightInfoBuffer->constNum = Var::getTexUnitNum(); // used as texture unit num here
@ -175,7 +175,7 @@ void DeferredRTLightingFeatGLSL::processPix( Vector<ShaderComponent*> &component
ShaderFeature::Resources DeferredRTLightingFeatGLSL::getResources( const MaterialFeatureData &fd )
{
// Skip deferred features, and use forward shading instead
if ( fd.features[MFT_ForwardShading] )
if ( !fd.features[MFT_isDeferred] )
return Parent::getResources( fd );
// HACK: See DeferredRTLightingFeatGLSL::setTexData.
@ -193,7 +193,7 @@ void DeferredRTLightingFeatGLSL::setTexData( Material::StageData &stageDat,
U32 &texIndex )
{
// Skip deferred features, and use forward shading instead
if ( fd.features[MFT_ForwardShading] )
if ( !fd.features[MFT_isDeferred] )
{
Parent::setTexData( stageDat, fd, passData, texIndex );
return;
@ -207,7 +207,7 @@ void DeferredRTLightingFeatGLSL::setTexData( Material::StageData &stageDat,
mLastTexIndex = texIndex;
passData.mTexType[ texIndex ] = Material::TexTarget;
passData.mSamplerNames[ texIndex ]= "lightInfoBuffer";
passData.mSamplerNames[ texIndex ]= "directLightingBuffer";
passData.mTexSlot[ texIndex++ ].texTarget = texTarget;
}
}
@ -227,7 +227,7 @@ void DeferredBumpFeatGLSL::processVert( Vector<ShaderComponent*> &componentLis
const bool useTexAnim = fd.features[MFT_TexAnim];
// Make sure there are texcoords
if( !fd.features[MFT_Parallax] && !fd.features[MFT_DiffuseMap] )
if( !fd.features[MFT_Parallax] && !fd.features[MFT_DiffuseMap])
{
getOutTexCoord( "texCoord",
@ -245,7 +245,7 @@ void DeferredBumpFeatGLSL::processVert( Vector<ShaderComponent*> &componentLis
output = meta;
}
else if ( fd.materialFeatures[MFT_NormalsOut] ||
fd.features[MFT_ForwardShading] ||
!fd.features[MFT_isDeferred] ||
!fd.features[MFT_RTLighting] )
{
Parent::processVert( componentList, fd );
@ -382,7 +382,7 @@ void DeferredBumpFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
}
}
else if ( fd.materialFeatures[MFT_NormalsOut] ||
fd.features[MFT_ForwardShading] ||
!fd.features[MFT_isDeferred] ||
!fd.features[MFT_RTLighting] )
{
Parent::processPix( componentList, fd );
@ -413,7 +413,7 @@ void DeferredBumpFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
ShaderFeature::Resources DeferredBumpFeatGLSL::getResources( const MaterialFeatureData &fd )
{
if ( fd.materialFeatures[MFT_NormalsOut] ||
fd.features[MFT_ForwardShading] ||
!fd.features[MFT_isDeferred] ||
fd.features[MFT_Parallax] ||
!fd.features[MFT_RTLighting] )
return Parent::getResources( fd );
@ -442,7 +442,7 @@ void DeferredBumpFeatGLSL::setTexData( Material::StageData &stageDat,
U32 &texIndex )
{
if ( fd.materialFeatures[MFT_NormalsOut] ||
fd.features[MFT_ForwardShading] ||
!fd.features[MFT_isDeferred] ||
!fd.features[MFT_RTLighting] )
{
Parent::setTexData( stageDat, fd, passData, texIndex );
@ -484,7 +484,7 @@ void DeferredBumpFeatGLSL::setTexData( Material::StageData &stageDat,
void DeferredPixelSpecularGLSL::processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
if( fd.features[MFT_ForwardShading] || !fd.features[MFT_RTLighting] )
if( !fd.features[MFT_isDeferred] || !fd.features[MFT_RTLighting] )
{
Parent::processVert( componentList, fd );
return;
@ -495,7 +495,7 @@ void DeferredPixelSpecularGLSL::processVert( Vector<ShaderComponent*> &component
void DeferredPixelSpecularGLSL::processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
if( fd.features[MFT_ForwardShading] || !fd.features[MFT_RTLighting] )
if( !fd.features[MFT_isDeferred] || !fd.features[MFT_RTLighting] )
{
Parent::processPix( componentList, fd );
return;
@ -518,26 +518,28 @@ void DeferredPixelSpecularGLSL::processPix( Vector<ShaderComponent*> &component
specCol->constSortPos = cspPotentialPrimitive;
}
Var *specPow = new Var;
specPow->setType( "float" );
specPow->setName( "specularPower" );
// If the gloss map flag is set, than the specular power is in the alpha
// channel of the specular map
if( fd.features[ MFT_GlossMap ] )
meta->addStatement( new GenOp( " @ = @.a * 255;\r\n", new DecOp( specPow ), specCol ) );
else
Var *smoothness = (Var*)LangElement::find("smoothness");
if (!smoothness)
{
specPow->uniform = true;
specPow->constSortPos = cspPotentialPrimitive;
smoothness = new Var("smoothness", "float");
// If the gloss map flag is set, than the specular power is in the alpha
// channel of the specular map
if (fd.features[MFT_GlossMap])
meta->addStatement(new GenOp(" @ = @.a;\r\n", new DecOp(smoothness), specCol));
else
{
smoothness->uniform = true;
smoothness->constSortPos = cspPotentialPrimitive;
}
}
Var *specStrength = (Var*)LangElement::find( "specularStrength" );
if (!specStrength)
Var *metalness = (Var*)LangElement::find("metalness");
if (!metalness)
{
specStrength = new Var( "specularStrength", "float" );
specStrength->uniform = true;
specStrength->constSortPos = cspPotentialPrimitive;
metalness = new Var("metalness", "float");
metalness->uniform = true;
metalness->constSortPos = cspPotentialPrimitive;
}
Var *lightInfoSamp = (Var *)LangElement::find( "lightInfoSample" );
@ -557,7 +559,7 @@ void DeferredPixelSpecularGLSL::processPix( Vector<ShaderComponent*> &component
}
// (a^m)^n = a^(m*n)
meta->addStatement( new GenOp( " @ = pow( abs(@), max((@ / AL_ConstantSpecularPower),1.0f)) * @;\r\n",
specDecl, d_specular, specPow, specStrength ) );
specDecl, d_specular, smoothness, metalness));
LangElement *specMul = new GenOp( "vec4( @.rgb, 0 ) * @", specCol, specular );
LangElement *final = specMul;
@ -577,7 +579,7 @@ void DeferredPixelSpecularGLSL::processPix( Vector<ShaderComponent*> &component
ShaderFeature::Resources DeferredPixelSpecularGLSL::getResources( const MaterialFeatureData &fd )
{
if( fd.features[MFT_ForwardShading] || !fd.features[MFT_RTLighting] )
if( !fd.features[MFT_isDeferred] || !fd.features[MFT_RTLighting] )
return Parent::getResources( fd );
Resources res;
@ -588,7 +590,7 @@ ShaderFeature::Resources DeferredPixelSpecularGLSL::getResources( const Material
ShaderFeature::Resources DeferredMinnaertGLSL::getResources( const MaterialFeatureData &fd )
{
Resources res;
if( !fd.features[MFT_ForwardShading] && fd.features[MFT_RTLighting] )
if( fd.features[MFT_isDeferred] && fd.features[MFT_RTLighting] )
{
res.numTex = 1;
res.numTexReg = 1;
@ -601,7 +603,7 @@ void DeferredMinnaertGLSL::setTexData( Material::StageData &stageDat,
RenderPassData &passData,
U32 &texIndex )
{
if( !fd.features[MFT_ForwardShading] && fd.features[MFT_RTLighting] )
if( fd.features[MFT_isDeferred] && fd.features[MFT_RTLighting] )
{
NamedTexTarget *texTarget = NamedTexTarget::find(RenderDeferredMgr::BufferName);
if ( texTarget )
@ -616,7 +618,7 @@ void DeferredMinnaertGLSL::setTexData( Material::StageData &stageDat,
void DeferredMinnaertGLSL::processPixMacros( Vector<GFXShaderMacro> &macros,
const MaterialFeatureData &fd )
{
if( !fd.features[MFT_ForwardShading] && fd.features[MFT_RTLighting] )
if( fd.features[MFT_isDeferred] && fd.features[MFT_RTLighting] )
{
// Pull in the uncondition method for the g buffer
NamedTexTarget *texTarget = NamedTexTarget::find( RenderDeferredMgr::BufferName );
@ -633,7 +635,7 @@ void DeferredMinnaertGLSL::processVert( Vector<ShaderComponent*> &componentLis
const MaterialFeatureData &fd )
{
// If there is no deferred information, bail on this feature
if( fd.features[MFT_ForwardShading] || !fd.features[MFT_RTLighting] )
if( !fd.features[MFT_isDeferred] || !fd.features[MFT_RTLighting] )
{
output = NULL;
return;
@ -650,7 +652,7 @@ void DeferredMinnaertGLSL::processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
// If there is no deferred information, bail on this feature
if( fd.features[MFT_ForwardShading] || !fd.features[MFT_RTLighting] )
if( !fd.features[MFT_isDeferred] || !fd.features[MFT_RTLighting] )
{
output = NULL;
return;
@ -695,12 +697,6 @@ void DeferredMinnaertGLSL::processPix( Vector<ShaderComponent*> &componentList,
void DeferredSubSurfaceGLSL::processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
// If there is no deferred information, bail on this feature
if( fd.features[MFT_ForwardShading] || !fd.features[MFT_RTLighting] )
{
output = NULL;
return;
}
Var *subSurfaceParams = new Var;
subSurfaceParams->setType( "vec4" );
@ -712,9 +708,13 @@ void DeferredSubSurfaceGLSL::processPix( Vector<ShaderComponent*> &componentLis
Var *d_NL_Att = (Var*)LangElement::find( "d_NL_Att" );
MultiLine *meta = new MultiLine;
meta->addStatement( new GenOp( " float subLamb = smoothstep(-@.a, 1.0, @) - smoothstep(0.0, 1.0, @);\r\n", subSurfaceParams, d_NL_Att, d_NL_Att ) );
meta->addStatement( new GenOp( " subLamb = max(0.0, subLamb);\r\n" ) );
meta->addStatement( new GenOp( " @;\r\n", assignColor( new GenOp( "vec4(@ + (subLamb * @.rgb), 1.0)", d_lightcolor, subSurfaceParams ), Material::Mul ) ) );
if (fd.features[MFT_isDeferred])
{
Var* targ = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget3));
meta->addStatement(new GenOp(" @.rgb += @.rgb*@.a;\r\n", targ, subSurfaceParams, subSurfaceParams));
output = meta;
return;
}
output = meta;
}

View file

@ -62,10 +62,24 @@ void DeferredSpecMapGLSL::processPix( Vector<ShaderComponent*> &componentList, c
specularMap->uniform = true;
specularMap->sampler = true;
specularMap->constNum = Var::getTexUnitNum();
//matinfo.g slot reserved for AO later
meta->addStatement(new GenOp(" @.g = 1.0;\r\n", material));
meta->addStatement(new GenOp(" @.b = dot(tex2D(@, @).rgb, vec3(0.3, 0.59, 0.11));\r\n", material, specularMap, texCoord));
meta->addStatement(new GenOp(" @.a = tex2D(@, @).a;\r\n", material, specularMap, texCoord));
LangElement *texOp = new GenOp( "tex2D(@, @)", specularMap, texCoord );
Var *specularColor = (Var*)LangElement::find("specularColor");
if (!specularColor) specularColor = new Var("specularColor", "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");
meta->addStatement(new GenOp(" @ = @.r;\r\n", new DecOp(smoothness), texOp));
meta->addStatement(new GenOp(" @ = @.b;\r\n", new DecOp(metalness), texOp));
if (fd.features[MFT_InvertSmoothness])
meta->addStatement(new GenOp(" @ = 1.0-@;\r\n", smoothness, smoothness));
meta->addStatement(new GenOp(" @ = @.ggga;\r\n", new DecOp(specularColor), texOp));
meta->addStatement(new GenOp(" @.bga = vec3(@,@.g,@);\r\n", material, smoothness, specularColor, metalness));
output = meta;
}
@ -145,44 +159,20 @@ void DeferredSpecVarsGLSL::processPix( Vector<ShaderComponent*> &componentList,
material->setName( getOutputTargetVarName(ShaderFeature::RenderTarget2) );
material->setStructName("OUT");
}
Var *metalness = new Var("metalness", "float");
metalness->uniform = true;
metalness->constSortPos = cspPotentialPrimitive;
Var *specStrength = new Var;
specStrength->setType( "float" );
specStrength->setName( "specularStrength" );
specStrength->uniform = true;
specStrength->constSortPos = cspPotentialPrimitive;
Var *smoothness = new Var("smoothness", "float");
smoothness->uniform = true;
smoothness->constSortPos = cspPotentialPrimitive;
Var *specPower = new Var;
specPower->setType("float");
specPower->setName("specularPower");
specPower->uniform = true;
specPower->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(" @.a = @/128;\r\n", material, specPower));
meta->addStatement(new GenOp(" @.b = @/5;\r\n", material, specStrength));
output = meta;
}
// Black -> Blue and Alpha of Color Buffer (representing no specular)
void DeferredEmptySpecGLSL::processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd )
{
// search for material var
Var *material = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget2) );
if ( !material )
{
// create material var
material = new Var;
material->setType( "vec4" );
material->setName( getOutputTargetVarName(ShaderFeature::RenderTarget2) );
material->setStructName("OUT");
}
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(" @.ba = vec2(0.0);\r\n", material));
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));
output = meta;
}

View file

@ -70,16 +70,4 @@ public:
virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const { return ShaderFeature::RenderTarget2; }
};
class DeferredEmptySpecGLSL : public ShaderFeatureGLSL
{
public:
virtual String getName() { return "Deferred Shading: Empty Specular"; }
virtual void processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const { return ShaderFeature::RenderTarget2; }
};
#endif

View file

@ -36,7 +36,7 @@ void DeferredRTLightingFeatHLSL::processPixMacros( Vector<GFXShaderMacro> &macro
const MaterialFeatureData &fd )
{
// Skip deferred features, and use forward shading instead
if ( fd.features[MFT_ForwardShading] )
if ( !fd.features[MFT_isDeferred] )
{
Parent::processPixMacros( macros, fd );
return;
@ -56,7 +56,7 @@ void DeferredRTLightingFeatHLSL::processVert( Vector<ShaderComponent*> &compon
const MaterialFeatureData &fd )
{
// Skip deferred features, and use forward shading instead
if ( fd.features[MFT_ForwardShading] )
if ( !fd.features[MFT_isDeferred] )
{
Parent::processVert( componentList, fd );
return;
@ -79,32 +79,33 @@ void DeferredRTLightingFeatHLSL::processPix( Vector<ShaderComponent*> &component
const MaterialFeatureData &fd )
{
// Skip deferred features, and use forward shading instead
if ( fd.features[MFT_ForwardShading] )
if ( !fd.features[MFT_isDeferred] )
{
Parent::processPix( componentList, fd );
Parent::processPix(componentList, fd);
return;
}
MultiLine *meta = new MultiLine;
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
Var *ssPos = connectComp->getElement( RT_TEXCOORD );
ssPos->setName( "screenspacePos" );
ssPos->setStructName( "IN" );
ssPos->setType( "float4" );
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>(componentList[C_CONNECTOR]);
Var *ssPos = connectComp->getElement(RT_TEXCOORD);
ssPos->setName("screenspacePos");
ssPos->setStructName("IN");
ssPos->setType("float4");
Var *uvScene = new Var;
uvScene->setType( "float2" );
uvScene->setName( "uvScene" );
LangElement *uvSceneDecl = new DecOp( uvScene );
uvScene->setType("float2");
uvScene->setName("uvScene");
LangElement *uvSceneDecl = new DecOp(uvScene);
String rtParamName = String::ToString( "rtParams%s", "lightInfoBuffer" );
Var *rtParams = (Var*) LangElement::find( rtParamName );
if( !rtParams )
String rtParamName = String::ToString("rtParams%s", "directLightingBuffer");
Var *rtParams = (Var*)LangElement::find(rtParamName);
if (!rtParams)
{
rtParams = new Var;
rtParams->setType( "float4" );
rtParams->setName( rtParamName );
rtParams->setType("float4");
rtParams->setName(rtParamName);
rtParams->uniform = true;
rtParams->constSortPos = cspPass;
}
@ -182,7 +183,7 @@ void DeferredRTLightingFeatHLSL::processPix( Vector<ShaderComponent*> &component
ShaderFeature::Resources DeferredRTLightingFeatHLSL::getResources( const MaterialFeatureData &fd )
{
// Skip deferred features, and use forward shading instead
if ( fd.features[MFT_ForwardShading] )
if ( !fd.features[MFT_isDeferred] )
return Parent::getResources( fd );
// HACK: See DeferredRTLightingFeatHLSL::setTexData.
@ -200,7 +201,7 @@ void DeferredRTLightingFeatHLSL::setTexData( Material::StageData &stageDat,
U32 &texIndex )
{
// Skip deferred features, and use forward shading instead
if ( fd.features[MFT_ForwardShading] )
if ( !fd.features[MFT_isDeferred] )
{
Parent::setTexData( stageDat, fd, passData, texIndex );
return;
@ -214,7 +215,7 @@ void DeferredRTLightingFeatHLSL::setTexData( Material::StageData &stageDat,
mLastTexIndex = texIndex;
passData.mTexType[ texIndex ] = Material::TexTarget;
passData.mSamplerNames[ texIndex ]= "lightInfoBuffer";
passData.mSamplerNames[ texIndex ]= "directLightingBuffer";
passData.mTexSlot[ texIndex++ ].texTarget = texTarget;
}
}
@ -252,7 +253,7 @@ void DeferredBumpFeatHLSL::processVert( Vector<ShaderComponent*> &componentLis
output = meta;
}
else if ( fd.materialFeatures[MFT_NormalsOut] ||
fd.features[MFT_ForwardShading] ||
!fd.features[MFT_isDeferred] ||
!fd.features[MFT_RTLighting] )
{
Parent::processVert( componentList, fd );
@ -412,7 +413,7 @@ void DeferredBumpFeatHLSL::processPix( Vector<ShaderComponent*> &componentList,
}
}
else if ( fd.materialFeatures[MFT_NormalsOut] ||
fd.features[MFT_ForwardShading] ||
!fd.features[MFT_isDeferred] ||
!fd.features[MFT_RTLighting] )
{
Parent::processPix( componentList, fd );
@ -426,13 +427,13 @@ void DeferredBumpFeatHLSL::processPix( Vector<ShaderComponent*> &componentList,
Var *texCoord = getInTexCoord( "texCoord", "float2", componentList );
Var *bumpMap = getNormalMapTex();
Var *bumpMapTex = (Var *)LangElement::find("bumpMapTex");
bumpSample = new Var;
bumpSample->setType( "float4" );
bumpSample->setName( "bumpSample" );
LangElement *bumpSampleDecl = new DecOp( bumpSample );
bumpSample->setType("float4");
bumpSample->setName("bumpSample");
Var *bumpMapTex = (Var *)LangElement::find("bumpMapTex");
LangElement *bumpSampleDecl = new DecOp(bumpSample);
output = new GenOp(" @ = @.Sample(@, @);\r\n", bumpSampleDecl, bumpMapTex, bumpMap, texCoord);
return;
@ -445,7 +446,7 @@ void DeferredBumpFeatHLSL::processPix( Vector<ShaderComponent*> &componentList,
ShaderFeature::Resources DeferredBumpFeatHLSL::getResources( const MaterialFeatureData &fd )
{
if ( fd.materialFeatures[MFT_NormalsOut] ||
fd.features[MFT_ForwardShading] ||
!fd.features[MFT_isDeferred] ||
fd.features[MFT_Parallax] ||
!fd.features[MFT_RTLighting] )
return Parent::getResources( fd );
@ -474,7 +475,7 @@ void DeferredBumpFeatHLSL::setTexData( Material::StageData &stageDat,
U32 &texIndex )
{
if ( fd.materialFeatures[MFT_NormalsOut] ||
fd.features[MFT_ForwardShading] ||
!fd.features[MFT_isDeferred] ||
!fd.features[MFT_RTLighting] )
{
Parent::setTexData( stageDat, fd, passData, texIndex );
@ -516,7 +517,7 @@ void DeferredBumpFeatHLSL::setTexData( Material::StageData &stageDat,
void DeferredPixelSpecularHLSL::processVert( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
if( fd.features[MFT_ForwardShading] || !fd.features[MFT_RTLighting] )
if( !fd.features[MFT_isDeferred] || !fd.features[MFT_RTLighting] )
{
Parent::processVert( componentList, fd );
return;
@ -527,7 +528,7 @@ void DeferredPixelSpecularHLSL::processVert( Vector<ShaderComponent*> &component
void DeferredPixelSpecularHLSL::processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
if( fd.features[MFT_ForwardShading] || !fd.features[MFT_RTLighting] )
if( !fd.features[MFT_isDeferred] || !fd.features[MFT_RTLighting] )
{
Parent::processPix( componentList, fd );
return;
@ -550,26 +551,28 @@ void DeferredPixelSpecularHLSL::processPix( Vector<ShaderComponent*> &component
specCol->constSortPos = cspPotentialPrimitive;
}
Var *specPow = new Var;
specPow->setType( "float" );
specPow->setName( "specularPower" );
// If the gloss map flag is set, than the specular power is in the alpha
// channel of the specular map
if( fd.features[ MFT_GlossMap ] )
meta->addStatement( new GenOp( " @ = @.a * 255;\r\n", new DecOp( specPow ), specCol ) );
else
Var *smoothness = (Var*)LangElement::find("smoothness");
if (!smoothness)
{
specPow->uniform = true;
specPow->constSortPos = cspPotentialPrimitive;
smoothness = new Var("smoothness", "float");
// If the gloss map flag is set, than the specular power is in the alpha
// channel of the specular map
if (fd.features[MFT_GlossMap])
meta->addStatement(new GenOp(" @ = @.a;\r\n", new DecOp(smoothness), specCol));
else
{
smoothness->uniform = true;
smoothness->constSortPos = cspPotentialPrimitive;
}
}
Var *specStrength = (Var*)LangElement::find( "specularStrength" );
if (!specStrength)
Var *metalness = (Var*)LangElement::find("metalness");
if (!metalness)
{
specStrength = new Var( "specularStrength", "float" );
specStrength->uniform = true;
specStrength->constSortPos = cspPotentialPrimitive;
metalness = new Var("metalness", "float");
metalness->uniform = true;
metalness->constSortPos = cspPotentialPrimitive;
}
Var *lightInfoSamp = (Var *)LangElement::find( "lightInfoSample" );
@ -591,7 +594,7 @@ void DeferredPixelSpecularHLSL::processPix( Vector<ShaderComponent*> &component
// (a^m)^n = a^(m*n)
meta->addStatement( new GenOp( " @ = pow( abs(@), max((@ / AL_ConstantSpecularPower),1.0f)) * @;\r\n",
specDecl, d_specular, specPow, specStrength));
specDecl, d_specular, smoothness, metalness));
LangElement *specMul = new GenOp( "float4( @.rgb, 0 ) * @", specCol, specular );
LangElement *final = specMul;
@ -611,7 +614,7 @@ void DeferredPixelSpecularHLSL::processPix( Vector<ShaderComponent*> &component
ShaderFeature::Resources DeferredPixelSpecularHLSL::getResources( const MaterialFeatureData &fd )
{
if( fd.features[MFT_ForwardShading] || !fd.features[MFT_RTLighting] )
if( !fd.features[MFT_isDeferred] || !fd.features[MFT_RTLighting] )
return Parent::getResources( fd );
Resources res;
@ -622,7 +625,7 @@ ShaderFeature::Resources DeferredPixelSpecularHLSL::getResources( const Material
ShaderFeature::Resources DeferredMinnaertHLSL::getResources( const MaterialFeatureData &fd )
{
Resources res;
if( !fd.features[MFT_ForwardShading] && fd.features[MFT_RTLighting] )
if( fd.features[MFT_isDeferred] && fd.features[MFT_RTLighting] )
{
res.numTex = 1;
res.numTexReg = 1;
@ -635,7 +638,7 @@ void DeferredMinnaertHLSL::setTexData( Material::StageData &stageDat,
RenderPassData &passData,
U32 &texIndex )
{
if( !fd.features[MFT_ForwardShading] && fd.features[MFT_RTLighting] )
if( fd.features[MFT_isDeferred] && fd.features[MFT_RTLighting] )
{
NamedTexTarget *texTarget = NamedTexTarget::find(RenderDeferredMgr::BufferName);
if ( texTarget )
@ -650,7 +653,7 @@ void DeferredMinnaertHLSL::setTexData( Material::StageData &stageDat,
void DeferredMinnaertHLSL::processPixMacros( Vector<GFXShaderMacro> &macros,
const MaterialFeatureData &fd )
{
if( !fd.features[MFT_ForwardShading] && fd.features[MFT_RTLighting] )
if( fd.features[MFT_isDeferred] && fd.features[MFT_RTLighting] )
{
// Pull in the uncondition method for the g buffer
NamedTexTarget *texTarget = NamedTexTarget::find( RenderDeferredMgr::BufferName );
@ -667,7 +670,7 @@ void DeferredMinnaertHLSL::processVert( Vector<ShaderComponent*> &componentLis
const MaterialFeatureData &fd )
{
// If there is no deferred information, bail on this feature
if( fd.features[MFT_ForwardShading] || !fd.features[MFT_RTLighting] )
if( !fd.features[MFT_isDeferred] || !fd.features[MFT_RTLighting] )
{
output = NULL;
return;
@ -684,7 +687,7 @@ void DeferredMinnaertHLSL::processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
// If there is no deferred information, bail on this feature
if( fd.features[MFT_ForwardShading] || !fd.features[MFT_RTLighting] )
if( !fd.features[MFT_isDeferred] || !fd.features[MFT_RTLighting] )
{
output = NULL;
return;
@ -737,12 +740,6 @@ void DeferredMinnaertHLSL::processPix( Vector<ShaderComponent*> &componentList,
void DeferredSubSurfaceHLSL::processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
// If there is no deferred information, bail on this feature
if( fd.features[MFT_ForwardShading] || !fd.features[MFT_RTLighting] )
{
output = NULL;
return;
}
Var *subSurfaceParams = new Var;
subSurfaceParams->setType( "float4" );
@ -754,9 +751,13 @@ void DeferredSubSurfaceHLSL::processPix( Vector<ShaderComponent*> &componentLis
Var *d_NL_Att = (Var*)LangElement::find( "d_NL_Att" );
MultiLine *meta = new MultiLine;
meta->addStatement( new GenOp( " float subLamb = smoothstep(-@.a, 1.0, @) - smoothstep(0.0, 1.0, @);\r\n", subSurfaceParams, d_NL_Att, d_NL_Att ) );
meta->addStatement( new GenOp( " subLamb = max(0.0, subLamb);\r\n" ) );
meta->addStatement( new GenOp( " @;\r\n", assignColor( new GenOp( "float4(@ + (subLamb * @.rgb), 1.0)", d_lightcolor, subSurfaceParams ), Material::Mul ) ) );
if (fd.features[MFT_isDeferred])
{
Var* targ = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget3));
meta->addStatement(new GenOp(" @.rgb += @.rgb*@.a;\r\n", targ, subSurfaceParams, subSurfaceParams));
output = meta;
return;
}
output = meta;
}

View file

@ -69,20 +69,23 @@ void DeferredSpecMapHLSL::processPix( Vector<ShaderComponent*> &componentList, c
specularMapTex->uniform = true;
specularMapTex->texture = true;
specularMapTex->constNum = specularMap->constNum;
//matinfo.g slot reserved for AO later
Var* specColor = new Var;
specColor->setName("specColor");
specColor->setType("float4");
LangElement *specColorElem = new DecOp(specColor);
meta->addStatement(new GenOp(" @.g = 1.0;\r\n", material));
//sample specular map
meta->addStatement(new GenOp(" @ = @.Sample(@, @);\r\n", specColorElem, specularMapTex, specularMap, texCoord));
LangElement *texOp = new GenOp(" @.Sample(@, @)", specularMapTex, specularMap, texCoord);
meta->addStatement(new GenOp(" @.b = dot(@.rgb, float3(0.3, 0.59, 0.11));\r\n", material, specColor));
meta->addStatement(new GenOp(" @.a = @.a;\r\n", material, specColor));
Var *specularColor = (Var*)LangElement::find("specularColor");
if (!specularColor) specularColor = new Var("specularColor", "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");
meta->addStatement(new GenOp(" @ = @.r;\r\n", new DecOp(smoothness), texOp));
meta->addStatement(new GenOp(" @ = @.b;\r\n", new DecOp(metalness), texOp));
if (fd.features[MFT_InvertSmoothness])
meta->addStatement(new GenOp(" @ = 1.0-@;\r\n", smoothness, smoothness));
meta->addStatement(new GenOp(" @ = @.ggga;\r\n", new DecOp(specularColor), texOp));
meta->addStatement(new GenOp(" @.bga = float3(@,@.g,@);\r\n", material, smoothness, specularColor, metalness));
output = meta;
}
@ -159,43 +162,20 @@ void DeferredSpecVarsHLSL::processPix( Vector<ShaderComponent*> &componentList,
material->setStructName( "OUT" );
}
Var *specStrength = new Var;
specStrength->setType( "float" );
specStrength->setName( "specularStrength" );
specStrength->uniform = true;
specStrength->constSortPos = cspPotentialPrimitive;
Var *metalness = new Var("metalness", "float");
metalness->uniform = true;
metalness->constSortPos = cspPotentialPrimitive;
Var *specPower = new Var;
specPower->setType( "float" );
specPower->setName( "specularPower" );
specPower->uniform = true;
specPower->constSortPos = cspPotentialPrimitive;
Var *smoothness = new Var("smoothness", "float");
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(" @.a = @/128;\r\n", material, specPower));
meta->addStatement(new GenOp(" @.b = @/5;\r\n", material, specStrength));
output = meta;
}
// Black -> Blue and Alpha of matinfo Buffer (representing no specular), White->G (representing No AO)
void DeferredEmptySpecHLSL::processPix( Vector<ShaderComponent*> &componentList, const MaterialFeatureData &fd )
{
// search for material var
Var *material = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget2));
if (!material)
{
// create color var
material = new Var;
material->setType("fragout");
material->setName(getOutputTargetVarName(ShaderFeature::RenderTarget2));
material->setStructName("OUT");
}
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(" @.ba = 0.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));
output = meta;
}

View file

@ -69,16 +69,4 @@ public:
virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const { return ShaderFeature::RenderTarget2; }
};
class DeferredEmptySpecHLSL : public ShaderFeatureHLSL
{
public:
virtual String getName() { return "Deferred Shading: Empty Specular"; }
virtual void processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd );
virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const { return ShaderFeature::RenderTarget2; }
};
#endif