Direct3D11 Engine/source changes

This commit is contained in:
rextimmy 2016-03-20 21:52:11 +10:00
parent 3a9b50f702
commit 41e5caf22b
81 changed files with 1291 additions and 617 deletions

View file

@ -396,9 +396,6 @@ void TerrainDetailMapFeatGLSL::processPix( Vector<ShaderComponent*> &component
const S32 detailIndex = getProcessIndex();
Var *inTex = getVertTexCoord( "texCoord" );
// new terrain
bool hasNormal = fd.features.hasFeature(MFT_TerrainNormalMap, detailIndex);
MultiLine *meta = new MultiLine;
// We need the negative tangent space view vector
@ -490,7 +487,6 @@ void TerrainDetailMapFeatGLSL::processPix( Vector<ShaderComponent*> &component
blendDepth->constSortPos = cspPrimitive;
}
Var *baseColor = (Var*)LangElement::find("baseColor");
ShaderFeature::OutputTarget target = ShaderFeature::DefaultTarget;
if(fd.features.hasFeature( MFT_DeferredTerrainDetailMap ))

View file

@ -38,7 +38,7 @@ namespace
{
void register_hlsl_shader_features_for_terrain(GFXAdapterType type)
{
if(type != Direct3D9 && type != Direct3D9_360)
if (type != Direct3D9 && type != Direct3D9_360 && type != Direct3D11)
return;
FEATUREMGR->registerFeature( MFT_TerrainBaseMap, new TerrainBaseMapFeatHLSL );
@ -70,9 +70,9 @@ MODULE_END;
TerrainFeatHLSL::TerrainFeatHLSL()
: mTorqueDep( "shaders/common/torque.hlsl" )
{
{
addDependency( &mTorqueDep );
}
}
Var* TerrainFeatHLSL::_getUniformVar( const char *name, const char *type, ConstantSortPosition csp )
{
@ -129,14 +129,18 @@ Var* TerrainFeatHLSL::_getInMacroCoord( Vector<ShaderComponent*> &componentList
Var* TerrainFeatHLSL::_getNormalMapTex()
{
String name( String::ToString( "normalMap%d", getProcessIndex() ) );
Var *normalMap = (Var*)LangElement::find( name );
String name(String::ToString("normalMap%d", getProcessIndex()));
Var *normalMap = (Var*)LangElement::find(name);
if ( !normalMap )
if (!normalMap)
{
normalMap = new Var;
normalMap->setType( "sampler2D" );
normalMap->setName( name );
if (mIsDirect3D11)
normalMap->setType("SamplerState");
else
normalMap->setType("sampler2D");
normalMap->setName(name);
normalMap->uniform = true;
normalMap->sampler = true;
normalMap->constNum = Var::getTexUnitNum();
@ -267,12 +271,27 @@ void TerrainBaseMapFeatHLSL::processPix( Vector<ShaderComponent*> &componentLis
Var *baseColor = new Var;
baseColor->setType( "float4" );
baseColor->setName( "baseColor" );
meta->addStatement( new GenOp( " @ = tex2D( @, @.xy );\r\n", new DecOp( baseColor ), diffuseMap, texCoord ) );
if (mIsDirect3D11)
{
diffuseMap->setType("SamplerState");
Var *diffuseTex = new Var;
diffuseTex->setType("Texture2D");
diffuseTex->setName("baseTexture");
diffuseTex->uniform = true;
diffuseTex->texture = true;
diffuseTex->constNum = diffuseMap->constNum;
meta->addStatement(new GenOp(" @ = @.Sample( @, @.xy );\r\n", new DecOp(baseColor), diffuseTex, diffuseMap, texCoord));
}
else
{
meta->addStatement(new GenOp(" @ = tex2D( @, @.xy );\r\n", new DecOp(baseColor), diffuseMap, texCoord));
}
meta->addStatement(new GenOp(" @ = toLinear(@);\r\n", baseColor, baseColor));
ShaderFeature::OutputTarget target = ShaderFeature::DefaultTarget;
ShaderFeature::OutputTarget target = ShaderFeature::DefaultTarget;
if (fd.features.hasFeature(MFT_isDeferred))
if (fd.features.hasFeature(MFT_isDeferred))
{
target= ShaderFeature::RenderTarget1;
}
@ -433,9 +452,25 @@ void TerrainDetailMapFeatHLSL::processPix( Vector<ShaderComponent*> &component
layerTex->sampler = true;
layerTex->constNum = Var::getTexUnitNum();
// Read the layer texture to get the samples.
meta->addStatement( new GenOp( " @ = round( tex2D( @, @.xy ) * 255.0f );\r\n",
new DecOp( layerSample ), layerTex, inTex ) );
if (mIsDirect3D11)
{
layerTex->setType("SamplerState");
Var* layerTexObj = new Var;
layerTexObj->setName("layerTexObj");
layerTexObj->setType("Texture2D");
layerTexObj->uniform = true;
layerTexObj->texture = true;
layerTexObj->constNum = layerTex->constNum;
// Read the layer texture to get the samples.
meta->addStatement(new GenOp(" @ = round( @.Sample( @, @.xy ) * 255.0f );\r\n",
new DecOp(layerSample), layerTexObj, layerTex, inTex));
}
else
{
// Read the layer texture to get the samples.
meta->addStatement(new GenOp(" @ = round( tex2D( @, @.xy ) * 255.0f );\r\n",
new DecOp(layerSample), layerTex, inTex));
}
}
Var *layerSize = (Var*)LangElement::find( "layerSize" );
@ -478,21 +513,52 @@ void TerrainDetailMapFeatHLSL::processPix( Vector<ShaderComponent*> &component
// 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 ) )
if (fd.features.hasFeature(MFT_TerrainParallaxMap, detailIndex))
{
// Get the rest of our inputs.
Var *normalMap = _getNormalMapTex();
// Call the library function to do the rest.
if(fd.features.hasFeature( MFT_IsDXTnm, detailIndex ) )
if (mIsDirect3D11)
{
meta->addStatement( new GenOp( " @.xy += parallaxOffsetDxtnm( @, @.xy, @, @.z * @ );\r\n",
inDet, normalMap, inDet, negViewTS, detailInfo, detailBlend ) );
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;
}
// 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",
inDet, normalMapTex, normalMap, inDet, negViewTS, detailInfo, detailBlend));
}
else
{
meta->addStatement(new GenOp(" @.xy += parallaxOffset( @, @, @.xy, @, @.z * @ );\r\n",
inDet, normalMapTex, normalMap, inDet, negViewTS, detailInfo, detailBlend));
}
}
else
{
meta->addStatement( new GenOp( " @.xy += parallaxOffset( @, @.xy, @, @.z * @ );\r\n",
inDet, normalMap, inDet, negViewTS, detailInfo, detailBlend ) );
// 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",
inDet, normalMap, inDet, negViewTS, detailInfo, detailBlend));
}
else
{
meta->addStatement(new GenOp(" @.xy += parallaxOffset( @, @.xy, @, @.z * @ );\r\n",
inDet, normalMap, inDet, negViewTS, detailInfo, detailBlend));
}
}
}
@ -531,27 +597,46 @@ void TerrainDetailMapFeatHLSL::processPix( Vector<ShaderComponent*> &component
//
//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 ) )
if (mIsDirect3D11)
{
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) );
detailMap->setType("SamplerState");
Var* detailTex = new Var;
detailTex->setName(String::ToString("detailTex%d", detailIndex));
detailTex->setType("Texture2D");
detailTex->uniform = true;
detailTex->texture = true;
detailTex->constNum = detailMap->constNum;
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));
}
else
{
meta->addStatement(new GenOp(" @ = ( @.Sample( @, @.xy ) * 2.0 ) - 1.0;\r\n",
detailColor, detailTex, detailMap, inDet));
}
}
else
{
meta->addStatement( new GenOp(" @ = tex2D(@,@.xy);\r\n",detailTex,detailMap,inDet));
meta->addStatement( new GenOp( " @ = ( @ * 2.0 ) - 1.0;\r\n",
detailColor, 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));
}
else
{
meta->addStatement(new GenOp(" @ = ( tex2D( @, @.xy ) * 2.0 ) - 1.0;\r\n",
detailColor, detailMap, inDet));
}
}
meta->addStatement( new GenOp( " @ *= @.y * @.w;\r\n",
detailColor, detailInfo, inDet ) );
Var *baseColor = (Var*)LangElement::find( "baseColor" );
ShaderFeature::OutputTarget target = ShaderFeature::DefaultTarget;
if(fd.features.hasFeature( MFT_DeferredTerrainDetailMap ))
@ -718,8 +803,21 @@ void TerrainMacroMapFeatHLSL::processPix( Vector<ShaderComponent*> &componentL
layerTex->constNum = Var::getTexUnitNum();
// Read the layer texture to get the samples.
meta->addStatement( new GenOp( " @ = round( tex2D( @, @.xy ) * 255.0f );\r\n",
new DecOp( layerSample ), layerTex, inTex ) );
if (mIsDirect3D11)
{
layerTex->setType("SamplerState");
Var *layerTexObj = new Var;
layerTexObj->setType("Texture2D");
layerTexObj->setName("macroLayerTexObj");
layerTexObj->uniform = true;
layerTexObj->texture = true;
layerTexObj->constNum = layerTex->constNum;
meta->addStatement(new GenOp(" @ = round( @.Sample( @, @.xy ) * 255.0f );\r\n",
new DecOp(layerSample), layerTexObj, layerTex, inTex));
}
else
meta->addStatement(new GenOp(" @ = round( tex2D( @, @.xy ) * 255.0f );\r\n",
new DecOp(layerSample), layerTex, inTex));
}
Var *layerSize = (Var*)LangElement::find( "layerSize" );
@ -752,7 +850,6 @@ void TerrainMacroMapFeatHLSL::processPix( Vector<ShaderComponent*> &componentL
if ( !blendTotal )
{
blendTotal = new Var;
//blendTotal->setName( "blendTotal" );
blendTotal->setName( "blendTotal" );
blendTotal->setType( "float" );
meta->addStatement( new GenOp( " @ = 0;\r\n", new DecOp( blendTotal ) ) );
@ -778,6 +875,20 @@ void TerrainMacroMapFeatHLSL::processPix( Vector<ShaderComponent*> &componentL
detailMap->sampler = true;
detailMap->constNum = Var::getTexUnitNum(); // used as texture unit num here
//Create texture object for directx 11
Var *detailTex = NULL;
if (mIsDirect3D11)
{
detailMap->setType("SamplerState");
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 )
@ -792,22 +903,30 @@ void TerrainMacroMapFeatHLSL::processPix( Vector<ShaderComponent*> &componentL
// We take two color samples and lerp between them for
// side projection layers... else a single sample.
//
if ( fd.features.hasFeature( MFT_TerrainSideProject, detailIndex ) )
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 ) );
if (mIsDirect3D11)
{
meta->addStatement(new GenOp(" @ = ( lerp( @.Sample( @, @.yz ), @.Sample( @, @.xz ), @.z ) * 2.0 ) - 1.0;\r\n",
detailColor, detailTex, detailMap, inDet, detailTex, detailMap, inDet, inTex));
}
else
meta->addStatement(new GenOp(" @ = ( lerp( tex2D( @, @.yz ), tex2D( @, @.xz ), @.z ) * 2.0 ) - 1.0;\r\n",
detailColor, detailMap, inDet, detailMap, inDet, inTex));
}
else
{
meta->addStatement( new GenOp( " @ = ( tex2D( @, @.xy ) * 2.0 ) - 1.0;\r\n",
detailColor, detailMap, inDet ) );
if (mIsDirect3D11)
meta->addStatement(new GenOp(" @ = ( @.Sample( @, @.xy ) * 2.0 ) - 1.0;\r\n",
detailColor, detailTex, detailMap, inDet));
else
meta->addStatement(new GenOp(" @ = ( tex2D( @, @.xy ) * 2.0 ) - 1.0;\r\n",
detailColor, detailMap, inDet));
}
meta->addStatement( new GenOp( " @ *= @.y * @.w;\r\n",
detailColor, detailInfo, inDet ) );
Var *baseColor = (Var*)LangElement::find( "baseColor" );
ShaderFeature::OutputTarget target = ShaderFeature::DefaultTarget;
if(fd.features.hasFeature(MFT_DeferredTerrainMacroMap))
@ -907,13 +1026,39 @@ void TerrainNormalMapFeatHLSL::processPix( Vector<ShaderComponent*> &component
// We take two normal samples and lerp between them for
// side projection layers... else a single sample.
LangElement *texOp;
if ( fd.features.hasFeature( MFT_TerrainSideProject, normalIndex ) )
if (mIsDirect3D11)
{
texOp = new GenOp( "lerp( tex2D( @, @.yz ), tex2D( @, @.xz ), @.z )",
normalMap, inDet, normalMap, inDet, inTex );
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;
}
if (fd.features.hasFeature(MFT_TerrainSideProject, normalIndex))
{
texOp = new GenOp("lerp( @.Sample( @, @.yz ), @.Sample( @, @.xz ), @.z )",
normalMapTex, normalMap, inDet, normalMapTex, normalMap, inDet, inTex);
}
else
texOp = new GenOp("@.Sample(@, @.xy)", normalMapTex, normalMap, inDet);
}
else
texOp = new GenOp( "tex2D(@, @.xy)", normalMap, inDet );
{
if (fd.features.hasFeature(MFT_TerrainSideProject, normalIndex))
{
texOp = new GenOp("lerp( tex2D( @, @.yz ), tex2D( @, @.xz ), @.z )",
normalMap, inDet, normalMap, inDet, inTex);
}
else
texOp = new GenOp("tex2D(@, @.xy)", normalMap, inDet);
}
// create bump normal
Var *bumpNorm = new Var;
@ -991,7 +1136,20 @@ void TerrainLightMapFeatHLSL::processPix( Vector<ShaderComponent*> &componentLis
meta->addStatement( new GenOp( " @ = 1;\r\n", new DecOp( lightMask ) ) );
}
meta->addStatement( new GenOp( " @[0] = tex2D( @, @.xy ).r;\r\n", lightMask, lightMap, inTex ) );
if (mIsDirect3D11)
{
lightMap->setType("SamplerState");
Var* lightMapTex = new Var;
lightMapTex->setName("lightMapTexObj");
lightMapTex->setType("Texture2D");
lightMapTex->uniform = true;
lightMapTex->texture = true;
lightMapTex->constNum = lightMap->constNum;
meta->addStatement(new GenOp(" @[0] = @.Sample( @, @.xy ).r;\r\n", lightMask, lightMapTex, lightMap, inTex));
}
else
meta->addStatement(new GenOp(" @[0] = tex2D( @, @.xy ).r;\r\n", lightMask, lightMap, inTex));
output = meta;
}

View file

@ -208,14 +208,14 @@ void TerrainBlock::_updateBaseTexture(bool writeToCache)
F32 copyOffsetY = 2.0f * GFX->getFillConventionOffset() / (F32)destSize.y;
GFXVertexPT points[4];
points[0].point = Point3F( -1.0 - copyOffsetX, -1.0 + copyOffsetY, 0.0 );
points[0].texCoord = Point2F( 0.0, 1.0f );
points[1].point = Point3F( -1.0 - copyOffsetX, 1.0 + copyOffsetY, 0.0 );
points[1].texCoord = Point2F( 0.0, 0.0f );
points[2].point = Point3F( 1.0 - copyOffsetX, 1.0 + copyOffsetY, 0.0 );
points[2].texCoord = Point2F( 1.0, 0.0f );
points[3].point = Point3F( 1.0 - copyOffsetX, -1.0 + copyOffsetY, 0.0 );
points[3].texCoord = Point2F( 1.0, 1.0f );
points[0].point = Point3F(1.0 - copyOffsetX, -1.0 + copyOffsetY, 0.0);
points[0].texCoord = Point2F(1.0, 1.0f);
points[1].point = Point3F(1.0 - copyOffsetX, 1.0 + copyOffsetY, 0.0);
points[1].texCoord = Point2F(1.0, 0.0f);
points[2].point = Point3F(-1.0 - copyOffsetX, -1.0 + copyOffsetY, 0.0);
points[2].texCoord = Point2F(0.0, 1.0f);
points[3].point = Point3F(-1.0 - copyOffsetX, 1.0 + copyOffsetY, 0.0);
points[3].texCoord = Point2F(0.0, 0.0f);
vb.set( GFX, 4, GFXBufferTypeVolatile );
GFXVertexPT *ptr = vb.lock();
@ -274,7 +274,7 @@ void TerrainBlock::_updateBaseTexture(bool writeToCache)
mBaseShaderConsts->setSafe( mBaseTexScaleConst, Point2F( scale, -scale ) );
mBaseShaderConsts->setSafe( mBaseTexIdConst, (F32)i );
GFX->drawPrimitive( GFXTriangleFan, 0, 2 );
GFX->drawPrimitive( GFXTriangleStrip, 0, 2 );
}
mBaseTarget->resolve();