From 2199fb688171ad7d48ffdaf72d7e7adf557ba0c1 Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Sun, 14 Dec 2025 02:29:31 -0600 Subject: [PATCH] use a nonlinear reflectionopacity curve, and the greater of metalness or reflectionopacity for ibl overtaking albedo --- .../game/core/rendering/shaders/gl/lighting.glsl | 9 +++++---- .../game/core/rendering/shaders/lighting.hlsl | 13 +++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Templates/BaseGame/game/core/rendering/shaders/gl/lighting.glsl b/Templates/BaseGame/game/core/rendering/shaders/gl/lighting.glsl index 3daeb12c7..35940b5a1 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/gl/lighting.glsl +++ b/Templates/BaseGame/game/core/rendering/shaders/gl/lighting.glsl @@ -592,9 +592,11 @@ vec4 computeForwardProbes(Surface surface, specular = mix(specular,textureLod(specularCubemapAR, vec4(surface.R, skylightCubemapIdx), lod).xyz, alpha); } + float reflectionOpacity = clamp(surface.baseColor.a, pow(max(length(specular),length(irradiance)),2.2),1.0); + float reflectionInfluence = max(surface.metalness, reflectionOpacity); vec2 envBRDF = textureLod(BRDFTexture, vec2(surface.NdotV, surface.roughness),0).rg; - vec3 diffuse = irradiance * lerp(surface.baseColor.rgb, vec3(0.04f,0.04f,0.04f), surface.metalness); - vec3 specularCol = ((specular * surface.baseColor.rgb) * envBRDF.x + envBRDF.y)*surface.metalness; + vec3 diffuse = irradiance * lerp(surface.baseColor.rgb, vec3(0.04f,0.04f,0.04f), reflectionInfluence); + vec3 specularCol = ((specular * surface.baseColor.rgb) * envBRDF.x + envBRDF.y)*reflectionInfluence; float horizonOcclusion = 1.3; float horizon = saturate( 1 + horizonOcclusion * dot(surface.R, surface.N)); @@ -608,8 +610,7 @@ vec4 computeForwardProbes(Surface surface, return vec4(lerp((finalColor), surface.baseColor.rgb,surface.metalness),surface.baseColor.a); else { - float reflectionOpacity = min(max(surface.baseColor.a,length(specular+irradiance)),1.0); - return vec4(finalColor, reflectionOpacity); + return vec4(finalColor, reflectionInfluence); } } diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl b/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl index fc0abf7a1..25c9f446c 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl @@ -597,24 +597,25 @@ float4 computeForwardProbes(Surface surface, specular = lerp(specular,TORQUE_TEXCUBEARRAYLOD(specularCubemapAR, surface.R, skylightCubemapIdx, lod).xyz,alpha); } + float reflectionOpacity = clamp(surface.baseColor.a, pow(max(length(specular),length(irradiance)),2.2),1.0); + float reflectionInfluence = max(surface.metalness, reflectionOpacity); float2 envBRDF = TORQUE_TEX2DLOD(BRDFTexture, float4(surface.NdotV, surface.roughness,0,0)).rg; - float3 diffuse = irradiance * lerp(surface.baseColor.rgb, 0.04f, surface.metalness); - float3 specularCol = ((specular * surface.baseColor.rgb) * envBRDF.x + envBRDF.y)*surface.metalness; + float3 diffuse = irradiance * lerp(surface.baseColor.rgb, 0.04f, reflectionInfluence); + float3 specularCol = ((specular * surface.baseColor.rgb) * envBRDF.x + envBRDF.y)*reflectionInfluence; float horizonOcclusion = 1.3; float horizon = saturate( 1 + horizonOcclusion * dot(surface.R, surface.N)); horizon *= horizon; // Final color output after environment lighting - float3 finalColor = diffuse + specularCol; + float3 finalColor = diffuse + specularCol* horizon; finalColor *= surface.ao; if(isCapturing == 1) - return float4(lerp((finalColor), surface.baseColor.rgb,surface.metalness),surface.baseColor.a); + return float4(lerp((finalColor), surface.baseColor.rgb, surface.metalness),surface.baseColor.a); else { - float reflectionOpacity = min(max(surface.baseColor.a,length(specular+irradiance)),1.0); - return float4(finalColor, reflectionOpacity); + return float4(finalColor, reflectionInfluence); } }