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)); } //