mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-29 16:25:42 +00:00
Direct3D11 Engine/source changes
This commit is contained in:
parent
3a9b50f702
commit
41e5caf22b
81 changed files with 1291 additions and 617 deletions
|
|
@ -126,6 +126,18 @@ void DeferredRTLightingFeatHLSL::processPix( Vector<ShaderComponent*> &component
|
|||
lightInfoBuffer->sampler = true;
|
||||
lightInfoBuffer->constNum = Var::getTexUnitNum(); // used as texture unit num here
|
||||
|
||||
Var* lightBufferTex = NULL;
|
||||
if (mIsDirect3D11)
|
||||
{
|
||||
lightInfoBuffer->setType("SamplerState");
|
||||
lightBufferTex = new Var;
|
||||
lightBufferTex->setName("lightInfoBufferTex");
|
||||
lightBufferTex->setType("Texture2D");
|
||||
lightBufferTex->uniform = true;
|
||||
lightBufferTex->texture = true;
|
||||
lightBufferTex->constNum = lightInfoBuffer->constNum;
|
||||
}
|
||||
|
||||
// Declare the RTLighting variables in this feature, they will either be assigned
|
||||
// in this feature, or in the tonemap/lightmap feature
|
||||
Var *d_lightcolor = new Var( "d_lightcolor", "float3" );
|
||||
|
|
@ -140,8 +152,12 @@ void DeferredRTLightingFeatHLSL::processPix( Vector<ShaderComponent*> &component
|
|||
|
||||
// Perform the uncondition here.
|
||||
String unconditionLightInfo = String::ToLower( AdvancedLightBinManager::smBufferName ) + "Uncondition";
|
||||
meta->addStatement( new GenOp( avar( " %s(tex2D(@, @), @, @, @);\r\n",
|
||||
unconditionLightInfo.c_str() ), lightInfoBuffer, uvScene, d_lightcolor, d_NL_Att, d_specular ) );
|
||||
if (mIsDirect3D11)
|
||||
meta->addStatement(new GenOp(avar(" %s(@.Sample(@, @), @, @, @);\r\n",
|
||||
unconditionLightInfo.c_str()), lightBufferTex, lightInfoBuffer, uvScene, d_lightcolor, d_NL_Att, d_specular));
|
||||
else
|
||||
meta->addStatement(new GenOp(avar(" %s(tex2D(@, @), @, @, @);\r\n",
|
||||
unconditionLightInfo.c_str()), lightInfoBuffer, uvScene, d_lightcolor, d_NL_Att, d_specular));
|
||||
|
||||
// If this has an interlaced pre-pass, do averaging here
|
||||
if( fd.features[MFT_InterlacedPrePass] )
|
||||
|
|
@ -157,8 +173,12 @@ void DeferredRTLightingFeatHLSL::processPix( Vector<ShaderComponent*> &component
|
|||
}
|
||||
|
||||
meta->addStatement( new GenOp( " float id_NL_Att, id_specular;\r\n float3 id_lightcolor;\r\n" ) );
|
||||
meta->addStatement( new GenOp( avar( " %s(tex2D(@, @ + float2(0.0, @.y)), id_lightcolor, id_NL_Att, id_specular);\r\n",
|
||||
unconditionLightInfo.c_str() ), lightInfoBuffer, uvScene, oneOverTargetSize ) );
|
||||
if (mIsDirect3D11)
|
||||
meta->addStatement(new GenOp(avar(" %s(@.Sample(@, @ + float2(0.0, @.y)), id_lightcolor, id_NL_Att, id_specular);\r\n",
|
||||
unconditionLightInfo.c_str()), lightBufferTex, lightInfoBuffer, uvScene, oneOverTargetSize));
|
||||
else
|
||||
meta->addStatement(new GenOp(avar(" %s(tex2D(@, @ + float2(0.0, @.y)), id_lightcolor, id_NL_Att, id_specular);\r\n",
|
||||
unconditionLightInfo.c_str()), lightInfoBuffer, uvScene, oneOverTargetSize));
|
||||
|
||||
meta->addStatement( new GenOp(" @ = lerp(@, id_lightcolor, 0.5);\r\n", d_lightcolor, d_lightcolor ) );
|
||||
meta->addStatement( new GenOp(" @ = lerp(@, id_NL_Att, 0.5);\r\n", d_NL_Att, d_NL_Att ) );
|
||||
|
|
@ -272,8 +292,17 @@ void DeferredBumpFeatHLSL::processPix( Vector<ShaderComponent*> &componentList,
|
|||
|
||||
// create texture var
|
||||
Var *bumpMap = getNormalMapTex();
|
||||
Var *texCoord = getInTexCoord( "texCoord", "float2", true, componentList );
|
||||
LangElement *texOp = new GenOp( "tex2D(@, @)", bumpMap, texCoord );
|
||||
Var *texCoord = getInTexCoord("texCoord", "float2", true, componentList);
|
||||
|
||||
LangElement *texOp = NULL;
|
||||
|
||||
if (mIsDirect3D11)
|
||||
{
|
||||
Var *bumpMapTex = (Var*)LangElement::find("bumpMapTex");
|
||||
texOp = new GenOp("@.Sample(@, @)", bumpMapTex, bumpMap, texCoord);
|
||||
}
|
||||
else
|
||||
texOp = new GenOp("tex2D(@, @)", bumpMap, texCoord);
|
||||
|
||||
// create bump normal
|
||||
Var *bumpNorm = new Var;
|
||||
|
|
@ -295,8 +324,25 @@ void DeferredBumpFeatHLSL::processPix( Vector<ShaderComponent*> &componentList,
|
|||
bumpMap->sampler = true;
|
||||
bumpMap->constNum = Var::getTexUnitNum();
|
||||
|
||||
texCoord = getInTexCoord( "detCoord", "float2", true, componentList );
|
||||
texOp = new GenOp( "tex2D(@, @)", bumpMap, texCoord );
|
||||
Var* detailNormalTex = NULL;
|
||||
if (mIsDirect3D11)
|
||||
{
|
||||
bumpMap->setType("SamplerState");
|
||||
detailNormalTex = new Var;
|
||||
detailNormalTex->setName("detailBumpMapTex");
|
||||
detailNormalTex->setType("Texture2D");
|
||||
detailNormalTex->uniform = true;
|
||||
detailNormalTex->texture = true;
|
||||
detailNormalTex->constNum = bumpMap->constNum;
|
||||
}
|
||||
|
||||
|
||||
texCoord = getInTexCoord("detCoord", "float2", true, componentList);
|
||||
|
||||
if (mIsDirect3D11)
|
||||
texOp = new GenOp("@.Sample(@, @)", detailNormalTex, bumpMap, texCoord);
|
||||
else
|
||||
texOp = new GenOp("tex2D(@, @)", bumpMap, texCoord);
|
||||
|
||||
Var *detailBump = new Var;
|
||||
detailBump->setName( "detailBump" );
|
||||
|
|
@ -333,25 +379,32 @@ void DeferredBumpFeatHLSL::processPix( Vector<ShaderComponent*> &componentList,
|
|||
else if (fd.features[MFT_AccuMap])
|
||||
{
|
||||
Var *bumpSample = (Var *)LangElement::find( "bumpSample" );
|
||||
if( bumpSample == NULL )
|
||||
if (bumpSample == NULL)
|
||||
{
|
||||
MultiLine *meta = new MultiLine;
|
||||
|
||||
Var *texCoord = getInTexCoord( "texCoord", "float2", true, componentList );
|
||||
Var *texCoord = getInTexCoord("texCoord", "float2", true, componentList);
|
||||
|
||||
Var *bumpMap = getNormalMapTex();
|
||||
|
||||
bumpSample = new Var;
|
||||
bumpSample->setType( "float4" );
|
||||
bumpSample->setName( "bumpSample" );
|
||||
LangElement *bumpSampleDecl = new DecOp( bumpSample );
|
||||
bumpSample->setType("float4");
|
||||
bumpSample->setName("bumpSample");
|
||||
LangElement *bumpSampleDecl = new DecOp(bumpSample);
|
||||
|
||||
meta->addStatement( new GenOp( " @ = tex2D(@, @);\r\n", bumpSampleDecl, bumpMap, texCoord ) );
|
||||
if (mIsDirect3D11)
|
||||
{
|
||||
Var *bumpMapTex = (Var *)LangElement::find("bumpMapTex");
|
||||
output = new GenOp(" @ = @.Sample(@, @);\r\n", bumpSampleDecl, bumpMapTex, bumpMap, texCoord);
|
||||
}
|
||||
else
|
||||
output = new GenOp(" @ = tex2D(@, @);\r\n", bumpSampleDecl, bumpMap, texCoord);
|
||||
|
||||
if ( fd.features.hasFeature( MFT_DetailNormalMap ) )
|
||||
{
|
||||
Var *bumpMap = (Var*)LangElement::find( "detailBumpMap" );
|
||||
if ( !bumpMap ) {
|
||||
if ( !bumpMap )
|
||||
{
|
||||
bumpMap = new Var;
|
||||
bumpMap->setType( "sampler2D" );
|
||||
bumpMap->setName( "detailBumpMap" );
|
||||
|
|
@ -360,8 +413,24 @@ void DeferredBumpFeatHLSL::processPix( Vector<ShaderComponent*> &componentList,
|
|||
bumpMap->constNum = Var::getTexUnitNum();
|
||||
}
|
||||
|
||||
Var* bumpMapTex = (Var*)LangElement::find("detailBumpMap");
|
||||
if (mIsDirect3D11 && !bumpMapTex)
|
||||
{
|
||||
bumpMap->setType("SamplerState");
|
||||
bumpMapTex = new Var;
|
||||
bumpMapTex->setName("detailBumpMapTex");
|
||||
bumpMapTex->setType("Texture2D");
|
||||
bumpMapTex->uniform = true;
|
||||
bumpMapTex->texture = true;
|
||||
bumpMapTex->constNum = bumpMap->constNum;
|
||||
}
|
||||
|
||||
texCoord = getInTexCoord( "detCoord", "float2", true, componentList );
|
||||
LangElement *texOp = new GenOp( "tex2D(@, @)", bumpMap, texCoord );
|
||||
LangElement *texOp = NULL;
|
||||
if (mIsDirect3D11)
|
||||
texOp = new GenOp("@.Sample(@, @)", bumpMap, bumpMapTex, texCoord);
|
||||
else
|
||||
texOp = new GenOp( "tex2D(@, @)", bumpMap, texCoord );
|
||||
|
||||
Var *detailBump = new Var;
|
||||
detailBump->setName( "detailBump" );
|
||||
|
|
@ -402,7 +471,14 @@ void DeferredBumpFeatHLSL::processPix( Vector<ShaderComponent*> &componentList,
|
|||
bumpSample->setName( "bumpSample" );
|
||||
LangElement *bumpSampleDecl = new DecOp( bumpSample );
|
||||
|
||||
output = new GenOp( " @ = tex2D(@, @);\r\n", bumpSampleDecl, bumpMap, texCoord );
|
||||
if (mIsDirect3D11)
|
||||
{
|
||||
Var *bumpMapTex = (Var *)LangElement::find("bumpMapTex");
|
||||
output = new GenOp(" @ = @.Sample(@, @);\r\n", bumpSampleDecl, bumpMapTex, bumpMap, texCoord);
|
||||
}
|
||||
else
|
||||
output = new GenOp(" @ = tex2D(@, @);\r\n", bumpSampleDecl, bumpMap, texCoord);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -547,7 +623,8 @@ void DeferredPixelSpecularHLSL::processPix( Vector<ShaderComponent*> &component
|
|||
AssertFatal( lightInfoSamp && d_specular && d_NL_Att,
|
||||
"DeferredPixelSpecularHLSL::processPix - Something hosed the deferred features!" );
|
||||
|
||||
if (fd.features[ MFT_AccuMap ]) {
|
||||
if (fd.features[ MFT_AccuMap ])
|
||||
{
|
||||
// change specularity where the accu texture is applied
|
||||
Var *accuPlc = (Var*) LangElement::find( "plc" );
|
||||
Var *accuSpecular = (Var*)LangElement::find( "accuSpecular" );
|
||||
|
|
@ -671,6 +748,18 @@ void DeferredMinnaertHLSL::processPix( Vector<ShaderComponent*> &componentList,
|
|||
prepassBuffer->sampler = true;
|
||||
prepassBuffer->constNum = Var::getTexUnitNum(); // used as texture unit num here
|
||||
|
||||
Var* prePassTex = NULL;
|
||||
if (mIsDirect3D11)
|
||||
{
|
||||
prepassBuffer->setType("SamplerState");
|
||||
prePassTex = new Var;
|
||||
prePassTex->setName("prePassTex");
|
||||
prePassTex->setType("Texture2D");
|
||||
prePassTex->uniform = true;
|
||||
prePassTex->texture = true;
|
||||
prePassTex->constNum = prepassBuffer->constNum;
|
||||
}
|
||||
|
||||
// Texture coord
|
||||
Var *uvScene = (Var*) LangElement::find( "uvScene" );
|
||||
AssertFatal(uvScene != NULL, "Unable to find UVScene, no RTLighting feature?");
|
||||
|
|
@ -684,7 +773,11 @@ void DeferredMinnaertHLSL::processPix( Vector<ShaderComponent*> &componentList,
|
|||
|
||||
Var *d_NL_Att = (Var*)LangElement::find( "d_NL_Att" );
|
||||
|
||||
meta->addStatement( new GenOp( avar( " float4 normalDepth = %s(@, @);\r\n", unconditionPrePassMethod.c_str() ), prepassBuffer, uvScene ) );
|
||||
if (mIsDirect3D11)
|
||||
meta->addStatement(new GenOp(avar(" float4 normalDepth = %s(@, ,@, @);\r\n", unconditionPrePassMethod.c_str()), prepassBuffer, prePassTex, uvScene));
|
||||
else
|
||||
meta->addStatement(new GenOp(avar(" float4 normalDepth = %s(@, @);\r\n", unconditionPrePassMethod.c_str()), prepassBuffer, uvScene));
|
||||
|
||||
meta->addStatement( new GenOp( " float vDotN = dot(normalDepth.xyz, @);\r\n", wsViewVec ) );
|
||||
meta->addStatement( new GenOp( " float Minnaert = pow( @, @) * pow(vDotN, 1.0 - @);\r\n", d_NL_Att, minnaertConstant, minnaertConstant ) );
|
||||
meta->addStatement( new GenOp( " @;\r\n", assignColor( new GenOp( "float4(Minnaert, Minnaert, Minnaert, 1.0)" ), Material::Mul ) ) );
|
||||
|
|
|
|||
|
|
@ -62,12 +62,35 @@ void DeferredSpecMapHLSL::processPix( Vector<ShaderComponent*> &componentList, c
|
|||
specularMap->uniform = true;
|
||||
specularMap->sampler = true;
|
||||
specularMap->constNum = Var::getTexUnitNum();
|
||||
LangElement *texOp = new GenOp( "tex2D(@, @)", specularMap, texCoord );
|
||||
|
||||
Var* specularMapTex = NULL;
|
||||
if (mIsDirect3D11)
|
||||
{
|
||||
specularMap->setType("SamplerState");
|
||||
specularMapTex = new Var;
|
||||
specularMapTex->setName("specularMapTex");
|
||||
specularMapTex->setType("Texture2D");
|
||||
specularMapTex->uniform = true;
|
||||
specularMapTex->texture = true;
|
||||
specularMapTex->constNum = specularMap->constNum;
|
||||
}
|
||||
|
||||
//matinfo.g slot reserved for AO later
|
||||
Var* specColor = new Var;
|
||||
specColor->setName("specColor");
|
||||
specColor->setType("float4");
|
||||
LangElement *specColorElem = new DecOp(specColor);
|
||||
|
||||
meta->addStatement(new GenOp(" @.g = 1.0;\r\n", material));
|
||||
meta->addStatement(new GenOp(" @.b = dot(tex2D(@, @).rgb, float3(0.3, 0.59, 0.11));\r\n", material, specularMap, texCoord));
|
||||
meta->addStatement(new GenOp(" @.a = tex2D(@, @).a;\r\n", material, specularMap, texCoord));
|
||||
//sample specular map
|
||||
if (mIsDirect3D11)
|
||||
meta->addStatement(new GenOp(" @ = @.Sample(@, @);\r\n", specColorElem, specularMapTex, specularMap, texCoord));
|
||||
else
|
||||
meta->addStatement(new GenOp(" @ = tex2D(@, @);\r\n", specColorElem, specularMap, texCoord));
|
||||
|
||||
meta->addStatement(new GenOp(" @.b = dot(@.rgb, float3(0.3, 0.59, 0.11));\r\n", material, specColor));
|
||||
meta->addStatement(new GenOp(" @.a = @.a;\r\n", material, specColor));
|
||||
|
||||
output = meta;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
#include "materials/materialFeatureTypes.h"
|
||||
#include "materials/materialFeatureData.h"
|
||||
#include "shaderGen/hlsl/shaderFeatureHLSL.h"
|
||||
|
||||
#include "gfx/gfxDevice.h"
|
||||
|
||||
GBufferConditionerHLSL::GBufferConditionerHLSL( const GFXFormat bufferFormat, const NormalSpace nrmSpace ) :
|
||||
Parent( bufferFormat )
|
||||
|
|
@ -114,7 +114,7 @@ void GBufferConditionerHLSL::processVert( Vector<ShaderComponent*> &componentLis
|
|||
// TODO: Total hack because Conditioner is directly derived
|
||||
// from ShaderFeature and not from ShaderFeatureHLSL.
|
||||
NamedFeatureHLSL dummy( String::EmptyString );
|
||||
dummy.mInstancingFormat = mInstancingFormat;
|
||||
dummy.setInstancingFormat( mInstancingFormat );
|
||||
Var *worldViewOnly = dummy.getWorldView( componentList, fd.features[MFT_UseInstancing], meta );
|
||||
|
||||
meta->addStatement( new GenOp(" @ = mul(@, float4( normalize(@), 0.0 ) ).xyz;\r\n",
|
||||
|
|
@ -222,6 +222,7 @@ Var* GBufferConditionerHLSL::printMethodHeader( MethodType methodType, const Str
|
|||
retVal = Parent::printMethodHeader( methodType, methodName, stream, meta );
|
||||
else
|
||||
{
|
||||
const bool isDirect3D11 = GFX->getAdapterType() == Direct3D11;
|
||||
Var *methodVar = new Var;
|
||||
methodVar->setName(methodName);
|
||||
methodVar->setType("inline float4");
|
||||
|
|
@ -237,12 +238,28 @@ Var* GBufferConditionerHLSL::printMethodHeader( MethodType methodType, const Str
|
|||
screenUV->setType("float2");
|
||||
DecOp *screenUVDecl = new DecOp(screenUV);
|
||||
|
||||
Var *prepassTex = NULL;
|
||||
DecOp *prepassTexDecl = NULL;
|
||||
if (isDirect3D11)
|
||||
{
|
||||
prepassSampler->setType("SamplerState");
|
||||
prepassTex = new Var;
|
||||
prepassTex->setName("prepassTexVar");
|
||||
prepassTex->setType("Texture2D");
|
||||
prepassTex->texture = true;
|
||||
prepassTex->constNum = prepassSampler->constNum;
|
||||
prepassTexDecl = new DecOp(prepassTex);
|
||||
}
|
||||
|
||||
Var *bufferSample = new Var;
|
||||
bufferSample->setName("bufferSample");
|
||||
bufferSample->setType("float4");
|
||||
DecOp *bufferSampleDecl = new DecOp(bufferSample);
|
||||
|
||||
meta->addStatement( new GenOp( "@(@, @)\r\n", methodDecl, prepassSamplerDecl, screenUVDecl ) );
|
||||
if (isDirect3D11)
|
||||
meta->addStatement(new GenOp("@(@, @, @)\r\n", methodDecl, prepassSamplerDecl, prepassTexDecl, screenUVDecl));
|
||||
else
|
||||
meta->addStatement( new GenOp( "@(@, @)\r\n", methodDecl, prepassSamplerDecl, screenUVDecl ) );
|
||||
|
||||
meta->addStatement( new GenOp( "{\r\n" ) );
|
||||
|
||||
|
|
@ -255,10 +272,14 @@ Var* GBufferConditionerHLSL::printMethodHeader( MethodType methodType, const Str
|
|||
// The gbuffer has no mipmaps, so use tex2dlod when
|
||||
// possible so that the shader compiler can optimize.
|
||||
meta->addStatement( new GenOp( " #if TORQUE_SM >= 30\r\n" ) );
|
||||
meta->addStatement( new GenOp( " @ = tex2Dlod(@, float4(@,0,0));\r\n", bufferSampleDecl, prepassSampler, screenUV ) );
|
||||
meta->addStatement( new GenOp( " #else\r\n" ) );
|
||||
meta->addStatement( new GenOp( " @ = tex2D(@, @);\r\n", bufferSampleDecl, prepassSampler, screenUV ) );
|
||||
meta->addStatement( new GenOp( " #endif\r\n\r\n" ) );
|
||||
if (isDirect3D11)
|
||||
meta->addStatement(new GenOp(" @ = @.SampleLevel(@, @,0);\r\n", bufferSampleDecl, prepassTex, prepassSampler, screenUV));
|
||||
else
|
||||
meta->addStatement(new GenOp(" @ = tex2Dlod(@, float4(@,0,0));\r\n", bufferSampleDecl, prepassSampler, screenUV));
|
||||
|
||||
meta->addStatement(new GenOp(" #else\r\n"));
|
||||
meta->addStatement(new GenOp(" @ = tex2D(@, @);\r\n", bufferSampleDecl, prepassSampler, screenUV));
|
||||
meta->addStatement(new GenOp(" #endif\r\n\r\n"));
|
||||
#endif
|
||||
|
||||
// We don't use this way of passing var's around, so this should cause a crash
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue