From 5690c64ef62f438408f32122a3768593e6e416cf Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Mon, 6 Apr 2026 16:55:55 -0500 Subject: [PATCH 1/2] dampness rework more respect for gravity, fewer texture lookups --- .../core/rendering/shaders/gl/lighting.glsl | 25 ++++++++--------- .../game/core/rendering/shaders/lighting.hlsl | 27 +++++++++---------- 2 files changed, 23 insertions(+), 29 deletions(-) diff --git a/Templates/BaseGame/game/core/rendering/shaders/gl/lighting.glsl b/Templates/BaseGame/game/core/rendering/shaders/gl/lighting.glsl index addc16541..7ee6b4dff 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/gl/lighting.glsl +++ b/Templates/BaseGame/game/core/rendering/shaders/gl/lighting.glsl @@ -434,25 +434,22 @@ void dampen(inout Surface surface, sampler2D WetnessTexture, float accumTime, fl { if (degree<=0.0) return; vec3 n = abs(surface.N); - float ang = clamp(n.z, 0.04, 0.96); + float ang = 1.1-(abs(surface.N.z)*sign(surface.N.z)); - float speed = -accumTime*(1.0-surface.linearRoughnessSq)*clamp((2.0-ang), 0.04, 0.96); - if ((n.x > 0.0) || (n.y > 0.0)) - speed *= -1.0; - vec2 wetoffset = vec2(speed,speed)*0.1; + float speed = accumTime * (1.0 - surface.linearRoughnessSq); + vec3 wetoffset = (surface.P+vec3(speed,speed,speed)) * 0.33; - vec3 wetNormal = texture(WetnessTexture, float2(surface.P.xy*0.1+wetoffset)).xyz; - wetNormal = lerp(wetNormal,texture(WetnessTexture,float2(surface.P.zx*0.1+wetoffset)).rgb ,n.y); - wetNormal = lerp(wetNormal,texture(WetnessTexture,float2(surface.P.zy*0.1+wetoffset)).rgb ,n.x); - surface.N = lerp(surface.N, wetNormal, degree); + vec3 wetNormal = texture(WetnessTexture, wetoffset.xy).xyz * (1.1-(n.z* n.z)); + wetNormal = lerp(wetNormal, texture(WetnessTexture, wetoffset.zx).rgb, n.y); + wetNormal = lerp(wetNormal, texture(WetnessTexture, wetoffset.zy).rgb, n.x); + wetNormal = normalize(wetNormal); + float wetness = wetNormal.b* degree; - float wetness = texture(WetnessTexture, vec2(surface.P.xy*0.1+wetoffset)).b; - wetness = lerp(wetness,texture(WetnessTexture,vec2(surface.P.zx*0.1+wetoffset)).b,n.y); - wetness = lerp(wetness,texture(WetnessTexture,vec2(surface.P.zy*0.1+wetoffset)).b,n.x); - wetness = pow(wetness*ang*degree,3); + wetNormal = normalize(wetNormal * 2.0 - 1.0); + surface.N = normalize(vec3(surface.N.xy + wetNormal.xy * wetness, surface.N.z)); surface.roughness = lerp(surface.roughness, 0.04f, wetness); - surface.baseColor.rgb = lerp(surface.baseColor.rgb, surface.baseColor.rgb*0.6+float3(0.4,0.4,0.4)*wetness, wetness); + surface.baseColor.rgb = lerp(surface.baseColor.rgb, surface.baseColor.rgb*0.6+vec3(0.4,0.4,0.4)*wetness, wetness); surface.metalness = lerp(surface.metalness, 0.96, wetness); updateSurface(surface); } diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl b/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl index 8b544ca9c..6af499e4e 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl @@ -436,25 +436,22 @@ void dampen(inout Surface surface, TORQUE_SAMPLER2D(WetnessTexture), float accum { if (degree<=0.0) return; float3 n = abs(surface.N); - float ang = clamp(n.z, 0.04, 0.96); + float ang = 1.1-(abs(surface.N.z)*sign(surface.N.z)); - float speed = -accumTime*(1.0-surface.linearRoughnessSq)*clamp((2.0-ang), 0.04, 0.96); - if ((n.x > 0.0) || (n.y > 0.0)) - speed *= -1.0; - float2 wetoffset = float2(speed,speed)*0.1; + float speed = accumTime * (1.0 - surface.linearRoughnessSq); + float3 wetoffset = (surface.P+float3(speed,speed,speed)) * 0.33; - float3 wetNormal = TORQUE_TEX2D(WetnessTexture, float2(surface.P.xy*0.1+wetoffset)).xyz; - wetNormal = lerp(wetNormal,TORQUE_TEX2D(WetnessTexture,float2(surface.P.zx*0.1+wetoffset)).rgb ,n.y); - wetNormal = lerp(wetNormal,TORQUE_TEX2D(WetnessTexture,float2(surface.P.zy*0.1+wetoffset)).rgb ,n.x); - surface.N = lerp(surface.N, wetNormal, degree); - - float wetness = TORQUE_TEX2D(WetnessTexture, float2(surface.P.xy*0.1+wetoffset)).b; - wetness = lerp(wetness,TORQUE_TEX2D(WetnessTexture,float2(surface.P.zx*0.1+wetoffset)).b,n.y); - wetness = lerp(wetness,TORQUE_TEX2D(WetnessTexture,float2(surface.P.zy*0.1+wetoffset)).b,n.x); - wetness = pow(wetness*ang*degree,3); + float3 wetNormal = TORQUE_TEX2D(WetnessTexture, wetoffset.xy).xyz * (1.1-(n.z* n.z)); + wetNormal = lerp(wetNormal, TORQUE_TEX2D(WetnessTexture, wetoffset.zx).rgb, n.y); + wetNormal = lerp(wetNormal, TORQUE_TEX2D(WetnessTexture, wetoffset.zy).rgb, n.x); + wetNormal = normalize(wetNormal); + float wetness = wetNormal.b* degree; + + wetNormal = normalize(wetNormal * 2.0 - 1.0); + surface.N = normalize(float3(surface.N.xy + wetNormal.xy * wetness, surface.N.z)); surface.roughness = lerp(surface.roughness, 0.04f, wetness); - surface.baseColor.rgb = lerp(surface.baseColor.rgb, surface.baseColor.rgb*0.6+float3(0.4,0.4,0.4)*wetness, wetness); + surface.baseColor.rgb = lerp(surface.baseColor.rgb, surface.baseColor.rgb * 0.6 + float3(0.4, 0.4, 0.4) * wetness, wetness); surface.metalness = lerp(surface.metalness, 0.96, wetness); surface.Update(); } From d85bbc0a1f6aef1abbd47563647fdfe7e8a26e8c Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Wed, 8 Apr 2026 19:27:43 -0500 Subject: [PATCH 2/2] account for translucencies --- Templates/BaseGame/game/core/rendering/shaders/gl/lighting.glsl | 2 +- Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Templates/BaseGame/game/core/rendering/shaders/gl/lighting.glsl b/Templates/BaseGame/game/core/rendering/shaders/gl/lighting.glsl index 7ee6b4dff..58b2881f2 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/gl/lighting.glsl +++ b/Templates/BaseGame/game/core/rendering/shaders/gl/lighting.glsl @@ -449,7 +449,7 @@ void dampen(inout Surface surface, sampler2D WetnessTexture, float accumTime, fl surface.N = normalize(vec3(surface.N.xy + wetNormal.xy * wetness, surface.N.z)); surface.roughness = lerp(surface.roughness, 0.04f, wetness); - surface.baseColor.rgb = lerp(surface.baseColor.rgb, surface.baseColor.rgb*0.6+vec3(0.4,0.4,0.4)*wetness, wetness); + surface.baseColor = vec4(lerp(surface.baseColor.rgb, surface.baseColor.rgb*0.6+vec3(0.4,0.4,0.4)*wetness, wetness), max(surface.baseColor.a, 0.4* wetness)); surface.metalness = lerp(surface.metalness, 0.96, wetness); updateSurface(surface); } diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl b/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl index 6af499e4e..b712e5ad0 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl @@ -451,7 +451,7 @@ void dampen(inout Surface surface, TORQUE_SAMPLER2D(WetnessTexture), float accum surface.N = normalize(float3(surface.N.xy + wetNormal.xy * wetness, surface.N.z)); surface.roughness = lerp(surface.roughness, 0.04f, wetness); - surface.baseColor.rgb = lerp(surface.baseColor.rgb, surface.baseColor.rgb * 0.6 + float3(0.4, 0.4, 0.4) * wetness, wetness); + surface.baseColor = float4(lerp(surface.baseColor.rgb, surface.baseColor.rgb * 0.6 + float3(0.4, 0.4, 0.4) * wetness, wetness), max(surface.baseColor.a, 0.4* wetness)); surface.metalness = lerp(surface.metalness, 0.96, wetness); surface.Update(); }