Implementation of reflection and skylight probes.

Moves lighting math to the diffuse/specular two-channel logic.
This commit is contained in:
Areloch 2018-09-16 22:15:07 -05:00
parent 83dd55e851
commit 2be32ad737
102 changed files with 12346 additions and 1911 deletions

View file

@ -49,6 +49,7 @@ namespace
FEATUREMGR->registerFeature( MFT_TerrainLightMap, new TerrainLightMapFeatGLSL );
FEATUREMGR->registerFeature( MFT_TerrainSideProject, new NamedFeatureGLSL( "Terrain Side Projection" ) );
FEATUREMGR->registerFeature( MFT_TerrainAdditive, new TerrainAdditiveFeatGLSL );
FEATUREMGR->registerFeature( MFT_TerrainCompositeMap, new TerrainCompositeMapFeatGLSL );
FEATUREMGR->registerFeature( MFT_DeferredTerrainBlankInfoMap, new TerrainBlankInfoMapFeatGLSL );
}
@ -141,6 +142,24 @@ Var* TerrainFeatGLSL::_getNormalMapTex()
return normalMap;
}
Var* TerrainFeatGLSL::_getCompositeMapTex()
{
String name(String::ToString("compositeMap%d", getProcessIndex()));
Var *compositeMap = (Var*)LangElement::find(name);
if (!compositeMap)
{
compositeMap = new Var;
compositeMap->setType("sampler2D");
compositeMap->setName(name);
compositeMap->uniform = true;
compositeMap->sampler = true;
compositeMap->constNum = Var::getTexUnitNum();
}
return compositeMap;
}
Var* TerrainFeatGLSL::_getDetailIdStrengthParallax()
{
String name( String::ToString( "detailIdStrengthParallax%d", getProcessIndex() ) );
@ -203,7 +222,7 @@ void TerrainBaseMapFeatGLSL::processVert( Vector<ShaderComponent*> &componentLis
// So instead i fixed this by flipping the base and detail
// coord y scale to compensate when rendering.
//
meta->addStatement( new GenOp( " @ = @.xyz * float3( @, @, -@ );\r\n",
meta->addStatement( new GenOp( " @ = @.xyz * vec3( @, @, -@ );\r\n",
new DecOp( inTex ), inPos, oneOverTerrainSize, oneOverTerrainSize, oneOverTerrainSize ) );
}
@ -223,7 +242,7 @@ void TerrainBaseMapFeatGLSL::processVert( Vector<ShaderComponent*> &componentLis
{
Var *inNormal = (Var*)LangElement::find( "normal" );
meta->addStatement(
new GenOp( " @.z = pow( abs( dot( normalize( float3( @.x, @.y, 0 ) ), float3( 0, 1, 0 ) ) ), 10.0 );\r\n",
new GenOp( " @.z = pow( abs( dot( normalize( vec3( @.x, @.y, 0 ) ), vec3( 0, 1, 0 ) ) ), 10.0 );\r\n",
outTex, inNormal, inNormal ) );
}
else
@ -239,8 +258,8 @@ void TerrainBaseMapFeatGLSL::processVert( Vector<ShaderComponent*> &componentLis
Var *inTangentZ = getVertTexCoord( "tcTangentZ" );
Var *inTanget = new Var( "T", "vec3" );
Var *squareSize = _getUniformVar( "squareSize", "float", cspPass );
meta->addStatement( new GenOp( " @ = normalize( float3( @, 0, @ ) );\r\n",
new DecOp( inTanget ), squareSize, inTangentZ ) );
meta->addStatement( new GenOp( " @ = normalize( vec3( @, 0, @ ) );\r\n",
new DecOp( inTanget ), squareSize, inTangentZ ) );
}
void TerrainBaseMapFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
@ -334,7 +353,7 @@ void TerrainDetailMapFeatGLSL::processVert( Vector<ShaderComponent*> &component
outNegViewTS->setName( "outNegViewTS" );
outNegViewTS->setStructName( "OUT" );
outNegViewTS->setType( "vec3" );
meta->addStatement( new GenOp( " @ = tMul( @, float3( @ - @.xyz ) );\r\n",
meta->addStatement( new GenOp( " @ = tMul( @, vec3( @ - @.xyz ) );\r\n",
outNegViewTS, objToTangentSpace, eyePos, inPos ) );
}
@ -490,7 +509,7 @@ void TerrainDetailMapFeatGLSL::processPix( Vector<ShaderComponent*> &component
{
// create color var
outColor = new Var;
outColor->setType("float4");
outColor->setType("vec4");
outColor->setName("col");
outColor->setStructName("OUT");
meta->addStatement(new GenOp(" @;\r\n", outColor));
@ -500,7 +519,7 @@ void TerrainDetailMapFeatGLSL::processPix( Vector<ShaderComponent*> &component
if (!detailColor)
{
detailColor = new Var;
detailColor->setType("float4");
detailColor->setType("vec4");
detailColor->setName("detailColor");
meta->addStatement(new GenOp(" @;\r\n", new DecOp(detailColor)));
}
@ -1106,6 +1125,176 @@ void TerrainAdditiveFeatGLSL::processPix( Vector<ShaderComponent*> &componentLis
//standard matInfo map contains data of the form .r = bitflags, .g = (will contain AO),
//.b = specular strength, a= spec power.
void TerrainCompositeMapFeatGLSL::processVert(Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd)
{
const S32 detailIndex = getProcessIndex();
// Grab incoming texture coords... the base map feature
// made sure this was created.
Var *inTex = (Var*)LangElement::find("texCoord");
AssertFatal(inTex, "The texture coord is missing!");
// Grab the input position.
Var *inPos = (Var*)LangElement::find("inPosition");
if (!inPos)
inPos = (Var*)LangElement::find("position");
// Get the object space eye position.
Var *eyePos = _getUniformVar("eyePos", "vec3", cspPotentialPrimitive);
MultiLine *meta = new MultiLine;
// If we have parallax mapping then make sure we've sent
// the negative view vector to the pixel shader.
if (fd.features.hasFeature(MFT_TerrainParallaxMap) &&
!LangElement::find("outNegViewTS"))
{
// Get the object to tangent transform which
// will consume 3 output registers.
Var *objToTangentSpace = getOutObjToTangentSpace(componentList, meta, fd);
// Now use a single output register to send the negative
// view vector in tangent space to the pixel shader.
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>(componentList[C_CONNECTOR]);
Var *outNegViewTS = connectComp->getElement(RT_TEXCOORD);
outNegViewTS->setName("outNegViewTS");
outNegViewTS->setStructName("OUT");
outNegViewTS->setType("vec3");
meta->addStatement(new GenOp(" @ = @ * vec3( @ - @.xyz );\r\n",
outNegViewTS, objToTangentSpace, eyePos, inPos));
}
// Get the distance from the eye to this vertex.
Var *dist = (Var*)LangElement::find("dist");
if (!dist)
{
dist = new Var;
dist->setType("float");
dist->setName("dist");
meta->addStatement(new GenOp(" @ = distance( @.xyz, @ );\r\n",
new DecOp(dist), inPos, eyePos));
}
// grab connector texcoord register
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>(componentList[C_CONNECTOR]);
Var *outTex = (Var*)LangElement::find(String::ToString("detCoord%d", detailIndex));
if (outTex == NULL)
{
outTex = connectComp->getElement(RT_TEXCOORD);
outTex->setName(String::ToString("detCoord%d", detailIndex));
outTex->setStructName("OUT");
outTex->setType("vec4");
}
// Get the detail scale and fade info.
Var *detScaleAndFade = (Var*)LangElement::find(String::ToString("detailScaleAndFade%d", detailIndex));
if (detScaleAndFade == NULL)
{
detScaleAndFade->setType("vec4");
detScaleAndFade->setName(String::ToString("detailScaleAndFade%d", detailIndex));
detScaleAndFade->uniform = true;
detScaleAndFade->constSortPos = cspPotentialPrimitive;
}
// Setup the detail coord.
//
// NOTE: You see here we scale the texture coord by 'xyx'
// to generate the detail coord. This y is here because
// its scale is flipped to correct for the non negative y
// in texCoord.
//
// See TerrainBaseMapFeatGLSL::processVert().
//
meta->addStatement(new GenOp(" @.xyz = @ * @.xyx;\r\n", outTex, inTex, detScaleAndFade));
// And sneak the detail fade thru the w detailCoord.
meta->addStatement(new GenOp(" @.w = clamp( ( @.z - @ ) * @.w, 0.0, 1.0 );\r\n",
outTex, detScaleAndFade, dist, detScaleAndFade));
output = meta;
}
U32 TerrainCompositeMapFeatGLSL::getOutputTargets(const MaterialFeatureData &fd) const
{
return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget2 : ShaderFeature::RenderTarget1;
}
void TerrainCompositeMapFeatGLSL::processPix(Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd)
{
/// Get the texture coord.
Var *inDet = _getInDetailCoord(componentList);
Var *inTex = getVertTexCoord("texCoord");
const S32 compositeIndex = getProcessIndex();
Var *compositeMap = _getCompositeMapTex();
// Sample the normal map.
//
// We take two normal samples and lerp between them for
// side projection layers... else a single sample.
LangElement *texOp;
if (fd.features.hasFeature(MFT_TerrainSideProject, compositeIndex))
{
texOp = new GenOp("lerp( tex2D( @, @.yz ), tex2D( @, @.xz ), @.z )",
compositeMap, inDet, compositeMap, inDet, inTex);
}
else
texOp = new GenOp("tex2D(@, @.xy)", compositeMap, inDet);
// search for material var
Var *material;
OutputTarget targ = RenderTarget1;
if (fd.features[MFT_isDeferred])
{
targ = RenderTarget2;
}
material = (Var*)LangElement::find(getOutputTargetVarName(targ));
MultiLine * meta = new MultiLine;
if (!material)
{
// create color var
material = new Var;
material->setType("fragout");
material->setName(getOutputTargetVarName(targ));
material->setStructName("OUT");
}
Var *detailBlend = (Var*)LangElement::find(String::ToString("detailBlend%d", compositeIndex));
AssertFatal(detailBlend, "The detail blend is missing!");
String matinfoName(String::ToString("matinfoCol%d", compositeIndex));
Var *matinfoCol = new Var(matinfoName, "vec3");
Var *priorComp = (Var*)LangElement::find(String::ToString("matinfoCol%d", compositeIndex - 1));
if (priorComp)
{
meta->addStatement(new GenOp(" @ = @.grb*@;\r\n", new DecOp(matinfoCol), texOp, detailBlend));
meta->addStatement(new GenOp(" @.gba += @;\r\n", material, matinfoCol));
}
else
{
meta->addStatement(new GenOp(" @ = lerp(vec3(1,0,0),@.grb,@);\r\n", new DecOp(matinfoCol), texOp, detailBlend));
meta->addStatement(new GenOp(" @ = vec4(0.0,@);\r\n", material, matinfoCol));
}
output = meta;
}
ShaderFeature::Resources TerrainCompositeMapFeatGLSL::getResources(const MaterialFeatureData &fd)
{
Resources res;
res.numTex = 1;
res.numTexReg += 1;
return res;
}
//here, it's merely a cutout for now, so that lightmapping (target3) doesn't get mangled.
//we'll most likely revisit that later. possibly several ways...
@ -1136,7 +1325,7 @@ void TerrainBlankInfoMapFeatGLSL::processPix(Vector<ShaderComponent*> &component
material->setStructName("OUT");
}
meta->addStatement(new GenOp(" @ = float4(0.0,0.0,0.0,0.0001);\r\n", material));
meta->addStatement(new GenOp(" @ = vec4(0.0,1.0,0.0,0.0001);\r\n", material));
output = meta;
}

View file

@ -45,7 +45,9 @@ public:
Var* _getInMacroCoord(Vector<ShaderComponent*> &componentList );
Var* _getNormalMapTex();
Var* _getCompositeMapTex();
static Var* _getUniformVar( const char *name, const char *type, ConstantSortPosition csp );
Var* _getDetailIdStrengthParallax();
@ -160,6 +162,22 @@ public:
virtual String getName() { return "Terrain Additive"; }
};
class TerrainCompositeMapFeatGLSL : public TerrainFeatGLSL
{
public:
virtual void processVert(Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd);
virtual void processPix(Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd);
virtual Resources getResources(const MaterialFeatureData &fd);
virtual U32 getOutputTargets(const MaterialFeatureData &fd) const;
virtual String getName() { return "Composite Matinfo map"; }
};
class TerrainBlankInfoMapFeatGLSL : public ShaderFeatureGLSL
{
public:

View file

@ -49,6 +49,7 @@ namespace
FEATUREMGR->registerFeature( MFT_TerrainLightMap, new TerrainLightMapFeatHLSL );
FEATUREMGR->registerFeature( MFT_TerrainSideProject, new NamedFeatureHLSL( "Terrain Side Projection" ) );
FEATUREMGR->registerFeature( MFT_TerrainAdditive, new TerrainAdditiveFeatHLSL );
FEATUREMGR->registerFeature( MFT_TerrainCompositeMap, new TerrainCompositeMapFeatHLSL );
FEATUREMGR->registerFeature( MFT_DeferredTerrainBlankInfoMap, new TerrainBlankInfoMapFeatHLSL );
}
};
@ -140,6 +141,24 @@ Var* TerrainFeatHLSL::_getNormalMapTex()
return normalMap;
}
Var* TerrainFeatHLSL::_getCompositeMapTex()
{
String name(String::ToString("compositeMap%d", getProcessIndex()));
Var *compositeMap = (Var*)LangElement::find(name);
if (!compositeMap)
{
compositeMap = new Var;
compositeMap->setType("SamplerState");
compositeMap->setName(name);
compositeMap->uniform = true;
compositeMap->sampler = true;
compositeMap->constNum = Var::getTexUnitNum();
}
return compositeMap;
}
Var* TerrainFeatHLSL::_getDetailIdStrengthParallax()
{
String name( String::ToString( "detailIdStrengthParallax%d", getProcessIndex() ) );
@ -1116,6 +1135,183 @@ void TerrainAdditiveFeatHLSL::processPix( Vector<ShaderComponent*> &componentLis
//standard matInfo map contains data of the form .r = bitflags, .g = (will contain AO),
//.b = specular strength, a= spec power.
void TerrainCompositeMapFeatHLSL::processVert(Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd)
{
const S32 detailIndex = getProcessIndex();
// Grab incoming texture coords... the base map feature
// made sure this was created.
Var *inTex = (Var*)LangElement::find("texCoord");
AssertFatal(inTex, "The texture coord is missing!");
// Grab the input position.
Var *inPos = (Var*)LangElement::find("inPosition");
if (!inPos)
inPos = (Var*)LangElement::find("position");
// Get the object space eye position.
Var *eyePos = _getUniformVar("eyePos", "float3", cspPotentialPrimitive);
MultiLine *meta = new MultiLine;
// If we have parallax mapping then make sure we've sent
// the negative view vector to the pixel shader.
if (fd.features.hasFeature(MFT_TerrainParallaxMap) &&
!LangElement::find("outNegViewTS"))
{
// Get the object to tangent transform which
// will consume 3 output registers.
Var *objToTangentSpace = getOutObjToTangentSpace(componentList, meta, fd);
// Now use a single output register to send the negative
// view vector in tangent space to the pixel shader.
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>(componentList[C_CONNECTOR]);
Var *outNegViewTS = connectComp->getElement(RT_TEXCOORD);
outNegViewTS->setName("outNegViewTS");
outNegViewTS->setStructName("OUT");
outNegViewTS->setType("float3");
meta->addStatement(new GenOp(" @ = mul( @, float3( @ - @.xyz ) );\r\n",
outNegViewTS, objToTangentSpace, eyePos, inPos));
}
// Get the distance from the eye to this vertex.
Var *dist = (Var*)LangElement::find("dist");
if (!dist)
{
dist = new Var;
dist->setType("float");
dist->setName("dist");
meta->addStatement(new GenOp(" @ = distance( @.xyz, @ );\r\n",
new DecOp(dist), inPos, eyePos));
}
// grab connector texcoord register
ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>(componentList[C_CONNECTOR]);
Var *outTex = (Var*)LangElement::find(String::ToString("detCoord%d", detailIndex));
if (outTex == NULL)
{
outTex = connectComp->getElement(RT_TEXCOORD);
outTex->setName(String::ToString("detCoord%d", detailIndex));
outTex->setStructName("OUT");
outTex->setType("float4");
}
// Get the detail scale and fade info.
Var *detScaleAndFade = (Var*)LangElement::find(String::ToString("detailScaleAndFade%d", detailIndex));
if (detScaleAndFade == NULL)
{
detScaleAndFade->setType("float4");
detScaleAndFade->setName(String::ToString("detailScaleAndFade%d", detailIndex));
detScaleAndFade->uniform = true;
detScaleAndFade->constSortPos = cspPotentialPrimitive;
}
// Setup the detail coord.
//
// NOTE: You see here we scale the texture coord by 'xyx'
// to generate the detail coord. This y is here because
// its scale is flipped to correct for the non negative y
// in texCoord.
//
// See TerrainBaseMapFeatHLSL::processVert().
//
meta->addStatement(new GenOp(" @.xyz = @ * @.xyx;\r\n", outTex, inTex, detScaleAndFade));
// And sneak the detail fade thru the w detailCoord.
meta->addStatement(new GenOp(" @.w = clamp( ( @.z - @ ) * @.w, 0.0, 1.0 );\r\n",
outTex, detScaleAndFade, dist, detScaleAndFade));
output = meta;
}
U32 TerrainCompositeMapFeatHLSL::getOutputTargets(const MaterialFeatureData &fd) const
{
return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget2 : ShaderFeature::RenderTarget1;
}
void TerrainCompositeMapFeatHLSL::processPix(Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd)
{
/// Get the texture coord.
Var *inDet = _getInDetailCoord(componentList);
Var *inTex = getVertTexCoord("texCoord");
const S32 compositeIndex = getProcessIndex();
Var *compositeMap = _getCompositeMapTex();
// Sample the normal map.
//
// We take two normal samples and lerp between them for
// side projection layers... else a single sample.
LangElement *texOp;
String name(String::ToString("compositeMapTex%d", getProcessIndex()));
Var *compositeMapTex = (Var*)LangElement::find(name);
if (!compositeMapTex)
{
compositeMapTex = new Var;
compositeMapTex->setName(String::ToString("compositeMapTex%d", getProcessIndex()));
compositeMapTex->setType("Texture2D");
compositeMapTex->uniform = true;
compositeMapTex->texture = true;
compositeMapTex->constNum = compositeMap->constNum;
}
if (fd.features.hasFeature(MFT_TerrainSideProject, compositeIndex))
{
texOp = new GenOp("lerp( @.Sample( @, @.yz ), @.Sample( @, @.xz ), @.z )",
compositeMapTex, compositeMap, inDet, compositeMapTex, compositeMap, inDet, inTex);
}
else
texOp = new GenOp("@.Sample(@, @.xy)", compositeMapTex, compositeMap, inDet);
// search for material var
Var *material;
OutputTarget targ = RenderTarget1;
if (fd.features[MFT_isDeferred])
{
targ = RenderTarget2;
}
material = (Var*)LangElement::find(getOutputTargetVarName(targ));
MultiLine * meta = new MultiLine;
if (!material)
{
// create color var
material = new Var;
material->setType("fragout");
material->setName(getOutputTargetVarName(targ));
material->setStructName("OUT");
}
Var *detailBlend = (Var*)LangElement::find(String::ToString("detailBlend%d", compositeIndex));
AssertFatal(detailBlend, "The detail blend is missing!");
String matinfoName(String::ToString("matinfoCol%d", compositeIndex));
Var *matinfoCol = new Var(matinfoName, "float3");
Var *priorComp = (Var*)LangElement::find(String::ToString("matinfoCol%d", compositeIndex - 1));
if (priorComp)
{
meta->addStatement(new GenOp(" @ = @.grb*@;\r\n", new DecOp(matinfoCol), texOp, detailBlend));
meta->addStatement(new GenOp(" @.gba += @;\r\n", material, matinfoCol));
}
else
{
meta->addStatement(new GenOp(" @ = lerp(float3(1,0,0),@.grb,@);\r\n", new DecOp(matinfoCol), texOp, detailBlend));
meta->addStatement(new GenOp(" @ = float4(0.0,@);\r\n", material, matinfoCol));
}
output = meta;
}
ShaderFeature::Resources TerrainCompositeMapFeatHLSL::getResources(const MaterialFeatureData &fd)
{
Resources res;
res.numTex = 1;
return res;
}
//here, it's merely a cutout for now, so that lightmapping (target3) doesn't get mangled.
//we'll most likely revisit that later. possibly several ways...

View file

@ -46,6 +46,7 @@ public:
Var* _getInMacroCoord(Vector<ShaderComponent*> &componentList );
Var* _getNormalMapTex();
Var* _getCompositeMapTex();
static Var* _getUniformVar( const char *name, const char *type, ConstantSortPosition csp );
@ -161,6 +162,22 @@ public:
virtual String getName() { return "Terrain Additive"; }
};
class TerrainCompositeMapFeatHLSL : public TerrainFeatHLSL
{
public:
virtual void processVert(Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd);
virtual void processPix(Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd);
virtual Resources getResources(const MaterialFeatureData &fd);
virtual U32 getOutputTargets(const MaterialFeatureData &fd) const;
virtual String getName() { return "Composite Matinfo map"; }
};
class TerrainBlankInfoMapFeatHLSL : public TerrainFeatHLSL
{
public:

View file

@ -59,7 +59,8 @@ Vector<String> _initSamplerNames()
{
samplerNames.push_back(avar("$normalMap%d",i));
samplerNames.push_back(avar("$detailMap%d",i));
samplerNames.push_back(avar("$macroMap%d",i));
samplerNames.push_back(avar("$macroMap%d", i));
samplerNames.push_back(avar("$compositeMap%d", i));
}
return samplerNames;
@ -149,6 +150,19 @@ void TerrainCellMaterial::_updateDefaultAnisotropy()
desc.samplers[sampler].minFilter = GFXTextureFilterLinear;
}
if (matInfo->compositeTexConst->isValid())
{
const S32 sampler = matInfo->compositeTexConst->getSamplerRegister();
if (maxAnisotropy > 1)
{
desc.samplers[sampler].minFilter = GFXTextureFilterAnisotropic;
desc.samplers[sampler].maxAnisotropy = maxAnisotropy;
}
else
desc.samplers[sampler].minFilter = GFXTextureFilterLinear;
}
} // for ( U32 m=0; m < pass.materials.size(); m++ )
// Set the updated stateblock.
@ -424,6 +438,14 @@ bool TerrainCellMaterial::_createPass( Vector<MaterialInfo*> *materials,
features.addFeature(MFT_isDeferred, featureIndex);
features.addFeature( MFT_TerrainDetailMap, featureIndex );
if (!(mat->getCompositeMap().isEmpty()))
{
if (deferredMat)
features.addFeature(MFT_isDeferred, featureIndex);
features.addFeature(MFT_TerrainCompositeMap, featureIndex);
features.removeFeature(MFT_DeferredTerrainBlankInfoMap);
}
pass->materials.push_back( (*materials)[i] );
normalMaps.increment();
@ -496,7 +518,7 @@ bool TerrainCellMaterial::_createPass( Vector<MaterialInfo*> *materials,
// isn't fooled into thinking there is a real bug. That is until
// we get down to a single material. If a single material case
// fails it means it cannot generate any passes at all!
const bool logErrors = matCount == 1;
const bool logErrors = true;// matCount == 1;
GFXShader::setLogging( logErrors, true );
pass->shader = SHADERGEN->getShader( featureData, getGFXVertexFormat<TerrVertex>(), NULL, mSamplerNames );
@ -613,6 +635,27 @@ bool TerrainCellMaterial::_createPass( Vector<MaterialInfo*> *materials,
&GFXStaticTextureProfile, "TerrainCellMaterial::_createPass() - DetailMap" );
}
matInfo->compositeTexConst = pass->shader->getShaderConstHandle(avar("$compositeMap%d", i));
if (matInfo->compositeTexConst->isValid())
{
matInfo->compositeTex.set(matInfo->mat->getCompositeMap(),
&GFXStaticTextureProfile, "TerrainCellMaterial::_createPass() - CompositeMap");
const S32 sampler = matInfo->compositeTexConst->getSamplerRegister();
Con::errorf("sampler=%i", sampler);
desc.samplers[sampler] = GFXSamplerStateDesc::getWrapLinear();
desc.samplers[sampler].magFilter = GFXTextureFilterLinear;
desc.samplers[sampler].mipFilter = GFXTextureFilterLinear;
if (maxAnisotropy > 1)
{
desc.samplers[sampler].minFilter = GFXTextureFilterAnisotropic;
desc.samplers[sampler].maxAnisotropy = maxAnisotropy;
}
else
desc.samplers[sampler].minFilter = GFXTextureFilterLinear;
}
matInfo->macroInfoVConst = pass->shader->getShaderConstHandle( avar( "$macroScaleAndFade%d", i ) );
matInfo->macroInfoPConst = pass->shader->getShaderConstHandle( avar( "$macroIdStrengthParallax%d", i ) );
@ -810,6 +853,8 @@ bool TerrainCellMaterial::setupPass( const SceneRenderState *state,
GFX->setTexture( matInfo->macroTexConst->getSamplerRegister(), matInfo->macroTex );
if ( matInfo->normalTexConst->isValid() )
GFX->setTexture( matInfo->normalTexConst->getSamplerRegister(), matInfo->normalTex );
if ( matInfo->compositeTexConst->isValid() )
GFX->setTexture( matInfo->compositeTexConst->getSamplerRegister(), matInfo->compositeTex );
}
pass.consts->setSafe( pass.layerSizeConst, (F32)mTerrain->mLayerTex.getWidth() );
@ -837,7 +882,7 @@ bool TerrainCellMaterial::setupPass( const SceneRenderState *state,
pass.lightParamsConst->isValid() )
{
if ( !mLightInfoTarget )
mLightInfoTarget = NamedTexTarget::find( "directLighting" );
mLightInfoTarget = NamedTexTarget::find( "diffuseLighting" );
GFXTextureObject *texObject = mLightInfoTarget->getTexture();

View file

@ -77,6 +77,9 @@ protected:
GFXShaderConstHandle *normalTexConst;
GFXTexHandle normalTex;
GFXShaderConstHandle *compositeTexConst;
GFXTexHandle compositeTex;
GFXShaderConstHandle *detailInfoVConst;
GFXShaderConstHandle *detailInfoPConst;

View file

@ -36,3 +36,4 @@ ImplementFeatureType( MFT_TerrainSideProject, MFG_Texture, 106.0f, false );
ImplementFeatureType( MFT_TerrainAdditive, MFG_PostProcess, 999.0f, false );
//Deferred Shading
ImplementFeatureType( MFT_DeferredTerrainBlankInfoMap, MFG_Texture, 104.1f, false);
ImplementFeatureType( MFT_TerrainCompositeMap, MFG_Texture, 104.2f, false);

View file

@ -36,6 +36,7 @@ DeclareFeatureType( MFT_TerrainLightMap );
DeclareFeatureType( MFT_TerrainSideProject );
DeclareFeatureType( MFT_TerrainAdditive );
//Deferred Shading
DeclareFeatureType( MFT_TerrainCompositeMap );
DeclareFeatureType( MFT_DeferredTerrainBlankInfoMap );

View file

@ -97,6 +97,7 @@ void TerrainMaterial::initPersistFields()
addField( "parallaxScale", TypeF32, Offset( mParallaxScale, TerrainMaterial ), "Used to scale the height from the normal map to give some self "
"occlusion effect (aka parallax) to the terrain material" );
addField("compositeMap", TypeStringFilename, Offset(mCompositeMap, TerrainMaterial), "Composite map for the material");
Parent::initPersistFields();
// Gotta call this at least once or it won't get created!

View file

@ -49,6 +49,9 @@ protected:
///
FileName mDetailMap;
///
FileName mCompositeMap;
/// The size of the detail map in meters used
/// to generate the texture coordinates for the
/// detail and normal maps.
@ -103,6 +106,8 @@ public:
const String& getMacroMap() const { return mMacroMap; }
const String& getCompositeMap() const { return mCompositeMap; }
F32 getDetailSize() const { return mDetailSize; }
F32 getDetailStrength() const { return mDetailStrength; }