From 2d18d5b280e2cdb63addab44eaca38ff2acd0d45 Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Fri, 13 Nov 2020 15:18:20 -0600 Subject: [PATCH 1/3] clamp borghtpass filter return values to smooth out bloom --- .../game/core/postFX/scripts/HDR/brightPassFilterP.glsl | 2 +- .../game/core/postFX/scripts/HDR/brightPassFilterP.hlsl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Templates/BaseGame/game/core/postFX/scripts/HDR/brightPassFilterP.glsl b/Templates/BaseGame/game/core/postFX/scripts/HDR/brightPassFilterP.glsl index 04d9e97c9..0384e5477 100644 --- a/Templates/BaseGame/game/core/postFX/scripts/HDR/brightPassFilterP.glsl +++ b/Templates/BaseGame/game/core/postFX/scripts/HDR/brightPassFilterP.glsl @@ -61,5 +61,5 @@ void main() average = vec4( 0.0f, 0.0f, 0.0f, 1.0f ); // Write the colour to the bright-pass render target - OUT_col = hdrEncode( average ); + OUT_col = hdrEncode( saturate(average) ); } diff --git a/Templates/BaseGame/game/core/postFX/scripts/HDR/brightPassFilterP.hlsl b/Templates/BaseGame/game/core/postFX/scripts/HDR/brightPassFilterP.hlsl index c3f04db93..ad1e0501f 100644 --- a/Templates/BaseGame/game/core/postFX/scripts/HDR/brightPassFilterP.hlsl +++ b/Templates/BaseGame/game/core/postFX/scripts/HDR/brightPassFilterP.hlsl @@ -58,5 +58,5 @@ float4 main( PFXVertToPix IN ) : TORQUE_TARGET0 average = float4( 0.0f, 0.0f, 0.0f, 1.0f ); // Write the colour to the bright-pass render target - return hdrEncode( average ); + return hdrEncode( saturate(average) ); } From c0b6007b9f1cc03a4975f18cc0312079918afe5d Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Fri, 13 Nov 2020 15:19:50 -0600 Subject: [PATCH 2/3] undefined preprocessors on some machines eval to true. given this is purely a bool anyway, might as well stick to ifdef --- .../BaseGame/game/core/rendering/shaders/gl/lighting.glsl | 6 +++--- .../BaseGame/game/core/rendering/shaders/lighting.hlsl | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Templates/BaseGame/game/core/rendering/shaders/gl/lighting.glsl b/Templates/BaseGame/game/core/rendering/shaders/gl/lighting.glsl index 2fc447a95..01de17b3e 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/gl/lighting.glsl +++ b/Templates/BaseGame/game/core/rendering/shaders/gl/lighting.glsl @@ -219,10 +219,10 @@ vec3 evaluateStandardBRDF(Surface surface, SurfaceToLight surfaceToLight) float D = D_GGX(surfaceToLight.NdotH, surface.linearRoughnessSq); vec3 Fr = D * F * Vis; -#if CAPTURING == true - return mix(Fd + Fr,surface.f0,surface.metalness); +#ifdef CAPTURING + return saturate(mix(Fd + Fr,surface.f0,surface.metalness)); #else - return Fd + Fr; + return saturate(Fd + Fr); #endif } diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl b/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl index b948eae27..617aa7a3b 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl @@ -220,10 +220,10 @@ float3 evaluateStandardBRDF(Surface surface, SurfaceToLight surfaceToLight) float D = D_GGX(surfaceToLight.NdotH, surface.linearRoughnessSq); float3 Fr = D * F * Vis; -#if CAPTURING == true - return lerp(Fd + Fr,surface.f0,surface.metalness); +#ifdef CAPTURING + return saturate(lerp(Fd + Fr,surface.f0,surface.metalness)); #else - return Fd + Fr; + return saturate(Fd + Fr); #endif } From 39574e7fee7c37ea51c12d11c58c0b909ceeef46 Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Fri, 13 Nov 2020 15:24:12 -0600 Subject: [PATCH 3/3] clamp factor entriely for getXXXLight calcs, and take metalness into account for reducing direct light diffusion imact (while this seems to make it match the tooling, I can't say I've seen this exact approach used, so might want to re-review the methodology) --- .../BaseGame/game/core/rendering/shaders/gl/lighting.glsl | 4 ++-- Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Templates/BaseGame/game/core/rendering/shaders/gl/lighting.glsl b/Templates/BaseGame/game/core/rendering/shaders/gl/lighting.glsl index 01de17b3e..3a5453fbf 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/gl/lighting.glsl +++ b/Templates/BaseGame/game/core/rendering/shaders/gl/lighting.glsl @@ -229,14 +229,14 @@ vec3 evaluateStandardBRDF(Surface surface, SurfaceToLight surfaceToLight) vec3 getDirectionalLight(Surface surface, SurfaceToLight surfaceToLight, vec3 lightColor, float lightIntensity, float shadow) { - vec3 factor = lightColor * max(surfaceToLight.NdotL, 0.0f) * shadow * lightIntensity; + vec3 factor = lightColor * max(surfaceToLight.NdotL * shadow * lightIntensity*(1.0-surface.metalness), 0.0f); return evaluateStandardBRDF(surface,surfaceToLight) * factor; } vec3 getPunctualLight(Surface surface, SurfaceToLight surfaceToLight, vec3 lightColor, float lightIntensity, float radius, float shadow) { float attenuation = getDistanceAtt(surfaceToLight.Lu, radius); - vec3 factor = lightColor * max(surfaceToLight.NdotL, 0.0f) * shadow * lightIntensity * attenuation; + vec3 factor = lightColor * max(surfaceToLight.NdotL * shadow * lightIntensity * attenuation*(1.0-surface.metalness), 0.0f); return evaluateStandardBRDF(surface,surfaceToLight) * factor; } diff --git a/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl b/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl index 617aa7a3b..2b9443a5a 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl +++ b/Templates/BaseGame/game/core/rendering/shaders/lighting.hlsl @@ -230,14 +230,14 @@ float3 evaluateStandardBRDF(Surface surface, SurfaceToLight surfaceToLight) float3 getDirectionalLight(Surface surface, SurfaceToLight surfaceToLight, float3 lightColor, float lightIntensity, float shadow) { - float3 factor = lightColor * max(surfaceToLight.NdotL, 0.0f) * shadow * lightIntensity; + float3 factor = lightColor * max(surfaceToLight.NdotL* shadow * lightIntensity*(1.0-surface.metalness), 0.0f) ; return evaluateStandardBRDF(surface,surfaceToLight) * factor; } float3 getPunctualLight(Surface surface, SurfaceToLight surfaceToLight, float3 lightColor, float lightIntensity, float radius, float shadow) { float attenuation = getDistanceAtt(surfaceToLight.Lu, radius); - float3 factor = lightColor * max(surfaceToLight.NdotL, 0.0f) * shadow * lightIntensity * attenuation; + float3 factor = lightColor * max(surfaceToLight.NdotL* shadow * lightIntensity * attenuation*(1.0-surface.metalness), 0.0f) ; return evaluateStandardBRDF(surface,surfaceToLight) * factor; }