From 5be18a4638121951bde2825a02b162ff5cf89cdb Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Mon, 6 Jun 2022 17:50:34 -0500 Subject: [PATCH 1/4] allow ambient light injection into ibl --- .../shaders/lighting/advanced/gl/reflectionProbeArrayP.glsl | 3 ++- .../shaders/lighting/advanced/reflectionProbeArrayP.hlsl | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/reflectionProbeArrayP.glsl b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/reflectionProbeArrayP.glsl index 813597c95..6ab0a8f18 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/reflectionProbeArrayP.glsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/reflectionProbeArrayP.glsl @@ -12,6 +12,7 @@ uniform sampler2D colorBuffer; uniform sampler2D matInfoBuffer; uniform sampler2D BRDFTexture; +uniform vec4 ambientColor; uniform vec4 rtParams0; uniform vec4 vsFarPlane; uniform mat4 cameraToWorld; @@ -202,6 +203,6 @@ void main() #if CAPTURING == 1 OUT_col = vec4(mix(surface.baseColor.rgb,(irradiance + specular* horizon) ,surface.metalness/2),0); #else - OUT_col = vec4((irradiance + specular* horizon) , 0);//alpha writes disabled + OUT_col = vec4((irradiance + specular* horizon)*ambientColor.rgb , 0);//alpha writes disabled #endif } diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/reflectionProbeArrayP.hlsl b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/reflectionProbeArrayP.hlsl index d9314329e..b649843f3 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/reflectionProbeArrayP.hlsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/reflectionProbeArrayP.hlsl @@ -8,7 +8,7 @@ TORQUE_UNIFORM_SAMPLER2D(deferredBuffer, 0); TORQUE_UNIFORM_SAMPLER2D(colorBuffer, 1); TORQUE_UNIFORM_SAMPLER2D(matInfoBuffer, 2); TORQUE_UNIFORM_SAMPLER2D(BRDFTexture, 3); - +uniform float4 ambientColor; uniform float4 rtParams0; uniform float4 vsFarPlane; uniform float4x4 cameraToWorld; @@ -190,6 +190,6 @@ float4 main(PFXVertToPix IN) : SV_TARGET #if CAPTURING == 1 return float4(lerp(surface.baseColor.rgb,(irradiance + specular* horizon) ,surface.metalness/2),0); #else - return float4((irradiance + specular* horizon) , 0);//alpha writes disabled + return float4((irradiance + specular* horizon)*ambientColor.rgb, 0);//alpha writes disabled #endif } From 0e0088cab99bfa9b83a2b9ee30e1a8ea2bd99f19 Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Tue, 7 Jun 2022 11:18:53 -0500 Subject: [PATCH 2/4] forward lit ambient application. fix GL side IBL overwriting forward lit color.a --- .../shaderGen/GLSL/shaderFeatureGLSL.cpp | 25 ++++++++++++++++--- .../shaderGen/HLSL/shaderFeatureHLSL.cpp | 10 +++++++- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp index 831808c76..736517e46 100644 --- a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp +++ b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp @@ -3033,6 +3033,15 @@ void ReflectionProbeFeatGLSL::processPix(Vector& componentList return; } + Var *curColor = (Var *)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget)); + + //Reflection vec + Var *ibl = (Var *)LangElement::find("ibl"); + if (!ibl) + { + ibl = new Var("ibl", "float3"); + } + Var* eyePos = (Var*)LangElement::find("eyePosWorld"); if (!eyePos) { @@ -3042,18 +3051,26 @@ void ReflectionProbeFeatGLSL::processPix(Vector& componentList eyePos->uniform = true; eyePos->constSortPos = cspPass; } - - Var *curColor = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget)); - + //Reflection vec String computeForwardProbes = String(" @.rgb = computeForwardProbes(@,@,@,@,@,@,@,@,@,\r\n\t\t"); computeForwardProbes += String("@,@,\r\n\t\t"); computeForwardProbes += String("@,@).rgb; \r\n"); - meta->addStatement(new GenOp(computeForwardProbes.c_str(), curColor, surface, cubeMips, numProbes, worldToObjArray, probeConfigData, inProbePosArray, refScaleArray, inRefPosArray, eyePos, + meta->addStatement(new GenOp(computeForwardProbes.c_str(), new DecOp(ibl), surface, cubeMips, numProbes, worldToObjArray, probeConfigData, inProbePosArray, refScaleArray, inRefPosArray, eyePos, skylightCubemapIdx, BRDFTexture, irradianceCubemapAR, specularCubemapAR)); + Var *ambient = (Var *)LangElement::find("ambient"); + if (!ambient) + { + ambient = new Var("ambient", "vec4"); + eyePos->uniform = true; + eyePos->constSortPos = cspPass; + } + meta->addStatement(new GenOp(" @.rgb *= @.rgb;\r\n", ibl, ambient)); + meta->addStatement(new GenOp(" @.rgb = @.rgb;\r\n", curColor, ibl)); + output = meta; } diff --git a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp index 360f8f918..d2888b889 100644 --- a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp +++ b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp @@ -3149,7 +3149,15 @@ void ReflectionProbeFeatHLSL::processPix(Vector &componentList meta->addStatement(new GenOp(computeForwardProbes.c_str(), new DecOp(ibl), surface, cubeMips, numProbes, worldToObjArray, probeConfigData, inProbePosArray, refScaleArray, inRefPosArray, eyePos, skylightCubemapIdx, BRDFTexture, irradianceCubemapAR, specularCubemapAR)); - + + Var *ambient = (Var *)LangElement::find("ambient"); + if (!ambient) + { + ambient = new Var("ambient","float4"); + eyePos->uniform = true; + eyePos->constSortPos = cspPass; + } + meta->addStatement(new GenOp(" @.rgb *= @.rgb;\r\n", ibl, ambient)); meta->addStatement(new GenOp(" @.rgb = @.rgb;\r\n", curColor, ibl)); output = meta; From de6ee93159470476776a7cffea6f3d1025be56ce Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Tue, 7 Jun 2022 22:05:47 -0500 Subject: [PATCH 3/4] slim ambient down to vec3, default to premul for translucency --- Engine/source/materials/materialDefinition.cpp | 2 +- Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp | 2 +- Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp | 2 +- .../shaders/lighting/advanced/gl/reflectionProbeArrayP.glsl | 4 ++-- .../shaders/lighting/advanced/reflectionProbeArrayP.hlsl | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Engine/source/materials/materialDefinition.cpp b/Engine/source/materials/materialDefinition.cpp index 4204dfe63..351158adf 100644 --- a/Engine/source/materials/materialDefinition.cpp +++ b/Engine/source/materials/materialDefinition.cpp @@ -536,7 +536,7 @@ bool Material::onAdd() if (mTranslucentBlendOp >= NumBlendTypes || mTranslucentBlendOp < 0) { Con::errorf("Invalid blend op in material: %s", getName()); - mTranslucentBlendOp = LerpAlpha; + mTranslucentBlendOp = PreMul; } SimSet* matSet = MATMGR->getMaterialSet(); diff --git a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp index 736517e46..5d40ba8bf 100644 --- a/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp +++ b/Engine/source/shaderGen/GLSL/shaderFeatureGLSL.cpp @@ -3064,7 +3064,7 @@ void ReflectionProbeFeatGLSL::processPix(Vector& componentList Var *ambient = (Var *)LangElement::find("ambient"); if (!ambient) { - ambient = new Var("ambient", "vec4"); + ambient = new Var("ambient", "vec3"); eyePos->uniform = true; eyePos->constSortPos = cspPass; } diff --git a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp index d2888b889..28f0d7ee2 100644 --- a/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp +++ b/Engine/source/shaderGen/HLSL/shaderFeatureHLSL.cpp @@ -3153,7 +3153,7 @@ void ReflectionProbeFeatHLSL::processPix(Vector &componentList Var *ambient = (Var *)LangElement::find("ambient"); if (!ambient) { - ambient = new Var("ambient","float4"); + ambient = new Var("ambient","float3"); eyePos->uniform = true; eyePos->constSortPos = cspPass; } diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/reflectionProbeArrayP.glsl b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/reflectionProbeArrayP.glsl index 6ab0a8f18..3b04224ac 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/reflectionProbeArrayP.glsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/gl/reflectionProbeArrayP.glsl @@ -12,7 +12,7 @@ uniform sampler2D colorBuffer; uniform sampler2D matInfoBuffer; uniform sampler2D BRDFTexture; -uniform vec4 ambientColor; +uniform vec3 ambientColor; uniform vec4 rtParams0; uniform vec4 vsFarPlane; uniform mat4 cameraToWorld; @@ -203,6 +203,6 @@ void main() #if CAPTURING == 1 OUT_col = vec4(mix(surface.baseColor.rgb,(irradiance + specular* horizon) ,surface.metalness/2),0); #else - OUT_col = vec4((irradiance + specular* horizon)*ambientColor.rgb , 0);//alpha writes disabled + OUT_col = vec4((irradiance + specular* horizon)*ambientColor, 0);//alpha writes disabled #endif } diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/reflectionProbeArrayP.hlsl b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/reflectionProbeArrayP.hlsl index b649843f3..484e38022 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/reflectionProbeArrayP.hlsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting/advanced/reflectionProbeArrayP.hlsl @@ -8,7 +8,7 @@ TORQUE_UNIFORM_SAMPLER2D(deferredBuffer, 0); TORQUE_UNIFORM_SAMPLER2D(colorBuffer, 1); TORQUE_UNIFORM_SAMPLER2D(matInfoBuffer, 2); TORQUE_UNIFORM_SAMPLER2D(BRDFTexture, 3); -uniform float4 ambientColor; +uniform float3 ambientColor; uniform float4 rtParams0; uniform float4 vsFarPlane; uniform float4x4 cameraToWorld; @@ -190,6 +190,6 @@ float4 main(PFXVertToPix IN) : SV_TARGET #if CAPTURING == 1 return float4(lerp(surface.baseColor.rgb,(irradiance + specular* horizon) ,surface.metalness/2),0); #else - return float4((irradiance + specular* horizon)*ambientColor.rgb, 0);//alpha writes disabled + return float4((irradiance + specular* horizon)*ambientColor, 0);//alpha writes disabled #endif } From 66820fee900c340c06a0df56c58c411891d80f1d Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Tue, 7 Jun 2022 22:06:48 -0500 Subject: [PATCH 4/4] let me underscore this is painfully incorrect and we'll want to revisit it when we have more time, but... this seems to fix mangled decal and decalroad rendering --- Engine/source/T3D/decal/decalManager.cpp | 1 + Engine/source/environment/decalRoad.cpp | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Engine/source/T3D/decal/decalManager.cpp b/Engine/source/T3D/decal/decalManager.cpp index 6d8c3b90b..2c683275a 100644 --- a/Engine/source/T3D/decal/decalManager.cpp +++ b/Engine/source/T3D/decal/decalManager.cpp @@ -1425,6 +1425,7 @@ void DecalManager::prepRenderImage( SceneRenderState* state ) ri->prim->numPrimitives = currentBatch->iCount / 3; ri->prim->startVertex = 0; ri->prim->numVertices = currentBatch->vCount; + ri->translucentSort = !currentBatch->matInst->getMaterial()->isTranslucent(); // Ugly hack for ProjectedShadow! if ( customTex ) diff --git a/Engine/source/environment/decalRoad.cpp b/Engine/source/environment/decalRoad.cpp index fb226507a..28be1efc8 100644 --- a/Engine/source/environment/decalRoad.cpp +++ b/Engine/source/environment/decalRoad.cpp @@ -734,7 +734,7 @@ void DecalRoad::prepRenderImage( SceneRenderState* state ) coreRI.sortDistSq = F32_MAX; // If we need lights then set them up. - if ( matInst->isForwardLit() ) + if ( matInst->isForwardLit() && !coreRI.lights[0]) { LightQuery query; query.init( getWorldSphere() ); @@ -784,6 +784,7 @@ void DecalRoad::prepRenderImage( SceneRenderState* state ) *ri = coreRI; + ri->matInst = matInst; ri->prim = renderPass->allocPrim(); ri->prim->type = GFXTriangleList; ri->prim->minIndex = 0; @@ -791,6 +792,7 @@ void DecalRoad::prepRenderImage( SceneRenderState* state ) ri->prim->numPrimitives = triangleCount; ri->prim->startVertex = 0; ri->prim->numVertices = endBatch.endVert + 1; + ri->translucentSort = !matInst->getMaterial()->isTranslucent(); // For sorting we first sort by render priority // and then by objectId.