|
@@ -30,6 +30,7 @@
|
|
|
#include "gfx/gfxDevice.h"
|
|
|
#include "shaderGen/langElement.h"
|
|
|
#include "shaderGen/shaderOp.h"
|
|
|
+#include "shaderGen/featureType.h"
|
|
|
#include "shaderGen/featureMgr.h"
|
|
|
#include "shaderGen/shaderGen.h"
|
|
|
#include "core/module.h"
|
|
@@ -48,7 +49,7 @@ 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_TerrainHeightBlend, new TerrainHeightMapBlendHLSL );
|
|
|
FEATUREMGR->registerFeature( MFT_TerrainORMMap, new TerrainORMMapFeatHLSL );
|
|
|
FEATUREMGR->registerFeature( MFT_DeferredTerrainBlankInfoMap, new TerrainBlankInfoMapFeatHLSL );
|
|
|
}
|
|
@@ -123,56 +124,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;
|
|
|
}
|
|
|
|
|
@@ -297,6 +373,26 @@ void TerrainBaseMapFeatHLSL::processPix( Vector<ShaderComponent*> &componentLis
|
|
|
}
|
|
|
|
|
|
meta->addStatement( new GenOp( " @;\r\n", assignColor( baseColor, Material::Mul,NULL,target ) ) );
|
|
|
+
|
|
|
+ if (fd.features[MFT_isDeferred])
|
|
|
+ {
|
|
|
+ // Set base ORM info
|
|
|
+ Var* ormConfig;
|
|
|
+ OutputTarget targ = RenderTarget1;
|
|
|
+ targ = RenderTarget2;
|
|
|
+ ormConfig = (Var*)LangElement::find(getOutputTargetVarName(targ));
|
|
|
+ if (!ormConfig)
|
|
|
+ {
|
|
|
+ // create color var
|
|
|
+ ormConfig = new Var;
|
|
|
+ ormConfig->setType("fragout");
|
|
|
+ ormConfig->setName(getOutputTargetVarName(targ));
|
|
|
+ ormConfig->setStructName("OUT");
|
|
|
+ }
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp(" @ = float4(0.0, 1.0, 1.0, 0.0);\r\n", ormConfig));
|
|
|
+ }
|
|
|
+
|
|
|
output = meta;
|
|
|
}
|
|
|
|
|
@@ -311,7 +407,7 @@ ShaderFeature::Resources TerrainBaseMapFeatHLSL::getResources( const MaterialFea
|
|
|
|
|
|
U32 TerrainBaseMapFeatHLSL::getOutputTargets( const MaterialFeatureData &fd ) const
|
|
|
{
|
|
|
- return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget1 : ShaderFeature::DefaultTarget;
|
|
|
+ return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget1 | ShaderFeature::RenderTarget2 : ShaderFeature::DefaultTarget;
|
|
|
}
|
|
|
|
|
|
TerrainDetailMapFeatHLSL::TerrainDetailMapFeatHLSL()
|
|
@@ -383,11 +479,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 +500,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,143 +587,97 @@ 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));
|
|
|
}
|
|
|
|
|
|
}
|
|
|
-
|
|
|
- // Check to see if we have a gbuffer normal.
|
|
|
- Var *gbNormal = (Var*)LangElement::find( "gbNormal" );
|
|
|
- // If we have a gbuffer normal and we don't have a
|
|
|
- // normal map feature then we need to lerp in a
|
|
|
- // default normal else the normals below this layer
|
|
|
- // will show thru.
|
|
|
- if (gbNormal &&
|
|
|
- !fd.features.hasFeature(MFT_TerrainNormalMap, detailIndex))
|
|
|
- {
|
|
|
- Var *viewToTangent = getInViewToTangent(componentList);
|
|
|
|
|
|
- meta->addStatement(new GenOp(" @ = lerp( @, @[2], min( @, @.w ) );\r\n",
|
|
|
- gbNormal, gbNormal, viewToTangent, detailBlend, inDet));
|
|
|
- }
|
|
|
-
|
|
|
- Var *detailColor = (Var*)LangElement::find( "detailColor" );
|
|
|
+ Var *detailColor = (Var*)LangElement::find(String::ToString("detailColor%d", detailIndex));
|
|
|
if ( !detailColor )
|
|
|
{
|
|
|
detailColor = new Var;
|
|
|
detailColor->setType( "float4" );
|
|
|
- detailColor->setName( "detailColor" );
|
|
|
+ detailColor->setName( String::ToString("detailColor%d", detailIndex) );
|
|
|
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.
|
|
|
-
|
|
|
-
|
|
|
- if ( GFX->getPixelShaderVersion() >= 3.0f )
|
|
|
- meta->addStatement( new GenOp( " if ( @ > 0.0f )\r\n", detailBlend ) );
|
|
|
-
|
|
|
- meta->addStatement( new GenOp( " {\r\n" ) );
|
|
|
-
|
|
|
- // Note that we're doing the standard greyscale detail
|
|
|
- // map technique here which can darken and lighten the
|
|
|
- // diffuse texture.
|
|
|
- //
|
|
|
- // We take two color samples and lerp between them for
|
|
|
- // side projection layers... else a single sample.
|
|
|
- //
|
|
|
-
|
|
|
//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 ) );
|
|
|
+ meta->addStatement(new GenOp(" @ *= @.y * @.w;\r\n",
|
|
|
+ detailColor, new IndexOp(detailInfo, detailIndex), inDet));
|
|
|
|
|
|
- ShaderFeature::OutputTarget target = ShaderFeature::DefaultTarget;
|
|
|
+ if (!fd.features.hasFeature(MFT_TerrainHeightBlend))
|
|
|
+ {
|
|
|
+ // Check to see if we have a gbuffer normal.
|
|
|
+ Var* gbNormal = (Var*)LangElement::find("gbNormal");
|
|
|
+
|
|
|
+ // If we have a gbuffer normal and we don't have a
|
|
|
+ // normal map feature then we need to lerp in a
|
|
|
+ // default normal else the normals below this layer
|
|
|
+ // will show thru.
|
|
|
+ if (gbNormal &&
|
|
|
+ !fd.features.hasFeature(MFT_TerrainNormalMap, detailIndex))
|
|
|
+ {
|
|
|
+ Var* viewToTangent = getInViewToTangent(componentList);
|
|
|
|
|
|
- if (fd.features.hasFeature(MFT_isDeferred))
|
|
|
- target= ShaderFeature::RenderTarget1;
|
|
|
+ meta->addStatement(new GenOp(" @ = lerp( @, @[2], min( @, @.w ) );\r\n",
|
|
|
+ gbNormal, gbNormal, viewToTangent, detailBlend, inDet));
|
|
|
+ }
|
|
|
|
|
|
- Var *outColor = (Var*)LangElement::find( getOutputTargetVarName(target) );
|
|
|
+ // If we're using SM 3.0 then take advantage of
|
|
|
+ // dynamic branching to skip layers per-pixel.
|
|
|
+ if (GFX->getPixelShaderVersion() >= 3.0f)
|
|
|
+ meta->addStatement(new GenOp(" if ( @ > 0.0f )\r\n", detailBlend));
|
|
|
|
|
|
- meta->addStatement(new GenOp(" @.rgb = toGamma(@.rgb);\r\n", outColor, outColor));
|
|
|
+ meta->addStatement(new GenOp(" {\r\n"));
|
|
|
|
|
|
- meta->addStatement( new GenOp( " @ += @ * @;\r\n",
|
|
|
- outColor, detailColor, detailBlend));
|
|
|
+ ShaderFeature::OutputTarget target = ShaderFeature::DefaultTarget;
|
|
|
|
|
|
- meta->addStatement(new GenOp(" @.rgb = toLinear(clamp(@.rgb, 0, 1));\r\n", outColor, outColor));
|
|
|
+ if (fd.features.hasFeature(MFT_isDeferred))
|
|
|
+ target = ShaderFeature::RenderTarget1;
|
|
|
|
|
|
- meta->addStatement( new GenOp( " }\r\n" ) );
|
|
|
+ Var* outColor = (Var*)LangElement::find(getOutputTargetVarName(target));
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp(" @.rgb = toGamma(@.rgb);\r\n", outColor, outColor));
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp(" @ += @ * @;\r\n",
|
|
|
+ outColor, detailColor, detailBlend));
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp(" @.rgb = toLinear(clamp(@.rgb, 0, 1));\r\n", outColor, outColor));
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp(" }\r\n"));
|
|
|
+ }
|
|
|
|
|
|
output = meta;
|
|
|
}
|
|
@@ -635,25 +691,12 @@ 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;
|
|
|
- }
|
|
|
-
|
|
|
- // 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() ) )
|
|
|
+ // Add Detail TextureArray
|
|
|
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 +757,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 +858,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 +885,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 +892,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 +904,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 ) );
|
|
|
+ meta->addStatement( new GenOp( " @ *= @.y * @.w;\r\n",
|
|
|
+ detailColor, new IndexOp(detailInfo, detailIndex), inDet ) );
|
|
|
|
|
|
ShaderFeature::OutputTarget target = ShaderFeature::DefaultTarget;
|
|
|
|
|
@@ -946,9 +969,12 @@ void TerrainNormalMapFeatHLSL::processVert( Vector<ShaderComponent*> &component
|
|
|
|
|
|
MultiLine *meta = new MultiLine;
|
|
|
|
|
|
- // Make sure the world to tangent transform
|
|
|
- // is created and available for the pixel shader.
|
|
|
- getOutViewToTangent( componentList, meta, fd );
|
|
|
+ if ( !fd.features.hasFeature(MFT_TerrainHeightBlend) )
|
|
|
+ {
|
|
|
+ // Make sure the world to tangent transform
|
|
|
+ // is created and available for the pixel shader.
|
|
|
+ getOutViewToTangent(componentList, meta, fd);
|
|
|
+ }
|
|
|
|
|
|
output = meta;
|
|
|
}
|
|
@@ -962,93 +988,71 @@ void TerrainNormalMapFeatHLSL::processPix( Vector<ShaderComponent*> &component
|
|
|
|
|
|
MultiLine *meta = new MultiLine;
|
|
|
|
|
|
- Var *viewToTangent = getInViewToTangent( componentList );
|
|
|
-
|
|
|
- // This var is read from GBufferConditionerHLSL and
|
|
|
- // used in the deferred output.
|
|
|
- Var *gbNormal = (Var*)LangElement::find( "gbNormal" );
|
|
|
- if ( !gbNormal )
|
|
|
- {
|
|
|
- gbNormal = new Var;
|
|
|
- gbNormal->setName( "gbNormal" );
|
|
|
- gbNormal->setType( "float3" );
|
|
|
- meta->addStatement( new GenOp( " @ = @[2];\r\n", new DecOp( gbNormal ), viewToTangent ) );
|
|
|
- }
|
|
|
-
|
|
|
const S32 normalIndex = getProcessIndex();
|
|
|
|
|
|
Var *detailBlend = (Var*)LangElement::find( String::ToString( "detailBlend%d", normalIndex ) );
|
|
|
AssertFatal( detailBlend, "The detail blend is missing!" );
|
|
|
|
|
|
- // If we're using SM 3.0 then take advantage of
|
|
|
- // dynamic branching to skip layers per-pixel.
|
|
|
- if ( GFX->getPixelShaderVersion() >= 3.0f )
|
|
|
- meta->addStatement( new GenOp( " if ( @ > 0.0f )\r\n", detailBlend ) );
|
|
|
-
|
|
|
- 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* 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;
|
|
|
- }
|
|
|
+ LangElement* texOp;
|
|
|
+
|
|
|
+ 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;
|
|
|
- bumpNorm->setName( "bumpNormal" );
|
|
|
- bumpNorm->setType( "float4" );
|
|
|
+ Var* bumpNorm = new Var;
|
|
|
+ bumpNorm->setName(String::ToString("bumpNormal%d", normalIndex));
|
|
|
+ bumpNorm->setType("float4");
|
|
|
|
|
|
- LangElement *bumpNormDecl = new DecOp( bumpNorm );
|
|
|
- meta->addStatement( expandNormalMap( texOp, bumpNormDecl, bumpNorm, fd ) );
|
|
|
+ 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.hasFeature(MFT_TerrainHeightBlend))
|
|
|
{
|
|
|
- if (fd.features.getNextFeatureIndex(MFT_TerrainNormalMap, normalIndex) == -1)
|
|
|
- meta->addStatement(new GenOp(" if ( @ > 0.0001f ){\r\n\r\n", blendTotal));
|
|
|
- }
|
|
|
+ Var* viewToTangent = getInViewToTangent(componentList);
|
|
|
+
|
|
|
+ // This var is read from GBufferConditionerHLSL and
|
|
|
+ // used in the deferred output.
|
|
|
+ Var* gbNormal = (Var*)LangElement::find("gbNormal");
|
|
|
+ if (!gbNormal)
|
|
|
+ {
|
|
|
+ gbNormal = new Var;
|
|
|
+ gbNormal->setName("gbNormal");
|
|
|
+ gbNormal->setType("float3");
|
|
|
+ meta->addStatement(new GenOp(" @ = @[2];\r\n", new DecOp(gbNormal), viewToTangent));
|
|
|
+ }
|
|
|
+
|
|
|
+ // If we're using SM 3.0 then take advantage of
|
|
|
+ // dynamic branching to skip layers per-pixel.
|
|
|
+ if (GFX->getPixelShaderVersion() >= 3.0f)
|
|
|
+ meta->addStatement(new GenOp(" if ( @ > 0.0f )\r\n", detailBlend));
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp(" {\r\n"));
|
|
|
+
|
|
|
// 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 ) );
|
|
|
+ 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"));
|
|
|
}
|
|
|
- // End the conditional block.
|
|
|
- meta->addStatement( new GenOp( " }\r\n" ) );
|
|
|
|
|
|
output = meta;
|
|
|
}
|
|
@@ -1056,14 +1060,27 @@ void TerrainNormalMapFeatHLSL::processPix( Vector<ShaderComponent*> &component
|
|
|
ShaderFeature::Resources TerrainNormalMapFeatHLSL::getResources( const MaterialFeatureData &fd )
|
|
|
{
|
|
|
Resources res;
|
|
|
-
|
|
|
- // 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_DeferredConditioner))
|
|
|
+ {
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ S32 featureIndex = 0, firstNormalMapIndex = 0;
|
|
|
+ for (int idx = 0; idx < fd.features.getCount(); ++idx) {
|
|
|
+ const FeatureType &type = fd.features.getAt(idx, &featureIndex);
|
|
|
+ if (type == MFT_TerrainNormalMap) {
|
|
|
+ firstNormalMapIndex = getMin(firstNormalMapIndex, featureIndex);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // We only need to process normals during the deferred.
|
|
|
+ if (getProcessIndex() == firstNormalMapIndex)
|
|
|
+ {
|
|
|
+ res.numTexReg += 1;
|
|
|
+ res.numTex += 1;
|
|
|
+ }
|
|
|
+
|
|
|
return res;
|
|
|
}
|
|
|
|
|
@@ -1116,35 +1133,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 +1199,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 +1220,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,36 +1240,28 @@ 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;
|
|
|
- OutputTarget targ = DefaultTarget;
|
|
|
+ OutputTarget targ = RenderTarget1;
|
|
|
if (fd.features[MFT_isDeferred])
|
|
|
{
|
|
|
targ = RenderTarget2;
|
|
@@ -1300,22 +1283,24 @@ void TerrainORMMapFeatHLSL::processPix(Vector<ShaderComponent*> &componentList,
|
|
|
|
|
|
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)
|
|
|
+
|
|
|
+ if (compositeIndex == 0)
|
|
|
{
|
|
|
- meta->addStatement(new GenOp(" @ = @.rgb*@;\r\n", new DecOp(matinfoCol), texOp, detailBlend));
|
|
|
- meta->addStatement(new GenOp(" @.gba += @;\r\n", ormConfig, matinfoCol));
|
|
|
+ meta->addStatement(new GenOp(" @ = float4(0.0, 0.0, 0.0, 0.0);\r\n", ormConfig));
|
|
|
}
|
|
|
- else
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp(" @ = @.rgb;\r\n", new DecOp(matinfoCol), texOp));
|
|
|
+
|
|
|
+ if (fd.features.hasFeature(MFT_InvertRoughness, compositeIndex))
|
|
|
{
|
|
|
- meta->addStatement(new GenOp(" @ = lerp(float3(1.0,1.0,0.0),@.rgb,@);\r\n", new DecOp(matinfoCol), texOp, detailBlend));
|
|
|
- meta->addStatement(new GenOp(" @ = float4(0.0,@);\r\n", ormConfig, matinfoCol));
|
|
|
+ meta->addStatement(new GenOp(" @.b = 1.0 - @.b;\r\n", matinfoCol, matinfoCol));
|
|
|
}
|
|
|
|
|
|
- if (fd.features[MFT_InvertRoughness])
|
|
|
+ meta->addStatement(new GenOp(" @ = lerp(float3(1.0, 1.0, 0.0), @, @.y * @.w);\r\n", matinfoCol, matinfoCol, new IndexOp(detailInfo, compositeIndex), inDet));
|
|
|
+
|
|
|
+ if (!fd.features.hasFeature(MFT_TerrainHeightBlend))
|
|
|
{
|
|
|
- meta->addStatement(new GenOp(" @.b = [email protected];\r\n", ormConfig, ormConfig));
|
|
|
+ meta->addStatement(new GenOp(" @.gba += @ * @;\r\n", ormConfig, matinfoCol, detailBlend));
|
|
|
}
|
|
|
|
|
|
output = meta;
|
|
@@ -1331,20 +1316,22 @@ ShaderFeature::Resources TerrainORMMapFeatHLSL::getResources(const MaterialFeatu
|
|
|
// reminder, the matinfo buffer is flags, smooth, ao, metal
|
|
|
U32 TerrainBlankInfoMapFeatHLSL::getOutputTargets(const MaterialFeatureData &fd) const
|
|
|
{
|
|
|
- return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget2 : ShaderFeature::DefaultTarget;
|
|
|
+ return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget2 : ShaderFeature::RenderTarget1;
|
|
|
}
|
|
|
|
|
|
void TerrainBlankInfoMapFeatHLSL::processPix(Vector<ShaderComponent*> &componentList,
|
|
|
const MaterialFeatureData &fd)
|
|
|
{
|
|
|
+ S32 compositeIndex = getProcessIndex();
|
|
|
+
|
|
|
// search for material var
|
|
|
Var *material;
|
|
|
- OutputTarget targ = DefaultTarget;
|
|
|
+ OutputTarget ormConfig = RenderTarget1;
|
|
|
if (fd.features[MFT_isDeferred])
|
|
|
{
|
|
|
- targ = RenderTarget2;
|
|
|
+ ormConfig = RenderTarget2;
|
|
|
}
|
|
|
- material = (Var*)LangElement::find(getOutputTargetVarName(targ));
|
|
|
+ material = (Var*)LangElement::find(getOutputTargetVarName(ormConfig));
|
|
|
|
|
|
MultiLine * meta = new MultiLine;
|
|
|
if (!material)
|
|
@@ -1352,11 +1339,380 @@ void TerrainBlankInfoMapFeatHLSL::processPix(Vector<ShaderComponent*> &component
|
|
|
// create color var
|
|
|
material = new Var;
|
|
|
material->setType("fragout");
|
|
|
- material->setName(getOutputTargetVarName(targ));
|
|
|
+ material->setName(getOutputTargetVarName(ormConfig));
|
|
|
material->setStructName("OUT");
|
|
|
}
|
|
|
|
|
|
- meta->addStatement(new GenOp(" @ = float4(0.0,1.0,1.0,0.0);\r\n", material));
|
|
|
+ if (compositeIndex == 0)
|
|
|
+ {
|
|
|
+ meta->addStatement(new GenOp(" @ = float4(0.0, 0.0, 0.0, 0.0);\r\n", material));
|
|
|
+ }
|
|
|
+
|
|
|
+ Var* detailBlend = (Var*)LangElement::find(String::ToString("detailBlend%d", compositeIndex));
|
|
|
+ AssertFatal(detailBlend, "The detail blend is missing!");
|
|
|
+
|
|
|
+ String matinfoName(String::ToString("matinfoCol%d", compositeIndex));
|
|
|
+
|
|
|
+ if (!fd.features.hasFeature(MFT_TerrainHeightBlend))
|
|
|
+ {
|
|
|
+ meta->addStatement(new GenOp(" @.gba += float3(@, @, 0.0);\r\n", material, detailBlend, detailBlend));
|
|
|
+ }
|
|
|
+
|
|
|
+ output = meta;
|
|
|
+}
|
|
|
+
|
|
|
+void TerrainHeightMapBlendHLSL::processVert(Vector<ShaderComponent*>& componentList,
|
|
|
+ const MaterialFeatureData& fd)
|
|
|
+{
|
|
|
+ // We only need to process normals during the deferred.
|
|
|
+ if (!fd.features.hasFeature(MFT_DeferredConditioner))
|
|
|
+ return;
|
|
|
+
|
|
|
+ MultiLine* meta = new MultiLine;
|
|
|
+
|
|
|
+ // Make sure the world to tangent transform
|
|
|
+ // is created and available for the pixel shader.
|
|
|
+ getOutViewToTangent(componentList, meta, fd);
|
|
|
+
|
|
|
+ output = meta;
|
|
|
+}
|
|
|
+
|
|
|
+void TerrainHeightMapBlendHLSL::processPix(Vector<ShaderComponent*>& componentList,
|
|
|
+ const MaterialFeatureData& fd)
|
|
|
+{
|
|
|
+
|
|
|
+ ShaderFeature::OutputTarget target = ShaderFeature::DefaultTarget;
|
|
|
+
|
|
|
+ if (fd.features.hasFeature(MFT_isDeferred))
|
|
|
+ target = ShaderFeature::RenderTarget1;
|
|
|
+
|
|
|
+ Var* outColor = (Var*)LangElement::find(getOutputTargetVarName(target));
|
|
|
+
|
|
|
+ if (!outColor)
|
|
|
+ return;
|
|
|
+
|
|
|
+ MultiLine* meta = new MultiLine;
|
|
|
+
|
|
|
+ // Count number of detail layers
|
|
|
+ int detailCount = 0;
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ if(LangElement::find(String::ToString("detailBlend%d", detailCount)) == NULL)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ ++detailCount;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( detailCount == 0 )
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Compute blend factors
|
|
|
+ for (S32 idx = 0; idx < detailCount; ++idx)
|
|
|
+ {
|
|
|
+ Var* detailBlend = (Var*)LangElement::find(String::ToString("detailBlend%d", idx));
|
|
|
+ Var* bumpNormal = (Var*)LangElement::find(String::ToString("bumpNormal%d", idx));
|
|
|
+ Var* blendDepth = (Var*)LangElement::find(String::ToString("blendDepth%d", idx));
|
|
|
+ if (!blendDepth)
|
|
|
+ {
|
|
|
+ blendDepth = new Var;
|
|
|
+ blendDepth->setType("float");
|
|
|
+ blendDepth->setName(String::ToString("blendDepth%d", idx));
|
|
|
+ blendDepth->uniform = true;
|
|
|
+ blendDepth->constSortPos = cspPrimitive;
|
|
|
+ }
|
|
|
+
|
|
|
+ Var* blendContrast = (Var*)LangElement::find(String::ToString("blendContrast%d", idx));
|
|
|
+ if (!blendContrast)
|
|
|
+ {
|
|
|
+ blendContrast = new Var;
|
|
|
+ blendContrast->setType("float");
|
|
|
+ blendContrast->setName(String::ToString("blendContrast%d", idx));
|
|
|
+ blendContrast->uniform = true;
|
|
|
+ blendContrast->constSortPos = cspPrimitive;
|
|
|
+ }
|
|
|
+
|
|
|
+ Var* detailH = (Var*)LangElement::find(String::ToString("detailH%d", idx));
|
|
|
+ if (!detailH)
|
|
|
+ {
|
|
|
+ detailH = new Var;
|
|
|
+ detailH->setType("float");
|
|
|
+ detailH->setName(String::ToString("detailH%d", idx));
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp(" @ = 0;\r\n",
|
|
|
+ new DecOp(detailH)));
|
|
|
+ meta->addStatement(new GenOp(" if (@ > 0.0f) {\r\n", detailBlend));
|
|
|
+ if (bumpNormal != NULL)
|
|
|
+ {
|
|
|
+ meta->addStatement(new GenOp(" @ = clamp(@.a + @, 0.0, 1.0);\r\n",
|
|
|
+ detailH, bumpNormal, blendDepth));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ meta->addStatement(new GenOp(" @ = clamp(0.5 + @, 0.0, 1.0);\r\n",
|
|
|
+ detailH, blendDepth));
|
|
|
+ }
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp(" @ = max((@ * 2.0f - 1.0f) * @ + 0.5f, 0.0f);\r\n",
|
|
|
+ detailH, detailH, blendContrast));
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp(" }\r\n"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp("\r\n"));
|
|
|
+
|
|
|
+ Var* depth = (Var*)LangElement::find("baseBlendDepth");
|
|
|
+ if (depth == NULL)
|
|
|
+ {
|
|
|
+ depth = new Var;
|
|
|
+ depth->setType("float");
|
|
|
+ depth->setName("baseBlendDepth");
|
|
|
+ depth->uniform = true;
|
|
|
+ depth->constSortPos = cspPrimitive;
|
|
|
+ }
|
|
|
+
|
|
|
+ Var* ma = (Var*)LangElement::find("ma");
|
|
|
+ if (ma == NULL)
|
|
|
+ {
|
|
|
+ ma = new Var;
|
|
|
+ ma->setType("float");
|
|
|
+ ma->setName("ma");
|
|
|
+ meta->addStatement(new GenOp(" @ = 0;\r\n",
|
|
|
+ new DecOp(ma)));
|
|
|
+ }
|
|
|
+
|
|
|
+ for (S32 idx = 0; idx < detailCount; ++idx)
|
|
|
+ {
|
|
|
+ Var* detailH = (Var*)LangElement::find(String::ToString("detailH%d", idx));
|
|
|
+ Var* detailBlend = (Var*)LangElement::find(String::ToString("detailBlend%d", idx));
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp(" @ = max(@, @ + @);\r\n",
|
|
|
+ ma, ma, detailH, detailBlend));
|
|
|
+ }
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp(" @ -= @;\r\n",
|
|
|
+ ma, depth));
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp("\r\n"));
|
|
|
+
|
|
|
+ for (S32 idx = 0; idx < detailCount; ++idx)
|
|
|
+ {
|
|
|
+ Var* detailH = (Var*)LangElement::find(String::ToString("detailH%d", idx));
|
|
|
+ Var* detailBlend = (Var*)LangElement::find(String::ToString("detailBlend%d", idx));
|
|
|
+ Var* detailB = (Var*)LangElement::find(String::ToString("detailB%d", idx));
|
|
|
+ if (!detailB)
|
|
|
+ {
|
|
|
+ detailB = new Var;
|
|
|
+ detailB->setType("float");
|
|
|
+ detailB->setName(String::ToString("detailB%d", idx));
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp(" @ = max(@ + @ - @, 0);\r\n",
|
|
|
+ new DecOp(detailB), detailH, detailBlend, ma));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp("\r\n"));
|
|
|
+
|
|
|
+ // Compute albedo
|
|
|
+ meta->addStatement(new GenOp(" @.rgb = toGamma(@.rgb);\r\n",
|
|
|
+ outColor, outColor));
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp(" @.rgb += (",
|
|
|
+ outColor));
|
|
|
+
|
|
|
+ for (S32 idx = 0; idx < detailCount; ++idx)
|
|
|
+ {
|
|
|
+ Var* detailColor = (Var*)LangElement::find(String::ToString("detailColor%d", idx));
|
|
|
+ Var* detailB = (Var*)LangElement::find(String::ToString("detailB%d", idx));
|
|
|
+
|
|
|
+
|
|
|
+ if (idx > 0)
|
|
|
+ {
|
|
|
+ meta->addStatement(new GenOp(" + "));
|
|
|
+ }
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp("@.rgb * @", detailColor, detailB));
|
|
|
+ }
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp(") / ("));
|
|
|
+
|
|
|
+ for (S32 idx = 0; idx < detailCount; ++idx)
|
|
|
+ {
|
|
|
+ Var* detailB = (Var*)LangElement::find(String::ToString("detailB%d", idx));
|
|
|
+
|
|
|
+ if (idx > 0)
|
|
|
+ {
|
|
|
+ meta->addStatement(new GenOp(" + "));
|
|
|
+ }
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp("@", detailB));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp(");\r\n"));
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp(" @.rgb = toLinear(clamp(@.rgb, 0, 1));\r\n",
|
|
|
+ outColor, outColor));
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp("\r\n"));
|
|
|
+
|
|
|
+ // Compute ORM
|
|
|
+ Var* ormOutput;
|
|
|
+ OutputTarget targ = DefaultTarget;
|
|
|
+ if (fd.features[MFT_isDeferred])
|
|
|
+ {
|
|
|
+ targ = RenderTarget2;
|
|
|
+ }
|
|
|
+ ormOutput = (Var*)LangElement::find(getOutputTargetVarName(targ));
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp(" @.gba = (",
|
|
|
+ ormOutput));
|
|
|
+
|
|
|
+ for (S32 idx = 0; idx < detailCount; ++idx)
|
|
|
+ {
|
|
|
+ Var* matinfoCol = (Var*)LangElement::find(String::ToString("matinfoCol%d", idx));
|
|
|
+ Var* detailB = (Var*)LangElement::find(String::ToString("detailB%d", idx));
|
|
|
+
|
|
|
+
|
|
|
+ if (idx > 0)
|
|
|
+ {
|
|
|
+ meta->addStatement(new GenOp(" + "));
|
|
|
+ }
|
|
|
+ if (matinfoCol)
|
|
|
+ {
|
|
|
+ meta->addStatement(new GenOp("@ * @", matinfoCol, detailB));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ meta->addStatement(new GenOp("float3(1.0, 1.0, 0.0) * @", detailB));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp(") / ("));
|
|
|
+
|
|
|
+ for (S32 idx = 0; idx < detailCount; ++idx)
|
|
|
+ {
|
|
|
+ Var* detailB = (Var*)LangElement::find(String::ToString("detailB%d", idx));
|
|
|
+
|
|
|
+ if (idx > 0)
|
|
|
+ {
|
|
|
+ meta->addStatement(new GenOp(" + "));
|
|
|
+ }
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp("@", detailB));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp(");\r\n"));
|
|
|
+
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp("\r\n"));
|
|
|
+
|
|
|
+ // Compute normal-specific blending factors
|
|
|
+ // LukasPJ: I'm not sure why this is necessary, it might not be.
|
|
|
+ Var* normalMa = (Var*)LangElement::find("normalMa");
|
|
|
+ if (normalMa == NULL)
|
|
|
+ {
|
|
|
+ normalMa = new Var;
|
|
|
+ normalMa->setType("float");
|
|
|
+ normalMa->setName("normalMa");
|
|
|
+ meta->addStatement(new GenOp(" @ = 0;\r\n",
|
|
|
+ new DecOp(normalMa)));
|
|
|
+ }
|
|
|
+
|
|
|
+ for (S32 idx = 0; idx < detailCount; ++idx)
|
|
|
+ {
|
|
|
+ Var* detCoord = (Var*)LangElement::find(String::ToString("detCoord%d", idx));
|
|
|
+
|
|
|
+ Var* detailH = (Var*)LangElement::find(String::ToString("detailH%d", idx));
|
|
|
+ Var* detailBlend = (Var*)LangElement::find(String::ToString("detailBlend%d", idx));
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp(" @ = max(@, @ + min(@, @.w));\r\n",
|
|
|
+ normalMa, normalMa, detailH, detailBlend, detCoord));
|
|
|
+ }
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp(" @ -= @;\r\n",
|
|
|
+ normalMa, depth));
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp("\r\n"));
|
|
|
+
|
|
|
+ for (S32 idx = 0; idx < detailCount; ++idx)
|
|
|
+ {
|
|
|
+ Var* detCoord = (Var*)LangElement::find(String::ToString("detCoord%d", idx));
|
|
|
+
|
|
|
+ Var* detailH = (Var*)LangElement::find(String::ToString("detailH%d", idx));
|
|
|
+ Var* detailBlend = (Var*)LangElement::find(String::ToString("detailBlend%d", idx));
|
|
|
+ Var* normalDetailB = (Var*)LangElement::find(String::ToString("normalDetailB%d", idx));
|
|
|
+ if (!normalDetailB)
|
|
|
+ {
|
|
|
+ normalDetailB = new Var;
|
|
|
+ normalDetailB->setType("float");
|
|
|
+ normalDetailB->setName(String::ToString("normalDetailB%d", idx));
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp(" @ = max(@ + min(@, @.w) - @, 0);\r\n",
|
|
|
+ new DecOp(normalDetailB), detailH, detailBlend, detCoord, normalMa));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Compute normals
|
|
|
+ Var* gbNormal = (Var*)LangElement::find("gbNormal");
|
|
|
+ if (!gbNormal)
|
|
|
+ {
|
|
|
+ gbNormal = new Var;
|
|
|
+ gbNormal->setName("gbNormal");
|
|
|
+ gbNormal->setType("float3");
|
|
|
+ meta->addStatement(new GenOp(" @;\r\n", new DecOp(gbNormal)));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (gbNormal != NULL)
|
|
|
+ {
|
|
|
+ meta->addStatement(new GenOp(" @ = (",
|
|
|
+ gbNormal));
|
|
|
+
|
|
|
+ for (S32 idx = 0; idx < detailCount; ++idx)
|
|
|
+ {
|
|
|
+ Var* normalDetailB = (Var*)LangElement::find(String::ToString("normalDetailB%d", idx));
|
|
|
+ Var* bumpNormal = (Var*)LangElement::find(String::ToString("bumpNormal%d", idx));
|
|
|
+ Var* viewToTangent = getInViewToTangent(componentList);
|
|
|
+
|
|
|
+
|
|
|
+ if (idx > 0)
|
|
|
+ {
|
|
|
+ meta->addStatement(new GenOp(" + "));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (bumpNormal != NULL)
|
|
|
+ {
|
|
|
+ meta->addStatement(new GenOp("mul(@.xyz, @) * @", bumpNormal, viewToTangent, normalDetailB));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ meta->addStatement(new GenOp("@[2] * @", viewToTangent, normalDetailB));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp(") / ("));
|
|
|
+
|
|
|
+ for (S32 idx = 0; idx < detailCount; ++idx)
|
|
|
+ {
|
|
|
+ Var* normalDetailB = (Var*)LangElement::find(String::ToString("normalDetailB%d", idx));
|
|
|
+
|
|
|
+ if (idx > 0)
|
|
|
+ {
|
|
|
+ meta->addStatement(new GenOp(" + "));
|
|
|
+ }
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp("@", normalDetailB));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ meta->addStatement(new GenOp(");\r\n"));
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
output = meta;
|
|
|
}
|