Core implementation of Physical Based Rendering.

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

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;
}