mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-19 19:35:26 +00:00
Implement Singlepass Terrain Render
This commit is contained in:
parent
49a8c0ad36
commit
87dd7ffc4a
35 changed files with 1658 additions and 951 deletions
|
|
@ -48,7 +48,6 @@ namespace
|
|||
FEATUREMGR->registerFeature( MFT_TerrainMacroMap, new NamedFeatureGLSL("TerrainMacroMap Deprecated")); // new TerrainMacroMapFeatGLSL);
|
||||
FEATUREMGR->registerFeature( MFT_TerrainLightMap, new TerrainLightMapFeatGLSL );
|
||||
FEATUREMGR->registerFeature( MFT_TerrainSideProject, new NamedFeatureGLSL( "Terrain Side Projection" ) );
|
||||
FEATUREMGR->registerFeature( MFT_TerrainAdditive, new TerrainAdditiveFeatGLSL );
|
||||
FEATUREMGR->registerFeature( MFT_TerrainORMMap, new TerrainORMMapFeatGLSL );
|
||||
FEATUREMGR->registerFeature( MFT_DeferredTerrainBlankInfoMap, new TerrainBlankInfoMapFeatGLSL );
|
||||
}
|
||||
|
|
@ -124,69 +123,90 @@ Var* TerrainFeatGLSL::_getInMacroCoord( Vector<ShaderComponent*> &componentList
|
|||
return inDet;
|
||||
}
|
||||
|
||||
Var* TerrainFeatGLSL::_getNormalMapTex()
|
||||
Var* TerrainFeatGLSL::_getDetailMapSampler()
|
||||
{
|
||||
String name( String::ToString( "normalMap%d", getProcessIndex() ) );
|
||||
Var *normalMap = (Var*)LangElement::find( name );
|
||||
|
||||
if ( !normalMap )
|
||||
String name("detailMapSampler");
|
||||
Var* detailMapSampler = (Var*)LangElement::find(name);
|
||||
|
||||
if (!detailMapSampler)
|
||||
{
|
||||
normalMap = new Var;
|
||||
normalMap->setType( "sampler2D" );
|
||||
normalMap->setName( name );
|
||||
normalMap->uniform = true;
|
||||
normalMap->sampler = true;
|
||||
normalMap->constNum = Var::getTexUnitNum();
|
||||
detailMapSampler = new Var;
|
||||
detailMapSampler->setName(name);
|
||||
detailMapSampler->setType("sampler2DArray");
|
||||
detailMapSampler->uniform = true;
|
||||
detailMapSampler->sampler = true;
|
||||
detailMapSampler->constNum = Var::getTexUnitNum();
|
||||
}
|
||||
|
||||
return normalMap;
|
||||
|
||||
return detailMapSampler;
|
||||
}
|
||||
|
||||
Var* TerrainFeatGLSL::_getORMConfigMapTex()
|
||||
Var* TerrainFeatGLSL::_getNormalMapSampler()
|
||||
{
|
||||
String name(String::ToString("ormConfigMap%d", getProcessIndex()));
|
||||
Var *ormConfigMap = (Var*)LangElement::find(name);
|
||||
String name("normalMapSampler");
|
||||
Var* normalMapSampler = (Var*)LangElement::find(name);
|
||||
|
||||
if (!ormConfigMap)
|
||||
{
|
||||
ormConfigMap = new Var;
|
||||
ormConfigMap->setType("sampler2D");
|
||||
ormConfigMap->setName(name);
|
||||
ormConfigMap->uniform = true;
|
||||
ormConfigMap->sampler = true;
|
||||
ormConfigMap->constNum = Var::getTexUnitNum();
|
||||
}
|
||||
if (!normalMapSampler)
|
||||
{
|
||||
normalMapSampler = new Var;
|
||||
normalMapSampler->setName(name);
|
||||
normalMapSampler->setType("sampler2DArray");
|
||||
normalMapSampler->uniform = true;
|
||||
normalMapSampler->sampler = true;
|
||||
normalMapSampler->constNum = Var::getTexUnitNum();
|
||||
}
|
||||
|
||||
return ormConfigMap;
|
||||
return normalMapSampler;
|
||||
}
|
||||
|
||||
Var* TerrainFeatGLSL::_getOrmMapSampler()
|
||||
{
|
||||
String name("ormMapSampler");
|
||||
Var* ormMapSampler = (Var*)LangElement::find(name);
|
||||
|
||||
if (!ormMapSampler)
|
||||
{
|
||||
ormMapSampler = new Var;
|
||||
ormMapSampler->setName(name);
|
||||
ormMapSampler->setType("sampler2DArray");
|
||||
ormMapSampler->uniform = true;
|
||||
ormMapSampler->sampler = true;
|
||||
ormMapSampler->constNum = Var::getTexUnitNum();
|
||||
}
|
||||
|
||||
return ormMapSampler;
|
||||
}
|
||||
|
||||
Var* TerrainFeatGLSL::_getDetailIdStrengthParallax()
|
||||
{
|
||||
String name( String::ToString( "detailIdStrengthParallax%d", getProcessIndex() ) );
|
||||
|
||||
Var *detailInfo = (Var*)LangElement::find( name );
|
||||
if ( !detailInfo )
|
||||
String name(String::ToString("detailIdStrengthParallax", getProcessIndex()));
|
||||
|
||||
Var* detailInfo = (Var*)LangElement::find(name);
|
||||
if (!detailInfo)
|
||||
{
|
||||
detailInfo = new Var;
|
||||
detailInfo->setType( "vec3" );
|
||||
detailInfo->setName( name );
|
||||
detailInfo->setType("vec4");
|
||||
detailInfo->setName(name);
|
||||
detailInfo->uniform = true;
|
||||
detailInfo->constSortPos = cspPotentialPrimitive;
|
||||
detailInfo->arraySize = getProcessIndex();
|
||||
}
|
||||
|
||||
|
||||
detailInfo->arraySize = mMax(detailInfo->arraySize, getProcessIndex() + 1);
|
||||
|
||||
return detailInfo;
|
||||
}
|
||||
|
||||
Var* TerrainFeatGLSL::_getMacroIdStrengthParallax()
|
||||
{
|
||||
String name( String::ToString( "macroIdStrengthParallax%d", getProcessIndex() ) );
|
||||
String name(String::ToString("macroIdStrengthParallax%d", getProcessIndex()));
|
||||
|
||||
Var *detailInfo = (Var*)LangElement::find( name );
|
||||
if ( !detailInfo )
|
||||
Var* detailInfo = (Var*)LangElement::find(name);
|
||||
if (!detailInfo)
|
||||
{
|
||||
detailInfo = new Var;
|
||||
detailInfo->setType( "vec3" );
|
||||
detailInfo->setName( name );
|
||||
detailInfo->setType("vec3");
|
||||
detailInfo->setName(name);
|
||||
detailInfo->uniform = true;
|
||||
detailInfo->constSortPos = cspPotentialPrimitive;
|
||||
}
|
||||
|
|
@ -377,11 +397,17 @@ void TerrainDetailMapFeatGLSL::processVert( Vector<ShaderComponent*> &component
|
|||
outTex->setType( "vec4" );
|
||||
|
||||
// Get the detail scale and fade info.
|
||||
Var *detScaleAndFade = new Var;
|
||||
detScaleAndFade->setType( "vec4" );
|
||||
detScaleAndFade->setName( String::ToString( "detailScaleAndFade%d", detailIndex ) );
|
||||
detScaleAndFade->uniform = true;
|
||||
detScaleAndFade->constSortPos = cspPotentialPrimitive;
|
||||
Var *detScaleAndFade = (Var*)LangElement::find("detailScaleAndFade");
|
||||
if (!detScaleAndFade)
|
||||
{
|
||||
detScaleAndFade = new Var;
|
||||
detScaleAndFade->setType("vec4");
|
||||
detScaleAndFade->setName("detailScaleAndFade");
|
||||
detScaleAndFade->uniform = true;
|
||||
detScaleAndFade->constSortPos = cspPotentialPrimitive;
|
||||
}
|
||||
|
||||
detScaleAndFade->arraySize = mMax(detScaleAndFade->arraySize, detailIndex + 1);
|
||||
|
||||
// Setup the detail coord.
|
||||
//
|
||||
|
|
@ -392,11 +418,11 @@ void TerrainDetailMapFeatGLSL::processVert( Vector<ShaderComponent*> &component
|
|||
//
|
||||
// See TerrainBaseMapFeatGLSL::processVert().
|
||||
//
|
||||
meta->addStatement( new GenOp( " @.xyz = @ * @.xyx;\r\n", outTex, inTex, detScaleAndFade ) );
|
||||
meta->addStatement( new GenOp( " @.xyz = @ * @.xyx;\r\n", outTex, inTex, new IndexOp(detScaleAndFade, detailIndex) ) );
|
||||
|
||||
// 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 ) );
|
||||
outTex, new IndexOp(detScaleAndFade, detailIndex), dist, new IndexOp(detScaleAndFade, detailIndex)) );
|
||||
|
||||
output = meta;
|
||||
}
|
||||
|
|
@ -473,7 +499,7 @@ void TerrainDetailMapFeatGLSL::processPix( Vector<ShaderComponent*> &component
|
|||
|
||||
// Calculate the blend for this detail texture.
|
||||
meta->addStatement( new GenOp( " @ = calcBlend( @.x, @.xy, @, @ );\r\n",
|
||||
new DecOp( detailBlend ), detailInfo, inTex, layerSize, layerSample ) );
|
||||
new DecOp( detailBlend ), new IndexOp(detailInfo, detailIndex), inTex, layerSize, layerSample ) );
|
||||
|
||||
// New terrain
|
||||
|
||||
|
|
@ -525,15 +551,10 @@ void TerrainDetailMapFeatGLSL::processPix( Vector<ShaderComponent*> &component
|
|||
}
|
||||
|
||||
// Get the detail texture.
|
||||
Var *detailMap = new Var;
|
||||
detailMap->setType("sampler2D");
|
||||
detailMap->setName(String::ToString("detailMap%d", detailIndex));
|
||||
detailMap->uniform = true;
|
||||
detailMap->sampler = true;
|
||||
detailMap->constNum = Var::getTexUnitNum(); // used as texture unit num here
|
||||
Var *detailMap = _getDetailMapSampler();
|
||||
|
||||
// Get the normal map texture.
|
||||
Var *normalMap = _getNormalMapTex();
|
||||
Var *normalMap = _getNormalMapSampler();
|
||||
|
||||
// Issue happens somewhere here -----
|
||||
|
||||
|
|
@ -541,8 +562,7 @@ void TerrainDetailMapFeatGLSL::processPix( Vector<ShaderComponent*> &component
|
|||
//
|
||||
// We take two normal samples and lerp between them for
|
||||
// side projection layers... else a single sample.
|
||||
LangElement *texOp;
|
||||
|
||||
//
|
||||
// Note that we're doing the standard greyscale detail
|
||||
// map technique here which can darken and lighten the
|
||||
// diffuse texture.
|
||||
|
|
@ -552,35 +572,17 @@ void TerrainDetailMapFeatGLSL::processPix( Vector<ShaderComponent*> &component
|
|||
//
|
||||
if (fd.features.hasFeature(MFT_TerrainSideProject, detailIndex))
|
||||
{
|
||||
meta->addStatement(new GenOp(" @ = ( lerp( tex2D( @, @.yz ), tex2D( @, @.xz ), @.z ) * 2.0 ) - 1.0;\r\n",
|
||||
detailColor, detailMap, inDet, detailMap, inDet, inTex));
|
||||
|
||||
texOp = new GenOp("lerp( tex2D( @, @.yz ), tex2D( @, @.xz ), @.z )",
|
||||
normalMap, inDet, normalMap, inDet, inTex);
|
||||
meta->addStatement(new GenOp(" @ = ( lerp( tex2D( @, vec3(@.yz, @.x) ), tex2D( @, vec3(@.xz, @.x) ), @.z ) * 2.0 ) - 1.0;\r\n",
|
||||
detailColor, detailMap, inDet, new IndexOp(detailInfo, detailIndex), detailMap, inDet, new IndexOp(detailInfo, detailIndex), inTex));
|
||||
}
|
||||
else
|
||||
{
|
||||
meta->addStatement(new GenOp(" @ = ( tex2D( @, @.xy ) * 2.0 ) - 1.0;\r\n",
|
||||
detailColor, detailMap, inDet));
|
||||
|
||||
texOp = new GenOp("tex2D(@, @.xy)", normalMap, inDet);
|
||||
meta->addStatement(new GenOp(" @ = ( tex2D( @, vec3(@.xy, @.x) ) * 2.0 ) - 1.0;\r\n",
|
||||
detailColor, detailMap, inDet, new IndexOp(detailInfo, detailIndex)));
|
||||
}
|
||||
|
||||
// New terrain
|
||||
|
||||
// Get a var and accumulate the blend amount.
|
||||
Var *blendTotal = (Var*)LangElement::find( "blendTotal" );
|
||||
if ( !blendTotal )
|
||||
{
|
||||
blendTotal = new Var;
|
||||
blendTotal->setName( "blendTotal" );
|
||||
blendTotal->setType( "float" );
|
||||
meta->addStatement( new GenOp( " @ = 0;\r\n", new DecOp( blendTotal ) ) );
|
||||
}
|
||||
|
||||
// Add to the blend total.
|
||||
meta->addStatement(new GenOp(" @ = max( @, @ );\r\n", blendTotal, blendTotal, detailBlend));
|
||||
|
||||
// If we had a parallax feature... then factor in the parallax
|
||||
// amount so that it fades out with the layer blending.
|
||||
if ( fd.features.hasFeature( MFT_TerrainParallaxMap, detailIndex ) )
|
||||
|
|
@ -588,13 +590,13 @@ void TerrainDetailMapFeatGLSL::processPix( Vector<ShaderComponent*> &component
|
|||
// Call the library function to do the rest.
|
||||
if (fd.features.hasFeature(MFT_IsBC3nm, detailIndex))
|
||||
{
|
||||
meta->addStatement(new GenOp(" @.xy += parallaxOffsetDxtnm( @, @.xy, @, @.z * @ );\r\n",
|
||||
inDet, normalMap, inDet, negViewTS, detailInfo, detailBlend));
|
||||
meta->addStatement(new GenOp(" @.xy += parallaxOffsetDxtnm( @, vec3(@.xy, @.x), @, @.z * @ );\r\n",
|
||||
inDet, normalMap, inDet, new IndexOp(detailInfo, detailIndex), negViewTS, new IndexOp(detailInfo, detailIndex), detailBlend));
|
||||
}
|
||||
else
|
||||
{
|
||||
meta->addStatement(new GenOp(" @.xy += parallaxOffset( @, @.xy, @, @.z * @ );\r\n",
|
||||
inDet, normalMap, inDet, negViewTS, detailInfo, detailBlend));
|
||||
meta->addStatement(new GenOp(" @.xy += parallaxOffset( @, vec3(@.xy, @.x), @, @.z * @ );\r\n",
|
||||
inDet, normalMap, inDet, new IndexOp(detailInfo, detailIndex), negViewTS, new IndexOp(detailInfo, detailIndex), detailBlend));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -632,17 +634,17 @@ void TerrainDetailMapFeatGLSL::processPix( Vector<ShaderComponent*> &component
|
|||
//
|
||||
if ( fd.features.hasFeature( MFT_TerrainSideProject, detailIndex ) )
|
||||
{
|
||||
meta->addStatement( new GenOp( " @ = ( lerp( tex2D( @, @.yz ), tex2D( @, @.xz ), @.z ) * 2.0 ) - 1.0;\r\n",
|
||||
detailColor, detailMap, inDet, detailMap, inDet, inTex ) );
|
||||
meta->addStatement( new GenOp( " @ = ( lerp( tex2D( @, vec3(@.yz, @.x) ), tex2D( @, vec3(@.xz, @.x) ), @.z ) * 2.0 ) - 1.0;\r\n",
|
||||
detailColor, detailMap, inDet, new IndexOp(detailInfo, detailIndex), detailMap, inDet, new IndexOp(detailInfo, detailIndex), inTex ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
meta->addStatement( new GenOp( " @ = ( tex2D( @, @.xy ) * 2.0 ) - 1.0;\r\n",
|
||||
detailColor, detailMap, inDet ) );
|
||||
meta->addStatement( new GenOp( " @ = ( tex2D( @, vec3(@.xy, @.x) ) * 2.0 ) - 1.0;\r\n",
|
||||
detailColor, detailMap, inDet, new IndexOp(detailInfo, detailIndex)) );
|
||||
}
|
||||
|
||||
meta->addStatement( new GenOp( " @ *= @.y * @.w;\r\n",
|
||||
detailColor, detailInfo, inDet ) );
|
||||
detailColor, new IndexOp(detailInfo, detailIndex), inDet ) );
|
||||
|
||||
|
||||
meta->addStatement(new GenOp(" @.rgb = toGamma(@.rgb);\r\n", outColor, outColor));
|
||||
|
|
@ -666,26 +668,13 @@ ShaderFeature::Resources TerrainDetailMapFeatGLSL::getResources( const MaterialF
|
|||
// If this is the first detail pass then we
|
||||
// samples from the layer tex.
|
||||
res.numTex += 1;
|
||||
res.numTexReg += 1;
|
||||
|
||||
// If this material also does parallax then it
|
||||
// will generate the negative view vector and the
|
||||
// worldToTanget transform.
|
||||
if ( fd.features.hasFeature( MFT_TerrainParallaxMap ) )
|
||||
res.numTexReg += 4;
|
||||
// Texture Array
|
||||
res.numTex += 1;
|
||||
res.numTexReg += 1;
|
||||
}
|
||||
|
||||
// sample from the detail texture for diffuse coloring.
|
||||
res.numTex += 1;
|
||||
|
||||
// If we have parallax for this layer then we'll also
|
||||
// be sampling the normal map for the parallax heightmap.
|
||||
if ( fd.features.hasFeature( MFT_TerrainParallaxMap, getProcessIndex() ) )
|
||||
res.numTex += 1;
|
||||
|
||||
// Finally we always send the detail texture
|
||||
// coord to the pixel shader.
|
||||
res.numTexReg += 1;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
@ -836,20 +825,6 @@ void TerrainMacroMapFeatGLSL::processPix( Vector<ShaderComponent*> &componentL
|
|||
meta->addStatement( new GenOp( " @ = calcBlend( @.x, @.xy, @, @ );\r\n",
|
||||
new DecOp( detailBlend ), detailInfo, inTex, layerSize, layerSample ) );
|
||||
|
||||
// Get a var and accumulate the blend amount.
|
||||
Var *blendTotal = (Var*)LangElement::find( "blendTotal" );
|
||||
if ( !blendTotal )
|
||||
{
|
||||
blendTotal = new Var;
|
||||
//blendTotal->setName( "blendTotal" );
|
||||
blendTotal->setName( "blendTotal" );
|
||||
blendTotal->setType( "float" );
|
||||
meta->addStatement( new GenOp( " @ = 0;\r\n", new DecOp( blendTotal ) ) );
|
||||
}
|
||||
|
||||
// Add to the blend total.
|
||||
meta->addStatement(new GenOp(" @ = max( @, @ );\r\n", blendTotal, blendTotal, detailBlend));
|
||||
|
||||
Var *detailColor = (Var*)LangElement::find( "macroColor" );
|
||||
if ( !detailColor )
|
||||
{
|
||||
|
|
@ -992,11 +967,12 @@ void TerrainNormalMapFeatGLSL::processPix( Vector<ShaderComponent*> &component
|
|||
meta->addStatement( new GenOp( " {\r\n" ) );
|
||||
|
||||
// Get the normal map texture.
|
||||
Var *normalMap = _getNormalMapTex();
|
||||
Var *normalMap = _getNormalMapSampler();
|
||||
|
||||
/// Get the texture coord.
|
||||
Var *inDet = _getInDetailCoord( componentList );
|
||||
Var *inTex = getVertTexCoord( "texCoord" );
|
||||
Var* detailInfo = _getDetailIdStrengthParallax();
|
||||
|
||||
// Sample the normal map.
|
||||
//
|
||||
|
|
@ -1005,11 +981,11 @@ void TerrainNormalMapFeatGLSL::processPix( Vector<ShaderComponent*> &component
|
|||
LangElement *texOp;
|
||||
if ( fd.features.hasFeature( MFT_TerrainSideProject, normalIndex ) )
|
||||
{
|
||||
texOp = new GenOp( "lerp( tex2D( @, @.yz ), tex2D( @, @.xz ), @.z )",
|
||||
normalMap, inDet, normalMap, inDet, inTex );
|
||||
texOp = new GenOp( "lerp( tex2D( @, vec3(@.yz, @.x) ), tex2D( @, vec3(@.xz, @.x) ), @.z )",
|
||||
normalMap, inDet, new IndexOp(detailInfo, normalIndex), normalMap, inDet, inTex, new IndexOp(detailInfo, normalIndex));
|
||||
}
|
||||
else
|
||||
texOp = new GenOp( "tex2D(@, @.xy)", normalMap, inDet );
|
||||
texOp = new GenOp( String::ToString("tex2D(@, vec3(@.xy, @.x))", normalIndex), normalMap, inDet, new IndexOp(detailInfo, normalIndex));
|
||||
|
||||
// create bump normal
|
||||
Var *bumpNorm = new Var;
|
||||
|
|
@ -1019,26 +995,11 @@ void TerrainNormalMapFeatGLSL::processPix( Vector<ShaderComponent*> &component
|
|||
LangElement *bumpNormDecl = new DecOp( bumpNorm );
|
||||
meta->addStatement( expandNormalMap( texOp, bumpNormDecl, bumpNorm, fd ) );
|
||||
|
||||
// If this is the last normal map then we
|
||||
// can test to see the total blend value
|
||||
// to see if we should clip the result.
|
||||
Var* blendTotal = (Var*)LangElement::find("blendTotal");
|
||||
if (blendTotal)
|
||||
{
|
||||
if (fd.features.getNextFeatureIndex(MFT_TerrainNormalMap, normalIndex) == -1)
|
||||
meta->addStatement(new GenOp(" if ( @ > 0.0001f ){\r\n\r\n", blendTotal));
|
||||
}
|
||||
// Normalize is done later...
|
||||
// Note: The reverse mul order is intentional. Affine matrix.
|
||||
meta->addStatement(new GenOp(" @ = lerp( @, tMul( @.xyz, @ ), min( @, @.w ) );\r\n",
|
||||
gbNormal, gbNormal, bumpNorm, viewToTangent, detailBlend, inDet));
|
||||
|
||||
if (blendTotal)
|
||||
{
|
||||
if (fd.features.getNextFeatureIndex(MFT_TerrainNormalMap, normalIndex) == -1)
|
||||
meta->addStatement(new GenOp(" }\r\n"));
|
||||
}
|
||||
|
||||
// End the conditional block.
|
||||
meta->addStatement( new GenOp( " }\r\n" ) );
|
||||
|
||||
|
|
@ -1049,6 +1010,13 @@ ShaderFeature::Resources TerrainNormalMapFeatGLSL::getResources( const MaterialF
|
|||
{
|
||||
Resources res;
|
||||
|
||||
if (getProcessIndex() == 0)
|
||||
{
|
||||
// Texture Array
|
||||
res.numTex += 1;
|
||||
res.numTexReg += 1;
|
||||
}
|
||||
|
||||
// We only need to process normals during the deferred.
|
||||
if ( fd.features.hasFeature( MFT_DeferredConditioner ) )
|
||||
{
|
||||
|
|
@ -1107,35 +1075,6 @@ ShaderFeature::Resources TerrainLightMapFeatGLSL::getResources( const MaterialFe
|
|||
return res;
|
||||
}
|
||||
|
||||
|
||||
void TerrainAdditiveFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
|
||||
const MaterialFeatureData &fd )
|
||||
{
|
||||
Var *color = NULL;
|
||||
Var* norm = NULL;
|
||||
if (fd.features[MFT_isDeferred])
|
||||
{
|
||||
color = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::RenderTarget1));
|
||||
norm = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget));
|
||||
}
|
||||
color = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget));
|
||||
|
||||
Var *blendTotal = (Var*)LangElement::find( "blendTotal" );
|
||||
if ( !color || !blendTotal )
|
||||
return;
|
||||
|
||||
MultiLine *meta = new MultiLine;
|
||||
|
||||
meta->addStatement( new GenOp( " clip( @ - 0.0001 );\r\n", blendTotal ) );
|
||||
meta->addStatement( new GenOp( " @.a = @;\r\n", color, blendTotal ) );
|
||||
if (fd.features[MFT_isDeferred])
|
||||
{
|
||||
meta->addStatement(new GenOp(" @.a = @;\r\n", norm, blendTotal));
|
||||
}
|
||||
|
||||
output = meta;
|
||||
}
|
||||
|
||||
//standard matInfo map contains data of the form .r = bitflags, .g = (will contain AO),
|
||||
//.b = specular strength, a= spec power.
|
||||
|
||||
|
|
@ -1197,21 +1136,25 @@ void TerrainORMMapFeatGLSL::processVert(Vector<ShaderComponent*> &componentList,
|
|||
Var *outTex = (Var*)LangElement::find(String::ToString("detCoord%d", detailIndex));
|
||||
if (outTex == NULL)
|
||||
{
|
||||
outTex = new Var;
|
||||
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));
|
||||
Var *detScaleAndFade = (Var*)LangElement::find("detailScaleAndFade");
|
||||
if (detScaleAndFade == NULL)
|
||||
{
|
||||
detScaleAndFade = new Var;
|
||||
detScaleAndFade->setType("vec4");
|
||||
detScaleAndFade->setName(String::ToString("detailScaleAndFade%d", detailIndex));
|
||||
detScaleAndFade->setName("detailScaleAndFade");
|
||||
detScaleAndFade->uniform = true;
|
||||
detScaleAndFade->constSortPos = cspPotentialPrimitive;
|
||||
}
|
||||
|
||||
detScaleAndFade->arraySize = mMax(detScaleAndFade->arraySize, detailIndex + 1);
|
||||
|
||||
// Setup the detail coord.
|
||||
//
|
||||
// NOTE: You see here we scale the texture coord by 'xyx'
|
||||
|
|
@ -1221,11 +1164,11 @@ void TerrainORMMapFeatGLSL::processVert(Vector<ShaderComponent*> &componentList,
|
|||
//
|
||||
// See TerrainBaseMapFeatGLSL::processVert().
|
||||
//
|
||||
meta->addStatement(new GenOp(" @.xyz = @ * @.xyx;\r\n", outTex, inTex, detScaleAndFade));
|
||||
meta->addStatement(new GenOp(" @.xyz = @ * @.xyx;\r\n", outTex, inTex, new IndexOp(detScaleAndFade, detailIndex)));
|
||||
|
||||
// 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));
|
||||
outTex, new IndexOp(detScaleAndFade, detailIndex), dist, new IndexOp(detScaleAndFade, detailIndex)));
|
||||
|
||||
output = meta;
|
||||
}
|
||||
|
|
@ -1241,9 +1184,10 @@ void TerrainORMMapFeatGLSL::processPix(Vector<ShaderComponent*> &componentList,
|
|||
/// Get the texture coord.
|
||||
Var *inDet = _getInDetailCoord(componentList);
|
||||
Var *inTex = getVertTexCoord("texCoord");
|
||||
Var* detailInfo = _getDetailIdStrengthParallax();
|
||||
|
||||
const S32 compositeIndex = getProcessIndex();
|
||||
Var *ormConfigMap = _getORMConfigMapTex();
|
||||
Var *ormConfigMap = _getOrmMapSampler();
|
||||
// Sample the normal map.
|
||||
//
|
||||
// We take two normal samples and lerp between them for
|
||||
|
|
@ -1252,11 +1196,11 @@ void TerrainORMMapFeatGLSL::processPix(Vector<ShaderComponent*> &componentList,
|
|||
|
||||
if (fd.features.hasFeature(MFT_TerrainSideProject, compositeIndex))
|
||||
{
|
||||
texOp = new GenOp("lerp( tex2D( @, @.yz ), tex2D( @, @.xz ), @.z )",
|
||||
ormConfigMap, inDet, ormConfigMap, inDet, inTex);
|
||||
texOp = new GenOp("lerp( tex2D( @, vec3(@.yz, @.x) ), tex2D( @, vec3(@.xz, @.x) ), @.z )",
|
||||
ormConfigMap, inDet, new IndexOp(detailInfo, compositeIndex), ormConfigMap, inDet, new IndexOp(detailInfo, compositeIndex), inTex);
|
||||
}
|
||||
else
|
||||
texOp = new GenOp("tex2D(@, @.xy)", ormConfigMap, inDet);
|
||||
texOp = new GenOp("tex2D(@, vec3(@.xy, @.x))", ormConfigMap, inDet, new IndexOp(detailInfo, compositeIndex));
|
||||
|
||||
// search for material var
|
||||
Var * ormConfig;
|
||||
|
|
|
|||
|
|
@ -44,9 +44,9 @@ public:
|
|||
|
||||
Var* _getInMacroCoord(Vector<ShaderComponent*> &componentList );
|
||||
|
||||
Var* _getNormalMapTex();
|
||||
|
||||
Var* _getORMConfigMapTex();
|
||||
Var* _getDetailMapSampler();
|
||||
Var* _getNormalMapSampler();
|
||||
Var* _getOrmMapSampler();
|
||||
|
||||
static Var* _getUniformVar( const char *name, const char *type, ConstantSortPosition csp );
|
||||
|
||||
|
|
@ -151,17 +151,6 @@ public:
|
|||
virtual String getName() { return "Terrain Lightmap Texture"; }
|
||||
};
|
||||
|
||||
|
||||
class TerrainAdditiveFeatGLSL : public TerrainFeatGLSL
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void processPix( Vector<ShaderComponent*> &componentList,
|
||||
const MaterialFeatureData &fd );
|
||||
|
||||
virtual String getName() { return "Terrain Additive"; }
|
||||
};
|
||||
|
||||
class TerrainORMMapFeatGLSL : public TerrainFeatGLSL
|
||||
{
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -48,7 +48,6 @@ namespace
|
|||
FEATUREMGR->registerFeature( MFT_TerrainMacroMap, new NamedFeatureHLSL("TerrainMacroMap Deprecated")); // new TerrainMacroMapFeatHLSL);
|
||||
FEATUREMGR->registerFeature( MFT_TerrainLightMap, new TerrainLightMapFeatHLSL );
|
||||
FEATUREMGR->registerFeature( MFT_TerrainSideProject, new NamedFeatureHLSL( "Terrain Side Projection" ) );
|
||||
FEATUREMGR->registerFeature( MFT_TerrainAdditive, new TerrainAdditiveFeatHLSL );
|
||||
FEATUREMGR->registerFeature( MFT_TerrainORMMap, new TerrainORMMapFeatHLSL );
|
||||
FEATUREMGR->registerFeature( MFT_DeferredTerrainBlankInfoMap, new TerrainBlankInfoMapFeatHLSL );
|
||||
}
|
||||
|
|
@ -123,56 +122,131 @@ Var* TerrainFeatHLSL::_getInMacroCoord( Vector<ShaderComponent*> &componentList
|
|||
return inDet;
|
||||
}
|
||||
|
||||
Var* TerrainFeatHLSL::_getNormalMapTex()
|
||||
Var* TerrainFeatHLSL::_getDetailMapSampler()
|
||||
{
|
||||
String name(String::ToString("normalMap%d", getProcessIndex()));
|
||||
Var *normalMap = (Var*)LangElement::find(name);
|
||||
String name("detailMapSampler");
|
||||
Var* detailMapSampler = (Var*)LangElement::find(name);
|
||||
|
||||
if (!normalMap)
|
||||
if(!detailMapSampler)
|
||||
{
|
||||
normalMap = new Var;
|
||||
normalMap->setType("SamplerState");
|
||||
normalMap->setName(name);
|
||||
normalMap->uniform = true;
|
||||
normalMap->sampler = true;
|
||||
normalMap->constNum = Var::getTexUnitNum();
|
||||
detailMapSampler = new Var;
|
||||
detailMapSampler->setName(name);
|
||||
detailMapSampler->setType("SamplerState");
|
||||
detailMapSampler->uniform = true;
|
||||
detailMapSampler->sampler = true;
|
||||
detailMapSampler->constNum = Var::getTexUnitNum();
|
||||
}
|
||||
|
||||
return normalMap;
|
||||
return detailMapSampler;
|
||||
}
|
||||
|
||||
Var* TerrainFeatHLSL::_getORMConfigMapTex()
|
||||
Var* TerrainFeatHLSL::_getDetailMapArray()
|
||||
{
|
||||
String name(String::ToString("ormConfigMap%d", getProcessIndex()));
|
||||
Var *ormConfigMap = (Var*)LangElement::find(name);
|
||||
String name("detailMapArray");
|
||||
Var* detailMapArray = (Var*)LangElement::find(name);
|
||||
|
||||
if (!ormConfigMap)
|
||||
if(!detailMapArray)
|
||||
{
|
||||
ormConfigMap = new Var;
|
||||
ormConfigMap->setType("SamplerState");
|
||||
ormConfigMap->setName(name);
|
||||
ormConfigMap->uniform = true;
|
||||
ormConfigMap->sampler = true;
|
||||
ormConfigMap->constNum = Var::getTexUnitNum();
|
||||
detailMapArray = new Var;
|
||||
detailMapArray->setName(name);
|
||||
detailMapArray->setType("Texture2DArray");
|
||||
detailMapArray->uniform = true;
|
||||
detailMapArray->texture = true;
|
||||
detailMapArray->constNum = _getDetailMapSampler()->constNum;
|
||||
}
|
||||
|
||||
return ormConfigMap;
|
||||
return detailMapArray;
|
||||
}
|
||||
|
||||
Var* TerrainFeatHLSL::_getNormalMapSampler()
|
||||
{
|
||||
String name("normalMapSampler");
|
||||
Var* normalMapSampler = (Var*)LangElement::find(name);
|
||||
|
||||
if (!normalMapSampler)
|
||||
{
|
||||
normalMapSampler = new Var;
|
||||
normalMapSampler->setName(name);
|
||||
normalMapSampler->setType("SamplerState");
|
||||
normalMapSampler->uniform = true;
|
||||
normalMapSampler->sampler = true;
|
||||
normalMapSampler->constNum = Var::getTexUnitNum();
|
||||
}
|
||||
|
||||
return normalMapSampler;
|
||||
}
|
||||
|
||||
Var* TerrainFeatHLSL::_getNormalMapArray()
|
||||
{
|
||||
String name("normalMapArray");
|
||||
Var* normalMapArray = (Var*)LangElement::find(name);
|
||||
|
||||
if (!normalMapArray)
|
||||
{
|
||||
normalMapArray = new Var;
|
||||
normalMapArray->setName(name);
|
||||
normalMapArray->setType("Texture2DArray");
|
||||
normalMapArray->uniform = true;
|
||||
normalMapArray->texture = true;
|
||||
normalMapArray->constNum = _getNormalMapSampler()->constNum;
|
||||
}
|
||||
|
||||
return normalMapArray;
|
||||
}
|
||||
|
||||
Var* TerrainFeatHLSL::_getOrmMapSampler()
|
||||
{
|
||||
String name("ormMapSampler");
|
||||
Var* ormMapSampler = (Var*)LangElement::find(name);
|
||||
|
||||
if (!ormMapSampler)
|
||||
{
|
||||
ormMapSampler = new Var;
|
||||
ormMapSampler->setName(name);
|
||||
ormMapSampler->setType("SamplerState");
|
||||
ormMapSampler->uniform = true;
|
||||
ormMapSampler->sampler = true;
|
||||
ormMapSampler->constNum = Var::getTexUnitNum();
|
||||
}
|
||||
|
||||
return ormMapSampler;
|
||||
}
|
||||
|
||||
Var* TerrainFeatHLSL::_getOrmMapArray()
|
||||
{
|
||||
String name("ormMapArray");
|
||||
Var* ormMapArray = (Var*)LangElement::find(name);
|
||||
|
||||
if (!ormMapArray)
|
||||
{
|
||||
ormMapArray = new Var;
|
||||
ormMapArray->setName(name);
|
||||
ormMapArray->setType("Texture2DArray");
|
||||
ormMapArray->uniform = true;
|
||||
ormMapArray->texture = true;
|
||||
ormMapArray->constNum = _getOrmMapSampler()->constNum;
|
||||
}
|
||||
|
||||
return ormMapArray;
|
||||
}
|
||||
|
||||
Var* TerrainFeatHLSL::_getDetailIdStrengthParallax()
|
||||
{
|
||||
String name( String::ToString( "detailIdStrengthParallax%d", getProcessIndex() ) );
|
||||
String name( String::ToString( "detailIdStrengthParallax", getProcessIndex() ) );
|
||||
|
||||
Var *detailInfo = (Var*)LangElement::find( name );
|
||||
if ( !detailInfo )
|
||||
{
|
||||
detailInfo = new Var;
|
||||
detailInfo->setType( "float3" );
|
||||
detailInfo->setType( "float4" );
|
||||
detailInfo->setName( name );
|
||||
detailInfo->uniform = true;
|
||||
detailInfo->constSortPos = cspPotentialPrimitive;
|
||||
detailInfo->arraySize = getProcessIndex();
|
||||
}
|
||||
|
||||
detailInfo->arraySize = mMax(detailInfo->arraySize, getProcessIndex() + 1);
|
||||
|
||||
return detailInfo;
|
||||
}
|
||||
|
||||
|
|
@ -383,11 +457,17 @@ void TerrainDetailMapFeatHLSL::processVert( Vector<ShaderComponent*> &component
|
|||
outTex->setType( "float4" );
|
||||
|
||||
// Get the detail scale and fade info.
|
||||
Var *detScaleAndFade = new Var;
|
||||
detScaleAndFade->setType( "float4" );
|
||||
detScaleAndFade->setName( String::ToString( "detailScaleAndFade%d", detailIndex ) );
|
||||
detScaleAndFade->uniform = true;
|
||||
detScaleAndFade->constSortPos = cspPotentialPrimitive;
|
||||
Var* detScaleAndFade = (Var*)LangElement::find("detailScaleAndFade");
|
||||
if (detScaleAndFade == NULL)
|
||||
{
|
||||
detScaleAndFade = new Var;
|
||||
detScaleAndFade->setType("float4");
|
||||
detScaleAndFade->setName("detailScaleAndFade");
|
||||
detScaleAndFade->uniform = true;
|
||||
detScaleAndFade->constSortPos = cspPotentialPrimitive;
|
||||
}
|
||||
|
||||
detScaleAndFade->arraySize = mMax(detScaleAndFade->arraySize, detailIndex + 1);
|
||||
|
||||
// Setup the detail coord.
|
||||
//
|
||||
|
|
@ -398,11 +478,11 @@ void TerrainDetailMapFeatHLSL::processVert( Vector<ShaderComponent*> &component
|
|||
//
|
||||
// See TerrainBaseMapFeatHLSL::processVert().
|
||||
//
|
||||
meta->addStatement( new GenOp( " @.xyz = @ * @.xyx;\r\n", outTex, inTex, detScaleAndFade ) );
|
||||
meta->addStatement( new GenOp( " @.xyz = @ * @.xyx;\r\n", outTex, inTex, new IndexOp(detScaleAndFade, detailIndex) ) );
|
||||
|
||||
// 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 ) );
|
||||
outTex, new IndexOp(detScaleAndFade, detailIndex), dist, new IndexOp(detScaleAndFade, detailIndex)) );
|
||||
|
||||
output = meta;
|
||||
}
|
||||
|
|
@ -485,52 +565,25 @@ void TerrainDetailMapFeatHLSL::processPix( Vector<ShaderComponent*> &component
|
|||
|
||||
// Calculate the blend for this detail texture.
|
||||
meta->addStatement( new GenOp( " @ = calcBlend( @.x, @.xy, @, @ );\r\n",
|
||||
new DecOp( detailBlend ), detailInfo, inTex, layerSize, layerSample ) );
|
||||
|
||||
// Get a var and accumulate the blend amount.
|
||||
Var *blendTotal = (Var*)LangElement::find( "blendTotal" );
|
||||
if ( !blendTotal )
|
||||
{
|
||||
blendTotal = new Var;
|
||||
blendTotal->setName( "blendTotal" );
|
||||
blendTotal->setType( "float" );
|
||||
meta->addStatement( new GenOp( " @ = 0;\r\n", new DecOp( blendTotal ) ) );
|
||||
}
|
||||
|
||||
// Add to the blend total.
|
||||
|
||||
meta->addStatement(new GenOp(" @ = max( @, @ );\r\n", blendTotal, blendTotal, detailBlend));
|
||||
new DecOp( detailBlend ), new IndexOp(detailInfo, detailIndex), inTex, layerSize, layerSample ) );
|
||||
|
||||
// If we had a parallax feature... then factor in the parallax
|
||||
// amount so that it fades out with the layer blending.
|
||||
if (fd.features.hasFeature(MFT_TerrainParallaxMap, detailIndex))
|
||||
{
|
||||
// Get the rest of our inputs.
|
||||
Var *normalMap = _getNormalMapTex();
|
||||
|
||||
String name(String::ToString("normalMapTex%d", getProcessIndex()));
|
||||
Var *normalMapTex = (Var*)LangElement::find(name);
|
||||
|
||||
if (!normalMapTex)
|
||||
{
|
||||
normalMapTex = new Var;
|
||||
normalMapTex->setName(String::ToString("normalMapTex%d", getProcessIndex()));
|
||||
normalMapTex->setType("Texture2D");
|
||||
normalMapTex->uniform = true;
|
||||
normalMapTex->texture = true;
|
||||
normalMapTex->constNum = normalMap->constNum;
|
||||
}
|
||||
Var* normalMapArray = _getNormalMapArray();
|
||||
Var* normalMapSampler = _getNormalMapSampler();
|
||||
|
||||
// Call the library function to do the rest.
|
||||
if (fd.features.hasFeature(MFT_IsBC3nm, detailIndex))
|
||||
{
|
||||
meta->addStatement(new GenOp(" @.xy += parallaxOffsetDxtnm( @, @, @.xy, @, @.z * @ );\r\n",
|
||||
inDet, normalMapTex, normalMap, inDet, negViewTS, detailInfo, detailBlend));
|
||||
meta->addStatement(new GenOp(" @.xy += parallaxOffsetDxtnmTexArray( @, @, float3(@.xy, @.x), @, @.z * @ );\r\n",
|
||||
inDet, normalMapArray, normalMapSampler, inDet, new IndexOp(detailInfo, detailIndex), negViewTS, new IndexOp(detailInfo, detailIndex), detailBlend));
|
||||
}
|
||||
else
|
||||
{
|
||||
meta->addStatement(new GenOp(" @.xy += parallaxOffset( @, @, @.xy, @, @.z * @ );\r\n",
|
||||
inDet, normalMapTex, normalMap, inDet, negViewTS, detailInfo, detailBlend));
|
||||
meta->addStatement(new GenOp(" @.xy += parallaxOffsetTexArray( @, @, float3(@.xy, @.x), @, @.z * @ );\r\n",
|
||||
inDet, normalMapArray, normalMapSampler, inDet, new IndexOp(detailInfo, detailIndex), negViewTS, new IndexOp(detailInfo, detailIndex), detailBlend));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -559,14 +612,6 @@ void TerrainDetailMapFeatHLSL::processPix( Vector<ShaderComponent*> &component
|
|||
meta->addStatement( new GenOp( " @;\r\n", new DecOp( detailColor ) ) );
|
||||
}
|
||||
|
||||
// Get the detail texture.
|
||||
Var *detailMap = new Var;
|
||||
detailMap->setType( "SamplerState" );
|
||||
detailMap->setName( String::ToString( "detailMap%d", detailIndex ) );
|
||||
detailMap->uniform = true;
|
||||
detailMap->sampler = true;
|
||||
detailMap->constNum = Var::getTexUnitNum(); // used as texture unit num here
|
||||
|
||||
// If we're using SM 3.0 then take advantage of
|
||||
// dynamic branching to skip layers per-pixel.
|
||||
|
||||
|
|
@ -585,27 +630,23 @@ void TerrainDetailMapFeatHLSL::processPix( Vector<ShaderComponent*> &component
|
|||
//
|
||||
|
||||
//Sampled detail texture that is not expanded
|
||||
Var* detailTex = new Var;
|
||||
detailTex->setName(String::ToString("detailTex%d", detailIndex));
|
||||
detailTex->setType("Texture2D");
|
||||
detailTex->uniform = true;
|
||||
detailTex->texture = true;
|
||||
detailTex->constNum = detailMap->constNum;
|
||||
Var* detailMapArray = _getDetailMapArray();
|
||||
Var* detailMapSampler = _getDetailMapSampler();
|
||||
|
||||
if (fd.features.hasFeature(MFT_TerrainSideProject, detailIndex))
|
||||
{
|
||||
|
||||
meta->addStatement(new GenOp(" @ = ( lerp( @.Sample( @, @.yz ), @.Sample( @, @.xz ), @.z ) * 2.0 ) - 1.0;\r\n",
|
||||
detailColor, detailTex, detailMap, inDet, detailTex, detailMap, inDet, inTex));
|
||||
meta->addStatement(new GenOp(" @ = ( lerp( @.Sample( @, float3(@.yz, @.x) ), @.Sample( @, float3(@.xz, @.x) ), @.z ) * 2.0 ) - 1.0;\r\n",
|
||||
detailColor, detailMapArray, detailMapSampler, inDet, new IndexOp(detailInfo, detailIndex), detailMapArray, detailMapSampler, inDet, new IndexOp(detailInfo, detailIndex), inTex));
|
||||
}
|
||||
else
|
||||
{
|
||||
meta->addStatement(new GenOp(" @ = ( @.Sample( @, @.xy ) * 2.0 ) - 1.0;\r\n",
|
||||
detailColor, detailTex, detailMap, inDet));
|
||||
meta->addStatement(new GenOp(" @ = ( @.Sample( @, float3(@.xy, @.x) ) * 2.0 ) - 1.0;\r\n",
|
||||
detailColor, detailMapArray, detailMapSampler, inDet, new IndexOp(detailInfo, detailIndex)));
|
||||
}
|
||||
|
||||
meta->addStatement( new GenOp( " @ *= @.y * @.w;\r\n",
|
||||
detailColor, detailInfo, inDet ) );
|
||||
detailColor, new IndexOp(detailInfo, detailIndex), inDet ) );
|
||||
|
||||
ShaderFeature::OutputTarget target = ShaderFeature::DefaultTarget;
|
||||
|
||||
|
|
@ -635,25 +676,24 @@ ShaderFeature::Resources TerrainDetailMapFeatHLSL::getResources( const MaterialF
|
|||
// If this is the first detail pass then we
|
||||
// samples from the layer tex.
|
||||
res.numTex += 1;
|
||||
res.numTexReg += 1;
|
||||
|
||||
// If this material also does parallax then it
|
||||
// will generate the negative view vector and the
|
||||
// worldToTanget transform.
|
||||
if ( fd.features.hasFeature( MFT_TerrainParallaxMap ) )
|
||||
res.numTexReg += 4;
|
||||
// Add Detail TextureArray
|
||||
res.numTex += 1;
|
||||
res.numTexReg += 1;
|
||||
}
|
||||
|
||||
// sample from the detail texture for diffuse coloring.
|
||||
res.numTex += 1;
|
||||
// res.numTex += 1;
|
||||
|
||||
// If we have parallax for this layer then we'll also
|
||||
// be sampling the normal map for the parallax heightmap.
|
||||
if ( fd.features.hasFeature( MFT_TerrainParallaxMap, getProcessIndex() ) )
|
||||
res.numTex += 1;
|
||||
//if ( fd.features.hasFeature( MFT_TerrainParallaxMap, getProcessIndex() ) )
|
||||
//res.numTex += 1;
|
||||
|
||||
// Finally we always send the detail texture
|
||||
// coord to the pixel shader.
|
||||
res.numTexReg += 1;
|
||||
// res.numTexReg += 1;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
@ -714,18 +754,24 @@ void TerrainMacroMapFeatHLSL::processVert( Vector<ShaderComponent*> &componentL
|
|||
outTex->setType( "float4" );
|
||||
|
||||
// Get the detail scale and fade info.
|
||||
Var *detScaleAndFade = new Var;
|
||||
detScaleAndFade->setType( "float4" );
|
||||
detScaleAndFade->setName( String::ToString( "macroScaleAndFade%d", detailIndex ) );
|
||||
detScaleAndFade->uniform = true;
|
||||
detScaleAndFade->constSortPos = cspPotentialPrimitive;
|
||||
Var* macroScaleAndFade = (Var*)LangElement::find("macroScaleAndFade");
|
||||
if (macroScaleAndFade == NULL)
|
||||
{
|
||||
macroScaleAndFade = new Var;
|
||||
macroScaleAndFade->setType("float4");
|
||||
macroScaleAndFade->setName("macroScaleAndFade");
|
||||
macroScaleAndFade->uniform = true;
|
||||
macroScaleAndFade->constSortPos = cspPotentialPrimitive;
|
||||
}
|
||||
|
||||
macroScaleAndFade->arraySize = mMax(macroScaleAndFade->arraySize, detailIndex + 1);
|
||||
|
||||
// Setup the detail coord.
|
||||
meta->addStatement( new GenOp( " @.xyz = @ * @.xyx;\r\n", outTex, inTex, detScaleAndFade ) );
|
||||
meta->addStatement( new GenOp( " @.xyz = @ * @.xyx;\r\n", outTex, inTex, new IndexOp(macroScaleAndFade, detailIndex)) );
|
||||
|
||||
// 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 ) );
|
||||
outTex, new IndexOp(macroScaleAndFade, detailIndex), dist, new IndexOp(macroScaleAndFade, detailIndex)) );
|
||||
|
||||
output = meta;
|
||||
}
|
||||
|
|
@ -809,20 +855,7 @@ void TerrainMacroMapFeatHLSL::processPix( Vector<ShaderComponent*> &componentL
|
|||
|
||||
// Calculate the blend for this detail texture.
|
||||
meta->addStatement( new GenOp( " @ = calcBlend( @.x, @.xy, @, @ );\r\n",
|
||||
new DecOp( detailBlend ), detailInfo, inTex, layerSize, layerSample ) );
|
||||
|
||||
// Get a var and accumulate the blend amount.
|
||||
Var *blendTotal = (Var*)LangElement::find( "blendTotal" );
|
||||
if ( !blendTotal )
|
||||
{
|
||||
blendTotal = new Var;
|
||||
blendTotal->setName( "blendTotal" );
|
||||
blendTotal->setType( "float" );
|
||||
meta->addStatement( new GenOp( " @ = 0;\r\n", new DecOp( blendTotal ) ) );
|
||||
}
|
||||
|
||||
// Add to the blend total.
|
||||
meta->addStatement(new GenOp(" @ = max( @, @ );\r\n", blendTotal, blendTotal, detailBlend));
|
||||
new DecOp( detailBlend ), new IndexOp(detailInfo, detailIndex), inTex, layerSize, layerSample ) );
|
||||
|
||||
// Check to see if we have a gbuffer normal.
|
||||
Var *gbNormal = (Var*)LangElement::find( "gbNormal" );
|
||||
|
|
@ -849,22 +882,6 @@ void TerrainMacroMapFeatHLSL::processPix( Vector<ShaderComponent*> &componentL
|
|||
meta->addStatement( new GenOp( " @;\r\n", new DecOp( detailColor ) ) );
|
||||
}
|
||||
|
||||
// Get the detail texture.
|
||||
Var *detailMap = new Var;
|
||||
detailMap->setType( "SamplerState" );
|
||||
detailMap->setName( String::ToString( "macroMap%d", detailIndex ) );
|
||||
detailMap->uniform = true;
|
||||
detailMap->sampler = true;
|
||||
detailMap->constNum = Var::getTexUnitNum(); // used as texture unit num here
|
||||
|
||||
//Create texture object for directx 11
|
||||
Var *detailTex = new Var;
|
||||
detailTex->setName(String::ToString("macroMapTex%d", detailIndex));
|
||||
detailTex->setType("Texture2D");
|
||||
detailTex->uniform = true;
|
||||
detailTex->texture = true;
|
||||
detailTex->constNum = detailMap->constNum;
|
||||
|
||||
// If we're using SM 3.0 then take advantage of
|
||||
// dynamic branching to skip layers per-pixel.
|
||||
if ( GFX->getPixelShaderVersion() >= 3.0f )
|
||||
|
|
@ -872,6 +889,9 @@ void TerrainMacroMapFeatHLSL::processPix( Vector<ShaderComponent*> &componentL
|
|||
|
||||
meta->addStatement( new GenOp( " {\r\n" ) );
|
||||
|
||||
Var* detailMapArray = _getDetailMapArray();
|
||||
Var* detailMapSampler = _getDetailMapSampler();
|
||||
|
||||
// Note that we're doing the standard greyscale detail
|
||||
// map technique here which can darken and lighten the
|
||||
// diffuse texture.
|
||||
|
|
@ -881,17 +901,17 @@ void TerrainMacroMapFeatHLSL::processPix( Vector<ShaderComponent*> &componentL
|
|||
//
|
||||
if (fd.features.hasFeature(MFT_TerrainSideProject, detailIndex))
|
||||
{
|
||||
meta->addStatement(new GenOp(" @ = ( lerp( @.Sample( @, @.yz ), @.Sample( @, @.xz ), @.z ) * 2.0 ) - 1.0;\r\n",
|
||||
detailColor, detailTex, detailMap, inDet, detailTex, detailMap, inDet, inTex));
|
||||
meta->addStatement(new GenOp(" @ = ( lerp( @.Sample( @, float3(@.yz, @.x) ), @.Sample( @, float3(@.xz, @.x) ), @.z ) * 2.0 ) - 1.0;\r\n",
|
||||
detailColor, detailMapArray, detailMapSampler, inDet, new IndexOp(detailInfo, detailIndex), detailMapArray, detailMapSampler, inDet, new IndexOp(detailInfo, detailIndex), inTex));
|
||||
}
|
||||
else
|
||||
{
|
||||
meta->addStatement(new GenOp(" @ = ( @.Sample( @, @.xy ) * 2.0 ) - 1.0;\r\n",
|
||||
detailColor, detailTex, detailMap, inDet));
|
||||
meta->addStatement(new GenOp(" @ = ( @.Sample( @, float3(@.xy, @.x) ) * 2.0 ) - 1.0;\r\n",
|
||||
detailColor, detailMapArray, detailMapSampler, inDet, new IndexOp(detailInfo, detailIndex)));
|
||||
}
|
||||
|
||||
meta->addStatement( new GenOp( " @ *= @.y * @.w;\r\n",
|
||||
detailColor, detailInfo, inDet ) );
|
||||
detailColor, new IndexOp(detailInfo, detailIndex), inDet ) );
|
||||
|
||||
ShaderFeature::OutputTarget target = ShaderFeature::DefaultTarget;
|
||||
|
||||
|
|
@ -987,38 +1007,28 @@ void TerrainNormalMapFeatHLSL::processPix( Vector<ShaderComponent*> &component
|
|||
|
||||
meta->addStatement( new GenOp( " {\r\n" ) );
|
||||
|
||||
// Get the normal map texture.
|
||||
Var *normalMap = _getNormalMapTex();
|
||||
|
||||
/// Get the texture coord.
|
||||
Var *inDet = _getInDetailCoord( componentList );
|
||||
Var *inTex = getVertTexCoord( "texCoord" );
|
||||
|
||||
Var* detailInfo = _getDetailIdStrengthParallax();
|
||||
|
||||
// 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("normalMapTex%d", getProcessIndex()));
|
||||
Var *normalMapTex = (Var*)LangElement::find(name);
|
||||
if (!normalMapTex)
|
||||
{
|
||||
normalMapTex = new Var;
|
||||
normalMapTex->setName(String::ToString("normalMapTex%d", getProcessIndex()));
|
||||
normalMapTex->setType("Texture2D");
|
||||
normalMapTex->uniform = true;
|
||||
normalMapTex->texture = true;
|
||||
normalMapTex->constNum = normalMap->constNum;
|
||||
}
|
||||
|
||||
Var* normalMapSampler = _getNormalMapSampler();
|
||||
Var* normalMapArray = _getNormalMapArray();
|
||||
|
||||
if (fd.features.hasFeature(MFT_TerrainSideProject, normalIndex))
|
||||
{
|
||||
texOp = new GenOp("lerp( @.Sample( @, @.yz ), @.Sample( @, @.xz ), @.z )",
|
||||
normalMapTex, normalMap, inDet, normalMapTex, normalMap, inDet, inTex);
|
||||
texOp = new GenOp("lerp( @.Sample( @, float3(@.yz, @.x) ), @.Sample( @, float3(@.xz, @.x) ), @.z )",
|
||||
normalMapArray, normalMapSampler, inDet, new IndexOp(detailInfo, normalIndex), normalMapArray, normalMapSampler, inDet, new IndexOp(detailInfo, normalIndex), inTex);
|
||||
}
|
||||
else
|
||||
texOp = new GenOp("@.Sample(@, @.xy)", normalMapTex, normalMap, inDet);
|
||||
texOp = new GenOp("@.Sample(@, float3(@.xy, @.x))", normalMapArray, normalMapSampler, inDet, new IndexOp(detailInfo, normalIndex));
|
||||
|
||||
// create bump normal
|
||||
Var *bumpNorm = new Var;
|
||||
|
|
@ -1028,25 +1038,11 @@ void TerrainNormalMapFeatHLSL::processPix( Vector<ShaderComponent*> &component
|
|||
LangElement *bumpNormDecl = new DecOp( bumpNorm );
|
||||
meta->addStatement( expandNormalMap( texOp, bumpNormDecl, bumpNorm, fd ) );
|
||||
|
||||
// If this is the last normal map then we
|
||||
// can test to see the total blend value
|
||||
// to see if we should clip the result.
|
||||
Var* blendTotal = (Var*)LangElement::find("blendTotal");
|
||||
if (blendTotal)
|
||||
{
|
||||
if (fd.features.getNextFeatureIndex(MFT_TerrainNormalMap, normalIndex) == -1)
|
||||
meta->addStatement(new GenOp(" if ( @ > 0.0001f ){\r\n\r\n", blendTotal));
|
||||
}
|
||||
// Normalize is done later...
|
||||
// Note: The reverse mul order is intentional. Affine matrix.
|
||||
meta->addStatement( new GenOp( " @ = lerp( @, mul( @.xyz, @ ), min( @, @.w ) );\r\n",
|
||||
gbNormal, gbNormal, bumpNorm, viewToTangent, detailBlend, inDet ) );
|
||||
|
||||
if (blendTotal)
|
||||
{
|
||||
if (fd.features.getNextFeatureIndex(MFT_TerrainNormalMap, normalIndex) == -1)
|
||||
meta->addStatement(new GenOp(" }\r\n"));
|
||||
}
|
||||
// End the conditional block.
|
||||
meta->addStatement( new GenOp( " }\r\n" ) );
|
||||
|
||||
|
|
@ -1056,14 +1052,21 @@ void TerrainNormalMapFeatHLSL::processPix( Vector<ShaderComponent*> &component
|
|||
ShaderFeature::Resources TerrainNormalMapFeatHLSL::getResources( const MaterialFeatureData &fd )
|
||||
{
|
||||
Resources res;
|
||||
|
||||
|
||||
if (getProcessIndex() == 0)
|
||||
{
|
||||
res.numTexReg += 1;
|
||||
res.numTex += 1;
|
||||
}
|
||||
|
||||
// If this is the first normal map and there
|
||||
// are no parallax features then we will
|
||||
// generate the worldToTanget transform.
|
||||
if ( !fd.features.hasFeature( MFT_TerrainParallaxMap ) &&
|
||||
( getProcessIndex() == 0 || !fd.features.hasFeature( MFT_TerrainNormalMap, getProcessIndex() - 1 ) ) )
|
||||
res.numTexReg = 3;
|
||||
res.numTex = 1;
|
||||
//if ( !fd.features.hasFeature( MFT_TerrainParallaxMap ) &&
|
||||
// ( getProcessIndex() == 0 || !fd.features.hasFeature( MFT_TerrainNormalMap, getProcessIndex() - 1 ) ) )
|
||||
// res.numTexReg = 3;
|
||||
//res.numTex = 1;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
@ -1116,35 +1119,6 @@ ShaderFeature::Resources TerrainLightMapFeatHLSL::getResources( const MaterialFe
|
|||
return res;
|
||||
}
|
||||
|
||||
void TerrainAdditiveFeatHLSL::processPix( Vector<ShaderComponent*> &componentList,
|
||||
const MaterialFeatureData &fd )
|
||||
{
|
||||
Var *color = NULL;
|
||||
Var* norm = NULL;
|
||||
if (fd.features[MFT_isDeferred])
|
||||
{
|
||||
color = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget1) );
|
||||
norm = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::DefaultTarget) );
|
||||
}
|
||||
else
|
||||
color = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::DefaultTarget) );
|
||||
|
||||
Var *blendTotal = (Var*)LangElement::find( "blendTotal" );
|
||||
if ( !color || !blendTotal )
|
||||
return;
|
||||
|
||||
MultiLine *meta = new MultiLine;
|
||||
|
||||
meta->addStatement( new GenOp( " clip( @ - 0.0001 );\r\n", blendTotal ) );
|
||||
meta->addStatement( new GenOp( " @.a = @;\r\n", color, blendTotal ) );
|
||||
if (fd.features[MFT_isDeferred])
|
||||
{
|
||||
meta->addStatement(new GenOp(" @.a = @;\r\n", norm, blendTotal));
|
||||
}
|
||||
|
||||
output = meta;
|
||||
}
|
||||
|
||||
//standard matInfo map contains data of the form .r = bitflags, .g = (will contain AO),
|
||||
//.b = specular strength, a= spec power.
|
||||
|
||||
|
|
@ -1211,15 +1185,18 @@ void TerrainORMMapFeatHLSL::processVert(Vector<ShaderComponent*> &componentList,
|
|||
outTex->setType("float4");
|
||||
}
|
||||
// Get the detail scale and fade info.
|
||||
Var *detScaleAndFade = (Var*)LangElement::find(String::ToString("detailScaleAndFade%d", detailIndex));
|
||||
Var *detScaleAndFade = (Var*)LangElement::find("detailScaleAndFade");
|
||||
if (detScaleAndFade == NULL)
|
||||
{
|
||||
detScaleAndFade = new Var;
|
||||
detScaleAndFade->setType("float4");
|
||||
detScaleAndFade->setName(String::ToString("detailScaleAndFade%d", detailIndex));
|
||||
detScaleAndFade->setName("detailScaleAndFade");
|
||||
detScaleAndFade->uniform = true;
|
||||
detScaleAndFade->constSortPos = cspPotentialPrimitive;
|
||||
}
|
||||
|
||||
detScaleAndFade->arraySize = mMax(detScaleAndFade->arraySize, detailIndex + 1);
|
||||
|
||||
// Setup the detail coord.
|
||||
//
|
||||
// NOTE: You see here we scale the texture coord by 'xyx'
|
||||
|
|
@ -1229,11 +1206,11 @@ void TerrainORMMapFeatHLSL::processVert(Vector<ShaderComponent*> &componentList,
|
|||
//
|
||||
// See TerrainBaseMapFeatHLSL::processVert().
|
||||
//
|
||||
meta->addStatement(new GenOp(" @.xyz = @ * @.xyx;\r\n", outTex, inTex, detScaleAndFade));
|
||||
meta->addStatement(new GenOp(" @.xyz = @ * @.xyx;\r\n", outTex, inTex, new IndexOp(detScaleAndFade, detailIndex)));
|
||||
|
||||
// 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));
|
||||
outTex, new IndexOp(detScaleAndFade, detailIndex), dist, new IndexOp(detScaleAndFade, detailIndex)));
|
||||
|
||||
output = meta;
|
||||
}
|
||||
|
|
@ -1249,32 +1226,24 @@ void TerrainORMMapFeatHLSL::processPix(Vector<ShaderComponent*> &componentList,
|
|||
/// Get the texture coord.
|
||||
Var *inDet = _getInDetailCoord(componentList);
|
||||
Var *inTex = getVertTexCoord("texCoord");
|
||||
Var* detailInfo = _getDetailIdStrengthParallax();
|
||||
|
||||
const S32 compositeIndex = getProcessIndex();
|
||||
Var *ormConfigMap = _getORMConfigMapTex();
|
||||
// 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("ormConfigMapTex%d", getProcessIndex()));
|
||||
Var *ormConfigMapTex = (Var*)LangElement::find(name);
|
||||
if (!ormConfigMapTex)
|
||||
{
|
||||
ormConfigMapTex = new Var;
|
||||
ormConfigMapTex->setName(String::ToString("ormConfigMapTex%d", getProcessIndex()));
|
||||
ormConfigMapTex->setType("Texture2D");
|
||||
ormConfigMapTex->uniform = true;
|
||||
ormConfigMapTex->texture = true;
|
||||
ormConfigMapTex->constNum = ormConfigMap->constNum;
|
||||
}
|
||||
|
||||
Var* ormMapArray = _getOrmMapArray();
|
||||
Var* ormMapSampler = _getOrmMapSampler();
|
||||
if (fd.features.hasFeature(MFT_TerrainSideProject, compositeIndex))
|
||||
{
|
||||
texOp = new GenOp("lerp( @.Sample( @, @.yz ), @.Sample( @, @.xz ), @.z )",
|
||||
ormConfigMapTex, ormConfigMap, inDet, ormConfigMapTex, ormConfigMap, inDet, inTex);
|
||||
texOp = new GenOp("lerp( @.Sample( @, float3(@.yz, @.x) ), @.Sample( @, float3(@.xz, @.x) ), @.z )",
|
||||
ormMapArray, ormMapSampler, inDet, new IndexOp(detailInfo, compositeIndex), ormMapArray, ormMapSampler, inDet, new IndexOp(detailInfo, compositeIndex), inTex);
|
||||
}
|
||||
else
|
||||
texOp = new GenOp("@.Sample(@, @.xy)", ormConfigMapTex, ormConfigMap, inDet);
|
||||
texOp = new GenOp("@.Sample(@, float3(@.xy, @.x))", ormMapArray, ormMapSampler, inDet, new IndexOp(detailInfo, compositeIndex));
|
||||
|
||||
// search for material var
|
||||
Var * ormConfig;
|
||||
|
|
|
|||
|
|
@ -45,6 +45,12 @@ public:
|
|||
|
||||
Var* _getInMacroCoord(Vector<ShaderComponent*> &componentList );
|
||||
|
||||
Var* _getDetailMapSampler();
|
||||
Var* _getDetailMapArray();
|
||||
Var* _getNormalMapSampler();
|
||||
Var* _getNormalMapArray();
|
||||
Var* _getOrmMapSampler();
|
||||
Var* _getOrmMapArray();
|
||||
Var* _getNormalMapTex();
|
||||
Var* _getORMConfigMapTex();
|
||||
|
||||
|
|
@ -151,17 +157,6 @@ public:
|
|||
virtual String getName() { return "Terrain Lightmap Texture"; }
|
||||
};
|
||||
|
||||
|
||||
class TerrainAdditiveFeatHLSL : public TerrainFeatHLSL
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void processPix( Vector<ShaderComponent*> &componentList,
|
||||
const MaterialFeatureData &fd );
|
||||
|
||||
virtual String getName() { return "Terrain Additive"; }
|
||||
};
|
||||
|
||||
class TerrainORMMapFeatHLSL : public TerrainFeatHLSL
|
||||
{
|
||||
public:
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -40,6 +40,7 @@
|
|||
#endif
|
||||
|
||||
|
||||
class GFXTextureArray;
|
||||
class SceneRenderState;
|
||||
struct SceneData;
|
||||
class TerrainMaterial;
|
||||
|
|
@ -58,8 +59,7 @@ protected:
|
|||
public:
|
||||
|
||||
MaterialInfo()
|
||||
:mat(NULL), layerId(0), detailTexConst(NULL), macroTexConst(NULL), normalTexConst(NULL),
|
||||
ormTexConst(NULL), detailInfoVConst(NULL), detailInfoPConst(NULL), macroInfoVConst(NULL), macroInfoPConst(NULL)
|
||||
:mat(NULL), layerId(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -69,95 +69,60 @@ protected:
|
|||
|
||||
TerrainMaterial *mat;
|
||||
U32 layerId;
|
||||
|
||||
GFXShaderConstHandle *detailTexConst;
|
||||
GFXTexHandle detailTex;
|
||||
|
||||
GFXShaderConstHandle *macroTexConst;
|
||||
GFXTexHandle macroTex;
|
||||
|
||||
GFXShaderConstHandle *normalTexConst;
|
||||
GFXTexHandle normalTex;
|
||||
|
||||
GFXShaderConstHandle *ormTexConst;
|
||||
GFXTexHandle ormTex;
|
||||
|
||||
GFXShaderConstHandle *detailInfoVConst;
|
||||
GFXShaderConstHandle *detailInfoPConst;
|
||||
|
||||
GFXShaderConstHandle *macroInfoVConst;
|
||||
GFXShaderConstHandle *macroInfoPConst;
|
||||
};
|
||||
|
||||
class Pass
|
||||
{
|
||||
public:
|
||||
///
|
||||
GFXShader *mShader;
|
||||
|
||||
Pass()
|
||||
: shader( NULL ),
|
||||
modelViewProjConst(NULL), worldViewOnly(NULL), viewToObj(NULL),
|
||||
eyePosWorldConst(NULL), eyePosConst(NULL),
|
||||
objTransConst(NULL), worldToObjConst(NULL), vEyeConst(NULL),
|
||||
layerSizeConst(NULL), lightParamsConst(NULL), lightInfoBufferConst(NULL),
|
||||
baseTexMapConst(NULL), layerTexConst(NULL),
|
||||
lightMapTexConst(NULL),
|
||||
squareSize(NULL), oneOverTerrainSize(NULL),
|
||||
fogDataConst(NULL), fogColorConst(NULL)
|
||||
{
|
||||
}
|
||||
GFXShaderConstBufferRef mConsts;
|
||||
|
||||
~Pass()
|
||||
{
|
||||
for ( U32 i=0; i < materials.size(); i++ )
|
||||
delete materials[i];
|
||||
}
|
||||
GFXStateBlockRef mStateBlock;
|
||||
GFXStateBlockRef mWireframeStateBlock;
|
||||
GFXStateBlockRef mReflectionStateBlock;
|
||||
|
||||
Vector<MaterialInfo*> materials;
|
||||
GFXShaderConstHandle *mModelViewProjConst;
|
||||
GFXShaderConstHandle *mWorldViewOnlyConst;
|
||||
GFXShaderConstHandle *mViewToObjConst;
|
||||
|
||||
///
|
||||
GFXShader *shader;
|
||||
GFXShaderConstHandle *mEyePosWorldConst;
|
||||
GFXShaderConstHandle *mEyePosConst;
|
||||
|
||||
GFXShaderConstBufferRef consts;
|
||||
GFXShaderConstHandle *mObjTransConst;
|
||||
GFXShaderConstHandle *mWorldToObjConst;
|
||||
GFXShaderConstHandle *mVEyeConst;
|
||||
|
||||
GFXStateBlockRef stateBlock;
|
||||
GFXStateBlockRef wireframeStateBlock;
|
||||
GFXStateBlockRef reflectionStateBlock;
|
||||
GFXShaderConstHandle *mLayerSizeConst;
|
||||
GFXShaderConstHandle *mLightParamsConst;
|
||||
GFXShaderConstHandle *mLightInfoBufferConst;
|
||||
|
||||
GFXShaderConstHandle *modelViewProjConst;
|
||||
GFXShaderConstHandle *worldViewOnly;
|
||||
GFXShaderConstHandle *viewToObj;
|
||||
GFXShaderConstHandle *mBaseTexMapConst;
|
||||
GFXShaderConstHandle *mLayerTexConst;
|
||||
|
||||
GFXShaderConstHandle *eyePosWorldConst;
|
||||
GFXShaderConstHandle *eyePosConst;
|
||||
GFXShaderConstHandle *mLightMapTexConst;
|
||||
|
||||
GFXShaderConstHandle *objTransConst;
|
||||
GFXShaderConstHandle *worldToObjConst;
|
||||
GFXShaderConstHandle *vEyeConst;
|
||||
GFXShaderConstHandle *mSquareSizeConst;
|
||||
GFXShaderConstHandle *mOneOverTerrainSizeConst;
|
||||
|
||||
GFXShaderConstHandle *layerSizeConst;
|
||||
GFXShaderConstHandle *lightParamsConst;
|
||||
GFXShaderConstHandle *lightInfoBufferConst;
|
||||
GFXShaderConstHandle* mDetailInfoVArrayConst;
|
||||
GFXShaderConstHandle* mDetailInfoPArrayConst;
|
||||
GFXShaderConstHandle* mMacroInfoVArrayConst;
|
||||
GFXShaderConstHandle* mMacroInfoPArrayConst;
|
||||
|
||||
GFXShaderConstHandle *baseTexMapConst;
|
||||
GFXShaderConstHandle *layerTexConst;
|
||||
GFXShaderConstHandle *mFogDataConst;
|
||||
GFXShaderConstHandle *mFogColorConst;
|
||||
|
||||
GFXShaderConstHandle *lightMapTexConst;
|
||||
|
||||
GFXShaderConstHandle *squareSize;
|
||||
GFXShaderConstHandle *oneOverTerrainSize;
|
||||
|
||||
GFXShaderConstHandle *fogDataConst;
|
||||
GFXShaderConstHandle *fogColorConst;
|
||||
};
|
||||
GFXShaderConstHandle *mDetailTexArrayConst;
|
||||
GFXShaderConstHandle *mMacroTexArrayConst;
|
||||
GFXShaderConstHandle *mNormalTexArrayConst;
|
||||
GFXShaderConstHandle *mOrmTexArrayConst;
|
||||
|
||||
TerrainBlock *mTerrain;
|
||||
|
||||
U64 mMaterials;
|
||||
|
||||
Vector<Pass> mPasses;
|
||||
|
||||
U32 mCurrPass;
|
||||
|
||||
U64 mMaterials;
|
||||
Vector<MaterialInfo*> mMaterialInfos;
|
||||
|
||||
static const Vector<String> mSamplerNames;
|
||||
|
||||
GFXTexHandle mBaseMapTexture;
|
||||
|
|
@ -175,14 +140,11 @@ protected:
|
|||
/// A vector of all terrain cell materials loaded in the system.
|
||||
static Vector<TerrainCellMaterial*> smAllMaterials;
|
||||
|
||||
bool _createPass( Vector<MaterialInfo*> *materials,
|
||||
Pass *pass,
|
||||
bool firstPass,
|
||||
bool deferredMat,
|
||||
bool _initShader( bool deferredMat,
|
||||
bool reflectMat,
|
||||
bool baseOnly );
|
||||
|
||||
void _updateMaterialConsts( Pass *pass );
|
||||
void _updateMaterialConsts();
|
||||
|
||||
public:
|
||||
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@
|
|||
#include "T3D/physics/physicsBody.h"
|
||||
#include "T3D/physics/physicsCollision.h"
|
||||
#include "console/engineAPI.h"
|
||||
#include "core/util/safeRelease.h"
|
||||
|
||||
#include "T3D/assets/TerrainMaterialAsset.h"
|
||||
using namespace Torque;
|
||||
|
|
@ -203,7 +204,11 @@ TerrainBlock::TerrainBlock()
|
|||
mScreenError( 16 ),
|
||||
mCastShadows( true ),
|
||||
mZoningDirty( false ),
|
||||
mUpdateBasetex ( true )
|
||||
mUpdateBasetex ( true ),
|
||||
mDetailTextureArray( NULL ),
|
||||
mMacroTextureArray( NULL ),
|
||||
mOrmTextureArray( NULL ),
|
||||
mNormalTextureArray( NULL )
|
||||
{
|
||||
mTypeMask = TerrainObjectType | StaticObjectType | StaticShapeObjectType;
|
||||
mNetFlags.set(Ghostable | ScopeAlways);
|
||||
|
|
@ -231,6 +236,11 @@ TerrainBlock::~TerrainBlock()
|
|||
editor->detachTerrain(this);
|
||||
#endif
|
||||
deleteZodiacPrimitiveBuffer();
|
||||
|
||||
SAFE_RELEASE(mDetailTextureArray);
|
||||
SAFE_RELEASE(mMacroTextureArray);
|
||||
SAFE_RELEASE(mNormalTextureArray);
|
||||
SAFE_RELEASE(mOrmTextureArray);
|
||||
}
|
||||
|
||||
void TerrainBlock::_onTextureEvent( GFXTexCallbackCode code )
|
||||
|
|
|
|||
|
|
@ -135,6 +135,11 @@ protected:
|
|||
///
|
||||
Vector<GFXTexHandle> mBaseTextures;
|
||||
|
||||
GFXTextureArray* mDetailTextureArray;
|
||||
GFXTextureArray* mMacroTextureArray;
|
||||
GFXTextureArray* mNormalTextureArray;
|
||||
GFXTextureArray* mOrmTextureArray;
|
||||
|
||||
///
|
||||
GFXTexHandle mLayerTex;
|
||||
|
||||
|
|
@ -324,6 +329,11 @@ public:
|
|||
|
||||
U32 getMaterialCount() const;
|
||||
|
||||
GFXTextureArray* getDetailTextureArray() const { return mDetailTextureArray; }
|
||||
GFXTextureArray* getMacroTextureArray() const { return mMacroTextureArray; }
|
||||
GFXTextureArray* getNormalTextureArray() const { return mNormalTextureArray; }
|
||||
GFXTextureArray* getOrmTextureArray() const { return mOrmTextureArray; }
|
||||
|
||||
//BaseMatInstance* getMaterialInst( U32 x, U32 y );
|
||||
|
||||
void setHeight( const Point2I &pos, F32 height );
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ void TerrainBlock::_updateMaterials()
|
|||
{
|
||||
TerrainMaterial *mat = mFile->mMaterials[i];
|
||||
|
||||
if (!mat->getDiffuseMap().isEmpty())
|
||||
if (mat->getDiffuseMap().isNotEmpty())
|
||||
{
|
||||
mBaseTextures[i].set(mat->getDiffuseMap(), &GFXStaticTextureSRGBProfile,
|
||||
"TerrainBlock::_updateMaterials() - DiffuseMap");
|
||||
|
|
@ -114,6 +114,63 @@ void TerrainBlock::_updateMaterials()
|
|||
mMaxDetailDistance = mat->getMacroDistance();
|
||||
}
|
||||
|
||||
Vector<GFXTexHandle> detailTexArray;
|
||||
detailTexArray.setSize(mFile->mMaterials.size());
|
||||
Vector<GFXTexHandle> macroTexArray;
|
||||
macroTexArray.setSize(mFile->mMaterials.size());
|
||||
Vector<GFXTexHandle> normalTexArray;
|
||||
normalTexArray.setSize(mFile->mMaterials.size());
|
||||
Vector<GFXTexHandle> ormTexArray;
|
||||
ormTexArray.setSize(mFile->mMaterials.size());
|
||||
|
||||
for (U32 i = 0; i < mFile->mMaterials.size(); i++)
|
||||
{
|
||||
TerrainMaterial* mat = mFile->mMaterials[i];
|
||||
GFXTextureProfile* profile = &GFXStaticTextureProfile;
|
||||
if (mat->getIsSRGB())
|
||||
profile = &GFXStaticTextureSRGBProfile;
|
||||
|
||||
if (mat->getDetailMap().isNotEmpty())
|
||||
detailTexArray[i] = TEXMGR->createTexture(mat->getDetailMap(), profile);
|
||||
if (mat->getMacroMap().isNotEmpty())
|
||||
macroTexArray[i] = TEXMGR->createTexture(mat->getMacroMap(), profile);
|
||||
if (mat->getNormalMap().isNotEmpty())
|
||||
normalTexArray[i] = TEXMGR->createTexture(mat->getNormalMap(), profile);
|
||||
if (mat->getORMConfigMap().isNotEmpty())
|
||||
ormTexArray[i] = TEXMGR->createTexture(mat->getORMConfigMap(), profile);
|
||||
}
|
||||
|
||||
mDetailTextureArray = NULL;
|
||||
mMacroTextureArray = NULL;
|
||||
mNormalTextureArray = NULL;
|
||||
mOrmTextureArray = NULL;
|
||||
|
||||
|
||||
mDetailTextureArray = GFX->createTextureArray();
|
||||
mMacroTextureArray = GFX->createTextureArray();
|
||||
mNormalTextureArray = GFX->createTextureArray();
|
||||
mOrmTextureArray = GFX->createTextureArray();
|
||||
|
||||
if(!mDetailTextureArray->fromTextureArray(detailTexArray))
|
||||
{
|
||||
Con::errorf("TerrainBlock::_updateMaterials - an issue with the diffuse terrain materials was detected. Please ensure they are all of the same size and format!");
|
||||
}
|
||||
|
||||
if(!mMacroTextureArray->fromTextureArray(macroTexArray))
|
||||
{
|
||||
Con::errorf("TerrainBlock::_updateMaterials - an issue with the detail terrain materials was detected. Please ensure they are all of the same size and format!");
|
||||
}
|
||||
|
||||
if(!mNormalTextureArray->fromTextureArray(normalTexArray))
|
||||
{
|
||||
Con::errorf("TerrainBlock::_updateMaterials - an issue with the normal terrain materials was detected. Please ensure they are all of the same size and format!");
|
||||
}
|
||||
|
||||
if(!mOrmTextureArray->fromTextureArray(ormTexArray))
|
||||
{
|
||||
Con::errorf("TerrainBlock::_updateMaterials - an issue with the orm terrain materials was detected. Please ensure they are all of the same size and format!");
|
||||
}
|
||||
|
||||
if ( mCell )
|
||||
mCell->deleteMaterials();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue