From 21c17d0ed1748973d4558fd76c1a893bb2e7906a Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Fri, 17 Sep 2021 01:24:20 -0500 Subject: [PATCH 01/20] cleanups for shadergen and the visibility feature math fixes, feature inclusion removal. will still need to circle back on why the crosshatch.. isn't --- .../lighting/shadowMap/shadowMatHook.cpp | 4 +--- .../shaderGen/GLSL/shaderFeatureGLSL.cpp | 24 ++++--------------- .../shaderGen/HLSL/shaderFeatureHLSL.cpp | 6 ++--- .../core/rendering/shaders/gl/torque.glsl | 4 ++-- 4 files changed, 11 insertions(+), 27 deletions(-) diff --git a/Engine/source/lighting/shadowMap/shadowMatHook.cpp b/Engine/source/lighting/shadowMap/shadowMatHook.cpp index 30f2db593..c6b8bab01 100644 --- a/Engine/source/lighting/shadowMap/shadowMatHook.cpp +++ b/Engine/source/lighting/shadowMap/shadowMatHook.cpp @@ -186,10 +186,8 @@ void ShadowMaterialHook::_overrideFeatures( ProcessedMaterial *mat, type == MFT_TexAnim || type == MFT_DiffuseMap || type == MFT_IsTranslucent || - type == MFT_Visibility || type == MFT_UseInstancing || - type == MFT_EyeSpaceDepthOut || - type == MFT_DeferredConditioner) + type == MFT_EyeSpaceDepthOut) newFeatures.addFeature(type); else if (type.getGroup() == MFG_PreTransform || type.getGroup() == MFG_Transform || diff --git a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp index 2bd24931d..3ee76ffdf 100644 --- a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp +++ b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp @@ -455,12 +455,12 @@ Var* ShaderFeatureGLSL::addOutVpos( MultiLine *meta, outVpos = connectComp->getElement( RT_TEXCOORD ); outVpos->setName( "outVpos" ); outVpos->setStructName( "OUT" ); - outVpos->setType( "vec4" ); + outVpos->setType( "vec3" ); Var *outPosition = (Var*) LangElement::find( "gl_Position" ); AssertFatal( outPosition, "ShaderFeatureGLSL::addOutVpos - Didn't find the output position." ); - meta->addStatement( new GenOp( " @ = @;\r\n", outVpos, outPosition ) ); + meta->addStatement( new GenOp( " @ = @.xyz;\r\n", outVpos, outPosition ) ); } return outVpos; @@ -474,25 +474,11 @@ Var* ShaderFeatureGLSL::getInVpos( MultiLine *meta, return inVpos; ShaderConnector *connectComp = dynamic_cast( componentList[C_CONNECTOR] ); - /* - if ( GFX->getPixelShaderVersion() >= 3.0f ) - { - inVpos = connectComp->getElement( RT_VPOS ); - inVpos->setName( "vpos" ); - inVpos->setStructName( "IN" ); - inVpos->setType( "vec2" ); - return inVpos; - } - */ inVpos = connectComp->getElement( RT_TEXCOORD ); inVpos->setName( "inVpos" ); inVpos->setStructName( "IN" ); inVpos->setType( "vec4" ); - - Var *vpos = new Var( "vpos", "vec2" ); - meta->addStatement( new GenOp( " @ = @.xy / @.w;\r\n", new DecOp( vpos ), inVpos, inVpos ) ); - - return vpos; + return inVpos; } Var* ShaderFeatureGLSL::getInWorldToTangent( Vector &componentList ) @@ -2473,7 +2459,7 @@ void VisibilityFeatGLSL::processPix( Vector &componentList, // Everything else does a fizzle. Var *vPos = getInVpos( meta, componentList ); - meta->addStatement( new GenOp( " fizzle( @, @ );\r\n", vPos, visibility ) ); + meta->addStatement( new GenOp( " fizzle( @.xy, @ );\r\n", vPos, visibility ) ); } ShaderFeature::Resources VisibilityFeatGLSL::getResources( const MaterialFeatureData &fd ) @@ -2616,7 +2602,7 @@ void FoliageFeatureGLSL::processVert( Vector &componentList, tangent->setType( "vec3" ); tangent->setName( "T" ); LangElement *tangentDec = new DecOp( tangent ); - meta->addStatement( new GenOp( " @;\n", tangentDec ) ); + meta->addStatement( new GenOp( " @ = vec3(1.0,0,0);\n", tangentDec ) ); // We add a float foliageFade to the OUT structure. ShaderConnector *connectComp = dynamic_cast( componentList[C_CONNECTOR] ); diff --git a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp index 80601ad68..2fe171aba 100644 --- a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp +++ b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp @@ -453,12 +453,12 @@ Var* ShaderFeatureHLSL::addOutVpos( MultiLine *meta, outVpos = connectComp->getElement( RT_TEXCOORD ); outVpos->setName( "outVpos" ); outVpos->setStructName( "OUT" ); - outVpos->setType( "float4" ); + outVpos->setType( "float3" ); Var *outPosition = (Var*) LangElement::find( "hpos" ); AssertFatal( outPosition, "ShaderFeatureHLSL::addOutVpos - Didn't find the output position." ); - meta->addStatement( new GenOp( " @ = @;\r\n", outVpos, outPosition ) ); + meta->addStatement( new GenOp( " @ = @.xyz;\r\n", outVpos, outPosition ) ); } return outVpos; @@ -2686,7 +2686,7 @@ void FoliageFeatureHLSL::processVert( Vector &componentList, tangent->setType( "float3" ); tangent->setName( "T" ); LangElement *tangentDec = new DecOp( tangent ); - meta->addStatement( new GenOp( " @;\n", tangentDec ) ); + meta->addStatement( new GenOp( " @ = float3(1.0,0,0);\n", tangentDec ) ); // We add a float foliageFade to the OUT structure. ShaderConnector *connectComp = dynamic_cast( componentList[C_CONNECTOR] ); diff --git a/Templates/BaseGame/game/core/rendering/shaders/gl/torque.glsl b/Templates/BaseGame/game/core/rendering/shaders/gl/torque.glsl index 5482bdaf3..4ec0303aa 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/gl/torque.glsl +++ b/Templates/BaseGame/game/core/rendering/shaders/gl/torque.glsl @@ -291,8 +291,8 @@ void fizzle(vec2 vpos, float visibility) // I'm sure there are many more patterns here to // discover for different effects. - mat2x2 m = mat2x2( vpos.x, vpos.y, 0.916, 0.350 ); - if( (visibility - fract( determinant( m ) )) < 0 ) //if(a < 0) discard; + mat2x2 m = mat2x2( vpos.x, 0.916, vpos.y, 0.350 ); + if( (visibility - fract( determinant( m ) )) < 0 ) discard; } #endif //TORQUE_PIXEL_SHADER From 8ce207561e487bd3495dbe4ed3b8cd9bbcc9c51f Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Mon, 20 Sep 2021 16:56:53 -0500 Subject: [PATCH 02/20] revert a bit causing crashes on certain 'nix boxes. --- Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp | 4 ++-- Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp index 3ee76ffdf..0cf46277c 100644 --- a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp +++ b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp @@ -455,12 +455,12 @@ Var* ShaderFeatureGLSL::addOutVpos( MultiLine *meta, outVpos = connectComp->getElement( RT_TEXCOORD ); outVpos->setName( "outVpos" ); outVpos->setStructName( "OUT" ); - outVpos->setType( "vec3" ); + outVpos->setType( "vec4" ); Var *outPosition = (Var*) LangElement::find( "gl_Position" ); AssertFatal( outPosition, "ShaderFeatureGLSL::addOutVpos - Didn't find the output position." ); - meta->addStatement( new GenOp( " @ = @.xyz;\r\n", outVpos, outPosition ) ); + meta->addStatement( new GenOp( " @ = @;\r\n", outVpos, outPosition ) ); } return outVpos; diff --git a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp index 2fe171aba..1ebc3982a 100644 --- a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp +++ b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp @@ -453,12 +453,12 @@ Var* ShaderFeatureHLSL::addOutVpos( MultiLine *meta, outVpos = connectComp->getElement( RT_TEXCOORD ); outVpos->setName( "outVpos" ); outVpos->setStructName( "OUT" ); - outVpos->setType( "float3" ); + outVpos->setType( "float4" ); Var *outPosition = (Var*) LangElement::find( "hpos" ); AssertFatal( outPosition, "ShaderFeatureHLSL::addOutVpos - Didn't find the output position." ); - meta->addStatement( new GenOp( " @ = @.xyz;\r\n", outVpos, outPosition ) ); + meta->addStatement( new GenOp( " @ = @;\r\n", outVpos, outPosition ) ); } return outVpos; From 9775d69988fc1ca269e13ef9d6e8b1caae8f8a58 Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Tue, 21 Sep 2021 17:10:07 -0500 Subject: [PATCH 03/20] pad shader uniform length pipe by 1 to avoid a bug with some integrated chips clipping --- Engine/source/gfx/gl/gfxGLShader.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Engine/source/gfx/gl/gfxGLShader.cpp b/Engine/source/gfx/gl/gfxGLShader.cpp index d2f2edd22..eed45b3e1 100644 --- a/Engine/source/gfx/gl/gfxGLShader.cpp +++ b/Engine/source/gfx/gl/gfxGLShader.cpp @@ -561,6 +561,7 @@ void GFXGLShader::initConstantDescs() if(!maxNameLength) return; + maxNameLength++; FrameTemp uniformName(maxNameLength); From c86cc489458cc4c1d32fbf40d08d996a6b91351c Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Wed, 22 Sep 2021 18:27:42 -0500 Subject: [PATCH 04/20] use srgb sapce for backbuffer --- Engine/source/postFx/postEffectManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Engine/source/postFx/postEffectManager.cpp b/Engine/source/postFx/postEffectManager.cpp index 7904c522d..d65e25e25 100644 --- a/Engine/source/postFx/postEffectManager.cpp +++ b/Engine/source/postFx/postEffectManager.cpp @@ -141,7 +141,7 @@ GFXTextureObject* PostEffectManager::getBackBufferTex() mBackBufferCopyTex.set( targetSize.x, targetSize.y, targetFormat, - &PostFxTargetProfile, "mBackBufferCopyTex" ); + &PostFxTextureSRGBProfile, "mBackBufferCopyTex" ); target->resolveTo( mBackBufferCopyTex ); mLastBackBufferTarget = target; From 5682bafb291fe7a5a865d256153d6229e74f4d4a Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Wed, 22 Sep 2021 18:28:19 -0500 Subject: [PATCH 05/20] kills off that second buffer in terrain rendering when in forward mode --- .../source/terrain/glsl/terrFeatureGLSL.cpp | 132 ++++++++-------- Engine/source/terrain/glsl/terrFeatureGLSL.h | 1 - .../source/terrain/hlsl/terrFeatureHLSL.cpp | 141 +++++++++--------- Engine/source/terrain/hlsl/terrFeatureHLSL.h | 2 - 4 files changed, 142 insertions(+), 134 deletions(-) diff --git a/Engine/source/terrain/glsl/terrFeatureGLSL.cpp b/Engine/source/terrain/glsl/terrFeatureGLSL.cpp index 14f321cce..d30e639ec 100644 --- a/Engine/source/terrain/glsl/terrFeatureGLSL.cpp +++ b/Engine/source/terrain/glsl/terrFeatureGLSL.cpp @@ -304,29 +304,28 @@ void TerrainBaseMapFeatGLSL::processPix( Vector &componentLis baseColor->setName( "baseColor" ); meta->addStatement( new GenOp( " @ = tex2D( @, @.xy );\r\n", new DecOp( baseColor ), diffuseMap, texCoord ) ); - ShaderFeature::OutputTarget target = ShaderFeature::DefaultTarget; + ShaderFeature::OutputTarget target = (fd.features[MFT_isDeferred]) ? RenderTarget1 : DefaultTarget; + meta->addStatement(new GenOp(" @;\r\n", assignColor(baseColor, Material::Mul, NULL, target))); - if(fd.features.hasFeature(MFT_isDeferred)) - { - target= ShaderFeature::RenderTarget1; - } - meta->addStatement( new GenOp( " @;\r\n", assignColor( baseColor, Material::Mul,NULL,target ) ) ); - - // Set base ORM info Var* ormConfig; - OutputTarget targ = RenderTarget1; - if (fd.features[MFT_isDeferred]) + if ((fd.features[MFT_isDeferred])) { - targ = RenderTarget2; + // Set base ORM info + ormConfig = (Var*)LangElement::find(getOutputTargetVarName(RenderTarget2)); + + if (!ormConfig) + { + // create color var + ormConfig = new Var; + ormConfig->setType("fragout"); + ormConfig->setName(getOutputTargetVarName(RenderTarget2)); + ormConfig->setStructName("OUT"); + } } - ormConfig = (Var*)LangElement::find(getOutputTargetVarName(targ)); - if (!ormConfig) + else { - // create color var - ormConfig = new Var; - ormConfig->setType("fragout"); - ormConfig->setName(getOutputTargetVarName(targ)); - ormConfig->setStructName("OUT"); + ormConfig = new Var("ORMConfig", "float4"); + meta->addStatement(new GenOp(" @;\r\n", new DecOp(ormConfig))); } meta->addStatement(new GenOp(" @ = float4(0.0, 1.0, 1.0, 0.0);\r\n", ormConfig)); @@ -347,7 +346,7 @@ ShaderFeature::Resources TerrainBaseMapFeatGLSL::getResources( const MaterialFea U32 TerrainBaseMapFeatGLSL::getOutputTargets( const MaterialFeatureData &fd ) const { - return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget1 | ShaderFeature::RenderTarget2 : ShaderFeature::DefaultTarget | ShaderFeature::RenderTarget1; + return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget2 | ShaderFeature::RenderTarget1 : ShaderFeature::DefaultTarget; } TerrainDetailMapFeatGLSL::TerrainDetailMapFeatGLSL() @@ -1167,24 +1166,36 @@ void TerrainORMMapFeatGLSL::processPix(Vector &componentList, else texOp = new GenOp("tex2D(@, vec3(@.xy, @.x))", ormConfigMap, inDet, new IndexOp(detailInfo, compositeIndex)); - // search for material var - Var * ormConfig; - OutputTarget targ = RenderTarget1; - if (fd.features[MFT_isDeferred]) - { - targ = RenderTarget2; - } - ormConfig = (Var*)LangElement::find(getOutputTargetVarName(targ)); + MultiLine* meta = new MultiLine; + // search for material var + Var* ormConfig; + if ((fd.features[MFT_isDeferred])) + { + // Set base ORM info + ormConfig = (Var*)LangElement::find(getOutputTargetVarName(RenderTarget2)); - MultiLine * meta = new MultiLine; - if (!ormConfig) - { - // create color var - ormConfig = new Var; - ormConfig->setType("fragout"); - ormConfig->setName(getOutputTargetVarName(targ)); - ormConfig->setStructName("OUT"); - } + if (!ormConfig) + { + // create color var + ormConfig = new Var; + ormConfig->setType("fragout"); + ormConfig->setName(getOutputTargetVarName(RenderTarget2)); + ormConfig->setStructName("OUT"); + } + } + else + { + ormConfig = (Var*)LangElement::find("ORMConfig"); + if (!ormConfig) + { + ormConfig = new Var("ORMConfig", "vec4"); + meta->addStatement(new GenOp(" @;\r\n", new DecOp(ormConfig))); + } + } + if (compositeIndex == 0) + { + meta->addStatement(new GenOp(" @ = vec4(0.0, 0.0, 0.0, 0.0);\r\n", ormConfig)); + } Var *detailBlend = (Var*)LangElement::find(String::ToString("detailBlend%d", compositeIndex)); AssertFatal(detailBlend, "The detail blend is missing!"); @@ -1192,11 +1203,6 @@ void TerrainORMMapFeatGLSL::processPix(Vector &componentList, String matinfoName(String::ToString("matinfoCol%d", compositeIndex)); Var *matinfoCol = new Var(matinfoName, "vec3"); - if (compositeIndex == 0) - { - meta->addStatement(new GenOp(" @ = vec4(0.0, 0.0, 0.0, 0.0);\r\n", ormConfig)); - } - meta->addStatement(new GenOp(" @ = @.rgb;\r\n", new DecOp(matinfoCol), texOp)); if (fd.features.hasFeature(MFT_InvertRoughness, compositeIndex)) @@ -1236,40 +1242,40 @@ ShaderFeature::Resources TerrainORMMapFeatGLSL::getResources(const MaterialFeatu return res; } - -U32 TerrainBlankInfoMapFeatGLSL::getOutputTargets(const MaterialFeatureData &fd) const -{ - return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget2 : ShaderFeature::RenderTarget1; -} - // reminder, the matinfo buffer is flags, smooth, ao, metal void TerrainBlankInfoMapFeatGLSL::processPix(Vector &componentList, const MaterialFeatureData &fd) { S32 compositeIndex = getProcessIndex(); - // search for material var - Var *material; - OutputTarget targ = DefaultTarget; - if (fd.features[MFT_isDeferred]) + MultiLine* meta = new MultiLine; Var* ormConfig; + if ((fd.features[MFT_isDeferred])) { - targ = RenderTarget2; - } - material = (Var*)LangElement::find(getOutputTargetVarName(targ)); + // Set base ORM info + ormConfig = (Var*)LangElement::find(getOutputTargetVarName(RenderTarget2)); - MultiLine * meta = new MultiLine; - if (!material) + if (!ormConfig) + { + // create color var + ormConfig = new Var; + ormConfig->setType("fragout"); + ormConfig->setName(getOutputTargetVarName(RenderTarget2)); + ormConfig->setStructName("OUT"); + } + } + else { - // create color var - material = new Var; - material->setType("vec4"); - material->setName(getOutputTargetVarName(targ)); - material->setStructName("OUT"); + ormConfig = (Var*)LangElement::find("ORMConfig"); + if (!ormConfig) + { + ormConfig = new Var("ORMConfig", "vec4"); + meta->addStatement(new GenOp(" @;\r\n", new DecOp(ormConfig))); + } } if (compositeIndex == 0) { - meta->addStatement(new GenOp(" @ = vec4(0.0, 0.0, 0.0, 0.0);\r\n", material)); + meta->addStatement(new GenOp(" @ = float4(0.0, 0.0, 0.0, 0.0);\r\n", ormConfig)); } Var* detailBlend = (Var*)LangElement::find(String::ToString("detailBlend%d", compositeIndex)); @@ -1277,7 +1283,7 @@ void TerrainBlankInfoMapFeatGLSL::processPix(Vector &component String matinfoName(String::ToString("matinfoCol%d", compositeIndex)); - meta->addStatement(new GenOp(" @.gba += vec3(@, @, 0.0);\r\n", material, detailBlend, detailBlend)); + meta->addStatement(new GenOp(" @.gba += vec3(@, @, 0.0);\r\n", ormConfig, detailBlend, detailBlend)); output = meta; } diff --git a/Engine/source/terrain/glsl/terrFeatureGLSL.h b/Engine/source/terrain/glsl/terrFeatureGLSL.h index 5b48c0a51..7d56a75bf 100644 --- a/Engine/source/terrain/glsl/terrFeatureGLSL.h +++ b/Engine/source/terrain/glsl/terrFeatureGLSL.h @@ -174,7 +174,6 @@ public: virtual void processPix(Vector &componentList, const MaterialFeatureData &fd); - virtual U32 getOutputTargets(const MaterialFeatureData &fd) const; virtual String getName() { return "Blank Matinfo map"; } }; diff --git a/Engine/source/terrain/hlsl/terrFeatureHLSL.cpp b/Engine/source/terrain/hlsl/terrFeatureHLSL.cpp index e136c82eb..362a012a3 100644 --- a/Engine/source/terrain/hlsl/terrFeatureHLSL.cpp +++ b/Engine/source/terrain/hlsl/terrFeatureHLSL.cpp @@ -337,27 +337,27 @@ void TerrainBaseMapFeatHLSL::processVert( Vector &componentLis new DecOp( inTanget ), squareSize, inTangentZ ) ); } -void TerrainBaseMapFeatHLSL::processPix( Vector &componentList, - const MaterialFeatureData &fd ) +void TerrainBaseMapFeatHLSL::processPix(Vector& componentList, + const MaterialFeatureData& fd) { // grab connector texcoord register - Var *texCoord = getInTexCoord( "texCoord", "float3", componentList ); + Var* texCoord = getInTexCoord("texCoord", "float3", componentList); // create texture var - Var *diffuseMap = new Var; - diffuseMap->setType( "SamplerState" ); - diffuseMap->setName( "baseTexMap" ); + Var* diffuseMap = new Var; + diffuseMap->setType("SamplerState"); + diffuseMap->setName("baseTexMap"); diffuseMap->uniform = true; diffuseMap->sampler = true; diffuseMap->constNum = Var::getTexUnitNum(); // used as texture unit num here - MultiLine *meta = new MultiLine; + MultiLine* meta = new MultiLine; - Var *baseColor = new Var; - baseColor->setType( "float4" ); - baseColor->setName( "baseColor" ); + Var* baseColor = new Var; + baseColor->setType("float4"); + baseColor->setName("baseColor"); - Var *diffuseTex = new Var; + Var* diffuseTex = new Var; diffuseTex->setType("Texture2D"); diffuseTex->setName("baseTexture"); diffuseTex->uniform = true; @@ -365,33 +365,31 @@ void TerrainBaseMapFeatHLSL::processPix( Vector &componentLis diffuseTex->constNum = diffuseMap->constNum; meta->addStatement(new GenOp(" @ = @.Sample( @, @.xy );\r\n", new DecOp(baseColor), diffuseTex, diffuseMap, texCoord)); - ShaderFeature::OutputTarget target = ShaderFeature::DefaultTarget; + ShaderFeature::OutputTarget target = (fd.features[MFT_isDeferred]) ? RenderTarget1 : DefaultTarget; + meta->addStatement(new GenOp(" @;\r\n", assignColor(baseColor, Material::Mul, NULL, target))); - if (fd.features.hasFeature(MFT_isDeferred)) - { - target= ShaderFeature::RenderTarget1; - } - - meta->addStatement( new GenOp( " @;\r\n", assignColor( baseColor, Material::Mul,NULL,target ) ) ); - - if (fd.features[MFT_isDeferred]) + Var* ormConfig; + if ((fd.features[MFT_isDeferred])) { // Set base ORM info - Var* ormConfig; - OutputTarget targ = RenderTarget1; - targ = RenderTarget2; - ormConfig = (Var*)LangElement::find(getOutputTargetVarName(targ)); + ormConfig = (Var*)LangElement::find(getOutputTargetVarName(RenderTarget2)); + if (!ormConfig) { // create color var ormConfig = new Var; ormConfig->setType("fragout"); - ormConfig->setName(getOutputTargetVarName(targ)); + ormConfig->setName(getOutputTargetVarName(RenderTarget2)); ormConfig->setStructName("OUT"); } - - meta->addStatement(new GenOp(" @ = float4(0.0, 1.0, 1.0, 0.0);\r\n", ormConfig)); } + else + { + ormConfig = new Var("ORMConfig", "float4"); + meta->addStatement(new GenOp(" @;\r\n", new DecOp(ormConfig))); + } + + meta->addStatement(new GenOp(" @ = float4(0.0, 1.0, 1.0, 0.0);\r\n", ormConfig)); output = meta; } @@ -407,7 +405,7 @@ ShaderFeature::Resources TerrainBaseMapFeatHLSL::getResources( const MaterialFea U32 TerrainBaseMapFeatHLSL::getOutputTargets( const MaterialFeatureData &fd ) const { - return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget1 | ShaderFeature::RenderTarget2 : ShaderFeature::DefaultTarget; + return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget2 | ShaderFeature::RenderTarget1 : ShaderFeature::DefaultTarget; } TerrainDetailMapFeatHLSL::TerrainDetailMapFeatHLSL() @@ -1259,23 +1257,35 @@ void TerrainORMMapFeatHLSL::processPix(Vector &componentList, else texOp = new GenOp("@.Sample(@, float3(@.xy, @.x))", ormMapArray, ormMapSampler, inDet, new IndexOp(detailInfo, compositeIndex)); + MultiLine* meta = new MultiLine; // search for material var - Var * ormConfig; - OutputTarget targ = RenderTarget1; - if (fd.features[MFT_isDeferred]) + Var* ormConfig; + if ((fd.features[MFT_isDeferred])) { - targ = RenderTarget2; - } - ormConfig = (Var*)LangElement::find(getOutputTargetVarName(targ)); + // Set base ORM info + ormConfig = (Var*)LangElement::find(getOutputTargetVarName(RenderTarget2)); - MultiLine * meta = new MultiLine; - if (!ormConfig) + if (!ormConfig) + { + // create color var + ormConfig = new Var; + ormConfig->setType("fragout"); + ormConfig->setName(getOutputTargetVarName(RenderTarget2)); + ormConfig->setStructName("OUT"); + } + } + else { - // create color var - ormConfig = new Var; - ormConfig->setType("fragout"); - ormConfig->setName(getOutputTargetVarName(targ)); - ormConfig->setStructName("OUT"); + ormConfig = (Var*)LangElement::find("ORMConfig"); + if (!ormConfig) + { + ormConfig = new Var("ORMConfig", "float4"); + meta->addStatement(new GenOp(" @;\r\n", new DecOp(ormConfig))); + } + } + if (compositeIndex == 0) + { + meta->addStatement(new GenOp(" @ = float4(0.0, 0.0, 0.0, 0.0);\r\n", ormConfig)); } Var *detailBlend = (Var*)LangElement::find(String::ToString("detailBlend%d", compositeIndex)); @@ -1284,11 +1294,6 @@ void TerrainORMMapFeatHLSL::processPix(Vector &componentList, String matinfoName(String::ToString("matinfoCol%d", compositeIndex)); Var *matinfoCol = new Var(matinfoName, "float3"); - if (compositeIndex == 0) - { - meta->addStatement(new GenOp(" @ = float4(0.0, 0.0, 0.0, 0.0);\r\n", ormConfig)); - } - meta->addStatement(new GenOp(" @ = @.rgb;\r\n", new DecOp(matinfoCol), texOp)); if (fd.features.hasFeature(MFT_InvertRoughness, compositeIndex)) @@ -1313,39 +1318,39 @@ ShaderFeature::Resources TerrainORMMapFeatHLSL::getResources(const MaterialFeatu return res; } -// reminder, the matinfo buffer is flags, smooth, ao, metal -U32 TerrainBlankInfoMapFeatHLSL::getOutputTargets(const MaterialFeatureData &fd) const -{ - return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget2 : ShaderFeature::RenderTarget1; -} - void TerrainBlankInfoMapFeatHLSL::processPix(Vector &componentList, const MaterialFeatureData &fd) { S32 compositeIndex = getProcessIndex(); - // search for material var - Var *material; - OutputTarget ormConfig = RenderTarget1; - if (fd.features[MFT_isDeferred]) + MultiLine * meta = new MultiLine; Var* ormConfig; + if ((fd.features[MFT_isDeferred])) { - ormConfig = RenderTarget2; - } - material = (Var*)LangElement::find(getOutputTargetVarName(ormConfig)); + // Set base ORM info + ormConfig = (Var*)LangElement::find(getOutputTargetVarName(RenderTarget2)); - MultiLine * meta = new MultiLine; - if (!material) + if (!ormConfig) + { + // create color var + ormConfig = new Var; + ormConfig->setType("fragout"); + ormConfig->setName(getOutputTargetVarName(RenderTarget2)); + ormConfig->setStructName("OUT"); + } + } + else { - // create color var - material = new Var; - material->setType("fragout"); - material->setName(getOutputTargetVarName(ormConfig)); - material->setStructName("OUT"); + ormConfig = (Var*)LangElement::find("ORMConfig"); + if (!ormConfig) + { + ormConfig = new Var("ORMConfig", "float4"); + meta->addStatement(new GenOp(" @;\r\n", new DecOp(ormConfig))); + } } if (compositeIndex == 0) { - meta->addStatement(new GenOp(" @ = float4(0.0, 0.0, 0.0, 0.0);\r\n", material)); + meta->addStatement(new GenOp(" @ = float4(0.0, 0.0, 0.0, 0.0);\r\n", ormConfig)); } Var* detailBlend = (Var*)LangElement::find(String::ToString("detailBlend%d", compositeIndex)); @@ -1355,7 +1360,7 @@ void TerrainBlankInfoMapFeatHLSL::processPix(Vector &component if (!fd.features.hasFeature(MFT_TerrainHeightBlend)) { - meta->addStatement(new GenOp(" @.gba += float3(@, @, 0.0);\r\n", material, detailBlend, detailBlend)); + meta->addStatement(new GenOp(" @.gba += float3(@, @, 0.0);\r\n", ormConfig, detailBlend, detailBlend)); } output = meta; diff --git a/Engine/source/terrain/hlsl/terrFeatureHLSL.h b/Engine/source/terrain/hlsl/terrFeatureHLSL.h index 829af9c6f..f3803f2d9 100644 --- a/Engine/source/terrain/hlsl/terrFeatureHLSL.h +++ b/Engine/source/terrain/hlsl/terrFeatureHLSL.h @@ -179,8 +179,6 @@ public: virtual void processPix(Vector &componentList, const MaterialFeatureData &fd); - - virtual U32 getOutputTargets(const MaterialFeatureData &fd) const; virtual String getName() { return "Blank Matinfo map"; } }; From e784b0140c32f2de6c5ca7ac5d23d3961cb28d00 Mon Sep 17 00:00:00 2001 From: Jeff Hutchinson Date: Wed, 22 Sep 2021 21:41:38 -0400 Subject: [PATCH 06/20] Let's fix the texcoord alignment for RT Lighting. --- .../source/shaderGen/GLSL/shaderFeatureGLSL.cpp | 16 +++++++--------- .../source/shaderGen/HLSL/shaderFeatureHLSL.cpp | 12 +++++------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp index 0cf46277c..e9604eb77 100644 --- a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp +++ b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp @@ -2090,12 +2090,15 @@ void RTLightingFeatGLSL::processVert( Vector &componentList, return; } - + + addOutWsPosition( componentList, fd.features[MFT_UseInstancing], meta ); + getOutWorldToTangent(componentList, meta, fd); + + output = meta; + // Find the incoming vertex normal. Var *inNormal = (Var*)LangElement::find( "normal" ); - - // Skip out on realtime lighting if we don't have a normal - // or we're doing some sort of baked lighting. + if ( !inNormal || fd.features[MFT_LightMap] || fd.features[MFT_ToneMap] || @@ -2119,11 +2122,6 @@ void RTLightingFeatGLSL::processVert( Vector &componentList, meta->addStatement( new GenOp( " @ = tMul( @, vec4( normalize( @ ), 0.0 ) ).xyz;\r\n", outNormal, objTrans, inNormal ) ); }*/ - addOutWsPosition( componentList, fd.features[MFT_UseInstancing], meta ); - - getOutWorldToTangent(componentList, meta, fd); - - output = meta; } void RTLightingFeatGLSL::processPix( Vector &componentList, diff --git a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp index 1ebc3982a..dfdb5439c 100644 --- a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp +++ b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp @@ -2178,11 +2178,14 @@ void RTLightingFeatHLSL::processVert( Vector &componentList, return; } + addOutWsPosition( componentList, fd.features[MFT_UseInstancing], meta ); + getOutWorldToTangent(componentList, meta, fd); + output = meta; + + // Find the incoming vertex normal. Var *inNormal = (Var*)LangElement::find( "normal" ); - // Skip out on realtime lighting if we don't have a normal - // or we're doing some sort of baked lighting. if ( !inNormal || fd.features[MFT_LightMap] || fd.features[MFT_ToneMap] || @@ -2205,11 +2208,6 @@ void RTLightingFeatHLSL::processVert( Vector &componentList, // Transform the normal to world space. meta->addStatement( new GenOp( " @ = mul( @, float4( normalize( @ ), 0.0 ) ).xyz;\r\n", outNormal, objTrans, inNormal ) ); } - - addOutWsPosition( componentList, fd.features[MFT_UseInstancing], meta ); - getOutWorldToTangent(componentList, meta, fd); - - output = meta; } void RTLightingFeatHLSL::processPix( Vector &componentList, From a1117b1c41ad728311c82aa558598971dedf8788 Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Sun, 3 Oct 2021 21:51:40 -0500 Subject: [PATCH 07/20] add getInWorldNormal method glsl side --- .../shaderGen/GLSL/shaderFeatureGLSL.cpp | 35 +++++++++++++------ .../source/shaderGen/GLSL/shaderFeatureGLSL.h | 1 + 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp index e9604eb77..73bb56fd1 100644 --- a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp +++ b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp @@ -765,6 +765,21 @@ Var* ShaderFeatureGLSL::getWsView( Var *wsPosition, MultiLine *meta ) return wsView; } +Var* ShaderFeatureGLSL::getInWorldNormal(Vector& componentList) +{ + Var* wsNormal = (Var*)LangElement::find("wsNormal"); + if (!wsNormal) + { + ShaderConnector* connectComp = dynamic_cast(componentList[C_CONNECTOR]); + wsNormal = connectComp->getElement(RT_TEXCOORD); + wsNormal->setName("wsNormal"); + wsNormal->setStructName("IN"); + wsNormal->setType("float3"); + } + + return wsNormal; +} + Var* ShaderFeatureGLSL::addOutDetailTexCoord( Vector &componentList, MultiLine *meta, bool useTexAnim, @@ -851,21 +866,23 @@ Var* ShaderFeatureGLSL::getSurface(Vector& componentList, Mult meta->addStatement(new GenOp(" @ = vec4(0.0,1.0,@,@);\r\n", colorDecl, roughness, metalness)); //reconstruct ormConfig, no ao darkening } - Var* wsNormal = (Var*)LangElement::find("wsNormal"); Var* normal = (Var*)LangElement::find("normal"); if (!normal) { normal = new Var("normal", "vec3"); meta->addStatement(new GenOp(" @;\r\n\n", new DecOp(normal))); + + Var* wsNormal = (Var*)LangElement::find("wsNormal"); if (!fd.features[MFT_NormalMap]) { - Var* worldToTangent = getInWorldToTangent(componentList); - meta->addStatement(new GenOp(" @ = normalize(tMul(@,vec3(0,0,1.0f)));\r\n\n", normal, worldToTangent)); + if (!wsNormal) + wsNormal = getInWorldNormal(componentList); + meta->addStatement(new GenOp(" @ = normalize( @ );\r\n\n", normal, wsNormal)); } else { - meta->addStatement(new GenOp(" @ = normalize( half3( @ ) );\r\n", normal, wsNormal)); - } + meta->addStatement(new GenOp(" @ = normalize( @ );\r\n", normal, wsNormal)); + } } Var* wsEyePos = (Var*)LangElement::find("eyePosWorld"); @@ -2142,14 +2159,10 @@ void RTLightingFeatGLSL::processPix( Vector &componentList, // Now the wsPosition and wsView. Var *wsPosition = getInWsPosition( componentList ); + Var* worldToTangent = getInWorldToTangent(componentList); + Var* wsNormal = getInWorldNormal(componentList); Var *wsView = getWsView( wsPosition, meta ); - // Create temporaries to hold results of lighting. - Var *rtShading = new Var( "rtShading", "vec4" ); - Var *specular = new Var( "specular", "vec4" ); - meta->addStatement( new GenOp( " @; @;\r\n", - new DecOp( rtShading ), new DecOp( specular ) ) ); - // Look for a light mask generated from a previous // feature (this is done for BL terrain lightmaps). LangElement *lightMask = LangElement::find( "lightMask" ); diff --git a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.h b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.h index 24a2a8115..d4dbb1886 100644 --- a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.h +++ b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.h @@ -137,6 +137,7 @@ public: MultiLine *meta ); Var* getSurface(Vector& componentList, MultiLine* meta, const MaterialFeatureData& fd); + Var* getInWorldNormal(Vector& componentList); // ShaderFeature Var* getVertTexCoord( const String &name ); From 661a192e878a951ac10d0d2f715e352fd5e57ba4 Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Sun, 3 Oct 2021 21:53:16 -0500 Subject: [PATCH 08/20] orderfix for RTLightingFeatHLSL vert vs pixel shader. the order needs to match, same as network comunicating --- Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp index dfdb5439c..ecd4619d0 100644 --- a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp +++ b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp @@ -879,12 +879,10 @@ Var* ShaderFeatureHLSL::getSurface(Vector& componentList, Mult meta->addStatement(new GenOp(" @;\r\n\n", new DecOp(normal))); Var* wsNormal = (Var*)LangElement::find("wsNormal"); - if (!fd.features[MFT_NormalMap]) { if (!wsNormal) wsNormal = getInWorldNormal(componentList); - meta->addStatement(new GenOp(" @ = normalize( @ );\r\n\n", normal, wsNormal)); } else @@ -2227,10 +2225,9 @@ void RTLightingFeatHLSL::processPix( Vector &componentList, MultiLine *meta = new MultiLine; // Now the wsPosition and wsView. - Var* worldToTangent = getInWorldToTangent(componentList); - Var* wsNormal = getInWorldNormal(componentList); Var *wsPosition = getInWsPosition( componentList ); - + Var* worldToTangent = getInWorldToTangent(componentList); + Var* wsNormal = getInWorldNormal(componentList); Var *wsView = getWsView( wsPosition, meta ); // Look for a light mask generated from a previous From 79ad78361d75e8f233a7504b949836d803ffc4fd Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Mon, 4 Oct 2021 18:24:33 -0500 Subject: [PATCH 09/20] item->importStatus cleanup for asset importer --- Engine/source/T3D/assets/assetImporter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Engine/source/T3D/assets/assetImporter.cpp b/Engine/source/T3D/assets/assetImporter.cpp index 5df1ca8ab..254df381d 100644 --- a/Engine/source/T3D/assets/assetImporter.cpp +++ b/Engine/source/T3D/assets/assetImporter.cpp @@ -1409,7 +1409,7 @@ void AssetImporter::processImportAssets(AssetImportObject* assetItem) Con::executef(this, processCommand.c_str(), item); } - item->importStatus == AssetImportObject::Processed; + item->importStatus = AssetImportObject::Processed; //try recusing on the children(if any) processImportAssets(item); @@ -2018,7 +2018,7 @@ void AssetImporter::validateAsset(AssetImportObject* assetItem) AssetQuery aQuery; U32 numAssetsFound = AssetDatabase.findAllAssets(&aQuery); - bool hasCollision = false; + hasCollision = false; for (U32 i = 0; i < numAssetsFound; i++) { StringTableEntry assetId = aQuery.mAssetList[i]; From eb8434c5a447b30886d94d54c04e7e3dd4edfeab Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Tue, 5 Oct 2021 00:23:26 -0500 Subject: [PATCH 10/20] don't try and sort ribbon particles --- Engine/source/T3D/fx/particleEmitter.cpp | 37 +++--------------------- 1 file changed, 4 insertions(+), 33 deletions(-) diff --git a/Engine/source/T3D/fx/particleEmitter.cpp b/Engine/source/T3D/fx/particleEmitter.cpp index c60dc6d49..79d2e6f1d 100644 --- a/Engine/source/T3D/fx/particleEmitter.cpp +++ b/Engine/source/T3D/fx/particleEmitter.cpp @@ -1908,50 +1908,21 @@ void ParticleEmitter::copyToVB( const Point3F &camPos, const LinearColorF &ambie if (mDataBlock->reverseOrder) { - buffPtr += 4 * (n_parts - 1); - // do sorted-oriented particles - if (mDataBlock->sortParticles) - { - SortParticle* partPtr = orderedVector.address(); - for (U32 i = 0; i < n_parts - 1; i++, partPtr++, buffPtr -= 4) - { - SortParticle* part = partPtr; - partPtr++; - setupRibbon(part->p, partPtr->p, partPtr->p, camPos, ambientColor, buffPtr); - } - } - // do unsorted-oriented particles - else - { Particle* oldPtr = NULL; - for (Particle* partPtr = part_list_head.next; partPtr != NULL; partPtr = partPtr->next, buffPtr -= 4) { + for (Particle* partPtr = part_list_head.next; partPtr != NULL; partPtr = partPtr->next, buffPtr -= 4) + { setupRibbon(partPtr, partPtr->next, oldPtr, camPos, ambientColor, buffPtr); oldPtr = partPtr; } - } } else { - // do sorted-oriented particles - if (mDataBlock->sortParticles) - { - SortParticle* partPtr = orderedVector.address(); - for (U32 i = 0; i < n_parts - 1; i++, partPtr++, buffPtr += 4) - { - SortParticle* part = partPtr; - partPtr++; - setupRibbon(part->p, partPtr->p, partPtr->p, camPos, ambientColor, buffPtr); - } - } - // do unsorted-oriented particles - else - { Particle* oldPtr = NULL; - for (Particle* partPtr = part_list_head.next; partPtr != NULL; partPtr = partPtr->next, buffPtr += 4) { + for (Particle* partPtr = part_list_head.next; partPtr != NULL; partPtr = partPtr->next, buffPtr += 4) + { setupRibbon(partPtr, partPtr->next, oldPtr, camPos, ambientColor, buffPtr); oldPtr = partPtr; } - } } PROFILE_END(); } From 42e90ad3fb7cbb5b5fa9c78baa8875e4ea2e8d46 Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Tue, 5 Oct 2021 14:46:37 -0500 Subject: [PATCH 11/20] RTLightingFeat work. 1) we do *not* in fact want to early out in the presence of MFT_ImposterVert. it mangles the position-send. 2) dx sucessfuly handles the if ( !fd.features[MFT_NormalMap] ) case, so use the same for gl --- Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp | 6 ++---- Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp | 3 --- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp index 73bb56fd1..6df9a01bf 100644 --- a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp +++ b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp @@ -2070,7 +2070,6 @@ RTLightingFeatGLSL::RTLightingFeatGLSL() void RTLightingFeatGLSL::processVert( Vector &componentList, const MaterialFeatureData &fd ) { - if (fd.features[MFT_ImposterVert]) return; MultiLine *meta = new MultiLine; ShaderConnector *connectComp = dynamic_cast( componentList[C_CONNECTOR] ); @@ -2124,8 +2123,7 @@ void RTLightingFeatGLSL::processVert( Vector &componentList, // If there isn't a normal map then we need to pass // the world space normal to the pixel shader ourselves. - //Temporarily disabled while we figure out how to better handle normals without a normal map - /*if ( !fd.features[MFT_NormalMap] ) + if ( !fd.features[MFT_NormalMap] ) { Var *outNormal = connectComp->getElement( RT_TEXCOORD ); outNormal->setName( "wsNormal" ); @@ -2137,7 +2135,7 @@ void RTLightingFeatGLSL::processVert( Vector &componentList, // Transform the normal to world space. meta->addStatement( new GenOp( " @ = tMul( @, vec4( normalize( @ ), 0.0 ) ).xyz;\r\n", outNormal, objTrans, inNormal ) ); - }*/ + } } diff --git a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp index ecd4619d0..eae07aa95 100644 --- a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp +++ b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp @@ -2136,8 +2136,6 @@ RTLightingFeatHLSL::RTLightingFeatHLSL() void RTLightingFeatHLSL::processVert( Vector &componentList, const MaterialFeatureData &fd ) { - if (fd.features[MFT_ImposterVert]) return; - MultiLine *meta = new MultiLine; ShaderConnector *connectComp = dynamic_cast( componentList[C_CONNECTOR] ); @@ -2192,7 +2190,6 @@ void RTLightingFeatHLSL::processVert( Vector &componentList, // If there isn't a normal map then we need to pass // the world space normal to the pixel shader ourselves. - //Temporarily disabled while we figure out how to better handle normals without a normal map if ( !fd.features[MFT_NormalMap] ) { Var *outNormal = connectComp->getElement( RT_TEXCOORD ); From 24bf807713a3a361406ae3365a5483b8e0be68cd Mon Sep 17 00:00:00 2001 From: Jeff Hutchinson Date: Wed, 6 Oct 2021 21:53:26 -0400 Subject: [PATCH 12/20] various shadergen fixes. --- .../shaderGen/GLSL/shaderFeatureGLSL.cpp | 1 + .../shaderGen/HLSL/shaderFeatureHLSL.cpp | 8 ++++ .../source/terrain/glsl/terrFeatureGLSL.cpp | 41 +++++++++++-------- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp index 6df9a01bf..b41dfc234 100644 --- a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp +++ b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp @@ -1982,6 +1982,7 @@ void ReflectCubeFeatGLSL::processPix( Vector &componentList, Var *envColor = new Var("envColor", "vec3"); meta->addStatement(new GenOp(" @ = @.rgb - (@.rgb * @);\r\n", new DecOp(dColor), targ, targ, metalness)); meta->addStatement(new GenOp(" @ = @.rgb*(@).rgb;\r\n", new DecOp(envColor), targ, texCube)); + meta->addStatement(new GenOp(" @.rgb = @+@;\r\n", targ, dColor, envColor)); } else if (lerpVal) meta->addStatement(new GenOp(" @ *= vec4(@.rgb*@.a, @.a);\r\n", targ, texCube, lerpVal, targ)); diff --git a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp index eae07aa95..0b5f79e4d 100644 --- a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp +++ b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp @@ -892,6 +892,14 @@ Var* ShaderFeatureHLSL::getSurface(Vector& componentList, Mult } Var* wsEyePos = (Var*)LangElement::find("eyePosWorld"); + + if (!wsEyePos) + { + wsEyePos = new Var("eyePosWorld", "float3"); + wsEyePos->uniform = true; + wsEyePos->constSortPos = cspPass; + } + Var* wsPosition = getInWsPosition(componentList); Var* wsView = getWsView(wsPosition, meta); diff --git a/Engine/source/terrain/glsl/terrFeatureGLSL.cpp b/Engine/source/terrain/glsl/terrFeatureGLSL.cpp index d30e639ec..3b66006ce 100644 --- a/Engine/source/terrain/glsl/terrFeatureGLSL.cpp +++ b/Engine/source/terrain/glsl/terrFeatureGLSL.cpp @@ -281,6 +281,8 @@ void TerrainBaseMapFeatGLSL::processVert( Vector &componentLis Var *squareSize = _getUniformVar( "squareSize", "float", cspPass ); meta->addStatement( new GenOp( " @ = normalize( vec3( @, 0, @ ) );\r\n", new DecOp( inTanget ), squareSize, inTangentZ ) ); + + getOutViewToTangent(componentList, meta, fd); } void TerrainBaseMapFeatGLSL::processPix( Vector &componentList, @@ -331,6 +333,8 @@ void TerrainBaseMapFeatGLSL::processPix( Vector &componentLis meta->addStatement(new GenOp(" @ = float4(0.0, 1.0, 1.0, 0.0);\r\n", ormConfig)); output = meta; + + Var* viewToTangent = getInViewToTangent(componentList); } ShaderFeature::Resources TerrainBaseMapFeatGLSL::getResources( const MaterialFeatureData &fd ) @@ -781,6 +785,22 @@ void TerrainMacroMapFeatGLSL::processPix( Vector &componentL meta->addStatement( new GenOp( " @ = calcBlend( @.x, @.xy, @, @ );\r\n", new DecOp( detailBlend ), detailInfo, inTex, layerSize, layerSample ) ); + // 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( "macroColor" ); if ( !detailColor ) { @@ -1224,21 +1244,7 @@ void TerrainORMMapFeatGLSL::processPix(Vector &componentList, ShaderFeature::Resources TerrainORMMapFeatGLSL::getResources(const MaterialFeatureData &fd) { Resources res; - - S32 featureIndex = 0, firstOrmMapIndex = 0; - for (int idx = 0; idx < fd.features.getCount(); ++idx) { - const FeatureType& type = fd.features.getAt(idx, &featureIndex); - if (type == MFT_TerrainORMMap) { - firstOrmMapIndex = getMin(firstOrmMapIndex, featureIndex); - } - } - - // We only need to process normals during the deferred. - if (getProcessIndex() == firstOrmMapIndex) - { - res.numTexReg = 1; - res.numTex = 1; - } + res.numTex = 1; return res; } @@ -1283,7 +1289,10 @@ void TerrainBlankInfoMapFeatGLSL::processPix(Vector &component String matinfoName(String::ToString("matinfoCol%d", compositeIndex)); - meta->addStatement(new GenOp(" @.gba += vec3(@, @, 0.0);\r\n", ormConfig, detailBlend, detailBlend)); + if (!fd.features.hasFeature(MFT_TerrainHeightBlend)) + { + meta->addStatement(new GenOp(" @.gba += vec3(@, @, 0.0);\r\n", ormConfig, detailBlend, detailBlend)); + } output = meta; } From 15b946fb35c86f6e4207cf55e71e55075444153e Mon Sep 17 00:00:00 2001 From: Robert MacGregor Date: Thu, 7 Oct 2021 09:59:03 -0400 Subject: [PATCH 13/20] * Adjustment: Utilize native compiler intrinsics for endian swapping when available. --- Engine/source/core/util/endian.h | 13 ++++++++++++- Engine/source/platform/types.gcc.h | 7 +++++-- Engine/source/platform/types.visualc.h | 7 +++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Engine/source/core/util/endian.h b/Engine/source/core/util/endian.h index 566f8be54..eaff3c03c 100644 --- a/Engine/source/core/util/endian.h +++ b/Engine/source/core/util/endian.h @@ -48,8 +48,12 @@ Convert the byte ordering on the U16 to and from big/little endian format. inline U16 endianSwap(const U16 in_swap) { +#ifdef TORQUE_U16_ENDIANSWAP_BUILTIN + return TORQUE_U16_ENDIANSWAP_BUILTIN(in_swap); +#else return U16(((in_swap >> 8) & 0x00ff) | ((in_swap << 8) & 0xff00)); +#endif } inline S16 endianSwap(const S16 in_swap) @@ -64,10 +68,14 @@ Convert the byte ordering on the U32 to and from big/little endian format. */ inline U32 endianSwap(const U32 in_swap) { +#ifdef TORQUE_U32_ENDIANSWAP_BUILTIN + return TORQUE_U32_ENDIANSWAP_BUILTIN(in_swap); +#else return U32(((in_swap >> 24) & 0x000000ff) | ((in_swap >> 8) & 0x0000ff00) | ((in_swap << 8) & 0x00ff0000) | ((in_swap << 24) & 0xff000000)); +#endif } inline S32 endianSwap(const S32 in_swap) @@ -77,12 +85,16 @@ inline S32 endianSwap(const S32 in_swap) inline U64 endianSwap(const U64 in_swap) { +#ifdef TORQUE_U64_ENDIANSWAP_BUILTIN + return TORQUE_U64_ENDIANSWAP_BUILTIN(in_swap); +#else U32 *inp = (U32 *) &in_swap; U64 ret; U32 *outp = (U32 *) &ret; outp[0] = endianSwap(inp[1]); outp[1] = endianSwap(inp[0]); return ret; +#endif } inline S64 endianSwap(const S64 in_swap) @@ -138,4 +150,3 @@ TORQUE_DECLARE_TEMPLATIZED_ENDIAN_CONV(F32) TORQUE_DECLARE_TEMPLATIZED_ENDIAN_CONV(F64) #endif - diff --git a/Engine/source/platform/types.gcc.h b/Engine/source/platform/types.gcc.h index 8255a251d..f6f4cf6df 100644 --- a/Engine/source/platform/types.gcc.h +++ b/Engine/source/platform/types.gcc.h @@ -107,7 +107,7 @@ typedef unsigned long U64; // This could be reconfigured for static builds, though minimal impact //# define TORQUE_SUPPORTS_NASM # endif -#else +#else # error "GCC: Unsupported Operating System" #endif @@ -169,5 +169,8 @@ typedef unsigned long U64; #endif #endif -#endif // INCLUDED_TYPES_GCC_H +#define TORQUE_U16_ENDIANSWAP_BUILTIN __builtin_bswap16 +#define TORQUE_U32_ENDIANSWAP_BUILTIN __builtin_bswap32 +#define TORQUE_U64_ENDIANSWAP_BUILTIN __builtin_bswap64 +#endif // INCLUDED_TYPES_GCC_H diff --git a/Engine/source/platform/types.visualc.h b/Engine/source/platform/types.visualc.h index 4ccc6ce42..1b62da721 100644 --- a/Engine/source/platform/types.visualc.h +++ b/Engine/source/platform/types.visualc.h @@ -69,7 +69,7 @@ typedef unsigned _int64 U64; # define TORQUE_OS_WIN # define TORQUE_OS_WIN64 # include "platform/types.win.h" -#else +#else # error "VC: Unsupported Operating System" #endif @@ -115,5 +115,8 @@ typedef unsigned _int64 U64; #define TORQUE_UNLIKELY #endif -#endif // INCLUDED_TYPES_VISUALC_H +#define TORQUE_U16_ENDIANSWAP_BUILTIN _byteswap_ushort +#define TORQUE_U32_ENDIANSWAP_BUILTIN _byteswap_ulong +#define TORQUE_U64_ENDIANSWAP_BUILTIN _byteswap_uint64 +#endif // INCLUDED_TYPES_VISUALC_H From cf9d15a9d48bed4c3174dfaa7156778448d4ea8b Mon Sep 17 00:00:00 2001 From: Robert MacGregor Date: Fri, 8 Oct 2021 17:23:16 -0400 Subject: [PATCH 14/20] * BugFix: Correct a Windows compilation error in the endian swap code due to a missing include. --- Engine/source/platform/types.visualc.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Engine/source/platform/types.visualc.h b/Engine/source/platform/types.visualc.h index 1b62da721..2be0e51b3 100644 --- a/Engine/source/platform/types.visualc.h +++ b/Engine/source/platform/types.visualc.h @@ -23,6 +23,7 @@ #ifndef INCLUDED_TYPES_VISUALC_H #define INCLUDED_TYPES_VISUALC_H +#include // For more information on VisualC++ predefined macros // http://support.microsoft.com/default.aspx?scid=kb;EN-US;q65472 From 23e5e891ed0f4a57ae11e3c4e1ba90953ee4228c Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Fri, 8 Oct 2021 23:45:20 -0500 Subject: [PATCH 15/20] simplify callOnModules --- .../game/core/utility/scripts/module.tscript | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/Templates/BaseGame/game/core/utility/scripts/module.tscript b/Templates/BaseGame/game/core/utility/scripts/module.tscript index a895f99bf..1f6a755d1 100644 --- a/Templates/BaseGame/game/core/utility/scripts/module.tscript +++ b/Templates/BaseGame/game/core/utility/scripts/module.tscript @@ -4,8 +4,7 @@ if (!isObject(ExecFilesList)) new ArrayObject(ExecFilesList); function callOnModules(%functionName, %moduleGroup, %var0, %var1, %var2, %var3, %var4, %var5, %var6) -{ - %maxvars = 7; // match this to i/o signature +{ //clear per module group file execution chain ExecFilesList.empty(); //Get our modules so we can exec any specific client-side loading/handling @@ -19,22 +18,9 @@ function callOnModules(%functionName, %moduleGroup, %var0, %var1, %var2, %var3, if(%module.group !$= %moduleGroup) continue; } - + // match this to i/o signature if(isObject(%module.scopeSet) && %module.scopeSet.isMethod(%functionName)) - { - %stryng = %module.scopeSet @ "." @ %functionName @ "("; - for (%a=0;%a<%maxvars;%a++) - { - if (%var[%a] !$= "") - { - %stryng = %stryng @ %var[%a]; - if (%a<%maxvars-1 && %var[%a+1] !$= "") - %stryng = %stryng @ ","; - } - } - %stryng = %stryng @ ");"; - eval(%stryng); - } + %module.scopeSet.call(%functionName, %var0, %var1, %var2, %var3, %var4, %var5, %var6); } %execFilecount = ExecFilesList.count(); From 506621352ceebea54eb3c706bfba252027ebd87a Mon Sep 17 00:00:00 2001 From: Areloch Date: Sat, 9 Oct 2021 00:07:01 -0500 Subject: [PATCH 16/20] Tweaks the MaterialAsset loading logic to continue to see if the matDefinition already points to an existing object(to avoid needlessly re-executing files over and over), but also validate other cases, and ensures that if we DO have an existing definition, we still process and load it in the asset itself properly. --- Engine/source/T3D/assets/MaterialAsset.cpp | 19 +++++++++++++++++-- Engine/source/T3D/assets/MaterialAsset.h | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Engine/source/T3D/assets/MaterialAsset.cpp b/Engine/source/T3D/assets/MaterialAsset.cpp index 57008b025..50e75ffa3 100644 --- a/Engine/source/T3D/assets/MaterialAsset.cpp +++ b/Engine/source/T3D/assets/MaterialAsset.cpp @@ -167,6 +167,12 @@ void MaterialAsset::initializeAsset() mScriptPath = getOwned() ? expandAssetFilePath(mScriptFile) : mScriptPath; + if (mMatDefinitionName == StringTable->EmptyString()) + { + mLoadedState = Failed; + return; + } + if (Torque::FS::IsScriptFile(mScriptPath)) { if (!Sim::findObject(mMatDefinitionName)) @@ -180,6 +186,10 @@ void MaterialAsset::initializeAsset() mLoadedState = Failed; } } + else + { + mLoadedState = DefinitionAlreadyExists; + } } loadMaterial(); @@ -189,6 +199,12 @@ void MaterialAsset::onAssetRefresh() { mScriptPath = getOwned() ? expandAssetFilePath(mScriptFile) : mScriptPath; + if (mMatDefinitionName == StringTable->EmptyString()) + { + mLoadedState = Failed; + return; + } + if (Torque::FS::IsScriptFile(mScriptPath)) { //Since we're refreshing, we can assume that the file we're executing WILL have an existing definition. @@ -204,7 +220,6 @@ void MaterialAsset::onAssetRefresh() //And now that we've executed, switch back to the prior behavior Con::setVariable("$Con::redefineBehavior", redefineBehaviorPrev.c_str()); - } loadMaterial(); @@ -232,7 +247,7 @@ void MaterialAsset::loadMaterial() if (mMaterialDefinition) SAFE_DELETE(mMaterialDefinition); - if (mLoadedState == ScriptLoaded && mMatDefinitionName != StringTable->EmptyString()) + if ((mLoadedState == ScriptLoaded || mLoadedState == DefinitionAlreadyExists) && mMatDefinitionName != StringTable->EmptyString()) { Material* matDef; if (!Sim::findObject(mMatDefinitionName, matDef)) diff --git a/Engine/source/T3D/assets/MaterialAsset.h b/Engine/source/T3D/assets/MaterialAsset.h index 07ec0227a..75b1f6b96 100644 --- a/Engine/source/T3D/assets/MaterialAsset.h +++ b/Engine/source/T3D/assets/MaterialAsset.h @@ -73,6 +73,7 @@ public: enum MaterialAssetErrCode { ScriptLoaded = AssetErrCode::Extended, + DefinitionAlreadyExists, Extended }; From 112dafd8a82bb4485a0dd0a6668e30da9676467f Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Sat, 9 Oct 2021 11:31:26 -0500 Subject: [PATCH 17/20] remove basiconly from decals and decal roads. seems we fixed the bit that was causing that to not render --- .../game/core/rendering/scripts/renderManager.tscript | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Templates/BaseGame/game/core/rendering/scripts/renderManager.tscript b/Templates/BaseGame/game/core/rendering/scripts/renderManager.tscript index 1eefa6cf5..8c024c222 100644 --- a/Templates/BaseGame/game/core/rendering/scripts/renderManager.tscript +++ b/Templates/BaseGame/game/core/rendering/scripts/renderManager.tscript @@ -59,8 +59,8 @@ function initRenderManager() DiffuseRenderPassManager.addManager( new RenderObjectMgr(ObjectBin) { bintype = "Object"; renderOrder = 0.6; processAddOrder = 0.6; } ); DiffuseRenderPassManager.addManager( new RenderObjectMgr(ShadowBin) { bintype = "Shadow"; renderOrder = 0.7; processAddOrder = 0.7; } ); - DiffuseRenderPassManager.addManager( new RenderMeshMgr(DecalRoadBin) { bintype = "DecalRoad"; renderOrder = 0.8; processAddOrder = 0.8; basicOnly = true;} ); - DiffuseRenderPassManager.addManager( new RenderMeshMgr(DecalBin) { bintype = "Decal"; renderOrder = 0.81; processAddOrder = 0.81; basicOnly = true;} ); + DiffuseRenderPassManager.addManager( new RenderMeshMgr(DecalRoadBin) { bintype = "DecalRoad"; renderOrder = 0.8; processAddOrder = 0.8; } ); + DiffuseRenderPassManager.addManager( new RenderMeshMgr(DecalBin) { bintype = "Decal"; renderOrder = 0.81; processAddOrder = 0.81;} ); DiffuseRenderPassManager.addManager( new RenderOcclusionMgr(OccluderBin){ bintype = "Occluder"; renderOrder = 0.9; processAddOrder = 0.9; } ); // Render the sky last From 0429b5afa56b8d1bf76d86ed4a41eb566f6d97c2 Mon Sep 17 00:00:00 2001 From: Jeff Hutchinson Date: Sat, 9 Oct 2021 18:47:12 -0400 Subject: [PATCH 18/20] Added more tests for torquescript --- Engine/source/console/test/ScriptTest.cpp | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Engine/source/console/test/ScriptTest.cpp b/Engine/source/console/test/ScriptTest.cpp index 05775694f..05f0582ff 100644 --- a/Engine/source/console/test/ScriptTest.cpp +++ b/Engine/source/console/test/ScriptTest.cpp @@ -889,6 +889,40 @@ TEST(Script, InnerObjectTests) ASSERT_EQ(nestedFuncCall.getInt(), 123); } +TEST(Script, MiscTesting) +{ + ConsoleValue test1 = RunScript(R"( + function testNotPassedInParameters(%a, %b, %c, %d) + { + if (%d $= "") + return true; + return false; + } + + return testNotPassedInParameters(1, 2); // skip passing in %c and %d + )"); + + ASSERT_EQ(test1.getBool(), true); + + ConsoleValue test2 = RunScript(R"( + function SimObject::concatNameTest(%this) + { + return true; + } + + new SimObject(WeirdTestObject1); + + function testObjectNameConcatination(%i) + { + return (WeirdTestObject @ %i).concatNameTest(); + } + + return testObjectNameConcatination(1); + )"); + + ASSERT_EQ(test2.getBool(), true); +} + TEST(Script, MiscRegressions) { ConsoleValue regression1 = RunScript(R"( From f7cf1c020c771b191415f26aff6dec1d7d75345d Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Sat, 9 Oct 2021 18:20:57 -0500 Subject: [PATCH 19/20] inject getworldtotangent and getworldnormal to ensure var order --- Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp index b41dfc234..bb09113a4 100644 --- a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp +++ b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp @@ -2974,6 +2974,8 @@ void ReflectionProbeFeatGLSL::processPix(Vector& componentList // Now the wsPosition and wsView. Var *wsPosition = getInWsPosition(componentList); + Var *worldToTangent = getInWorldToTangent(componentList); + Var *wsNormal = getInWorldNormal(componentList); Var *wsView = getWsView(wsPosition, meta); //Reflection Probe WIP From d53dcb03c2715d11aaab0fdb73d6bebb7e95f650 Mon Sep 17 00:00:00 2001 From: Robert MacGregor Date: Sat, 9 Oct 2021 22:13:06 -0400 Subject: [PATCH 20/20] * [AssetBrowser] BugFix: Correct an error where on Linux the select asset path function would not list any directories. --- .../game/tools/assetBrowser/scripts/directoryHandling.tscript | 4 ++-- .../game/tools/assetBrowser/scripts/selectPath.tscript | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/directoryHandling.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/directoryHandling.tscript index 3eb822f21..4f13dfb8b 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/directoryHandling.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/directoryHandling.tscript @@ -216,7 +216,7 @@ function directoryHandler::getFolderTreeItemFromAddress(%this, %address) //break down the address %folderCount = getTokenCount(%address, "/"); - if(startsWith(%address, "Data/") || startsWith(%address, "Tools/") || startsWith(%address, "Core/")) + if(startsWith(%address, "data/") || startsWith(%address, "tools/") || startsWith(%address, "core/")) { %curItem = %this.treeCtrl.findChildItemByName(1, "Modules"); } @@ -242,7 +242,7 @@ function directoryHandler::expandTreeToAddress(%this, %address) %rootId = AssetBrowser-->filterTree.findItemByName("Content"); %this.treeCtrl.expandItem(%rootId); - if(startsWith(%address, "Data/") || startsWith(%address, "Tools/") || startsWith(%address, "Core/")) + if(startsWith(%address, "data/") || startsWith(%address, "tools/") || startsWith(%address, "core/")) { %curItem = %this.treeCtrl.findChildItemByName(1, "Modules"); } diff --git a/Templates/BaseGame/game/tools/assetBrowser/scripts/selectPath.tscript b/Templates/BaseGame/game/tools/assetBrowser/scripts/selectPath.tscript index 691a546e0..7db32c752 100644 --- a/Templates/BaseGame/game/tools/assetBrowser/scripts/selectPath.tscript +++ b/Templates/BaseGame/game/tools/assetBrowser/scripts/selectPath.tscript @@ -22,7 +22,7 @@ function SelectAssetPath::showDialog(%this, %startingPath, %callback, %promptTex %this.callback = %callback; %dataItem = SelectAssetPath-->folderTree.insertItem(0, "Data"); - %this.dirHandler.loadFolders("Data", %dataItem); + %this.dirHandler.loadFolders("data", %dataItem); %this.dirHandler.expandTreeToAddress(%startingPath); %id = %this.dirHandler.getFolderTreeItemFromAddress(%startingPath); @@ -60,4 +60,4 @@ function SelectAssetPath::newFolder(%this) { AssetBrowser_newFolderNameTxt.text = "NewFolder"; Canvas.pushDialog(AssetBrowser_newFolder); -} \ No newline at end of file +}