From 26801dbe77dd3e0a4ccacd8be49d7ab8cb6fa3f6 Mon Sep 17 00:00:00 2001 From: Samuel Skiff Date: Fri, 26 Aug 2022 18:05:25 -0500 Subject: [PATCH] Bloom Tweaks & OpenGL Support --- .../postFX/scripts/Bloom/BloomPostFX.tscript | 10 ++- .../postFX/scripts/Bloom/bloomThresholdP.hlsl | 2 +- .../postFX/scripts/Bloom/downSampleP.hlsl | 2 +- .../scripts/Bloom/gl/bloomStrengthP.glsl | 56 ++++++++++++++++ .../scripts/Bloom/gl/bloomThresholdP.glsl | 39 +++++++++++ .../postFX/scripts/Bloom/gl/downSampleP.glsl | 62 +++++++++++++++++ .../postFX/scripts/Bloom/gl/upSampleP.glsl | 66 +++++++++++++++++++ .../core/postFX/scripts/Bloom/upSampleP.hlsl | 4 +- .../scripts/default.postfxpreset.tscript | 20 +++--- Templates/BaseGame/game/core/settings.xml | 43 +++++++++--- 10 files changed, 279 insertions(+), 25 deletions(-) create mode 100644 Templates/BaseGame/game/core/postFX/scripts/Bloom/gl/bloomStrengthP.glsl create mode 100644 Templates/BaseGame/game/core/postFX/scripts/Bloom/gl/bloomThresholdP.glsl create mode 100644 Templates/BaseGame/game/core/postFX/scripts/Bloom/gl/downSampleP.glsl create mode 100644 Templates/BaseGame/game/core/postFX/scripts/Bloom/gl/upSampleP.glsl diff --git a/Templates/BaseGame/game/core/postFX/scripts/Bloom/BloomPostFX.tscript b/Templates/BaseGame/game/core/postFX/scripts/Bloom/BloomPostFX.tscript index 06e810fec..dc7620d12 100644 --- a/Templates/BaseGame/game/core/postFX/scripts/Bloom/BloomPostFX.tscript +++ b/Templates/BaseGame/game/core/postFX/scripts/Bloom/BloomPostFX.tscript @@ -39,6 +39,8 @@ singleton ShaderData( PFX_BloomThreshold_Shader ) { DXVertexShaderFile = $Core::CommonShaderPath @ "/postFX/postFxV.hlsl"; DXPixelShaderFile = "./bloomThresholdP.hlsl"; + OGLVertexShaderFile= $Core::CommonShaderPath @ "/postFX/gl/postFxV.glsl"; + OGLPixelShaderFile = "./gl/bloomThresholdP.glsl"; samplerNames[0] = "$inputTex"; @@ -49,6 +51,8 @@ singleton ShaderData( PFX_BloomDownSample_Shader ) { DXVertexShaderFile = $Core::CommonShaderPath @ "/postFX/postFxV.hlsl"; DXPixelShaderFile = "./downSampleP.hlsl"; + OGLVertexShaderFile= $Core::CommonShaderPath @ "/postFX/gl/postFxV.glsl"; + OGLPixelShaderFile = "./gl/downSampleP.glsl"; samplerNames[0] = "$inputTex"; @@ -59,6 +63,8 @@ singleton ShaderData( PFX_BloomUpSample_Shader ) { DXVertexShaderFile = $Core::CommonShaderPath @ "/postFX/postFxV.hlsl"; DXPixelShaderFile = "./upSampleP.hlsl"; + OGLVertexShaderFile= $Core::CommonShaderPath @ "/postFX/gl/postFxV.glsl"; + OGLPixelShaderFile = "./gl/upSampleP.glsl"; samplerNames[0] = "$nxtTex"; samplerNames[1] = "$mipTex"; @@ -70,6 +76,8 @@ singleton ShaderData( PFX_BloomStrength_Shader ) { DXVertexShaderFile = $Core::CommonShaderPath @ "/postFX/postFxV.hlsl"; DXPixelShaderFile = "./bloomStrengthP.hlsl"; + OGLVertexShaderFile= $Core::CommonShaderPath @ "/postFX/gl/postFxV.glsl"; + OGLPixelShaderFile = "./gl/bloomStrengthP.glsl"; samplerNames[0] = "$inputTex"; samplerNames[1] = "$dirtTex"; @@ -296,7 +304,7 @@ singleton PostEffect( BloomPostFX ) renderTime = "PFXBeforeBin"; renderBin = "EditorBin"; - renderPriority = 9998; + renderPriority = 10000; shader = PFX_BloomThreshold_Shader; stateBlock = BloomPostFX_SampleStateBlock; diff --git a/Templates/BaseGame/game/core/postFX/scripts/Bloom/bloomThresholdP.hlsl b/Templates/BaseGame/game/core/postFX/scripts/Bloom/bloomThresholdP.hlsl index 5a8b44143..597afc1bd 100644 --- a/Templates/BaseGame/game/core/postFX/scripts/Bloom/bloomThresholdP.hlsl +++ b/Templates/BaseGame/game/core/postFX/scripts/Bloom/bloomThresholdP.hlsl @@ -29,6 +29,6 @@ float4 main(PFXVertToPix IN) : TORQUE_TARGET0 { float4 screenColor = TORQUE_TEX2D(inputTex, IN.uv0); float brightness = max(screenColor.r, max(screenColor.g, screenColor.b)); - float contribution = saturate(brightness - threshold); + float contribution = saturate(brightness - threshold) / max(brightness, 0.0001f); return screenColor * contribution; } diff --git a/Templates/BaseGame/game/core/postFX/scripts/Bloom/downSampleP.hlsl b/Templates/BaseGame/game/core/postFX/scripts/Bloom/downSampleP.hlsl index dd8e7fce3..555c5fd2e 100644 --- a/Templates/BaseGame/game/core/postFX/scripts/Bloom/downSampleP.hlsl +++ b/Templates/BaseGame/game/core/postFX/scripts/Bloom/downSampleP.hlsl @@ -22,7 +22,7 @@ #include "core/rendering/shaders/postFX/postFx.hlsl" -static const int KERNEL_SAMPLES = 9; +#define KERNEL_SAMPLES 9 static const float3 KERNEL[9] = { float3( 0.0000f, 0.0000f, 0.2500f), float3( 1.0000f, 0.0000f, 0.1250f), diff --git a/Templates/BaseGame/game/core/postFX/scripts/Bloom/gl/bloomStrengthP.glsl b/Templates/BaseGame/game/core/postFX/scripts/Bloom/gl/bloomStrengthP.glsl new file mode 100644 index 000000000..547dcabba --- /dev/null +++ b/Templates/BaseGame/game/core/postFX/scripts/Bloom/gl/bloomStrengthP.glsl @@ -0,0 +1,56 @@ +//----------------------------------------------------------------------------- +// Copyright (c) 2012 GarageGames, LLC +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +//----------------------------------------------------------------------------- + +#include "core/rendering/shaders/gl/hlslCompat.glsl" +#include "shadergen:/autogenConditioners.h" + +uniform sampler2D inputTex; +uniform sampler2D dirtTex; +uniform float strength; +// XY: Dirt Texture Size/Scale +// Z: Dirt Effect Strength +uniform float3 dirtParams; +// XY: Edge Min & Max Distance +// Z: Edge Min Value +uniform float3 edgeParams; +uniform float2 oneOverTargetSize; + +in float2 uv0; + +out float4 OUT_col; + +void main() +{ + #if defined(USE_DIRT) + float edge = distance(uv0, float2(0.5f, 0.5f)); + edge = max(smoothstep(edgeParams.x, edgeParams.y, edge), edgeParams.z); + float3 dirt = tex2D(dirtTex, uv0 / (dirtParams.xy * oneOverTargetSize)).rgb * dirtParams.z * edge; + #endif + + float4 upSample = tex2D(inputTex, uv0) * strength; + + #if defined(USE_DIRT) + upSample.rgb += upSample.rgb * dirt; + #endif + + OUT_col = upSample; +} diff --git a/Templates/BaseGame/game/core/postFX/scripts/Bloom/gl/bloomThresholdP.glsl b/Templates/BaseGame/game/core/postFX/scripts/Bloom/gl/bloomThresholdP.glsl new file mode 100644 index 000000000..0ee574fb0 --- /dev/null +++ b/Templates/BaseGame/game/core/postFX/scripts/Bloom/gl/bloomThresholdP.glsl @@ -0,0 +1,39 @@ +//----------------------------------------------------------------------------- +// Copyright (c) 2012 GarageGames, LLC +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +//----------------------------------------------------------------------------- + +#include "core/rendering/shaders/gl/hlslCompat.glsl" +#include "shadergen:/autogenConditioners.h" + +uniform sampler2D inputTex; +uniform float threshold; + +in float2 uv0; + +out float4 OUT_col; + +void main() +{ + float4 screenColor = tex2D(inputTex, uv0); + float brightness = max(screenColor.r, max(screenColor.g, screenColor.b)); + float contribution = saturate(brightness - threshold) / max(brightness, 0.0001); + OUT_col = screenColor * contribution; +} diff --git a/Templates/BaseGame/game/core/postFX/scripts/Bloom/gl/downSampleP.glsl b/Templates/BaseGame/game/core/postFX/scripts/Bloom/gl/downSampleP.glsl new file mode 100644 index 000000000..2eed66607 --- /dev/null +++ b/Templates/BaseGame/game/core/postFX/scripts/Bloom/gl/downSampleP.glsl @@ -0,0 +1,62 @@ +//----------------------------------------------------------------------------- +// Copyright (c) 2012 GarageGames, LLC +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +//----------------------------------------------------------------------------- + +#include "core/rendering/shaders/gl/hlslCompat.glsl" +#include "shadergen:/autogenConditioners.h" + +#define KERNEL_SAMPLES 9 +const float3 KERNEL[9] = float3[]( + float3( 0.0000, 0.0000, 0.2500), + float3( 1.0000, 0.0000, 0.1250), + float3( 0.0000, 1.0000, 0.1250), + float3(-1.0000, 0.0000, 0.1250), + float3( 0.0000,-1.0000, 0.1250), + float3( 1.0000, 1.0000, 0.0625), + float3( 1.0000,-1.0000, 0.0625), + float3(-1.0000,-1.0000, 0.0625), + float3(-1.0000, 1.0000, 0.0625) +); + +uniform sampler2D inputTex; +uniform float2 oneOverTargetSize; + +in float2 uv0; + +out float4 OUT_col; + +void main() +{ + float4 downSample = float4(0, 0, 0, 0); + + for (int i=0; i + - - MainMenuGUI - PlayGUI - - - - core/ + + + core/ - - Deferred + + Deferred + + + 0.560687482 + 12 + 0 + 12 + 12 + 12 + + + MainMenuGUI + PlayGUI