mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-11 06:34:36 +00:00
Update GLSL Shadergen. Not used on DX9.
This commit is contained in:
parent
ba36617aec
commit
9221b4dd10
20 changed files with 1944 additions and 1128 deletions
|
|
@ -35,16 +35,12 @@
|
|||
void DeferredRTLightingFeatGLSL::processPixMacros( Vector<GFXShaderMacro> ¯os,
|
||||
const MaterialFeatureData &fd )
|
||||
{
|
||||
/// TODO: This needs to be done via some sort of material
|
||||
/// feature and not just allow all translucent elements to
|
||||
/// read from the light prepass.
|
||||
/*
|
||||
if ( fd.features[MFT_IsTranslucent] )
|
||||
// Skip deferred features, and use forward shading instead
|
||||
if ( fd.features[MFT_ForwardShading] )
|
||||
{
|
||||
Parent::processPixMacros( macros, fd );
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
// Pull in the uncondition method for the light info buffer
|
||||
NamedTexTarget *texTarget = NamedTexTarget::find( AdvancedLightBinManager::smBufferName );
|
||||
|
|
@ -59,48 +55,42 @@ void DeferredRTLightingFeatGLSL::processPixMacros( Vector<GFXShaderMacro> ¯o
|
|||
void DeferredRTLightingFeatGLSL::processVert( Vector<ShaderComponent*> &componentList,
|
||||
const MaterialFeatureData &fd )
|
||||
{
|
||||
/// TODO: This needs to be done via some sort of material
|
||||
/// feature and not just allow all translucent elements to
|
||||
/// read from the light prepass.
|
||||
/*
|
||||
if ( fd.features[MFT_IsTranslucent] )
|
||||
// Skip deferred features, and use forward shading instead
|
||||
if ( fd.features[MFT_ForwardShading] )
|
||||
{
|
||||
Parent::processVert( componentList, fd );
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
// Pass screen space position to pixel shader to compute a full screen buffer uv
|
||||
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
|
||||
Var *ssPos = connectComp->getElement( RT_TEXCOORD );
|
||||
ssPos->setName( "screenspacePos" );
|
||||
ssPos->setStructName( "OUT" );
|
||||
ssPos->setType( "vec4" );
|
||||
|
||||
// Var *outPosition = (Var*) LangElement::find( "hpos" );
|
||||
// AssertFatal( outPosition, "No hpos, ohnoes." );
|
||||
Var *outPosition = (Var*) LangElement::find( "gl_Position" );
|
||||
AssertFatal( outPosition, "No gl_Position, ohnoes." );
|
||||
|
||||
output = new GenOp( " @ = gl_Position;\r\n", ssPos );
|
||||
output = new GenOp( " @ = @;\r\n", ssPos, outPosition );
|
||||
}
|
||||
|
||||
void DeferredRTLightingFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
|
||||
const MaterialFeatureData &fd )
|
||||
{
|
||||
/// TODO: This needs to be done via some sort of material
|
||||
/// feature and not just allow all translucent elements to
|
||||
/// read from the light prepass.
|
||||
/*
|
||||
if ( fd.features[MFT_IsTranslucent] )
|
||||
// Skip deferred features, and use forward shading instead
|
||||
if ( fd.features[MFT_ForwardShading] )
|
||||
{
|
||||
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( "vec4" );
|
||||
|
||||
Var *uvScene = new Var;
|
||||
|
|
@ -108,18 +98,20 @@ void DeferredRTLightingFeatGLSL::processPix( Vector<ShaderComponent*> &component
|
|||
uvScene->setName( "uvScene" );
|
||||
LangElement *uvSceneDecl = new DecOp( uvScene );
|
||||
|
||||
Var *rtParams = (Var*) LangElement::find( "renderTargetParams" );
|
||||
String rtParamName = String::ToString( "rtParams%s", "lightInfoBuffer" );
|
||||
Var *rtParams = (Var*) LangElement::find( rtParamName );
|
||||
if( !rtParams )
|
||||
{
|
||||
rtParams = new Var;
|
||||
rtParams->setType( "vec4" );
|
||||
rtParams->setName( "renderTargetParams" );
|
||||
rtParams->setName( rtParamName );
|
||||
rtParams->uniform = true;
|
||||
rtParams->constSortPos = cspPass;
|
||||
}
|
||||
|
||||
meta->addStatement( new GenOp( " @ = @.xy / @.w;\r\n", uvSceneDecl, ssPos, ssPos ) ); // get the screen coord... its -1 to +1
|
||||
meta->addStatement( new GenOp( " @ = ( @ + 1.0 ) / 2.0;\r\n", uvScene, uvScene ) ); // get the screen coord to 0 to 1
|
||||
meta->addStatement( new GenOp( " @.y = 1.0 - @.y;\r\n", uvScene, uvScene ) ); // flip the y axis
|
||||
meta->addStatement( new GenOp( " @ = ( @ * @.zw ) + @.xy;\r\n", uvScene, uvScene, rtParams, rtParams) ); // scale it down and offset it to the rt size
|
||||
|
||||
Var *lightInfoSamp = new Var;
|
||||
|
|
@ -134,36 +126,60 @@ void DeferredRTLightingFeatGLSL::processPix( Vector<ShaderComponent*> &component
|
|||
lightInfoBuffer->sampler = true;
|
||||
lightInfoBuffer->constNum = Var::getTexUnitNum(); // used as texture unit num here
|
||||
|
||||
String unconditionLightInfo = String::ToLower( AdvancedLightBinManager::smBufferName ) + "Uncondition";
|
||||
|
||||
meta->addStatement( new GenOp( " vec3 d_lightcolor;\r\n" ) );
|
||||
meta->addStatement( new GenOp( " float d_NL_Att;\r\n" ) );
|
||||
meta->addStatement( new GenOp( " float d_specular;\r\n" ) );
|
||||
meta->addStatement( new GenOp( avar( " %s(texture2D(@, @), d_lightcolor, d_NL_Att, d_specular);\r\n", unconditionLightInfo.c_str() ),
|
||||
lightInfoBuffer, uvScene ) );
|
||||
// Declare the RTLighting variables in this feature, they will either be assigned
|
||||
// in this feature, or in the tonemap/lightmap feature
|
||||
Var *d_lightcolor = new Var( "d_lightcolor", "vec3" );
|
||||
meta->addStatement( new GenOp( " @;\r\n", new DecOp( d_lightcolor ) ) );
|
||||
|
||||
Var *rtShading = new Var;
|
||||
rtShading->setType( "vec4" );
|
||||
rtShading->setName( "rtShading" );
|
||||
LangElement *rtShadingDecl = new DecOp( rtShading );
|
||||
meta->addStatement( new GenOp( " @ = vec4( d_lightcolor, 1.0 );\r\n", rtShadingDecl ) );
|
||||
Var *d_NL_Att = new Var( "d_NL_Att", "float" );
|
||||
meta->addStatement( new GenOp( " @;\r\n", new DecOp( d_NL_Att ) ) );
|
||||
|
||||
Var *d_specular = new Var( "d_specular", "float" );
|
||||
meta->addStatement( new GenOp( " @;\r\n", new DecOp( d_specular ) ) );
|
||||
|
||||
|
||||
// Perform the uncondition here.
|
||||
String unconditionLightInfo = String::ToLower( AdvancedLightBinManager::smBufferName ) + "Uncondition";
|
||||
meta->addStatement( new GenOp( avar( " %s(tex2D(@, @), @, @, @);\r\n",
|
||||
unconditionLightInfo.c_str() ), lightInfoBuffer, uvScene, d_lightcolor, d_NL_Att, d_specular ) );
|
||||
|
||||
// If this has an interlaced pre-pass, do averaging here
|
||||
if( fd.features[MFT_InterlacedPrePass] )
|
||||
{
|
||||
Var *oneOverTargetSize = (Var*) LangElement::find( "oneOverTargetSize" );
|
||||
if( !oneOverTargetSize )
|
||||
{
|
||||
oneOverTargetSize = new Var;
|
||||
oneOverTargetSize->setType( "vec2" );
|
||||
oneOverTargetSize->setName( "oneOverTargetSize" );
|
||||
oneOverTargetSize->uniform = true;
|
||||
oneOverTargetSize->constSortPos = cspPass;
|
||||
}
|
||||
|
||||
meta->addStatement( new GenOp( " float id_NL_Att, id_specular;\r\n float3 id_lightcolor;\r\n" ) );
|
||||
meta->addStatement( new GenOp( avar( " %s(tex2D(@, @ + float2(0.0, @.y)), id_lightcolor, id_NL_Att, id_specular);\r\n",
|
||||
unconditionLightInfo.c_str() ), lightInfoBuffer, uvScene, oneOverTargetSize ) );
|
||||
|
||||
meta->addStatement( new GenOp(" @ = lerp(@, id_lightcolor, 0.5);\r\n", d_lightcolor, d_lightcolor ) );
|
||||
meta->addStatement( new GenOp(" @ = lerp(@, id_NL_Att, 0.5);\r\n", d_NL_Att, d_NL_Att ) );
|
||||
meta->addStatement( new GenOp(" @ = lerp(@, id_specular, 0.5);\r\n", d_specular, d_specular ) );
|
||||
}
|
||||
|
||||
// This is kind of weak sauce
|
||||
if( !fd.features[MFT_SubSurface] && !fd.features[MFT_ToneMap] && !fd.features[MFT_LightMap] )
|
||||
meta->addStatement( new GenOp( " @;\r\n", assignColor( rtShading, Material::Mul ) ) );
|
||||
if( !fd.features[MFT_VertLit] && !fd.features[MFT_ToneMap] && !fd.features[MFT_LightMap] && !fd.features[MFT_SubSurface] )
|
||||
meta->addStatement( new GenOp( " @;\r\n", assignColor( new GenOp( "float4(@, 1.0)", d_lightcolor ), Material::Mul ) ) );
|
||||
|
||||
output = meta;
|
||||
}
|
||||
|
||||
ShaderFeature::Resources DeferredRTLightingFeatGLSL::getResources( const MaterialFeatureData &fd )
|
||||
{
|
||||
/// TODO: This needs to be done via some sort of material
|
||||
/// feature and not just allow all translucent elements to
|
||||
/// read from the light prepass.
|
||||
/*
|
||||
if( fd.features[MFT_IsTranslucent] )
|
||||
// Skip deferred features, and use forward shading instead
|
||||
if ( fd.features[MFT_ForwardShading] )
|
||||
return Parent::getResources( fd );
|
||||
*/
|
||||
|
||||
// HACK: See DeferredRTLightingFeatGLSL::setTexData.
|
||||
mLastTexIndex = 0;
|
||||
|
||||
Resources res;
|
||||
res.numTex = 1;
|
||||
|
|
@ -176,21 +192,22 @@ void DeferredRTLightingFeatGLSL::setTexData( Material::StageData &stageDat,
|
|||
RenderPassData &passData,
|
||||
U32 &texIndex )
|
||||
{
|
||||
/// TODO: This needs to be done via some sort of material
|
||||
/// feature and not just allow all translucent elements to
|
||||
/// read from the light prepass.
|
||||
/*
|
||||
if( fd.features[MFT_IsTranslucent] )
|
||||
// Skip deferred features, and use forward shading instead
|
||||
if ( fd.features[MFT_ForwardShading] )
|
||||
{
|
||||
Parent::setTexData( stageDat, fd, passData, texIndex );
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
NamedTexTarget *texTarget = NamedTexTarget::find( AdvancedLightBinManager::smBufferName );
|
||||
if( texTarget )
|
||||
{
|
||||
passData.mTexType[ texIndex ] = Material::TexTarget;
|
||||
// HACK: We store this for use in DeferredRTLightingFeatGLSL::processPix()
|
||||
// which cannot deduce the texture unit itself.
|
||||
mLastTexIndex = texIndex;
|
||||
|
||||
passData.mTexType[ texIndex ] = Material::TexTarget;
|
||||
passData.mSamplerNames[ texIndex ]= "lightInfoBuffer";
|
||||
passData.mTexSlot[ texIndex++ ].texTarget = texTarget;
|
||||
}
|
||||
}
|
||||
|
|
@ -205,92 +222,31 @@ void DeferredBumpFeatGLSL::processVert( Vector<ShaderComponent*> &componentLis
|
|||
// to the pixel shader.
|
||||
MultiLine *meta = new MultiLine;
|
||||
|
||||
// setup texture space matrix
|
||||
Var *texSpaceMat = (Var*) LangElement::find( "objToTangentSpace" );
|
||||
if( !texSpaceMat )
|
||||
{
|
||||
LangElement * texSpaceSetup = setupTexSpaceMat( componentList, &texSpaceMat );
|
||||
meta->addStatement( texSpaceSetup );
|
||||
texSpaceMat = (Var*) LangElement::find( "objToTangentSpace" );
|
||||
}
|
||||
|
||||
// turn obj->tangent into world->tangent
|
||||
Var *worldToTangent = new Var;
|
||||
worldToTangent->setType( "mat3" );
|
||||
worldToTangent->setName( "worldToTangent" );
|
||||
LangElement *worldToTangentDecl = new DecOp( worldToTangent );
|
||||
|
||||
// Get the world->obj transform
|
||||
Var *worldToObj = new Var;
|
||||
worldToObj->setType( "mat4" );
|
||||
worldToObj->setName( "worldToObj" );
|
||||
worldToObj->uniform = true;
|
||||
worldToObj->constSortPos = cspPrimitive;
|
||||
|
||||
Var *mat3Conversion = new Var;
|
||||
mat3Conversion->setType( "mat3" );
|
||||
mat3Conversion->setName( "worldToObjMat3" );
|
||||
LangElement* mat3Lang = new DecOp(mat3Conversion);
|
||||
meta->addStatement( new GenOp( " @ = mat3(@[0].xyz, @[1].xyz, @[2].xyz);\r\n ", mat3Lang, worldToObj, worldToObj, worldToObj) );
|
||||
|
||||
// assign world->tangent transform
|
||||
meta->addStatement( new GenOp( " @ = @ * @;\r\n", worldToTangentDecl, texSpaceMat, mat3Conversion ) );
|
||||
|
||||
// send transform to pixel shader
|
||||
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
|
||||
|
||||
Var *worldToTangentR1 = connectComp->getElement( RT_TEXCOORD );
|
||||
worldToTangentR1->setName( "worldToTangentR1" );
|
||||
worldToTangentR1->setType( "vec3" );
|
||||
meta->addStatement( new GenOp( " @ = @[0];\r\n", worldToTangentR1, worldToTangent ) );
|
||||
|
||||
Var *worldToTangentR2 = connectComp->getElement( RT_TEXCOORD );
|
||||
worldToTangentR2->setName( "worldToTangentR2" );
|
||||
worldToTangentR2->setType( "vec3" );
|
||||
meta->addStatement( new GenOp( " @ = @[1];\r\n", worldToTangentR2, worldToTangent ) );
|
||||
|
||||
Var *worldToTangentR3 = connectComp->getElement( RT_TEXCOORD );
|
||||
worldToTangentR3->setName( "worldToTangentR3" );
|
||||
worldToTangentR3->setType( "vec3" );
|
||||
meta->addStatement( new GenOp( " @ = @[2];\r\n", worldToTangentR3, worldToTangent ) );
|
||||
// We need the view to tangent space transform in the pixel shader.
|
||||
getOutViewToTangent( componentList, meta, fd );
|
||||
|
||||
// Make sure there are texcoords
|
||||
if( !fd.features[MFT_DiffuseMap] )
|
||||
if( !fd.features[MFT_Parallax] && !fd.features[MFT_DiffuseMap] )
|
||||
{
|
||||
// find incoming texture var
|
||||
Var *inTex = getVertTexCoord( "texCoord" );
|
||||
const bool useTexAnim = fd.features[MFT_TexAnim];
|
||||
|
||||
// grab connector texcoord register
|
||||
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
|
||||
Var *outTex = connectComp->getElement( RT_TEXCOORD );
|
||||
outTex->setName( "outTexCoord" );
|
||||
outTex->setType( "vec2" );
|
||||
outTex->mapsToSampler = true;
|
||||
getOutTexCoord( "texCoord",
|
||||
"vec2",
|
||||
true,
|
||||
useTexAnim,
|
||||
meta,
|
||||
componentList );
|
||||
|
||||
if( fd.features[MFT_TexAnim] )
|
||||
{
|
||||
inTex->setType( "vec4" );
|
||||
|
||||
// create texture mat var
|
||||
Var *texMat = new Var;
|
||||
texMat->setType( "mat4" );
|
||||
texMat->setName( "texMat" );
|
||||
texMat->uniform = true;
|
||||
texMat->constSortPos = cspPotentialPrimitive;
|
||||
|
||||
meta->addStatement( new GenOp( " @ = @ * @;\r\n", outTex, texMat, inTex ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
// setup language elements to output incoming tex coords to output
|
||||
meta->addStatement( new GenOp( " @ = @;\r\n", outTex, inTex ) );
|
||||
}
|
||||
if ( fd.features.hasFeature( MFT_DetailNormalMap ) )
|
||||
addOutDetailTexCoord( componentList,
|
||||
meta,
|
||||
useTexAnim );
|
||||
}
|
||||
|
||||
output = meta;
|
||||
}
|
||||
else if ( fd.materialFeatures[MFT_NormalsOut] ||
|
||||
fd.features[MFT_IsTranslucent] ||
|
||||
fd.features[MFT_ForwardShading] ||
|
||||
!fd.features[MFT_RTLighting] )
|
||||
{
|
||||
Parent::processVert( componentList, fd );
|
||||
|
|
@ -312,52 +268,12 @@ void DeferredBumpFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
|
|||
{
|
||||
MultiLine *meta = new MultiLine;
|
||||
|
||||
// Pull the world->tangent transform from the vertex shader
|
||||
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
|
||||
|
||||
Var *worldToTangentR1 = connectComp->getElement( RT_TEXCOORD );
|
||||
worldToTangentR1->setName( "worldToTangentR1" );
|
||||
worldToTangentR1->setType( "vec3" );
|
||||
|
||||
Var *worldToTangentR2 = connectComp->getElement( RT_TEXCOORD );
|
||||
worldToTangentR2->setName( "worldToTangentR2" );
|
||||
worldToTangentR2->setType( "vec3" );
|
||||
|
||||
Var *worldToTangentR3 = connectComp->getElement( RT_TEXCOORD );
|
||||
worldToTangentR3->setName( "worldToTangentR3" );
|
||||
worldToTangentR3->setType( "vec3" );
|
||||
|
||||
Var *worldToTangent = new Var;
|
||||
worldToTangent->setType( "mat3" );
|
||||
worldToTangent->setName( "worldToTangent" );
|
||||
LangElement *worldToTangentDecl = new DecOp( worldToTangent );
|
||||
|
||||
// Build world->tangent matrix
|
||||
meta->addStatement( new GenOp( " @;\r\n", worldToTangentDecl ) );
|
||||
meta->addStatement( new GenOp( " @[0] = @;\r\n", worldToTangent, worldToTangentR1 ) );
|
||||
meta->addStatement( new GenOp( " @[1] = @;\r\n", worldToTangent, worldToTangentR2 ) );
|
||||
meta->addStatement( new GenOp( " @[2] = @;\r\n", worldToTangent, worldToTangentR3 ) );
|
||||
Var *viewToTangent = getInViewToTangent( componentList );
|
||||
|
||||
// create texture var
|
||||
Var *bumpMap = new Var;
|
||||
bumpMap->setType( "sampler2D" );
|
||||
bumpMap->setName( "bumpMap" );
|
||||
bumpMap->uniform = true;
|
||||
bumpMap->sampler = true;
|
||||
bumpMap->constNum = Var::getTexUnitNum(); // used as texture unit num here
|
||||
|
||||
Var *texCoord = (Var*) LangElement::find( "outTexCoord" );
|
||||
if( !texCoord )
|
||||
{
|
||||
// grab connector texcoord register
|
||||
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
|
||||
texCoord = connectComp->getElement( RT_TEXCOORD );
|
||||
texCoord->setName( "outTexCoord" );
|
||||
texCoord->setType( "vec2" );
|
||||
texCoord->mapsToSampler = true;
|
||||
}
|
||||
|
||||
LangElement * texOp = new GenOp( "texture2D(@, @)", bumpMap, texCoord );
|
||||
Var *bumpMap = getNormalMapTex();
|
||||
Var *texCoord = getInTexCoord( "texCoord", "vec2", true, componentList );
|
||||
LangElement *texOp = new GenOp( "tex2D(@, @)", bumpMap, texCoord );
|
||||
|
||||
// create bump normal
|
||||
Var *bumpNorm = new Var;
|
||||
|
|
@ -367,56 +283,75 @@ void DeferredBumpFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
|
|||
LangElement *bumpNormDecl = new DecOp( bumpNorm );
|
||||
meta->addStatement( expandNormalMap( texOp, bumpNormDecl, bumpNorm, fd ) );
|
||||
|
||||
// If we have a detail normal map we add the xy coords of
|
||||
// it to the base normal map. This gives us the effect we
|
||||
// want with few instructions and minial artifacts.
|
||||
if ( fd.features.hasFeature( MFT_DetailNormalMap ) )
|
||||
{
|
||||
bumpMap = new Var;
|
||||
bumpMap->setType( "sampler2D" );
|
||||
bumpMap->setName( "detailBumpMap" );
|
||||
bumpMap->uniform = true;
|
||||
bumpMap->sampler = true;
|
||||
bumpMap->constNum = Var::getTexUnitNum();
|
||||
|
||||
texCoord = getInTexCoord( "detCoord", "vec2", true, componentList );
|
||||
texOp = new GenOp( "tex2D(@, @)", bumpMap, texCoord );
|
||||
|
||||
Var *detailBump = new Var;
|
||||
detailBump->setName( "detailBump" );
|
||||
detailBump->setType( "vec4" );
|
||||
meta->addStatement( expandNormalMap( texOp, new DecOp( detailBump ), detailBump, fd ) );
|
||||
|
||||
Var *detailBumpScale = new Var;
|
||||
detailBumpScale->setType( "float" );
|
||||
detailBumpScale->setName( "detailBumpStrength" );
|
||||
detailBumpScale->uniform = true;
|
||||
detailBumpScale->constSortPos = cspPass;
|
||||
meta->addStatement( new GenOp( " @.xy += @.xy * @;\r\n", bumpNorm, detailBump, detailBumpScale ) );
|
||||
}
|
||||
|
||||
// This var is read from GBufferConditionerHLSL and
|
||||
// used in the prepass output.
|
||||
//
|
||||
// By using the 'half' type here we get a bunch of partial
|
||||
// precision optimized code on further operations on the normal
|
||||
// which helps alot on older Geforce cards.
|
||||
//
|
||||
Var *gbNormal = new Var;
|
||||
gbNormal->setName( "gbNormal" );
|
||||
gbNormal->setType( "vec3" );
|
||||
gbNormal->setType( "half3" );
|
||||
LangElement *gbNormalDecl = new DecOp( gbNormal );
|
||||
|
||||
// Normalize is done later...
|
||||
// Note: The reverse mul order is intentional. Affine matrix.
|
||||
meta->addStatement( new GenOp( " @ = @.xyz * @;\r\n", gbNormalDecl, bumpNorm, worldToTangent ) );
|
||||
meta->addStatement( new GenOp( " @ = half3(tMul( @.xyz, @ ));\r\n", gbNormalDecl, bumpNorm, viewToTangent ) );
|
||||
|
||||
output = meta;
|
||||
return;
|
||||
}
|
||||
else if ( fd.materialFeatures[MFT_NormalsOut] ||
|
||||
fd.features[MFT_IsTranslucent] ||
|
||||
fd.features[MFT_ForwardShading] ||
|
||||
!fd.features[MFT_RTLighting] )
|
||||
{
|
||||
Parent::processPix( componentList, fd );
|
||||
return;
|
||||
}
|
||||
else if ( fd.features[MFT_PixSpecular] )
|
||||
else if ( fd.features[MFT_PixSpecular] && !fd.features[MFT_SpecularMap] )
|
||||
{
|
||||
Var *bumpSample = (Var *)LangElement::find( "bumpSample" );
|
||||
if( bumpSample == NULL )
|
||||
{
|
||||
Var *texCoord = (Var*) LangElement::find( "outTexCoord" );
|
||||
if( !texCoord )
|
||||
{
|
||||
// grab connector texcoord register
|
||||
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
|
||||
texCoord = connectComp->getElement( RT_TEXCOORD );
|
||||
texCoord->setName( "outTexCoord" );
|
||||
texCoord->setType( "vec2" );
|
||||
texCoord->mapsToSampler = true;
|
||||
}
|
||||
Var *texCoord = getInTexCoord( "texCoord", "vec2", true, componentList );
|
||||
|
||||
Var *bumpMap = new Var;
|
||||
bumpMap->setType( "sampler2D" );
|
||||
bumpMap->setName( "bumpMap" );
|
||||
bumpMap->uniform = true;
|
||||
bumpMap->sampler = true;
|
||||
bumpMap->constNum = Var::getTexUnitNum(); // used as texture unit num here
|
||||
Var *bumpMap = getNormalMapTex();
|
||||
|
||||
bumpSample = new Var;
|
||||
bumpSample->setType( "vec4" );
|
||||
bumpSample->setName( "bumpSample" );
|
||||
LangElement *bumpSampleDecl = new DecOp( bumpSample );
|
||||
|
||||
output = new GenOp( " @ = texture2D(@, @);\r\n", bumpSampleDecl, bumpMap, texCoord );
|
||||
output = new GenOp( " @ = tex2D(@, @);\r\n", bumpSampleDecl, bumpMap, texCoord );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -427,7 +362,7 @@ void DeferredBumpFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
|
|||
ShaderFeature::Resources DeferredBumpFeatGLSL::getResources( const MaterialFeatureData &fd )
|
||||
{
|
||||
if ( fd.materialFeatures[MFT_NormalsOut] ||
|
||||
fd.features[MFT_IsTranslucent] ||
|
||||
fd.features[MFT_ForwardShading] ||
|
||||
fd.features[MFT_Parallax] ||
|
||||
!fd.features[MFT_RTLighting] )
|
||||
return Parent::getResources( fd );
|
||||
|
|
@ -437,7 +372,16 @@ ShaderFeature::Resources DeferredBumpFeatGLSL::getResources( const MaterialFeatu
|
|||
{
|
||||
res.numTex = 1;
|
||||
res.numTexReg = 1;
|
||||
|
||||
if ( fd.features[MFT_PrePassConditioner] &&
|
||||
fd.features.hasFeature( MFT_DetailNormalMap ) )
|
||||
{
|
||||
res.numTex += 1;
|
||||
if ( !fd.features.hasFeature( MFT_DetailMap ) )
|
||||
res.numTexReg += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
@ -447,21 +391,28 @@ void DeferredBumpFeatGLSL::setTexData( Material::StageData &stageDat,
|
|||
U32 &texIndex )
|
||||
{
|
||||
if ( fd.materialFeatures[MFT_NormalsOut] ||
|
||||
fd.features[MFT_IsTranslucent] ||
|
||||
fd.features[MFT_ForwardShading] ||
|
||||
!fd.features[MFT_RTLighting] )
|
||||
{
|
||||
Parent::setTexData( stageDat, fd, passData, texIndex );
|
||||
return;
|
||||
}
|
||||
|
||||
GFXTextureObject *normalMap = stageDat.getTex( MFT_NormalMap );
|
||||
if ( !fd.features[MFT_Parallax] && !fd.features[MFT_SpecularMap] &&
|
||||
( fd.features[MFT_PrePassConditioner] ||
|
||||
fd.features[MFT_PixSpecular] ) &&
|
||||
normalMap )
|
||||
fd.features[MFT_PixSpecular] ) )
|
||||
{
|
||||
passData.mTexType[ texIndex ] = Material::Bump;
|
||||
passData.mTexSlot[ texIndex++ ].texObject = normalMap;
|
||||
passData.mSamplerNames[ texIndex ] = "bumpMap";
|
||||
passData.mTexSlot[ texIndex++ ].texObject = stageDat.getTex( MFT_NormalMap );
|
||||
|
||||
if ( fd.features[MFT_PrePassConditioner] &&
|
||||
fd.features.hasFeature( MFT_DetailNormalMap ) )
|
||||
{
|
||||
passData.mTexType[ texIndex ] = Material::DetailBump;
|
||||
passData.mSamplerNames[ texIndex ] = "detailBumpMap";
|
||||
passData.mTexSlot[ texIndex++ ].texObject = stageDat.getTex( MFT_DetailNormalMap );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -469,7 +420,7 @@ void DeferredBumpFeatGLSL::setTexData( Material::StageData &stageDat,
|
|||
void DeferredPixelSpecularGLSL::processVert( Vector<ShaderComponent*> &componentList,
|
||||
const MaterialFeatureData &fd )
|
||||
{
|
||||
if( fd.features[MFT_IsTranslucent] || !fd.features[MFT_RTLighting] )
|
||||
if( fd.features[MFT_ForwardShading] || !fd.features[MFT_RTLighting] )
|
||||
{
|
||||
Parent::processVert( componentList, fd );
|
||||
return;
|
||||
|
|
@ -480,7 +431,7 @@ void DeferredPixelSpecularGLSL::processVert( Vector<ShaderComponent*> &component
|
|||
void DeferredPixelSpecularGLSL::processPix( Vector<ShaderComponent*> &componentList,
|
||||
const MaterialFeatureData &fd )
|
||||
{
|
||||
if( fd.features[MFT_IsTranslucent] || !fd.features[MFT_RTLighting] )
|
||||
if( fd.features[MFT_ForwardShading] || !fd.features[MFT_RTLighting] )
|
||||
{
|
||||
Parent::processPix( componentList, fd );
|
||||
return;
|
||||
|
|
@ -523,19 +474,18 @@ void DeferredPixelSpecularGLSL::processPix( Vector<ShaderComponent*> &component
|
|||
specStrength->uniform = true;
|
||||
specStrength->constSortPos = cspPotentialPrimitive;
|
||||
|
||||
Var *constSpecPow = new Var;
|
||||
constSpecPow->setType( "float" );
|
||||
constSpecPow->setName( "constantSpecularPower" );
|
||||
constSpecPow->uniform = true;
|
||||
constSpecPow->constSortPos = cspPass;
|
||||
|
||||
Var *lightInfoSamp = (Var *)LangElement::find( "lightInfoSample" );
|
||||
AssertFatal( lightInfoSamp, "Something hosed the deferred features! Can't find lightInfoSample" );
|
||||
Var *d_specular = (Var*)LangElement::find( "d_specular" );
|
||||
Var *d_NL_Att = (Var*)LangElement::find( "d_NL_Att" );
|
||||
|
||||
AssertFatal( lightInfoSamp && d_specular && d_NL_Att,
|
||||
"DeferredPixelSpecularGLSL::processPix - Something hosed the deferred features!" );
|
||||
|
||||
// (a^m)^n = a^(m*n)
|
||||
meta->addStatement( new GenOp( " @ = pow(d_specular, ceil(@ / @)) * @;\r\n", specDecl, specPow, constSpecPow, specStrength ) );
|
||||
meta->addStatement( new GenOp( " @ = pow( abs(@), max((@ / AL_ConstantSpecularPower),1.0f)) * @;\r\n",
|
||||
specDecl, d_specular, specPow, specStrength ) );
|
||||
|
||||
LangElement *specMul = new GenOp( "@ * @", specCol, specular );
|
||||
LangElement *specMul = new GenOp( "float4( @.rgb, 0 ) * @", specCol, specular );
|
||||
LangElement *final = specMul;
|
||||
|
||||
// We we have a normal map then mask the specular
|
||||
|
|
@ -545,14 +495,15 @@ void DeferredPixelSpecularGLSL::processPix( Vector<ShaderComponent*> &component
|
|||
final = new GenOp( "@ * @.a", final, bumpSample );
|
||||
}
|
||||
|
||||
// add to color meta->addStatement( new GenOp( " @;\r\n", assignColor( final, Material::Add ) ) );
|
||||
// add to color
|
||||
meta->addStatement( new GenOp( " @;\r\n", assignColor( final, Material::Add ) ) );
|
||||
|
||||
output = meta;
|
||||
}
|
||||
|
||||
ShaderFeature::Resources DeferredPixelSpecularGLSL::getResources( const MaterialFeatureData &fd )
|
||||
{
|
||||
if( fd.features[MFT_IsTranslucent] || !fd.features[MFT_RTLighting] )
|
||||
if( fd.features[MFT_ForwardShading] || !fd.features[MFT_RTLighting] )
|
||||
return Parent::getResources( fd );
|
||||
|
||||
Resources res;
|
||||
|
|
@ -563,7 +514,7 @@ ShaderFeature::Resources DeferredPixelSpecularGLSL::getResources( const Material
|
|||
ShaderFeature::Resources DeferredMinnaertGLSL::getResources( const MaterialFeatureData &fd )
|
||||
{
|
||||
Resources res;
|
||||
if( !fd.features[MFT_IsTranslucent] && fd.features[MFT_RTLighting] )
|
||||
if( !fd.features[MFT_ForwardShading] && fd.features[MFT_RTLighting] )
|
||||
{
|
||||
res.numTex = 1;
|
||||
res.numTexReg = 1;
|
||||
|
|
@ -576,7 +527,7 @@ void DeferredMinnaertGLSL::setTexData( Material::StageData &stageDat,
|
|||
RenderPassData &passData,
|
||||
U32 &texIndex )
|
||||
{
|
||||
if( !fd.features[MFT_IsTranslucent] && fd.features[MFT_RTLighting] )
|
||||
if( !fd.features[MFT_ForwardShading] && fd.features[MFT_RTLighting] )
|
||||
{
|
||||
NamedTexTarget *texTarget = NamedTexTarget::find(RenderPrePassMgr::BufferName);
|
||||
if ( texTarget )
|
||||
|
|
@ -590,7 +541,7 @@ void DeferredMinnaertGLSL::setTexData( Material::StageData &stageDat,
|
|||
void DeferredMinnaertGLSL::processPixMacros( Vector<GFXShaderMacro> ¯os,
|
||||
const MaterialFeatureData &fd )
|
||||
{
|
||||
if( !fd.features[MFT_IsTranslucent] && fd.features[MFT_RTLighting] )
|
||||
if( !fd.features[MFT_ForwardShading] && fd.features[MFT_RTLighting] )
|
||||
{
|
||||
// Pull in the uncondition method for the g buffer
|
||||
NamedTexTarget *texTarget = NamedTexTarget::find( RenderPrePassMgr::BufferName );
|
||||
|
|
@ -607,55 +558,24 @@ void DeferredMinnaertGLSL::processVert( Vector<ShaderComponent*> &componentLis
|
|||
const MaterialFeatureData &fd )
|
||||
{
|
||||
// If there is no deferred information, bail on this feature
|
||||
if( fd.features[MFT_IsTranslucent] || !fd.features[MFT_RTLighting] )
|
||||
if( fd.features[MFT_ForwardShading] || !fd.features[MFT_RTLighting] )
|
||||
{
|
||||
output = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
// grab incoming vert position
|
||||
Var *inVertPos = (Var*) LangElement::find( "position" );
|
||||
AssertFatal( inVertPos, "Something went bad with ShaderGen. The vertex position should be already defined." );
|
||||
|
||||
// grab output for gbuffer normal
|
||||
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
|
||||
Var *outWSEyeVec= connectComp->getElement( RT_TEXCOORD );
|
||||
outWSEyeVec->setName( "outWSViewVec" );
|
||||
outWSEyeVec->setType( "vec4" );
|
||||
|
||||
// create objToWorld variable
|
||||
Var *objToWorld = (Var*) LangElement::find( "objTrans" );
|
||||
if( !objToWorld )
|
||||
{
|
||||
objToWorld = new Var;
|
||||
objToWorld->setType( "mat4x4" );
|
||||
objToWorld->setName( "objTrans" );
|
||||
objToWorld->uniform = true;
|
||||
objToWorld->constSortPos = cspPrimitive;
|
||||
}
|
||||
|
||||
// Eye Pos world
|
||||
Var *eyePosWorld = (Var*) LangElement::find( "eyePosWorld" );
|
||||
if( !eyePosWorld )
|
||||
{
|
||||
eyePosWorld = new Var;
|
||||
eyePosWorld->setType( "vec3" );
|
||||
eyePosWorld->setName( "eyePosWorld" );
|
||||
eyePosWorld->uniform = true;
|
||||
eyePosWorld->constSortPos = cspPass;
|
||||
}
|
||||
|
||||
// Kick out the world-space normal
|
||||
LangElement *statement = new GenOp( " @ = vec4(@, @) - vec4(@, 0.0);\r\n",
|
||||
outWSEyeVec, objToWorld, inVertPos, eyePosWorld );
|
||||
output = statement;
|
||||
// Make sure we pass the world space position to the
|
||||
// pixel shader so we can calculate a view vector.
|
||||
MultiLine *meta = new MultiLine;
|
||||
addOutWsPosition( componentList, fd.features[MFT_UseInstancing], meta );
|
||||
output = meta;
|
||||
}
|
||||
|
||||
void DeferredMinnaertGLSL::processPix( Vector<ShaderComponent*> &componentList,
|
||||
const MaterialFeatureData &fd )
|
||||
{
|
||||
// If there is no deferred information, bail on this feature
|
||||
if( fd.features[MFT_IsTranslucent] || !fd.features[MFT_RTLighting] )
|
||||
if( fd.features[MFT_ForwardShading] || !fd.features[MFT_RTLighting] )
|
||||
{
|
||||
output = NULL;
|
||||
return;
|
||||
|
|
@ -679,25 +599,19 @@ void DeferredMinnaertGLSL::processPix( Vector<ShaderComponent*> &componentList,
|
|||
Var *uvScene = (Var*) LangElement::find( "uvScene" );
|
||||
AssertFatal(uvScene != NULL, "Unable to find UVScene, no RTLighting feature?");
|
||||
|
||||
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
|
||||
Var *wsViewVec = (Var*) LangElement::find( "wsPos" );
|
||||
if( !wsViewVec )
|
||||
{
|
||||
wsViewVec = connectComp->getElement( RT_TEXCOORD );
|
||||
wsViewVec->setName( "outWSViewVec" );
|
||||
wsViewVec->setType( "vec4" );
|
||||
wsViewVec->mapsToSampler = false;
|
||||
wsViewVec->uniform = false;
|
||||
}
|
||||
MultiLine *meta = new MultiLine;
|
||||
|
||||
// Get the world space view vector.
|
||||
Var *wsViewVec = getWsView( getInWsPosition( componentList ), meta );
|
||||
|
||||
String unconditionPrePassMethod = String::ToLower(RenderPrePassMgr::BufferName) + "Uncondition";
|
||||
|
||||
MultiLine *meta = new MultiLine;
|
||||
meta->addStatement( new GenOp( avar( " vec4 normalDepth = %s(texture2D(@, @));\r\n", unconditionPrePassMethod.c_str() ), prepassBuffer, uvScene ) );
|
||||
meta->addStatement( new GenOp( " vec3 worldViewVec = normalize(@.xyz / @.w);\r\n", wsViewVec, wsViewVec ) );
|
||||
meta->addStatement( new GenOp( " float vDotN = dot(normalDepth.xyz, worldViewVec);\r\n" ) );
|
||||
meta->addStatement( new GenOp( " float Minnaert = pow(d_NL_Att, @) * pow(vDotN, 1.0 - @);\r\n", minnaertConstant, minnaertConstant ) );
|
||||
meta->addStatement( new GenOp( " @;\r\n", assignColor( new GenOp( "vec4(Minnaert, Minnaert, Minnaert, 1.0)" ), Material::Mul ) ) );
|
||||
Var *d_NL_Att = (Var*)LangElement::find( "d_NL_Att" );
|
||||
|
||||
meta->addStatement( new GenOp( avar( " float4 normalDepth = %s(@, @);\r\n", unconditionPrePassMethod.c_str() ), prepassBuffer, uvScene ) );
|
||||
meta->addStatement( new GenOp( " float vDotN = dot(normalDepth.xyz, @);\r\n", wsViewVec ) );
|
||||
meta->addStatement( new GenOp( " float Minnaert = pow( @, @) * pow(vDotN, 1.0 - @);\r\n", d_NL_Att, minnaertConstant, minnaertConstant ) );
|
||||
meta->addStatement( new GenOp( " @;\r\n", assignColor( new GenOp( "float4(Minnaert, Minnaert, Minnaert, 1.0)" ), Material::Mul ) ) );
|
||||
|
||||
output = meta;
|
||||
}
|
||||
|
|
@ -707,7 +621,7 @@ void DeferredSubSurfaceGLSL::processPix( Vector<ShaderComponent*> &componentLis
|
|||
const MaterialFeatureData &fd )
|
||||
{
|
||||
// If there is no deferred information, bail on this feature
|
||||
if( fd.features[MFT_IsTranslucent] || !fd.features[MFT_RTLighting] )
|
||||
if( fd.features[MFT_ForwardShading] || !fd.features[MFT_RTLighting] )
|
||||
{
|
||||
output = NULL;
|
||||
return;
|
||||
|
|
@ -719,12 +633,13 @@ void DeferredSubSurfaceGLSL::processPix( Vector<ShaderComponent*> &componentLis
|
|||
subSurfaceParams->uniform = true;
|
||||
subSurfaceParams->constSortPos = cspPotentialPrimitive;
|
||||
|
||||
Var *inColor = (Var*) LangElement::find( "rtShading" );
|
||||
Var *d_lightcolor = (Var*)LangElement::find( "d_lightcolor" );
|
||||
Var *d_NL_Att = (Var*)LangElement::find( "d_NL_Att" );
|
||||
|
||||
MultiLine *meta = new MultiLine;
|
||||
meta->addStatement( new GenOp( " float subLamb = smoothstep(-@.a, 1.0, d_NL_Att) - smoothstep(0.0, 1.0, d_NL_Att);\r\n", subSurfaceParams ) );
|
||||
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(@.rgb + (subLamb * @.rgb), 1.0)", inColor, subSurfaceParams ), Material::Mul ) ) );
|
||||
meta->addStatement( new GenOp( " @;\r\n", assignColor( new GenOp( "float4(@ + (subLamb * @.rgb), 1.0)", d_lightcolor, subSurfaceParams ), Material::Mul ) ) );
|
||||
|
||||
output = meta;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue