mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-29 00:05:40 +00:00
commit
908be4818f
112 changed files with 2645 additions and 680 deletions
|
|
@ -26,6 +26,7 @@
|
|||
#include "terrain/terrFeatureTypes.h"
|
||||
#include "materials/materialFeatureTypes.h"
|
||||
#include "materials/materialFeatureData.h"
|
||||
#include "materials/processedMaterial.h"
|
||||
#include "gfx/gfxDevice.h"
|
||||
#include "shaderGen/langElement.h"
|
||||
#include "shaderGen/shaderOp.h"
|
||||
|
|
@ -47,9 +48,12 @@ namespace
|
|||
FEATUREMGR->registerFeature( MFT_TerrainMacroMap, 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_TerrainAdditive, new TerrainAdditiveFeatHLSL );
|
||||
FEATUREMGR->registerFeature( MFT_DeferredTerrainBaseMap, new TerrainBaseMapFeatHLSL );
|
||||
FEATUREMGR->registerFeature( MFT_DeferredTerrainMacroMap, new TerrainMacroMapFeatHLSL );
|
||||
FEATUREMGR->registerFeature( MFT_DeferredTerrainDetailMap, new TerrainDetailMapFeatHLSL );
|
||||
FEATUREMGR->registerFeature( MFT_DeferredTerrainBlankInfoMap, new TerrainBlankInfoMapFeatHLSL );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
MODULE_BEGIN( TerrainFeatHLSL )
|
||||
|
|
@ -250,10 +254,6 @@ void TerrainBaseMapFeatHLSL::processPix( Vector<ShaderComponent*> &componentLis
|
|||
// grab connector texcoord register
|
||||
Var *texCoord = getInTexCoord( "texCoord", "float3", true, componentList );
|
||||
|
||||
// We do nothing more if this is a prepass.
|
||||
if ( fd.features.hasFeature( MFT_PrePassConditioner ) )
|
||||
return;
|
||||
|
||||
// create texture var
|
||||
Var *diffuseMap = new Var;
|
||||
diffuseMap->setType( "sampler2D" );
|
||||
|
|
@ -269,8 +269,15 @@ void TerrainBaseMapFeatHLSL::processPix( Vector<ShaderComponent*> &componentLis
|
|||
baseColor->setName( "baseColor" );
|
||||
meta->addStatement( new GenOp( " @ = tex2D( @, @.xy );\r\n", new DecOp( baseColor ), diffuseMap, texCoord ) );
|
||||
meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", baseColor, baseColor));
|
||||
meta->addStatement( new GenOp( " @;\r\n", assignColor( baseColor, Material::Mul ) ) );
|
||||
|
||||
ShaderFeature::OutputTarget target = ShaderFeature::DefaultTarget;
|
||||
|
||||
if (fd.features.hasFeature(MFT_isDeferred))
|
||||
{
|
||||
target= ShaderFeature::RenderTarget1;
|
||||
}
|
||||
|
||||
meta->addStatement( new GenOp( " @;\r\n", assignColor( baseColor, Material::Mul,NULL,target ) ) );
|
||||
output = meta;
|
||||
}
|
||||
|
||||
|
|
@ -278,14 +285,16 @@ ShaderFeature::Resources TerrainBaseMapFeatHLSL::getResources( const MaterialFea
|
|||
{
|
||||
Resources res;
|
||||
res.numTexReg = 1;
|
||||
|
||||
// We only sample from the base map during a diffuse pass.
|
||||
if ( !fd.features.hasFeature( MFT_PrePassConditioner ) )
|
||||
res.numTex = 1;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
U32 TerrainBaseMapFeatHLSL::getOutputTargets( const MaterialFeatureData &fd ) const
|
||||
{
|
||||
return fd.features[MFT_DeferredTerrainBaseMap] ? ShaderFeature::RenderTarget1 : ShaderFeature::DefaultTarget;
|
||||
}
|
||||
|
||||
TerrainDetailMapFeatHLSL::TerrainDetailMapFeatHLSL()
|
||||
: mTorqueDep( "shaders/common/torque.hlsl" ),
|
||||
mTerrainDep( "shaders/common/terrain/terrain.hlsl" )
|
||||
|
|
@ -477,7 +486,7 @@ void TerrainDetailMapFeatHLSL::processPix( Vector<ShaderComponent*> &component
|
|||
// Call the library function to do the rest.
|
||||
if(fd.features.hasFeature( MFT_IsDXTnm, detailIndex ) )
|
||||
{
|
||||
meta->addStatement( new GenOp( " @.xy += parallaxOffsetDxtnm( @, @.xy, @, @.z * @ );\r\n",
|
||||
meta->addStatement( new GenOp( " @.xy += parallaxOffsetDxtnm( @, @.xy, @, @.z * @ );\r\n",
|
||||
inDet, normalMap, inDet, negViewTS, detailInfo, detailBlend ) );
|
||||
}
|
||||
else
|
||||
|
|
@ -487,29 +496,6 @@ void TerrainDetailMapFeatHLSL::processPix( Vector<ShaderComponent*> &component
|
|||
}
|
||||
}
|
||||
|
||||
// If this is a prepass then we skip color.
|
||||
if ( fd.features.hasFeature( MFT_PrePassConditioner ) )
|
||||
{
|
||||
// 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 ) );
|
||||
}
|
||||
|
||||
output = meta;
|
||||
return;
|
||||
}
|
||||
|
||||
Var *detailColor = (Var*)LangElement::find( "detailColor" );
|
||||
if ( !detailColor )
|
||||
{
|
||||
|
|
@ -543,21 +529,35 @@ void TerrainDetailMapFeatHLSL::processPix( Vector<ShaderComponent*> &component
|
|||
// 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->setType("float4");
|
||||
detailTex->setName("detailTex");
|
||||
meta->addStatement( new GenOp( " @;\r\n", new DecOp( detailTex ) ) );
|
||||
|
||||
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( @, @.yz ), tex2D( @, @.xz ), @.z);\r\n",detailTex,detailMap,inDet,detailMap,inDet,inTex));
|
||||
meta->addStatement( new GenOp( " @ = ( @ * 2.0 ) - 1.0;\r\n", detailColor, detailTex) );
|
||||
}
|
||||
else
|
||||
{
|
||||
meta->addStatement( new GenOp( " @ = ( tex2D( @, @.xy ) * 2.0 ) - 1.0;\r\n",
|
||||
detailColor, detailMap, inDet ) );
|
||||
meta->addStatement( new GenOp(" @ = tex2D(@,@.xy);\r\n",detailTex,detailMap,inDet));
|
||||
meta->addStatement( new GenOp( " @ = ( @ * 2.0 ) - 1.0;\r\n",
|
||||
detailColor, detailTex) );
|
||||
}
|
||||
|
||||
meta->addStatement( new GenOp( " @ *= @.y * @.w;\r\n",
|
||||
detailColor, detailInfo, inDet ) );
|
||||
|
||||
Var *outColor = (Var*)LangElement::find( "col" );
|
||||
Var *baseColor = (Var*)LangElement::find( "baseColor" );
|
||||
ShaderFeature::OutputTarget target = ShaderFeature::DefaultTarget;
|
||||
|
||||
if(fd.features.hasFeature( MFT_DeferredTerrainDetailMap ))
|
||||
target= ShaderFeature::RenderTarget1;
|
||||
|
||||
Var *outColor = (Var*)LangElement::find( getOutputTargetVarName(target) );
|
||||
|
||||
meta->addStatement( new GenOp( " @ += @ * @;\r\n",
|
||||
outColor, detailColor, detailBlend));
|
||||
|
|
@ -584,9 +584,7 @@ ShaderFeature::Resources TerrainDetailMapFeatHLSL::getResources( const MaterialF
|
|||
res.numTexReg += 4;
|
||||
}
|
||||
|
||||
// If this isn't the prepass then we sample
|
||||
// from the detail texture for diffuse coloring.
|
||||
if ( !fd.features.hasFeature( MFT_PrePassConditioner ) )
|
||||
// sample from the detail texture for diffuse coloring.
|
||||
res.numTex += 1;
|
||||
|
||||
// If we have parallax for this layer then we'll also
|
||||
|
|
@ -601,6 +599,11 @@ ShaderFeature::Resources TerrainDetailMapFeatHLSL::getResources( const MaterialF
|
|||
return res;
|
||||
}
|
||||
|
||||
U32 TerrainDetailMapFeatHLSL::getOutputTargets( const MaterialFeatureData &fd ) const
|
||||
{
|
||||
return fd.features[MFT_DeferredTerrainDetailMap] ? ShaderFeature::RenderTarget1 : ShaderFeature::DefaultTarget;
|
||||
}
|
||||
|
||||
|
||||
TerrainMacroMapFeatHLSL::TerrainMacroMapFeatHLSL()
|
||||
: mTorqueDep( "shaders/common/torque.hlsl" ),
|
||||
|
|
@ -758,29 +761,6 @@ void TerrainMacroMapFeatHLSL::processPix( Vector<ShaderComponent*> &componentL
|
|||
// Add to the blend total.
|
||||
meta->addStatement( new GenOp( " @ += @;\r\n", blendTotal, detailBlend ) );
|
||||
|
||||
// If this is a prepass then we skip color.
|
||||
if ( fd.features.hasFeature( MFT_PrePassConditioner ) )
|
||||
{
|
||||
// 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 ) );
|
||||
}
|
||||
|
||||
output = meta;
|
||||
return;
|
||||
}
|
||||
|
||||
Var *detailColor = (Var*)LangElement::find( "macroColor" );
|
||||
if ( !detailColor )
|
||||
{
|
||||
|
|
@ -826,8 +806,14 @@ void TerrainMacroMapFeatHLSL::processPix( Vector<ShaderComponent*> &componentL
|
|||
meta->addStatement( new GenOp( " @ *= @.y * @.w;\r\n",
|
||||
detailColor, detailInfo, inDet ) );
|
||||
|
||||
//Var *baseColor = (Var*)LangElement::find( "baseColor" );
|
||||
Var *outColor = (Var*)LangElement::find( "col" );
|
||||
Var *baseColor = (Var*)LangElement::find( "baseColor" );
|
||||
|
||||
ShaderFeature::OutputTarget target = ShaderFeature::DefaultTarget;
|
||||
|
||||
if(fd.features.hasFeature(MFT_DeferredTerrainMacroMap))
|
||||
target= ShaderFeature::RenderTarget1;
|
||||
|
||||
Var *outColor = (Var*)LangElement::find( getOutputTargetVarName(target) );
|
||||
|
||||
meta->addStatement(new GenOp(" @ += @ * @;\r\n",
|
||||
outColor, detailColor, detailBlend));
|
||||
|
|
@ -837,8 +823,6 @@ void TerrainMacroMapFeatHLSL::processPix( Vector<ShaderComponent*> &componentL
|
|||
output = meta;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ShaderFeature::Resources TerrainMacroMapFeatHLSL::getResources( const MaterialFeatureData &fd )
|
||||
{
|
||||
Resources res;
|
||||
|
|
@ -850,9 +834,6 @@ ShaderFeature::Resources TerrainMacroMapFeatHLSL::getResources( const MaterialFe
|
|||
res.numTex += 1;
|
||||
}
|
||||
|
||||
// If this isn't the prepass then we sample
|
||||
// from the detail texture for diffuse coloring.
|
||||
if ( !fd.features.hasFeature( MFT_PrePassConditioner ) )
|
||||
res.numTex += 1;
|
||||
|
||||
// Finally we always send the detail texture
|
||||
|
|
@ -862,6 +843,11 @@ ShaderFeature::Resources TerrainMacroMapFeatHLSL::getResources( const MaterialFe
|
|||
return res;
|
||||
}
|
||||
|
||||
U32 TerrainMacroMapFeatHLSL::getOutputTargets( const MaterialFeatureData &fd ) const
|
||||
{
|
||||
return fd.features[MFT_DeferredTerrainMacroMap] ? ShaderFeature::RenderTarget1 : ShaderFeature::DefaultTarget;
|
||||
}
|
||||
|
||||
void TerrainNormalMapFeatHLSL::processVert( Vector<ShaderComponent*> &componentList,
|
||||
const MaterialFeatureData &fd )
|
||||
{
|
||||
|
|
@ -881,9 +867,6 @@ void TerrainNormalMapFeatHLSL::processVert( Vector<ShaderComponent*> &component
|
|||
void TerrainNormalMapFeatHLSL::processPix( Vector<ShaderComponent*> &componentList,
|
||||
const MaterialFeatureData &fd )
|
||||
{
|
||||
// We only need to process normals during the prepass.
|
||||
if ( !fd.features.hasFeature( MFT_PrePassConditioner ) )
|
||||
return;
|
||||
|
||||
MultiLine *meta = new MultiLine;
|
||||
|
||||
|
|
@ -1019,11 +1002,15 @@ ShaderFeature::Resources TerrainLightMapFeatHLSL::getResources( const MaterialFe
|
|||
return res;
|
||||
}
|
||||
|
||||
|
||||
void TerrainAdditiveFeatHLSL::processPix( Vector<ShaderComponent*> &componentList,
|
||||
const MaterialFeatureData &fd )
|
||||
{
|
||||
Var *color = (Var*) LangElement::find( "col" );
|
||||
Var *color = NULL;
|
||||
if (fd.features[MFT_DeferredTerrainDetailMap])
|
||||
color = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget1) );
|
||||
else
|
||||
color = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::DefaultTarget) );
|
||||
|
||||
Var *blendTotal = (Var*)LangElement::find( "blendTotal" );
|
||||
if ( !color || !blendTotal )
|
||||
return;
|
||||
|
|
@ -1033,5 +1020,43 @@ void TerrainAdditiveFeatHLSL::processPix( Vector<ShaderComponent*> &componentLis
|
|||
meta->addStatement( new GenOp( " clip( @ - 0.0001 );\r\n", blendTotal ) );
|
||||
meta->addStatement( new GenOp( " @.a = @;\r\n", color, blendTotal ) );
|
||||
|
||||
|
||||
output = meta;
|
||||
}
|
||||
|
||||
//standard matInfo map contains data of the form .r = bitflags, .g = (will contain AO),
|
||||
//.b = specular strength, a= spec power.
|
||||
//here, it's merely a cutout for now, so that lightmapping (target3) doesn't get mangled.
|
||||
//we'll most likely revisit that later. possibly several ways...
|
||||
|
||||
U32 TerrainBlankInfoMapFeatHLSL::getOutputTargets(const MaterialFeatureData &fd) const
|
||||
{
|
||||
return fd.features[MFT_DeferredTerrainBaseMap] ? ShaderFeature::RenderTarget2 : ShaderFeature::RenderTarget1;
|
||||
}
|
||||
|
||||
void TerrainBlankInfoMapFeatHLSL::processPix(Vector<ShaderComponent*> &componentList,
|
||||
const MaterialFeatureData &fd)
|
||||
{
|
||||
// search for material var
|
||||
Var *material;
|
||||
OutputTarget targ = RenderTarget1;
|
||||
if (fd.features[MFT_isDeferred])
|
||||
{
|
||||
targ = RenderTarget2;
|
||||
}
|
||||
material = (Var*)LangElement::find(getOutputTargetVarName(targ));
|
||||
|
||||
MultiLine * meta = new MultiLine;
|
||||
if (!material)
|
||||
{
|
||||
// create color var
|
||||
material = new Var;
|
||||
material->setType("fragout");
|
||||
material->setName(getOutputTargetVarName(targ));
|
||||
material->setStructName("OUT");
|
||||
}
|
||||
|
||||
meta->addStatement(new GenOp(" @ = float4(0.0,0.0,0.0,0.0001);\r\n", material));
|
||||
|
||||
output = meta;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,6 +68,8 @@ public:
|
|||
virtual Resources getResources( const MaterialFeatureData &fd );
|
||||
|
||||
virtual String getName() { return "Terrain Base Texture"; }
|
||||
|
||||
virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const;
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -91,6 +93,8 @@ public:
|
|||
virtual Resources getResources( const MaterialFeatureData &fd );
|
||||
|
||||
virtual String getName() { return "Terrain Detail Texture"; }
|
||||
|
||||
virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const;
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -114,6 +118,8 @@ public:
|
|||
virtual Resources getResources( const MaterialFeatureData &fd );
|
||||
|
||||
virtual String getName() { return "Terrain Macro Texture"; }
|
||||
|
||||
virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const;
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -155,4 +161,15 @@ public:
|
|||
virtual String getName() { return "Terrain Additive"; }
|
||||
};
|
||||
|
||||
class TerrainBlankInfoMapFeatHLSL : public TerrainFeatHLSL
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void processPix(Vector<ShaderComponent*> &componentList,
|
||||
const MaterialFeatureData &fd);
|
||||
|
||||
virtual U32 getOutputTargets(const MaterialFeatureData &fd) const;
|
||||
virtual String getName() { return "Blank Matinfo map"; }
|
||||
};
|
||||
|
||||
#endif // _TERRFEATUREHLSL_H_
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue