From 556937ec090b14a031dee1003d9032fbb194887a Mon Sep 17 00:00:00 2001 From: marauder2k7 Date: Tue, 10 Jan 2023 04:06:22 +0000 Subject: [PATCH 1/2] Initial Commit (cherry picked from commit 05a2f8c4cf07b46be651aa140499b99931d91eee) --- .../core/postFX/scripts/HDR/HDRPostFX.tscript | 7 +- .../scripts/HDR/HDR_Bloom/downSampleP.glsl | 71 ++++++++---- .../scripts/HDR/HDR_Bloom/downSampleP.hlsl | 67 ++++++++---- .../scripts/HDR/HDR_Bloom/upSampleP.glsl | 46 ++++---- .../scripts/HDR/HDR_Bloom/upSampleP.hlsl | 43 ++++---- .../postFX/scripts/HDR/HDR_colorUtils.glsl | 8 +- .../postFX/scripts/HDR/HDR_colorUtils.hlsl | 8 +- .../postFX/scripts/HDR/HDR_finalPass.glsl | 8 +- .../postFX/scripts/HDR/HDR_finalPass.hlsl | 6 +- .../postFX/scripts/SMAA/gl/BBtoGamma.glsl | 2 +- .../rendering/shaders/gl/scatterSkyP.glsl | 3 +- .../core/rendering/shaders/gl/torque.glsl | 103 +++++++++++++----- .../game/core/rendering/shaders/torque.hlsl | 91 ++++++++++++++-- 13 files changed, 314 insertions(+), 149 deletions(-) diff --git a/Templates/BaseGame/game/core/postFX/scripts/HDR/HDRPostFX.tscript b/Templates/BaseGame/game/core/postFX/scripts/HDR/HDRPostFX.tscript index 69f49db0b..8909c8d45 100644 --- a/Templates/BaseGame/game/core/postFX/scripts/HDR/HDRPostFX.tscript +++ b/Templates/BaseGame/game/core/postFX/scripts/HDR/HDRPostFX.tscript @@ -283,8 +283,7 @@ function HDRPostFX::setShaderConsts( %this ) %tonemapMode = 4; else if($PostFX::HDRPostFX::tonemapMode $= "Linear") %tonemapMode = 5; - - + %combinePass.setShaderConst( "$g_fTonemapMode", %tonemapMode ); %clampedGamma = mClamp( $pref::Video::Gamma, 2.0, 2.5); @@ -302,6 +301,7 @@ function HDRPostFX::setShaderConsts( %this ) { %mip = %bloom.getObject(%this.mipsCount + %idx); %mip.setShaderConst("$filterRadius", $PostFX::HDRPostFX::radius); + %mip.setShaderConst("$mipId", %idx); } %strength = $PostFX::HDRPostFX::intensity; @@ -447,7 +447,7 @@ function HDRPostFX::populatePostFXSettings(%this) PostEffectEditorInspector.addField("$PostFX::HDRPostFX::enableBloom", "Enable Bloom", "bool", "", $PostFX::HDRPostFX::enableBloom, ""); PostEffectEditorInspector.addField("$PostFX::HDRPostFX::threshold", "Threshold", "range", "", $PostFX::HDRPostFX::threshold, "0 2 10"); PostEffectEditorInspector.addField("$PostFX::HDRPostFX::intensity", "Intensity", "range", "", $PostFX::HDRPostFX::intensity, "0 10 10"); - PostEffectEditorInspector.addField("$PostFX::HDRPostFX::radius", "Radius", "float", "", $PostFX::HDRPostFX::radius, ""); + PostEffectEditorInspector.addField("$PostFX::HDRPostFX::radius", "Radius", "range", "", $PostFX::HDRPostFX::radius, "0 25 50"); PostEffectEditorInspector.endGroup(); PostEffectEditorInspector.startGroup("HDR - Lens Dirt"); @@ -763,4 +763,3 @@ function LuminanceVisPostFX::onDisabled( %this ) { HDRPostFX.skip = false; } - diff --git a/Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_Bloom/downSampleP.glsl b/Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_Bloom/downSampleP.glsl index 6f6f5eb62..4de52cdc2 100644 --- a/Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_Bloom/downSampleP.glsl +++ b/Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_Bloom/downSampleP.glsl @@ -20,43 +20,66 @@ // IN THE SOFTWARE. //----------------------------------------------------------------------------- +#include "core/rendering/shaders/gl/torque.glsl" #include "core/rendering/shaders/gl/hlslCompat.glsl" #include "core/rendering/shaders/postFX/gl/postFx.glsl" +#include "core/postFX/scripts/HDR/HDR_colorUtils.glsl" #include "shadergen:/autogenConditioners.h" - -#line 27 - -#define KERNEL_SAMPLES 9 -const vec3 KERNEL[9] = vec3[]( - vec3( 0.0000, 0.0000, 0.2500), - vec3( 1.0000, 0.0000, 0.1250), - vec3( 0.0000, 1.0000, 0.1250), - vec3(-1.0000, 0.0000, 0.1250), - vec3( 0.0000,-1.0000, 0.1250), - vec3( 1.0000, 1.0000, 0.0625), - vec3( 1.0000,-1.0000, 0.0625), - vec3(-1.0000,-1.0000, 0.0625), - vec3(-1.0000, 1.0000, 0.0625) -); - +#line 28 uniform sampler2D inputTex; uniform vec2 oneOverTargetSize; +uniform int mipId; out vec4 OUT_col; void main() { vec4 downSample = vec4(0, 0, 0, 0); + float x = oneOverTargetSize.x; + float y = oneOverTargetSize.y; - for (int i=0; i= squareNum); } -// #define TORQUE_STOCK_GAMMA -#ifdef TORQUE_STOCK_GAMMA +// RGB -> HSL +vec3 rgbToHSL(vec3 col) +{ + float cmax, cmin, h, s, l; + cmax = max(col.r, max(col.g, col.b)); + cmin = min(col.r, min(col.g, col.b)); + l = min(1.0, (cmax + cmin) / 2.0); + + if (cmax == cmin) { + h = s = 0.0; /* achromatic */ + } + else + { + float cdelta = cmax - cmin; + s = l > 0.5 ? cdelta / (2.0 - cmax - cmin) : cdelta / (cmax + cmin); + if (cmax == col.r) { + h = (col.g - col.b) / cdelta + (col.g < col.b ? 6.0 : 0.0); + } + else if (cmax == col.g) { + h = (col.b - col.r) / cdelta + 2.0; + } + else { + h = (col.r - col.b) / cdelta + 4.0; + } + } + h /= 6.0; + + + return vec3(h,s,l); +} + +// HSL -> RGB +vec3 hslToRGB(vec3 hsl) +{ + float nr, ng, nb, chroma, h, s, l; + h = hsl.r; + s = hsl.g; + l = hsl.b; + + nr = abs(h * 6.0 - 3.0) - 1.0; + ng = 2.0 - abs(h * 6.0 - 2.0); + nb = 2.0 - abs(h * 6.0 - 4.0); + + nr = clamp(nr, 0.0, 1.0); + nb = clamp(nb, 0.0, 1.0); + ng = clamp(ng, 0.0, 1.0); + + chroma = (1.0 - abs(2.0 * l - 1.0)) * s; + + return vec3((nr - 0.5) * chroma + l, (ng - 0.5) * chroma + l, (nb - 0.5) * chroma + l); +} + // Sample in linear space. Decodes gamma. +float toLinear(float col) +{ + if(col < 0.04045) + { + return (col < 0.0) ? 0.0 : col * (1.0 / 12.92); + } + + return pow(abs(col + 0.055) * (1.0 / 1.055), 2.4); +} vec4 toLinear(vec4 tex) { - return tex; -} -// Encodes gamma. -vec4 toGamma(vec4 tex) -{ - return tex; + return vec4(toLinear(tex.r),toLinear(tex.g),toLinear(tex.b), tex.a); } + vec3 toLinear(vec3 tex) { - return tex; + return vec3(toLinear(tex.r),toLinear(tex.g),toLinear(tex.b)); } + // Encodes gamma. -vec3 toGamma(vec3 tex) +float toGamma(float col) { - return tex; + if(col < 0.0031308) + { + return (col < 0.0) ? 0.0 : col * 12.92; + } + + return 1.055 * pow(abs(col), 1.0 / 2.4) - 0.055; } -#else -// Sample in linear space. Decodes gamma. -vec4 toLinear(vec4 tex) -{ - return vec4(pow(abs(tex.rgb), vec3(2.2)), tex.a); -} -// Encodes gamma. + vec4 toGamma(vec4 tex) { - return vec4(pow(abs(tex.rgb), vec3(1.0/2.2)), tex.a); + return vec4(toGamma(tex.r), toGamma(tex.g), toGamma(tex.b), tex.a); } -// Sample in linear space. Decodes gamma. -vec3 toLinear(vec3 tex) -{ - return pow(abs(tex), vec3(2.2)); -} -// Encodes gamma. + vec3 toGamma(vec3 tex) { - return pow(abs(tex), vec3(1.0/2.2)); + return vec3(toGamma(tex.r), toGamma(tex.g), toGamma(tex.b)); } -#endif // vec3 PBRFresnel(vec3 albedo, vec3 indirect, float metalness, float fresnel) { diff --git a/Templates/BaseGame/game/core/rendering/shaders/torque.hlsl b/Templates/BaseGame/game/core/rendering/shaders/torque.hlsl index 6365d547a..8f4e30a22 100644 --- a/Templates/BaseGame/game/core/rendering/shaders/torque.hlsl +++ b/Templates/BaseGame/game/core/rendering/shaders/torque.hlsl @@ -301,25 +301,98 @@ bool getFlag(float flags, int num) return (fmod(process, pow(2, squareNum)) >= squareNum); } +// RGB -> HSL +float3 rgbToHSL(float3 col) +{ + float cmax, cmin, h, s, l; + cmax = max(col.r, max(col.g, col.b)); + cmin = min(col.r, min(col.g, col.b)); + l = min(1.0, (cmax + cmin) / 2.0); + + if (cmax == cmin) { + h = s = 0.0; /* achromatic */ + } + else + { + float cdelta = cmax - cmin; + s = l > 0.5 ? cdelta / (2.0 - cmax - cmin) : cdelta / (cmax + cmin); + if (cmax == col.r) { + h = (col.g - col.b) / cdelta + (col.g < col.b ? 6.0 : 0.0); + } + else if (cmax == col.g) { + h = (col.b - col.r) / cdelta + 2.0; + } + else { + h = (col.r - col.b) / cdelta + 4.0; + } + } + h /= 6.0; + + + return float3(h,s,l); +} + +// HSL -> RGB +float3 hslToRGB(float3 hsl) +{ + float nr, ng, nb, chroma, h, s, l; + h = hsl.r; + s = hsl.g; + l = hsl.b; + + nr = abs(h * 6.0 - 3.0) - 1.0; + ng = 2.0 - abs(h * 6.0 - 2.0); + nb = 2.0 - abs(h * 6.0 - 4.0); + + nr = clamp(nr, 0.0, 1.0); + nb = clamp(nb, 0.0, 1.0); + ng = clamp(ng, 0.0, 1.0); + + chroma = (1.0 - abs(2.0 * l - 1.0)) * s; + + return float3((nr - 0.5) * chroma + l, (ng - 0.5) * chroma + l, (nb - 0.5) * chroma + l); + +} + // Sample in linear space. Decodes gamma. +float toLinear(float col) +{ + if(col < 0.04045) + { + return (col < 0.0) ? 0.0 : col * (1.0 / 12.92); + } + + return pow(abs(col + 0.055) * (1.0 / 1.055), 2.4); +} float4 toLinear(float4 tex) { - return float4(pow(abs(tex.rgb), 2.2), tex.a); + return float4(toLinear(tex.r),toLinear(tex.g),toLinear(tex.b), tex.a); } -// Encodes gamma. -float4 toGamma(float4 tex) -{ - return float4(pow(abs(tex.rgb), 1.0/2.2), tex.a); -} -// Sample in linear space. Decodes gamma. + float3 toLinear(float3 tex) { - return pow(abs(tex.rgb), 2.2); + return float3(toLinear(tex.r),toLinear(tex.g),toLinear(tex.b)); } + // Encodes gamma. +float toGamma(float col) +{ + if(col < 0.0031308) + { + return (col < 0.0) ? 0.0 : col * 12.92; + } + + return 1.055 * pow(abs(col), 1.0 / 2.4) - 0.055; +} + +float4 toGamma(float4 tex) +{ + return float4(toGamma(tex.r), toGamma(tex.g), toGamma(tex.b), tex.a); +} + float3 toGamma(float3 tex) { - return pow(abs(tex.rgb), 1.0/2.2); + return float3(toGamma(tex.r), toGamma(tex.g), toGamma(tex.b)); } // From e83028d9ae4eb447a6db4b205549adfd0c0c2e4f Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Fri, 20 Jan 2023 12:23:12 -0600 Subject: [PATCH 2/2] preserve glowmap operating as faux lights for probes via oversaturation (cherry picked from commit 5a2e04838ec2f11e119377d5380f3ed517b7cc56) --- .../BaseGame/game/core/postFX/scripts/HDR/HDR_finalPass.glsl | 2 +- .../BaseGame/game/core/postFX/scripts/HDR/HDR_finalPass.hlsl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_finalPass.glsl b/Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_finalPass.glsl index f229af12d..a30360b8f 100644 --- a/Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_finalPass.glsl +++ b/Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_finalPass.glsl @@ -100,7 +100,7 @@ void main() vec4 bloom = texture( bloomTex, IN_uv2 ); // Add the bloom effect. - _sample.rgb = mix(_sample.rgb, bloom.rgb, vec3(0.4)); + _sample.rgb +=bloom.rgb; //Apply Exposure _sample.rgb *= TO_Exposure(_sample.rgb, exposureValue, colorFilter); diff --git a/Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_finalPass.hlsl b/Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_finalPass.hlsl index 7a2195df5..9a5d1f311 100644 --- a/Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_finalPass.hlsl +++ b/Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_finalPass.hlsl @@ -95,7 +95,7 @@ float4 main( PFXVertToPix IN ) : TORQUE_TARGET0 float4 bloom = TORQUE_TEX2D( bloomTex, IN.uv2 ); // Add the bloom effect. - sample.rgb = lerp(sample.rgb, bloom.rgb, float3(0.04, 0.04, 0.04)); + sample.rgb += bloom.rgb; //Apply Exposure sample.rgb *= TO_Exposure(sample.rgb, exposureValue, colorFilter);