From ade74c10161b143e282b48d40e1a42652e3bdd60 Mon Sep 17 00:00:00 2001 From: Samuel Skiff Date: Fri, 19 Aug 2022 18:26:55 -0500 Subject: [PATCH] BloomWIP 1 --- .gitignore | 2 + .../postFX/scripts/Bloom/BloomPostFX.tscript | 153 ++++++++++++++++++ .../core/postFX/scripts/Bloom/bloomP.hlsl | 32 ++++ .../postFX/scripts/Bloom/downSampleP.hlsl | 62 +++++++ .../core/postFX/scripts/Bloom/upSampleP.hlsl | 57 +++++++ .../scripts/default.postfxpreset.tscript | 22 +-- 6 files changed, 307 insertions(+), 21 deletions(-) create mode 100644 Templates/BaseGame/game/core/postFX/scripts/Bloom/BloomPostFX.tscript create mode 100644 Templates/BaseGame/game/core/postFX/scripts/Bloom/bloomP.hlsl create mode 100644 Templates/BaseGame/game/core/postFX/scripts/Bloom/downSampleP.hlsl create mode 100644 Templates/BaseGame/game/core/postFX/scripts/Bloom/upSampleP.hlsl diff --git a/.gitignore b/.gitignore index 86c26bc28..c968f47c7 100644 --- a/.gitignore +++ b/.gitignore @@ -184,3 +184,5 @@ Project Manager.exe projects.xml Qt*.dll .vs +Engine/lib/assimp/include/assimp/config.h +Engine/lib/assimp/revision.h diff --git a/Templates/BaseGame/game/core/postFX/scripts/Bloom/BloomPostFX.tscript b/Templates/BaseGame/game/core/postFX/scripts/Bloom/BloomPostFX.tscript new file mode 100644 index 000000000..d3a56d713 --- /dev/null +++ b/Templates/BaseGame/game/core/postFX/scripts/Bloom/BloomPostFX.tscript @@ -0,0 +1,153 @@ +//----------------------------------------------------------------------------- +// 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. +//----------------------------------------------------------------------------- + +singleton ShaderData( PFX_Bloom_Shader ) +{ + DXVertexShaderFile = $Core::CommonShaderPath @ "/postFX/postFxV.hlsl"; + DXPixelShaderFile = "./bloomP.hlsl"; + + samplerNames[0] = "$inputTex"; + + pixVersion = 3.0; +}; + +singleton ShaderData( PFX_BloomDownSample_Shader ) +{ + DXVertexShaderFile = $Core::CommonShaderPath @ "/postFX/postFxV.hlsl"; + DXPixelShaderFile = "./downSampleP.hlsl"; + + samplerNames[0] = "$inputTex"; + + pixVersion = 3.0; +}; + +singleton GFXStateBlockData( BloomPostFX_SampleStateBlock : PFX_DefaultStateBlock ) +{ + samplersDefined = true; + samplerStates[0] = SamplerClampLinear; +}; + +function BloomPostFX::setShaderConsts( %this ) +{ +} + +function BloomPostFX::preProcess( %this ) +{ +} + +function BloomPostFX::onAdd(%this) +{ + //Register the postFX with the manager + PostFXManager.registerPostEffect(%this); +} + +function BloomPostFX::onEnabled( %this ) +{ + return true; +} + +function BloomPostFX::onDisabled( %this ) +{ + return true; +} + +//This is used to populate the PostFXEditor's settings so the post FX can be edited +//This is automatically polled for any postFX that has been registered(in our onAdd) and the settings +//are thus exposed for editing +function BloomPostFX::populatePostFXSettings(%this) +{ + PostEffectEditorInspector.startGroup("BloomPostFX - General"); + PostEffectEditorInspector.addCallbackField("$PostFX::BloomPostFX::Enabled", "Enabled", "bool", "", $PostFX::BloomPostFX::Enabled, "", "toggleBloomPostFX"); + PostEffectEditorInspector.endGroup(); +} + +//This is called back from our callbackField defined in populatePostFXSettings to +//Allow us to easily toggle the postFX and have it respond immediately +function PostEffectEditorInspector::toggleBloomPostFX(%this) +{ + if($PostFX::BloomPostFX::Enabled) + BloomPostFX.enable(); + else + BloomPostFX.disable(); +} + +//This function pair(applyFromPreset and settingsApply) are done the way they are, with the separated variables +//so that we can effectively store the 'settings' away from the live variables that the postFX's actually utilize +//when rendering. This allows us to modify things but still leave room for reverting or temporarily applying them +function BloomPostFX::applyFromPreset(%this) +{ + if($PostFX::BloomPostFX::Enabled) + %this.enable(); + else + %this.disable(); +} + +function BloomPostFX::savePresetSettings(%this) +{ + PostFXManager::savePresetSetting("$PostFX::BloomPostFX::Enabled"); +} + +//Our actual postFX +singleton PostEffect( BloomPostFX ) +{ + enabled = false; + allowReflectPass = false; + + renderTime = "PFXAfterBin"; + renderBin = "EditorBin"; + renderPriority = 9999; + + shader = PFX_Bloom_Shader; + stateBlock = BloomPostFX_SampleStateBlock; + texture[0] = "$backBuffer"; + target = "$outTex"; + targetFormat = "GFXFormatR16G16B16A16F"; + + new PostEffect() + { + allowReflectPass = false; + shader = PFX_BloomDownSample_Shader; + stateBlock = BloomPostFX_SampleStateBlock; + texture[0] = "$inTex"; + target = "#bloom0"; + targetScale = "0.5 0.5"; + }; + + new PostEffect() + { + allowReflectPass = false; + shader = PFX_BloomDownSample_Shader; + stateBlock = BloomPostFX_SampleStateBlock; + texture[0] = "#bloom0"; + target = "#bloom1"; + targetScale = "0.25 0.25"; + }; + + new PostEffect() + { + allowReflectPass = false; + shader = PFX_PassthruShader; + stateBlock = BloomPostFX_SampleStateBlock; + texture[0] = "#bloom1"; + target = "$backBuffer"; + }; +}; diff --git a/Templates/BaseGame/game/core/postFX/scripts/Bloom/bloomP.hlsl b/Templates/BaseGame/game/core/postFX/scripts/Bloom/bloomP.hlsl new file mode 100644 index 000000000..1935ac7c1 --- /dev/null +++ b/Templates/BaseGame/game/core/postFX/scripts/Bloom/bloomP.hlsl @@ -0,0 +1,32 @@ +//----------------------------------------------------------------------------- +// 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/postFX/postFx.hlsl" + +TORQUE_UNIFORM_SAMPLER2D(inputTex, 0); + +float4 main(PFXVertToPix IN) : TORQUE_TARGET0 +{ + float4 color = TORQUE_TEX2D(inputTex, IN.uv0); + float brightness = max(color.r, max(color.g, color.b)); + return float4(color.rgb * pow(brightness, 8.0f), color.a); +} diff --git a/Templates/BaseGame/game/core/postFX/scripts/Bloom/downSampleP.hlsl b/Templates/BaseGame/game/core/postFX/scripts/Bloom/downSampleP.hlsl new file mode 100644 index 000000000..a6051ca0c --- /dev/null +++ b/Templates/BaseGame/game/core/postFX/scripts/Bloom/downSampleP.hlsl @@ -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/postFX/postFx.hlsl" + +//----------------------------------------------------------------------------- +// Data +//----------------------------------------------------------------------------- + +TORQUE_UNIFORM_SAMPLER2D(inputTex, 0); +//uniform float2 targetSize; + +//----------------------------------------------------------------------------- +// Main +//----------------------------------------------------------------------------- +float4 main(PFXVertToPix IN) : TORQUE_TARGET0 +{ + float2 texSize = 1.0f / float2(1024.0f, 1024.0f); + float x = texSize.x; + float y = texSize.y; + float4 a = TORQUE_TEX2D( inputTex, IN.uv0 + float2(-x*2.0f, y*2.0f)); + float4 b = TORQUE_TEX2D( inputTex, IN.uv0 + float2( 0.0f , y*2.0f)); + float4 c = TORQUE_TEX2D( inputTex, IN.uv0 + float2( x*2.0f, y*2.0f)); + + float4 d = TORQUE_TEX2D( inputTex, IN.uv0 + float2(-x*2.0f, 0.0f)); + float4 e = TORQUE_TEX2D( inputTex, IN.uv0); + float4 f = TORQUE_TEX2D( inputTex, IN.uv0 + float2( x*2.0f, 0.0f)); + + float4 g = TORQUE_TEX2D( inputTex, IN.uv0 + float2(-x*2.0f,-y*2.0f)); + float4 h = TORQUE_TEX2D( inputTex, IN.uv0 + float2( 0.0f ,-y*2.0f)); + float4 i = TORQUE_TEX2D( inputTex, IN.uv0 + float2( x*2.0f,-y*2.0f)); + + float4 j = TORQUE_TEX2D( inputTex, IN.uv0 + float2(-x, y)); + float4 k = TORQUE_TEX2D( inputTex, IN.uv0 + float2( x, y)); + float4 l = TORQUE_TEX2D( inputTex, IN.uv0 + float2(-x,-y)); + float4 m = TORQUE_TEX2D( inputTex, IN.uv0 + float2( x,-y)); + + float4 sample = e * 0.125f; + sample += (a+c+g+i) * 0.03125f; + sample += (b+d+f+h) * 0.0625; + sample += (j+k+l+m) * 0.125; + return sample; +} \ No newline at end of file diff --git a/Templates/BaseGame/game/core/postFX/scripts/Bloom/upSampleP.hlsl b/Templates/BaseGame/game/core/postFX/scripts/Bloom/upSampleP.hlsl new file mode 100644 index 000000000..00b1678d4 --- /dev/null +++ b/Templates/BaseGame/game/core/postFX/scripts/Bloom/upSampleP.hlsl @@ -0,0 +1,57 @@ +//----------------------------------------------------------------------------- +// 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/postFX/postFx.hlsl" + +struct Conn +{ + float4 hpos : TORQUE_POSITION; + float2 texCoord : TEXCOORD0; +}; + +TORQUE_UNIFORM_SAMPLER2D(inputTex0, 0); +TORQUE_UNIFORM_SAMPLER2D(inputTex1, 1); +uniform float filterRadius; + +float4 main( Conn V_IN ) : TORQUE_TARGET0 +{ + float x = filterRadius; + float y = filterRadius; + + float4 a = TORQUE_TEX2D( inputTex0, V_IN.texCoord + float2(-x, y)); + float4 b = TORQUE_TEX2D( inputTex0, V_IN.texCoord + float2( 0, y)); + float4 c = TORQUE_TEX2D( inputTex0, V_IN.texCoord + float2( x, y)); + + float4 d = TORQUE_TEX2D( inputTex0, V_IN.texCoord + float2(-x, 0)); + float4 e = TORQUE_TEX2D( inputTex0, V_IN.texCoord); + float4 f = TORQUE_TEX2D( inputTex0, V_IN.texCoord + float2( x, 0)); + + float4 g = TORQUE_TEX2D( inputTex0, V_IN.texCoord + float2(-x,-y)); + float4 h = TORQUE_TEX2D( inputTex0, V_IN.texCoord + float2( 0,-y)); + float4 i = TORQUE_TEX2D( inputTex0, V_IN.texCoord + float2( x,-y)); + + float4 sample = e * 4.0f; + sample += (b+d+f+h) * 2.0f; + sample += (a+c+g+i); + sample *= 1.0f / 16.0f; + return sample * 0.75f + TORQUE_TEX2D(inputTex1, V_IN.texCoord) * 0.25f; +} diff --git a/Templates/BaseGame/game/core/postFX/scripts/default.postfxpreset.tscript b/Templates/BaseGame/game/core/postFX/scripts/default.postfxpreset.tscript index 87cbec96c..8b1378917 100644 --- a/Templates/BaseGame/game/core/postFX/scripts/default.postfxpreset.tscript +++ b/Templates/BaseGame/game/core/postFX/scripts/default.postfxpreset.tscript @@ -1,21 +1 @@ -$PostFX::HDRPostFX::Enabled = 1; -$PostFX::HDRPostFX::ExposureValue = "1"; -$PostFX::HDRPostFX::minLuminace = "0.001"; -$PostFX::HDRPostFX::whiteCutoff = "1.0"; -$PostFX::HDRPostFX::adaptRate = "1"; -$PostFX::HDRPostFX::tonemapMode = "ACES"; -$PostFX::HDRPostFX::enableBloom = "1"; -$PostFX::HDRPostFX::brightPassThreshold = "0.2"; -$PostFX::HDRPostFX::gaussMultiplier = "0.145"; -$PostFX::HDRPostFX::gaussMean = "0"; -$PostFX::HDRPostFX::gaussStdDev = "0.5"; -$PostFX::HDRPostFX::enableAutoExposure = "0"; -$PostFX::HDRPostFX::keyValue = "0.18"; -$PostFX::HDRPostFX::enableBlueShift = "0"; -$PostFX::HDRPostFX::blueShiftColor = "1.05 0.97 1.27"; -$PostFX::SharpenPostFX::Enabled = "1"; -$PostFX::SharpenPostFX::sharpness = "0.15"; -$PostFX::VignettePostFX::Enabled = "1"; -$PostFX::VignettePostFX::VMin = "0.25"; -$PostFX::VignettePostFX::VMax = "0.9"; -$PostFX::VignettePostFX::Color = "0 0 0 1"; +