From c8e950ccbc3bcc1c4a9b1a91c19156de3462ccf9 Mon Sep 17 00:00:00 2001 From: Samuel Skiff Date: Thu, 1 Sep 2022 00:48:16 -0500 Subject: [PATCH] Merge Bloom post effect with HDR post effect --- .../postFX/scripts/Bloom/BloomPostFX.tscript | 326 ---------------- .../core/postFX/scripts/HDR/HDRPostFX.tscript | 361 ++++++++++++------ .../HDR/HDR_Bloom/bloomGaussBlurHP.glsl | 72 ---- .../HDR/HDR_Bloom/bloomGaussBlurHP.hlsl | 111 ------ .../HDR/HDR_Bloom/bloomGaussBlurVP.glsl | 71 ---- .../HDR/HDR_Bloom/bloomGaussBlurVP.hlsl | 108 ------ ...ownScale4x4P.glsl => bloomInitSample.glsl} | 45 ++- ...ownScale4x4P.hlsl => bloomInitSample.hlsl} | 49 +-- .../gl => HDR/HDR_Bloom}/bloomStrengthP.glsl | 2 +- .../HDR_Bloom}/bloomStrengthP.hlsl | 2 +- .../gl => HDR/HDR_Bloom}/bloomThresholdP.glsl | 0 .../HDR_Bloom}/bloomThresholdP.hlsl | 0 .../gl => HDR/HDR_Bloom}/downSampleP.glsl | 0 .../{Bloom => HDR/HDR_Bloom}/downSampleP.hlsl | 0 .../scripts/HDR/HDR_Bloom/downScale4x4V.glsl | 141 ------- .../scripts/HDR/HDR_Bloom/downScale4x4V.hlsl | 138 ------- .../gl => HDR/HDR_Bloom}/upSampleP.glsl | 0 .../{Bloom => HDR/HDR_Bloom}/upSampleP.hlsl | 0 .../postFX/scripts/HDR/HDR_finalPass.glsl | 4 +- .../postFX/scripts/HDR/HDR_finalPass.hlsl | 4 +- 20 files changed, 303 insertions(+), 1131 deletions(-) delete mode 100644 Templates/BaseGame/game/core/postFX/scripts/Bloom/BloomPostFX.tscript delete mode 100644 Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_Bloom/bloomGaussBlurHP.glsl delete mode 100644 Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_Bloom/bloomGaussBlurHP.hlsl delete mode 100644 Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_Bloom/bloomGaussBlurVP.glsl delete mode 100644 Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_Bloom/bloomGaussBlurVP.hlsl rename Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_Bloom/{downScale4x4P.glsl => bloomInitSample.glsl} (65%) rename Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_Bloom/{downScale4x4P.hlsl => bloomInitSample.hlsl} (62%) rename Templates/BaseGame/game/core/postFX/scripts/{Bloom/gl => HDR/HDR_Bloom}/bloomStrengthP.glsl (97%) rename Templates/BaseGame/game/core/postFX/scripts/{Bloom => HDR/HDR_Bloom}/bloomStrengthP.hlsl (97%) rename Templates/BaseGame/game/core/postFX/scripts/{Bloom/gl => HDR/HDR_Bloom}/bloomThresholdP.glsl (100%) rename Templates/BaseGame/game/core/postFX/scripts/{Bloom => HDR/HDR_Bloom}/bloomThresholdP.hlsl (100%) rename Templates/BaseGame/game/core/postFX/scripts/{Bloom/gl => HDR/HDR_Bloom}/downSampleP.glsl (100%) rename Templates/BaseGame/game/core/postFX/scripts/{Bloom => HDR/HDR_Bloom}/downSampleP.hlsl (100%) delete mode 100644 Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_Bloom/downScale4x4V.glsl delete mode 100644 Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_Bloom/downScale4x4V.hlsl rename Templates/BaseGame/game/core/postFX/scripts/{Bloom/gl => HDR/HDR_Bloom}/upSampleP.glsl (100%) rename Templates/BaseGame/game/core/postFX/scripts/{Bloom => HDR/HDR_Bloom}/upSampleP.hlsl (100%) diff --git a/Templates/BaseGame/game/core/postFX/scripts/Bloom/BloomPostFX.tscript b/Templates/BaseGame/game/core/postFX/scripts/Bloom/BloomPostFX.tscript deleted file mode 100644 index 7dbdaff31..000000000 --- a/Templates/BaseGame/game/core/postFX/scripts/Bloom/BloomPostFX.tscript +++ /dev/null @@ -1,326 +0,0 @@ -//----------------------------------------------------------------------------- -// 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. -//----------------------------------------------------------------------------- - -// Inspired by bloom described in paper listed here: -// http://www.iryoku.com/next-generation-post-processing-in-call-of-duty-advanced-warfare - -$PostFX::BloomPostFX::threshold = 0.75; -$PostFX::BloomPostFX::intensity = 1.0; -$PostFX::BloomPostFX::radius = 4.0; - -$PostFX::BloomPostFX::dirtEnabled = true; -$PostFX::BloomPostFX::dirtScale = 2048.0; -$PostFX::BloomPostFX::dirtIntensity = 2.0; -$PostFX::BloomPostFX::dirtEdgeMinDist = 0.125; -$PostFX::BloomPostFX::dirtEdgeMaxDist = 0.75; -$PostFX::BloomPostFX::dirtEdgeMinVal = 0.05; -$PostFX::BloomPostFX::dirtImage = "core/postFX/images/lensDirt.png"; - -singleton ShaderData( Bloom_ThresholdShader ) -{ - DXVertexShaderFile = $Core::CommonShaderPath @ "/postFX/postFxV.hlsl"; - DXPixelShaderFile = "./bloomThresholdP.hlsl"; - OGLVertexShaderFile= $Core::CommonShaderPath @ "/postFX/gl/postFxV.glsl"; - OGLPixelShaderFile = "./gl/bloomThresholdP.glsl"; - - samplerNames[0] = "$inputTex"; - - pixVersion = 3.0; -}; - -singleton ShaderData( Bloom_DownSampleShader ) -{ - DXVertexShaderFile = $Core::CommonShaderPath @ "/postFX/postFxV.hlsl"; - DXPixelShaderFile = "./downSampleP.hlsl"; - OGLVertexShaderFile= $Core::CommonShaderPath @ "/postFX/gl/postFxV.glsl"; - OGLPixelShaderFile = "./gl/downSampleP.glsl"; - - samplerNames[0] = "$inputTex"; - - pixVersion = 3.0; -}; - -singleton ShaderData( Bloom_UpSampleShader ) -{ - 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"; - - pixVersion = 3.0; -}; - -singleton ShaderData( Bloom_StrengthShader ) -{ - 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"; - - pixVersion = 3.0; -}; - -singleton GFXStateBlockData( Bloom_SampleStateBlock : PFX_DefaultStateBlock ) -{ - samplersDefined = true; - samplerStates[0] = SamplerClampLinear; - samplerStates[1] = SamplerClampLinear; -}; - -singleton GFXStateBlockData( Bloom_Add_SampleStateBlock : PFX_DefaultStateBlock ) -{ - // Do a one to one blend. - blendDefined = true; - blendEnable = true; - blendSrc = GFXBlendOne; - blendDest = GFXBlendOne; - - samplersDefined = true; - samplerStates[0] = SamplerClampLinear; - samplerStates[1] = SamplerWrapLinear; -}; - -function BloomPostFX::setShaderConsts( %this ) -{ - %this.setShaderConst("$threshold", $PostFX::BloomPostFX::threshold); - - %blur = %this->bloomBlur; - for (%idx = 0; %idx < %this.mipsCount; %idx++) - { - %mip = %blur.getObject(%this.mipsCount + %idx); - %mip.setShaderConst("$filterRadius", $PostFX::BloomPostFX::radius); - } - - %final = %this->bloomFinal; - %final.setShaderConst("$strength", $PostFX::BloomPostFX::intensity); - - %dirtScale = $PostFX::BloomPostFX::dirtScale; - %dirtIntensity = $PostFX::BloomPostFX::dirtIntensity; - %final.setShaderConst("$dirtParams", %dirtScale SPC %dirtScale SPC %dirtIntensity); - - %edgeMin = $PostFX::BloomPostFX::dirtEdgeMinDist; - %edgeMax = $PostFX::BloomPostFX::dirtEdgeMaxDist; - %edgeVal = $PostFX::BloomPostFX::dirtEdgeMinVal; - %final.setShaderConst("$edgeParams", %edgeMin SPC %edgeMax SPC %edgeVal); -} - -function BloomPostFX::preProcess( %this ) -{ - if (%this.dirtEnabled != $PostFX::BloomPostFX::dirtEnabled) - { - %this.dirtEnabled = $PostFX::BloomPostFX::dirtEnabled; - - %final = %this->bloomFinal; - if (%this.dirtEnabled) - { - %final.setShaderMacro("USE_DIRT"); - } else { - %final.removeShaderMacro("USE_DIRT"); - } - } - - if(%this.dirtImage !$= $PostFX::BloomPostFX::dirtImage) - { - if ($PostFX::BloomPostFX::dirtImage $= "") - $PostFX::BloomPostFX::dirtImage = "core/postFX/images/lensDirt.png"; - - %this.dirtImage = $PostFX::BloomPostFX::dirtImage; - - %final = %this->bloomFinal; - %final.setTexture(1, %this.dirtImage); - } -} - -// This function sets up s sort of "mip-chain" for the bloom effect -// Not really "optimal" but it works well enough -function BloomPostFX::SetupBlurFX( %this ) -{ - %blurFX = new PostEffect() - { - internalName = "bloomBlur"; - allowReflectPass = false; - shader = Bloom_DownSampleShader; - stateBlock = Bloom_SampleStateBlock; - texture[0] = "#threshold"; - target = "#bloom_0"; - targetScale = "0.5 0.5"; - targetFormat = %this.mipTexFormat; - }; - - %textureName = "#bloom_0"; - for (%idx = 0; %idx < %this.mipsCount; %idx++) - { - %mipName = "bloom_" @ (%idx + 1); - %mipFX = new PostEffect() - { - internalName = %mipName; - allowReflectPass = false; - shader = Bloom_DownSampleShader; - stateBlock = Bloom_SampleStateBlock; - texture[0] = %textureName; - target = "#" @ %mipName; - targetScale = "0.5 0.5"; - targetFormat = %this.mipTexFormat; - }; - - %blurFX.add(%mipFX); - %textureName = "#" @ %mipName; - } - - for (%idx = %this.mipsCount; %idx > 0; %idx--) - { - %nxt = "#bloom_" @ (%idx - 1); - %mipName = "upSample_" @ (%idx - 1); - - %mipFX = new PostEffect() - { - internalName = %mipName; - allowReflectPass = false; - shader = Bloom_UpSampleShader; - stateBlock = Bloom_SampleStateBlock; - texture[0] = %nxt; - texture[1] = %textureName; - target = "#" @ %mipName; - targetScale = "1.0 1.0"; - targetFormat = %this.mipTexFormat; - }; - - %blurFX.add(%mipFX); - %textureName = "#" @ %mipName; - } - - %this.add(%blurFX); -} - -function BloomPostFX::onAdd(%this) -{ - %this.SetupBlurFX(); - //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.addField("$PostFX::BloomPostFX::threshold", "Threshold", "range", "", $PostFX::BloomPostFX::threshold, "0 1 10"); - PostEffectEditorInspector.addField("$PostFX::BloomPostFX::intensity", "Intensity", "range", "", $PostFX::BloomPostFX::intensity, "0 10 10"); - PostEffectEditorInspector.addField("$PostFX::BloomPostFX::radius", "Radius", "float", "", $PostFX::BloomPostFX::radius, ""); - PostEffectEditorInspector.endGroup(); - - PostEffectEditorInspector.startGroup("BloomPostFX - Lens Dirt"); - PostEffectEditorInspector.addField("$PostFX::BloomPostFX::dirtEnabled", "Enable Dirt", "bool", "", $PostFX::BloomPostFX::dirtEnabled, ""); - PostEffectEditorInspector.addField("$PostFX::BloomPostFX::dirtScale", "Scale", "float", "", $PostFX::BloomPostFX::dirtScale, ""); - PostEffectEditorInspector.addField("$PostFX::BloomPostFX::dirtIntensity", "Intensity", "float", "", $PostFX::BloomPostFX::dirtIntensity, ""); - PostEffectEditorInspector.addField("$PostFX::BloomPostFX::dirtEdgeMinDist", "Min Dist", "range", "", $PostFX::BloomPostFX::dirtEdgeMinDist, "0 1 10"); - PostEffectEditorInspector.addField("$PostFX::BloomPostFX::dirtEdgeMaxDist", "Max Dist", "range", "", $PostFX::BloomPostFX::dirtEdgeMaxDist, "0 1 10"); - PostEffectEditorInspector.addField("$PostFX::BloomPostFX::dirtEdgeMinVal", "Min Value", "range", "", $PostFX::BloomPostFX::dirtEdgeMinVal, "0 1 10"); - PostEffectEditorInspector.addField("$PostFX::BloomPostFX::dirtImage", "Dirt Image", "image", "", $PostFX::BloomPostFX::dirtImage, ""); - 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"); - PostFXManager::savePresetSetting("$PostFX::BloomPostFX::threshold"); - PostFXManager::savePresetSetting("$PostFX::BloomPostFX::intensity"); - PostFXManager::savePresetSetting("$PostFX::BloomPostFX::radius"); - - PostFXManager::savePresetSetting("$PostFX::BloomPostFX::dirtEnabled"); - PostFXManager::savePresetSetting("$PostFX::BloomPostFX::dirtScale"); - PostFXManager::savePresetSetting("$PostFX::BloomPostFX::dirtIntensity"); - PostFXManager::savePresetSetting("$PostFX::BloomPostFX::dirtImage"); - - PostFXManager::savePresetSetting("$PostFX::BloomPostFX::dirtEdgeMinDist"); - PostFXManager::savePresetSetting("$PostFX::BloomPostFX::dirtEdgeMaxDist"); - PostFXManager::savePresetSetting("$PostFX::BloomPostFX::dirtEdgeMinVal"); -} - -//Our actual postFX -singleton PostEffect( BloomPostFX ) -{ - mipsCount = 5; - mipTexFormat = "GFXFormatR16G16B16A16F"; - - enabled = false; - allowReflectPass = false; - - renderTime = "PFXBeforeBin"; - renderBin = "EditorBin"; - renderPriority = 10000; - - shader = Bloom_ThresholdShader; - stateBlock = Bloom_SampleStateBlock; - texture[0] = "$backBuffer"; - target = "#threshold"; - targetFormat = "GFXFormatR16G16B16A16F"; - - new PostEffect() - { - internalName = "bloomFinal"; - allowReflectPass = false; - shader = Bloom_StrengthShader; - stateBlock = Bloom_Add_SampleStateBlock; - texture[0] = "#upSample_0"; - target = "$backBuffer"; - }; -}; diff --git a/Templates/BaseGame/game/core/postFX/scripts/HDR/HDRPostFX.tscript b/Templates/BaseGame/game/core/postFX/scripts/HDR/HDRPostFX.tscript index 1d0b7485d..b20b978b3 100644 --- a/Templates/BaseGame/game/core/postFX/scripts/HDR/HDRPostFX.tscript +++ b/Templates/BaseGame/game/core/postFX/scripts/HDR/HDRPostFX.tscript @@ -56,74 +56,89 @@ $PostFX::HDRPostFX::minLuminace = 0.001; /// average scene luminance. $PostFX::HDRPostFX::adaptRate = 0.85; -/// Blends between the scene and the bloomed scene. -$PostFX::HDRPostFX::enableBloom = 1.0; +// Inspired by bloom described in paper listed here: +// http://www.iryoku.com/next-generation-post-processing-in-call-of-duty-advanced-warfare -/// The threshold luminace value for pixels which are -/// considered "bright" and need to be bloomed. -$PostFX::HDRPostFX::brightPassThreshold = 0.08; +$PostFX::HDRPostFX::enableBloom = true; +$PostFX::HDRPostFX::threshold = 0.0; +$PostFX::HDRPostFX::intensity = 1.0; +$PostFX::HDRPostFX::radius = 4.0; -/// These are used in the gaussian blur of the -/// bright pass for the bloom effect. -$PostFX::HDRPostFX::gaussMultiplier = 0.4; -$PostFX::HDRPostFX::gaussMean = 0; -$PostFX::HDRPostFX::gaussStdDev = 0.5; +$PostFX::HDRPostFX::enableDirt = true; +$PostFX::HDRPostFX::dirtScale = 2048.0; +$PostFX::HDRPostFX::dirtIntensity = 2.0; +$PostFX::HDRPostFX::dirtEdgeMinDist = 0.125; +$PostFX::HDRPostFX::dirtEdgeMaxDist = 0.75; +$PostFX::HDRPostFX::dirtEdgeMinVal = 0.05; +$PostFX::HDRPostFX::dirtImage = "core/postFX/images/lensDirt.png"; // The tonemapping algo to use $PostFX::HDRPostFX::tonemapMode = "ACES"; $PostFX::HDRPostFX::enableAutoExposure = true; - -singleton ShaderData( HDR_BrightPassShader ) +singleton ShaderData( HDR_BloomInitShader ) { - DXVertexShaderFile = $Core::CommonShaderPath @ "/postFX/postFxV.hlsl"; - DXPixelShaderFile = "./HDR_utils/brightPassFilterP.hlsl"; - OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFX/gl/postFxV.glsl"; - OGLPixelShaderFile = "./HDR_utils/brightPassFilterP.glsl"; - - samplerNames[0] = "$inputTex"; - samplerNames[1] = "$luminanceTex"; - - pixVersion = 3.0; -}; - -singleton ShaderData( HDR_DownScale4x4Shader ) -{ - DXVertexShaderFile = "./HDR_Bloom/downScale4x4V.hlsl"; - DXPixelShaderFile = "./HDR_Bloom/downScale4x4P.hlsl"; - OGLVertexShaderFile = "./HDR_Bloom/downScale4x4V.glsl"; - OGLPixelShaderFile = "./HDR_Bloom/downScale4x4P.glsl"; - - samplerNames[0] = "$inputTex"; - - pixVersion = 2.0; -}; - -singleton ShaderData( HDR_BloomGaussBlurHShader ) -{ - DXVertexShaderFile = $Core::CommonShaderPath @ "/postFX/postFxV.hlsl"; - DXPixelShaderFile = "./HDR_Bloom/bloomGaussBlurHP.hlsl"; - OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFX/gl/postFxV.glsl"; - OGLPixelShaderFile = "./HDR_Bloom/bloomGaussBlurHP.glsl"; + DXVertexShaderFile = $Core::CommonShaderPath @ "/postFX/postFxV.hlsl"; + DXPixelShaderFile = "./HDR_Bloom/bloomInitSample.hlsl"; + OGLVertexShaderFile= $Core::CommonShaderPath @ "/postFX/gl/postFxV.glsl"; + OGLPixelShaderFile = "./HDR_Bloom/bloomInitSample.glsl"; samplerNames[0] = "$inputTex"; pixVersion = 3.0; }; -singleton ShaderData( HDR_BloomGaussBlurVShader ) +singleton ShaderData( HDR_BloomThresholdShader ) { - DXVertexShaderFile = $Core::CommonShaderPath @ "/postFX/postFxV.hlsl"; - DXPixelShaderFile = "./HDR_Bloom/bloomGaussBlurVP.hlsl"; - OGLVertexShaderFile = $Core::CommonShaderPath @ "/postFX/gl/postFxV.glsl"; - OGLPixelShaderFile = "./HDR_Bloom/bloomGaussBlurVP.glsl"; + DXVertexShaderFile = $Core::CommonShaderPath @ "/postFX/postFxV.hlsl"; + DXPixelShaderFile = "./HDR_Bloom/bloomThresholdP.hlsl"; + OGLVertexShaderFile= $Core::CommonShaderPath @ "/postFX/gl/postFxV.glsl"; + OGLPixelShaderFile = "./HDR_Bloom/bloomThresholdP.glsl"; samplerNames[0] = "$inputTex"; pixVersion = 3.0; }; +singleton ShaderData( HDR_BloomDownSampleShader ) +{ + DXVertexShaderFile = $Core::CommonShaderPath @ "/postFX/postFxV.hlsl"; + DXPixelShaderFile = "./HDR_Bloom/downSampleP.hlsl"; + OGLVertexShaderFile= $Core::CommonShaderPath @ "/postFX/gl/postFxV.glsl"; + OGLPixelShaderFile = "./HDR_Bloom/downSampleP.glsl"; + + samplerNames[0] = "$inputTex"; + + pixVersion = 3.0; +}; + +singleton ShaderData( HDR_BloomUpSampleShader ) +{ + DXVertexShaderFile = $Core::CommonShaderPath @ "/postFX/postFxV.hlsl"; + DXPixelShaderFile = "./HDR_Bloom/upSampleP.hlsl"; + OGLVertexShaderFile= $Core::CommonShaderPath @ "/postFX/gl/postFxV.glsl"; + OGLPixelShaderFile = "./HDR_Bloom/upSampleP.glsl"; + + samplerNames[0] = "$nxtTex"; + samplerNames[1] = "$mipTex"; + + pixVersion = 3.0; +}; + +singleton ShaderData( HDR_BloomDirtShader ) +{ + DXVertexShaderFile = $Core::CommonShaderPath @ "/postFX/postFxV.hlsl"; + DXPixelShaderFile = "./HDR_Bloom/bloomStrengthP.hlsl"; + OGLVertexShaderFile= $Core::CommonShaderPath @ "/postFX/gl/postFxV.glsl"; + OGLPixelShaderFile = "./HDR_Bloom/bloomStrengthP.glsl"; + + samplerNames[0] = "$inputTex"; + samplerNames[1] = "$dirtTex"; + + pixVersion = 3.0; +}; + singleton ShaderData( HDR_SampleLumShader ) { DXVertexShaderFile = $Core::CommonShaderPath @ "/postFX/postFxV.hlsl"; @@ -191,6 +206,13 @@ singleton GFXStateBlockData( HDR_DownSampleStateBlock : PFX_DefaultStateBlock ) samplerStates[1] = SamplerClampLinear; }; +singleton GFXStateBlockData( HDR_LensDirtStateBlock : PFX_DefaultStateBlock ) +{ + samplersDefined = true; + samplerStates[0] = SamplerClampLinear; + samplerStates[1] = SamplerWrapLinear; +}; + singleton GFXStateBlockData( HDR_CombineStateBlock : PFX_DefaultStateBlock ) { samplersDefined = true; @@ -223,23 +245,7 @@ singleton GFXStateBlockData( HDRStateBlock ) function HDRPostFX::setShaderConsts( %this ) { - %this.setShaderConst( "$brightPassThreshold", $PostFX::HDRPostFX::brightPassThreshold ); - %this.setShaderConst( "$g_fMiddleGray", $PostFX::HDRPostFX::keyValue ); - %this.setShaderConst( "$exposureValue", $PostFX::HDRPostFX::exposureValue ); - %this.setShaderConst( "$whitePoint", $PostFX::HDRPostFX::whitePoint ); - %this.setShaderConst( "$logContrast", $PostFX::HDRPostFX::logContrast ); - %this.setShaderConst( "$saturationValue", $PostFX::HDRPostFX::saturationValue ); - - - %bloomH = %this-->bloomH; - %bloomH.setShaderConst( "$gaussMultiplier", $PostFX::HDRPostFX::gaussMultiplier ); - %bloomH.setShaderConst( "$gaussMean", $PostFX::HDRPostFX::gaussMean ); - %bloomH.setShaderConst( "$gaussStdDev", $PostFX::HDRPostFX::gaussStdDev ); - - %bloomV = %this-->bloomV; - %bloomV.setShaderConst( "$gaussMultiplier", $PostFX::HDRPostFX::gaussMultiplier ); - %bloomV.setShaderConst( "$gaussMean", $PostFX::HDRPostFX::gaussMean ); - %bloomV.setShaderConst( "$gaussStdDev", $PostFX::HDRPostFX::gaussStdDev ); + %this.setShaderConst( "$g_fMiddleGray", $PostFX::HDRPostFX::keyValue ); %minLuminace = $PostFX::HDRPostFX::minLuminace; if ( %minLuminace <= 0.0 ) @@ -262,8 +268,7 @@ function HDRPostFX::setShaderConsts( %this ) %combinePass.setShaderConst( "$colorFilter", $PostFX::HDRPostFX::colorFilter ); %combinePass.setShaderConst( "$saturationValue", $PostFX::HDRPostFX::saturationValue ); %combinePass.setShaderConst( "$logContrast", $PostFX::HDRPostFX::logContrast ); - - %combinePass.setShaderConst( "$g_fBloomScale", $PostFX::HDRPostFX::enableBloom ); + %combinePass.setShaderConst( "$g_fEnableAutoExposure", $PostFX::HDRPostFX::enableAutoExposure ); %tonemapMode = 1; @@ -285,7 +290,35 @@ function HDRPostFX::setShaderConsts( %this ) %combinePass.setShaderConst( "$g_fOneOverGamma", 1 / %clampedGamma ); %combinePass.setShaderConst( "$Brightness", $pref::Video::Brightness ); %combinePass.setShaderConst( "$Contrast", $pref::Video::Contrast ); - + + // /----- BLOOM CONSTS -----/ + %bloom = %this->hdrbloom; + %bloom.skip = !$PostFX::HDRPostFX::enableBloom; + + %bloom.setShaderConst("$threshold", $PostFX::HDRPostFX::threshold); + + for (%idx = 0; %idx < %this.mipsCount; %idx++) + { + %mip = %bloom.getObject(%this.mipsCount + %idx); + %mip.setShaderConst("$filterRadius", $PostFX::HDRPostFX::radius); + } + + %strength = $PostFX::HDRPostFX::intensity; + if (!$PostFX::HDRPostFX::enableBloom) + %strength = 0.0; + + %bloomFinal = %this->hdrbloom_end; + %bloomFinal.setShaderConst("$strength", %strength); + + %dirtScale = $PostFX::HDRPostFX::dirtScale; + %dirtIntensity = $PostFX::HDRPostFX::dirtIntensity; + %bloomFinal.setShaderConst("$dirtParams", %dirtScale SPC %dirtScale SPC %dirtIntensity); + + %edgeMin = $PostFX::HDRPostFX::dirtEdgeMinDist; + %edgeMax = $PostFX::HDRPostFX::dirtEdgeMaxDist; + %edgeVal = $PostFX::HDRPostFX::dirtEdgeMinVal; + %bloomFinal.setShaderConst("$edgeParams", %edgeMin SPC %edgeMax SPC %edgeVal); + // \----- BLOOM CONSTS -----\ } function HDRPostFX::preProcess( %this ) @@ -293,7 +326,31 @@ function HDRPostFX::preProcess( %this ) %combinePass = %this-->combinePass; if ( %combinePass.texture[3] !$= $PostFX::HDRPostFX::colorCorrectionRamp ) - %combinePass.setTexture( 3, $PostFX::HDRPostFX::colorCorrectionRamp ); + %combinePass.setTexture( 3, $PostFX::HDRPostFX::colorCorrectionRamp ); + + // /----- BLOOM CONSTS -----/ + %bloomFinal = %this->hdrbloom_end; + + if (%this.enableDirt != $PostFX::HDRPostFX::enableDirt) + { + %this.enableDirt = $PostFX::HDRPostFX::enableDirt; + + if (%this.enableDirt) + { + %bloomFinal.setShaderMacro("USE_DIRT"); + } else { + %bloomFinal.removeShaderMacro("USE_DIRT"); + } + } + + if(%bloomFinal.texture[1] !$= $PostFX::HDRPostFX::dirtImage) + { + if ($PostFX::HDRPostFX::dirtImage $= "") + $PostFX::HDRPostFX::dirtImage = "core/postFX/images/lensDirt.png"; + + %bloomFinal.setTexture(1, $PostFX::HDRPostFX::dirtImage); + } + // \----- BLOOM CONSTS -----\ } function HDRPostFX::onEnabled( %this ) @@ -355,6 +412,8 @@ function HDRPostFX::onDisabled( %this ) function HDRPostFX::onAdd( %this ) { + %this.SetupBloomFX(); + PostFXManager.registerPostEffect(%this); $PostFX::HDRPostFX::enableToneMapping = 1; @@ -382,11 +441,24 @@ function HDRPostFX::populatePostFXSettings(%this) PostEffectEditorInspector.addField("$PostFX::HDRPostFX::colorFilter", "Color Tint", "colorF", "", $PostFX::HDRPostFX::colorFilter, "0 0 0"); PostEffectEditorInspector.endGroup(); - PostEffectEditorInspector.startGroup("HDR - HDR Bloom"); - PostEffectEditorInspector.addField("$PostFX::HDRPostFX::enableBloom", "Enable HDR Bloom", "bool", "", $PostFX::HDRPostFX::enableBloom, ""); - PostEffectEditorInspector.addField("$PostFX::HDRPostFX::gaussMultiplier", "Bloom Multiplier", "range", "", $PostFX::HDRPostFX::gaussMultiplier, "0.0 1.0 2.0"); - PostEffectEditorInspector.addField("$PostFX::HDRPostFX::brightPassThreshold", "Bright Pass Threshold", "float", "", $PostFX::HDRPostFX::brightPassThreshold, ""); - PostEffectEditorInspector.endGroup(); + // /----- BLOOM SETTINGS -----/ + PostEffectEditorInspector.startGroup("HDR - Bloom"); + PostEffectEditorInspector.addField("$PostFX::HDRPostFX::enableBloom", "Enable Bloom", "bool", "", $PostFX::HDRPostFX::enableBloom, ""); + PostEffectEditorInspector.addField("$PostFX::HDRPostFX::threshold", "Threshold", "range", "", $PostFX::HDRPostFX::threshold, "0 1 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.endGroup(); + + PostEffectEditorInspector.startGroup("HDR - Lens Dirt"); + PostEffectEditorInspector.addField("$PostFX::HDRPostFX::enableDirt", "Enable Dirt", "bool", "", $PostFX::HDRPostFX::enableDirt, ""); + PostEffectEditorInspector.addField("$PostFX::HDRPostFX::dirtScale", "Scale", "float", "", $PostFX::HDRPostFX::dirtScale, ""); + PostEffectEditorInspector.addField("$PostFX::HDRPostFX::dirtIntensity", "Intensity", "float", "", $PostFX::HDRPostFX::dirtIntensity, ""); + PostEffectEditorInspector.addField("$PostFX::HDRPostFX::dirtEdgeMinDist", "Min Dist", "range", "", $PostFX::HDRPostFX::dirtEdgeMinDist, "0 1 10"); + PostEffectEditorInspector.addField("$PostFX::HDRPostFX::dirtEdgeMaxDist", "Max Dist", "range", "", $PostFX::HDRPostFX::dirtEdgeMaxDist, "0 1 10"); + PostEffectEditorInspector.addField("$PostFX::HDRPostFX::dirtEdgeMinVal", "Min Value", "range", "", $PostFX::HDRPostFX::dirtEdgeMinVal, "0 1 10"); + PostEffectEditorInspector.addField("$PostFX::HDRPostFX::dirtImage", "Dirt Image", "image", "", $PostFX::HDRPostFX::dirtImage, ""); + PostEffectEditorInspector.endGroup(); + // \----- BLOOM SETTINGS -----\ PostEffectEditorInspector.startGroup("HDR - Adaptation"); PostEffectEditorInspector.addField("$PostFX::HDRPostFX::enableAutoExposure", "Enable Auto Exposure", "bool", "", $PostFX::HDRPostFX::enableAutoExposure, ""); @@ -426,11 +498,93 @@ function HDRPostFX::savePresetSettings(%this) PostFXManager::savePresetSetting("$PostFX::HDRPostFX::whiteCutoff"); PostFXManager::savePresetSetting("$PostFX::HDRPostFX::adaptRate"); PostFXManager::savePresetSetting("$PostFX::HDRPostFX::tonemapMode"); - PostFXManager::savePresetSetting("$PostFX::HDRPostFX::enableBloom"); - PostFXManager::savePresetSetting("$PostFX::HDRPostFX::brightPassThreshold"); - PostFXManager::savePresetSetting("$PostFX::HDRPostFX::gaussMultiplier"); PostFXManager::savePresetSetting("$PostFX::HDRPostFX::enableAutoExposure"); PostFXManager::savePresetSetting("$PostFX::HDRPostFX::keyValue"); + + // /----- BLOOM SETTINGS -----/ + PostFXManager::savePresetSetting("$PostFX::HDRPostFX::enableBloom"); + PostFXManager::savePresetSetting("$PostFX::HDRPostFX::threshold"); + PostFXManager::savePresetSetting("$PostFX::HDRPostFX::intensity"); + PostFXManager::savePresetSetting("$PostFX::HDRPostFX::radius"); + PostFXManager::savePresetSetting("$PostFX::HDRPostFX::enableDirt"); + PostFXManager::savePresetSetting("$PostFX::HDRPostFX::dirtScale"); + PostFXManager::savePresetSetting("$PostFX::HDRPostFX::dirtIntensity"); + PostFXManager::savePresetSetting("$PostFX::HDRPostFX::dirtImage"); + PostFXManager::savePresetSetting("$PostFX::HDRPostFX::dirtEdgeMinDist"); + PostFXManager::savePresetSetting("$PostFX::HDRPostFX::dirtEdgeMaxDist"); + PostFXManager::savePresetSetting("$PostFX::HDRPostFX::dirtEdgeMinVal"); + // \----- BLOOM SETTINGS -----\ +} + +// This function sets up s sort of "mip-chain" for the bloom effect +// Not really "optimal" but it works well enough +function HDRPostFX::SetupBloomFX( %this ) +{ + %bloomFX = new PostEffect() + { + internalName = "hdrbloom"; + allowReflectPass = false; + shader = HDR_BloomThresholdShader; + stateBlock = HDR_DownSampleStateBlock; + texture[0] = "#hdrInitBloom"; + target = "#hdrbloom_0"; + targetFormat = %this.mipTexFormat; + }; + + %textureName = "#hdrbloom_0"; + for (%idx = 0; %idx < %this.mipsCount; %idx++) + { + %mipName = "hdrbloom_" @ (%idx + 1); + %mipFX = new PostEffect() + { + internalName = %mipName; + allowReflectPass = false; + shader = HDR_BloomDownSampleShader; + stateBlock = HDR_DownSampleStateBlock; + texture[0] = %textureName; + target = "#" @ %mipName; + targetScale = "0.5 0.5"; + targetFormat = %this.mipTexFormat; + }; + + %bloomFX.add(%mipFX); + %textureName = "#" @ %mipName; + } + + for (%idx = %this.mipsCount; %idx > 0; %idx--) + { + %nxt = "#hdrbloom_" @ (%idx - 1); + %mipName = "hdrbloom_up_" @ (%idx - 1); + + %mipFX = new PostEffect() + { + internalName = %mipName; + allowReflectPass = false; + shader = HDR_BloomUpSampleShader; + stateBlock = HDR_DownSampleStateBlock; + texture[0] = %nxt; + texture[1] = %textureName; + target = "#" @ %mipName; + targetFormat = %this.mipTexFormat; + }; + + %bloomFX.add(%mipFX); + %textureName = "#" @ %mipName; + } + + %finalFX = new PostEffect() + { + internalName = "hdrbloom_end"; + allowReflectPass = false; + shader = HDR_BloomDirtShader; + stateBlock = HDR_LensDirtStateBlock; + texture[0] = "#hdrbloom_up_0"; + target = "#hdrbloom_end"; + targetFormat = %this.mipTexFormat; + }; + %this.add(%finalFX); + + %this.add(%bloomFX); } singleton PostEffect( HDRPostFX ) @@ -443,6 +597,12 @@ singleton PostEffect( HDRPostFX ) renderTime = "PFXBeforeBin"; renderBin = "EditorBin"; renderPriority = 9999; + + // Hardcoded bloom settings. + // -- Amount of mip targets the bloom uses. + mipsCount = 5; + // -- Texture format for mip targets. + mipTexFormat = "GFXFormatR16G16B16A16F"; // The bright pass generates a bloomed version of // the scene for pixels which are brighter than a @@ -452,48 +612,15 @@ singleton PostEffect( HDRPostFX ) // at the end of this post effect chain. // - shader = HDR_BrightPassShader; - stateBlock = HDR_DownSampleStateBlock; - texture[0] = "$backBuffer"; - texture[1] = "#adaptedLum"; - target = "$outTex"; - targetFormat = "GFXFormatR16G16B16A16F"; - targetScale = "0.5 0.5"; - - new PostEffect() - { - allowReflectPass = false; - shader = HDR_DownScale4x4Shader; - stateBlock = HDR_DownSampleStateBlock; - texture[0] = "$inTex"; - target = "$outTex"; - targetFormat = "GFXFormatR16G16B16A16F"; - targetScale = "0.25 0.25"; - }; - - new PostEffect() - { - allowReflectPass = false; - internalName = "bloomH"; - - shader = HDR_BloomGaussBlurHShader; - stateBlock = HDR_DownSampleStateBlock; - texture[0] = "$inTex"; - target = "$outTex"; - targetFormat = "GFXFormatR16G16B16A16F"; - }; + shader = HDR_BloomInitShader; + stateBlock = HDR_DownSampleStateBlock; + texture[0] = "$backBuffer"; + texture[1] = "#adaptedLum"; + target = "#hdrInitBloom"; + targetFormat = "GFXFormatR16G16B16A16F"; + targetScale = "0.5 0.5"; - new PostEffect() - { - allowReflectPass = false; - internalName = "bloomV"; - - shader = HDR_BloomGaussBlurVShader; - stateBlock = HDR_DownSampleStateBlock; - texture[0] = "$inTex"; - target = "#bloomFinal"; - targetFormat = "GFXFormatR16G16B16A16F"; - }; + // Bloom should get inserted about here. // BrightPass End @@ -572,7 +699,7 @@ singleton PostEffect( HDRPostFX ) stateBlock = HDR_CombineStateBlock; texture[0] = "$backBuffer"; texture[1] = "#adaptedLum"; - texture[2] = "#bloomFinal"; + texture[2] = "#hdrbloom_end"; texture[3] = $PostFX::HDRPostFX::colorCorrectionRamp; target = "$backBuffer"; }; diff --git a/Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_Bloom/bloomGaussBlurHP.glsl b/Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_Bloom/bloomGaussBlurHP.glsl deleted file mode 100644 index 48e654ddc..000000000 --- a/Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_Bloom/bloomGaussBlurHP.glsl +++ /dev/null @@ -1,72 +0,0 @@ -//----------------------------------------------------------------------------- -// 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" -#include "core/rendering/shaders/postFX/gl/postFx.glsl" - -uniform sampler2D inputTex ; -uniform vec2 oneOverTargetSize; -uniform float gaussMultiplier; -uniform float gaussMean; -uniform float gaussStdDev; - -out vec4 OUT_col; - -#define PI 3.141592654 - -float computeGaussianValue( float x, float mean, float std_deviation ) -{ - // The gaussian equation is defined as such: - /* - -(x - mean)^2 - ------------- - 1.0 2*std_dev^2 - f(x,mean,std_dev) = -------------------- * e^ - sqrt(2*pi*std_dev^2) - - */ - - float tmp = ( 1.0f / sqrt( 2.0f * PI * std_deviation * std_deviation ) ); - float tmp2 = exp( ( -( ( x - mean ) * ( x - mean ) ) ) / ( 2.0f * std_deviation * std_deviation ) ); - return tmp * tmp2; -} - -void main() -{ - vec4 color = vec4( 0.0f, 0.0f, 0.0f, 0.0f ); - float offset = 0; - float weight = 0; - float x = 0; - float fI = 0; - - for( int i = 0; i < 9; i++ ) - { - fI = float(i); - offset = (i - 4.0) * oneOverTargetSize.x; - x = (i - 4.0) / 4.0; - weight = gaussMultiplier * computeGaussianValue( x, gaussMean, gaussStdDev ); - color += (texture( inputTex, IN_uv0 + vec2( offset, 0.0f ) ) * weight ); - } - - OUT_col = vec4( color.rgb, 1.0f ); -} \ No newline at end of file diff --git a/Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_Bloom/bloomGaussBlurHP.hlsl b/Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_Bloom/bloomGaussBlurHP.hlsl deleted file mode 100644 index 48e490e7c..000000000 --- a/Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_Bloom/bloomGaussBlurHP.hlsl +++ /dev/null @@ -1,111 +0,0 @@ -//----------------------------------------------------------------------------- -// 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); -uniform float2 oneOverTargetSize; -uniform float gaussMultiplier; -uniform float gaussMean; -uniform float gaussStdDev; - -#define PI 3.141592654 - -float computeGaussianValue( float x, float mean, float std_deviation ) -{ - // The gaussian equation is defined as such: - /* - -(x - mean)^2 - ------------- - 1.0 2*std_dev^2 - f(x,mean,std_dev) = -------------------- * e^ - sqrt(2*pi*std_dev^2) - - */ - - float tmp = ( 1.0f / sqrt( 2.0f * PI * std_deviation * std_deviation ) ); - float tmp2 = exp( ( -( ( x - mean ) * ( x - mean ) ) ) / ( 2.0f * std_deviation * std_deviation ) ); - return tmp * tmp2; -} - -float SCurve (float x) -{ - x = x * 2.0 - 1.0; - return -x * abs(x) * 0.5 + x + 0.5; -} - -float4 BlurH (TORQUE_SAMPLER2D(source), float2 size, float2 uv, float radius) -{ - if (radius >= 1.0) - { - float4 A = float4(0.0,0.0,0.0,0.0); - float4 C = float4(0.0,0.0,0.0,0.0); - - float width = 1.0 / size.x; - - float divisor = 0.0; - float weight = 0.0; - - float radiusMultiplier = 1.0 / radius; - - // Hardcoded for radius 20 (normally we input the radius - // in there), needs to be literal here - - for (float x = -20.0; x <= 20.0; x++) - { - A = TORQUE_TEX2D(source, uv + float2(x * width, 0.0)); - - weight = SCurve(1.0 - (abs(x) * radiusMultiplier)); - - C += A * weight; - - divisor += weight; - } - - return float4(C.r / divisor, C.g / divisor, C.b / divisor, 1.0); - } - - return TORQUE_TEX2D(source, uv); -} - -float4 main( PFXVertToPix IN ) : TORQUE_TARGET0 -{ - float4 color = { 0.0f, 0.0f, 0.0f, 0.0f }; - float offset = 0; - float weight = 0; - float x = 0; - float fI = 0; - - for( int i = 0; i < 9; i++ ) - { - fI = (float)i; - offset = (i - 4.0) * oneOverTargetSize.x; - x = (i - 4.0) / 4.0; - weight = gaussMultiplier * computeGaussianValue( x, gaussMean, gaussStdDev ); - color += (TORQUE_TEX2D( inputTex, IN.uv0 + float2( offset, 0.0f ) ) * weight ); - } - - //float2 targetSize = 1/oneOverTargetSize; - //float4 color = BlurH(TORQUE_SAMPLER2D_MAKEARG(inputTex), targetSize, IN.uv0, 20.0); - - return float4( color.rgb, 1.0f ); -} \ No newline at end of file diff --git a/Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_Bloom/bloomGaussBlurVP.glsl b/Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_Bloom/bloomGaussBlurVP.glsl deleted file mode 100644 index 04e45e1e3..000000000 --- a/Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_Bloom/bloomGaussBlurVP.glsl +++ /dev/null @@ -1,71 +0,0 @@ -//----------------------------------------------------------------------------- -// 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" -#include "core/rendering/shaders/postFX/gl/postFx.glsl" - -uniform sampler2D inputTex ; -uniform vec2 oneOverTargetSize; -uniform float gaussMultiplier; -uniform float gaussMean; -uniform float gaussStdDev; - -out vec4 OUT_col; - -#define D3DX_PI 3.141592654 - -float computeGaussianValue( float x, float mean, float std_deviation ) -{ - // The gaussian equation is defined as such: - /* - -(x - mean)^2 - ------------- - 1.0 2*std_dev^2 - f(x,mean,std_dev) = -------------------- * e^ - sqrt(2*pi*std_dev^2) - - */ - float tmp = ( 1.0f / sqrt( 2.0f * D3DX_PI * std_deviation * std_deviation ) ); - float tmp2 = exp( ( -( ( x - mean ) * ( x - mean ) ) ) / ( 2.0f * std_deviation * std_deviation ) ); - return tmp * tmp2; -} - -void main() -{ - vec4 color = vec4( 0.0f, 0.0f, 0.0f, 0.0f ); - float offset = 0; - float weight = 0; - float x = 0; - float fI = 0; - - for( int i = 0; i < 9; i++ ) - { - fI = float(i); - offset = (fI - 4.0) * oneOverTargetSize.y; - x = (fI - 4.0) / 4.0; - weight = gaussMultiplier * computeGaussianValue( x, gaussMean, gaussStdDev ); - color += (texture( inputTex, IN_uv0 + vec2( 0.0f, offset ) ) * weight ); - } - - OUT_col = vec4( color.rgb, 1.0f ); -} \ No newline at end of file diff --git a/Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_Bloom/bloomGaussBlurVP.hlsl b/Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_Bloom/bloomGaussBlurVP.hlsl deleted file mode 100644 index bd8e16a16..000000000 --- a/Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_Bloom/bloomGaussBlurVP.hlsl +++ /dev/null @@ -1,108 +0,0 @@ -//----------------------------------------------------------------------------- -// 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); -uniform float2 oneOverTargetSize; -uniform float gaussMultiplier; -uniform float gaussMean; -uniform float gaussStdDev; - -#define D3DX_PI 3.141592654 - -float computeGaussianValue( float x, float mean, float std_deviation ) -{ - // The gaussian equation is defined as such: - /* - -(x - mean)^2 - ------------- - 1.0 2*std_dev^2 - f(x,mean,std_dev) = -------------------- * e^ - sqrt(2*pi*std_dev^2) - - */ - float tmp = ( 1.0f / sqrt( 2.0f * D3DX_PI * std_deviation * std_deviation ) ); - float tmp2 = exp( ( -( ( x - mean ) * ( x - mean ) ) ) / ( 2.0f * std_deviation * std_deviation ) ); - return tmp * tmp2; -} - -float SCurve (float x) -{ - x = x * 2.0 - 1.0; - return -x * abs(x) * 0.5 + x + 0.5; -} - -float4 BlurV (TORQUE_SAMPLER2D(source), float2 size, float2 uv, float radius) -{ - if (radius >= 1.0) - { - float4 A = float4(0.0,0.0,0.0,0.0); - float4 C = float4(0.0,0.0,0.0,0.0); - - float height = 1.0 / size.y; - - float divisor = 0.0; - float weight = 0.0; - - float radiusMultiplier = 1.0 / radius; - - for (float y = -20.0; y <= 20.0; y++) - { - A = TORQUE_TEX2D(source, uv + float2(0.0, y * height)); - - weight = SCurve(1.0 - (abs(y) * radiusMultiplier)); - - C += A * weight; - - divisor += weight; - } - - return float4(C.r / divisor, C.g / divisor, C.b / divisor, 1.0); - } - - return TORQUE_TEX2D(source, uv); -} - - -float4 main( PFXVertToPix IN ) : TORQUE_TARGET0 -{ - float4 color = { 0.0f, 0.0f, 0.0f, 0.0f }; - float offset = 0; - float weight = 0; - float x = 0; - float fI = 0; - - for( int i = 0; i < 9; i++ ) - { - fI = (float)i; - offset = (fI - 4.0) * oneOverTargetSize.y; - x = (fI - 4.0) / 4.0; - weight = gaussMultiplier * computeGaussianValue( x, gaussMean, gaussStdDev ); - color += (TORQUE_TEX2D( inputTex, IN.uv0 + float2( 0.0f, offset ) ) * weight ); - } - - //float2 targetSize = 1/oneOverTargetSize; - //float4 color = BlurV(TORQUE_SAMPLER2D_MAKEARG(inputTex), targetSize, IN.uv0, 20.0); - - return float4( color.rgb, 1.0f ); -} \ No newline at end of file diff --git a/Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_Bloom/downScale4x4P.glsl b/Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_Bloom/bloomInitSample.glsl similarity index 65% rename from Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_Bloom/downScale4x4P.glsl rename to Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_Bloom/bloomInitSample.glsl index 5945ca60e..3c6ef6e6c 100644 --- a/Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_Bloom/downScale4x4P.glsl +++ b/Templates/BaseGame/game/core/postFX/scripts/HDR/HDR_Bloom/bloomInitSample.glsl @@ -20,31 +20,40 @@ // IN THE SOFTWARE. //----------------------------------------------------------------------------- -#define IN_GLSL -#include "core/rendering/shaders/shdrConsts.h" #include "core/rendering/shaders/gl/hlslCompat.glsl" +#include "core/rendering/shaders/postFX/gl/postFx.glsl" +#include "core/rendering/shaders/gl/torque.glsl" #include "shadergen:/autogenConditioners.h" -in vec4 texCoords[8]; -#define IN_texCoords texCoords +#define KERNEL_SAMPLES 4 +const vec2 KERNEL[9] = vec2[]( + vec2( 0.5, 0.5), + vec2( 0.5,-0.5), + vec2(-0.5,-0.5), + vec2(-0.5, 0.5) +); uniform sampler2D inputTex; +uniform sampler2D luminanceTex; +uniform float g_fMiddleGray; +uniform vec2 oneOverTargetSize; out vec4 OUT_col; - -//----------------------------------------------------------------------------- -// Main -//----------------------------------------------------------------------------- + void main() { - // We calculate the texture coords - // in the vertex shader as an optimization. - vec4 _sample = vec4(0.0f); - for ( int i = 0; i < 8; i++ ) - { - _sample += texture( inputTex, IN_texCoords[i].xy ); - _sample += texture( inputTex, IN_texCoords[i].zw ); - } + const float weight = 1.0 / KERNEL_SAMPLES; + vec4 downSample = vec4(0, 0, 0, 0); - OUT_col = _sample / 16; -} \ No newline at end of file + for (int i=0; i