From 878b2e2aece225b892fca36656747c5ae3191a53 Mon Sep 17 00:00:00 2001 From: Samuel Skiff Date: Sun, 21 Aug 2022 01:55:25 -0500 Subject: [PATCH] Bloom Tweaks --- .../postFX/scripts/Bloom/BloomPostFX.tscript | 159 +++++++++++--- .../postFX/scripts/Bloom/bloomCombineP.hlsl | 36 ++++ .../{bloomP.hlsl => bloomThresholdP.hlsl} | 4 +- .../postFX/scripts/Bloom/downSampleP.hlsl | 48 ++--- .../core/postFX/scripts/Bloom/upSampleP.hlsl | 198 +++++++++++++++--- .../scripts/default.postfxpreset.tscript | 4 + 6 files changed, 366 insertions(+), 83 deletions(-) create mode 100644 Templates/BaseGame/game/core/postFX/scripts/Bloom/bloomCombineP.hlsl rename Templates/BaseGame/game/core/postFX/scripts/Bloom/{bloomP.hlsl => bloomThresholdP.hlsl} (92%) diff --git a/Templates/BaseGame/game/core/postFX/scripts/Bloom/BloomPostFX.tscript b/Templates/BaseGame/game/core/postFX/scripts/Bloom/BloomPostFX.tscript index 36d89dacb..f1cd5e770 100644 --- a/Templates/BaseGame/game/core/postFX/scripts/Bloom/BloomPostFX.tscript +++ b/Templates/BaseGame/game/core/postFX/scripts/Bloom/BloomPostFX.tscript @@ -20,10 +20,17 @@ // IN THE SOFTWARE. //----------------------------------------------------------------------------- -singleton ShaderData( PFX_Bloom_Shader ) +$PostFX::BloomPostFX::threshold = 1.0; +$PostFX::BloomPostFX::intensity = 0.5; +$PostFX::BloomPostFX::radius = 8.0; + +// Valid Values: 0, 1, 2, 3 +$PostFX::BloomPostFX::quality = 1; + +singleton ShaderData( PFX_BloomThreshold_Shader ) { DXVertexShaderFile = $Core::CommonShaderPath @ "/postFX/postFxV.hlsl"; - DXPixelShaderFile = "./bloomP.hlsl"; + DXPixelShaderFile = "./bloomThresholdP.hlsl"; samplerNames[0] = "$inputTex"; @@ -40,19 +47,72 @@ singleton ShaderData( PFX_Bloom_Shader ) // pixVersion = 3.0; //}; +singleton ShaderData( PFX_BloomUpSample_Shader ) +{ + DXVertexShaderFile = $Core::CommonShaderPath @ "/postFX/postFxV.hlsl"; + DXPixelShaderFile = "./upSampleP.hlsl"; + + samplerNames[0] = "$inputTex"; + + pixVersion = 3.0; +}; + +singleton ShaderData( PFX_BloomCombine_Shader ) +{ + DXVertexShaderFile = $Core::CommonShaderPath @ "/postFX/postFxV.hlsl"; + DXPixelShaderFile = "./bloomCombineP.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 ) -//{ -//} +singleton GFXStateBlockData( BloomPostFX_Combine_SampleStateBlock : PFX_DefaultStateBlock ) +{ + samplersDefined = true; + samplerStates[0] = SamplerClampLinear; + samplerStates[1] = SamplerClampLinear; + samplerStates[2] = SamplerClampLinear; +}; + +function BloomPostFX::setShaderConsts( %this ) +{ + %this.setShaderConst("$threshold", $PostFX::BloomPostFX::threshold); + + %blurOne = %this->blur_one; + %blurOne.setShaderConst("$blurRadius", $PostFX::BloomPostFX::radius); + + %blurTwo = %this->blur_two; + %blurTwo.setShaderConst("$blurRadius", $PostFX::BloomPostFX::radius); + + %combine = %this->bloom_combine; + %combine.setShaderConst("$intensity", $PostFX::BloomPostFX::intensity); + + %steps = mRound($PostFX::BloomPostFX::radius * 0.333 + 1); + echo(%steps); + + %blurOne.setShaderConst("$numSteps", %steps); + %blurTwo.setShaderConst("$numSteps", %steps); +} + +function BloomPostFX::preProcess( %this ) +{ + if ( $PostFX::BloomPostFX::quality !$= %this.quality ) + { + %this.quality = mClamp( mRound( $PostFX::BloomPostFX::quality ), 0, 3 ); + + %blurOne = %this->blur_one; + %blurTwo = %this->blur_two; + %blurOne.setShaderMacro( "QUALITY", %this.quality ); + %blurTwo.setShaderMacro( "QUALITY", %this.quality ); + } +} function BloomPostFX::onAdd(%this) { @@ -77,6 +137,10 @@ function BloomPostFX::populatePostFXSettings(%this) { PostEffectEditorInspector.startGroup("BloomPostFX - General"); PostEffectEditorInspector.addCallbackField("$PostFX::BloomPostFX::Enabled", "Enabled", "bool", "", $PostFX::BloomPostFX::Enabled, "", "toggleBloomPostFX"); + PostEffectEditorInspector.addField("$PostFX::BloomPostFX::quality", "Quality", "list", "0,1,2,3", $PostFX::BloomPostFX::quality, "0,1,2,3"); + PostEffectEditorInspector.addField("$PostFX::BloomPostFX::threshold", "Threshold", "range", "", $PostFX::BloomPostFX::threshold, "0 1 10"); + PostEffectEditorInspector.addField("$PostFX::BloomPostFX::intensity", "Intensity", "range", "", $PostFX::BloomPostFX::intensity, "0 2 10"); + PostEffectEditorInspector.addField("$PostFX::BloomPostFX::radius", "Radius", "float", "", $PostFX::BloomPostFX::radius, ""); PostEffectEditorInspector.endGroup(); } @@ -104,6 +168,10 @@ function BloomPostFX::applyFromPreset(%this) function BloomPostFX::savePresetSettings(%this) { PostFXManager::savePresetSetting("$PostFX::BloomPostFX::Enabled"); + PostFXManager::savePresetSetting("$PostFX::BloomPostFX::quality"); + PostFXManager::savePresetSetting("$PostFX::BloomPostFX::threshold"); + PostFXManager::savePresetSetting("$PostFX::BloomPostFX::intensity"); + PostFXManager::savePresetSetting("$PostFX::BloomPostFX::radius"); } //Our actual postFX @@ -112,34 +180,15 @@ singleton PostEffect( BloomPostFX ) enabled = false; allowReflectPass = false; - renderTime = "PFXAfterBin"; - renderBin = "EditorBin"; - renderPriority = 9999; + renderTime = "PFXAfterDiffuse"; + renderBin = "ObjTranslucentBin"; + renderPriority = 0.9; - shader = PFX_Bloom_Shader; + shader = PFX_BloomThreshold_Shader; stateBlock = BloomPostFX_SampleStateBlock; texture[0] = "$backBuffer"; target = "$outTex"; - - // 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"; - // }; + targetClear = PFXTargetClear_OnDraw; new PostEffect() { @@ -147,6 +196,50 @@ singleton PostEffect( BloomPostFX ) shader = PFX_PassthruShader; stateBlock = BloomPostFX_SampleStateBlock; texture[0] = "$inTex"; + target = "#bloom0"; + targetScale = "0.5 0.5"; + }; + + new PostEffect() + { + allowReflectPass = false; + shader = PFX_PassthruShader; + stateBlock = BloomPostFX_SampleStateBlock; + texture[0] = "#bloom0"; + target = "#bloom1"; + targetScale = "0.25 0.25"; + }; + + new PostEffect() + { + internalName = "blur_one"; + allowReflectPass = false; + shader = PFX_BloomUpSample_Shader; + stateBlock = BloomPostFX_SampleStateBlock; + texture[0] = "#bloom0"; + target = "#blur0"; + }; + + new PostEffect() + { + internalName = "blur_two"; + allowReflectPass = false; + shader = PFX_BloomUpSample_Shader; + stateBlock = BloomPostFX_SampleStateBlock; + texture[0] = "#bloom1"; + target = "#blur1"; + targetScale = "0.5 0.5"; + }; + + new PostEffect() + { + internalName = "bloom_combine"; + allowReflectPass = false; + shader = PFX_BloomCombine_Shader; + stateBlock = BloomPostFX_Combine_SampleStateBlock; + texture[0] = "#blur0"; + texture[1] = "#blur1"; + texture[2] = "$backBuffer"; target = "$backBuffer"; }; }; diff --git a/Templates/BaseGame/game/core/postFX/scripts/Bloom/bloomCombineP.hlsl b/Templates/BaseGame/game/core/postFX/scripts/Bloom/bloomCombineP.hlsl new file mode 100644 index 000000000..0493464ab --- /dev/null +++ b/Templates/BaseGame/game/core/postFX/scripts/Bloom/bloomCombineP.hlsl @@ -0,0 +1,36 @@ +//----------------------------------------------------------------------------- +// 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(inputTex0, 0); +TORQUE_UNIFORM_SAMPLER2D(inputTex1, 1); +TORQUE_UNIFORM_SAMPLER2D(colorTex, 2); +uniform float intensity; + +float4 main(PFXVertToPix IN) : TORQUE_TARGET0 +{ + float4 bloom = (TORQUE_TEX2D(inputTex0, IN.uv0) + TORQUE_TEX2D(inputTex1, IN.uv0)) * 0.5f; + float4 screenColor = TORQUE_TEX2D(colorTex, IN.uv0); + screenColor.rgb += bloom.rgb * intensity; + return screenColor; +} diff --git a/Templates/BaseGame/game/core/postFX/scripts/Bloom/bloomP.hlsl b/Templates/BaseGame/game/core/postFX/scripts/Bloom/bloomThresholdP.hlsl similarity index 92% rename from Templates/BaseGame/game/core/postFX/scripts/Bloom/bloomP.hlsl rename to Templates/BaseGame/game/core/postFX/scripts/Bloom/bloomThresholdP.hlsl index c71ad2830..546bcdc2c 100644 --- a/Templates/BaseGame/game/core/postFX/scripts/Bloom/bloomP.hlsl +++ b/Templates/BaseGame/game/core/postFX/scripts/Bloom/bloomThresholdP.hlsl @@ -23,10 +23,12 @@ #include "core/rendering/shaders/postFX/postFx.hlsl" TORQUE_UNIFORM_SAMPLER2D(inputTex, 0); +uniform float threshold; float4 main(PFXVertToPix IN) : TORQUE_TARGET0 { float4 screenColor = TORQUE_TEX2D(inputTex, IN.uv0); float brightness = max(screenColor.r, max(screenColor.g, screenColor.b)); - return float4(screenColor.rgb * saturate(pow(brightness, 8.0f)), screenColor.a); + //clip(brightness - threshold); + return screenColor * saturate(pow(brightness, threshold*8.0f)); } diff --git a/Templates/BaseGame/game/core/postFX/scripts/Bloom/downSampleP.hlsl b/Templates/BaseGame/game/core/postFX/scripts/Bloom/downSampleP.hlsl index 8996badcc..c8b282c94 100644 --- a/Templates/BaseGame/game/core/postFX/scripts/Bloom/downSampleP.hlsl +++ b/Templates/BaseGame/game/core/postFX/scripts/Bloom/downSampleP.hlsl @@ -27,35 +27,35 @@ //----------------------------------------------------------------------------- TORQUE_UNIFORM_SAMPLER2D(inputTex, 0); -//uniform float2 oneOverTargetSize; +uniform float2 oneOverTargetSize; //----------------------------------------------------------------------------- // Main //----------------------------------------------------------------------------- float4 main(PFXVertToPix IN) : TORQUE_TARGET0 { - float x = 0.01f; - float y = 0.01f; - 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)); + float x = oneOverTargetSize.x; + float y = oneOverTargetSize.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; + float4 downSample = e * 0.125f; + downSample += (a+c+g+i) * 0.03125f; + downSample += (b+d+f+h) * 0.0625; + downSample += (j+k+l+m) * 0.125; + return downSample; } \ 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 index 6bea2ecf5..d69bb26b0 100644 --- a/Templates/BaseGame/game/core/postFX/scripts/Bloom/upSampleP.hlsl +++ b/Templates/BaseGame/game/core/postFX/scripts/Bloom/upSampleP.hlsl @@ -20,38 +20,186 @@ // IN THE SOFTWARE. //----------------------------------------------------------------------------- +#include "core/rendering/shaders/torque.hlsl" #include "core/rendering/shaders/postFX/postFx.hlsl" -struct Conn -{ - float4 hpos : TORQUE_POSITION; - float2 texCoord : TEXCOORD0; +#if QUALITY == 3 + +static const int KERNEL_SAMPLES = 64; +static const float3 KERNEL[64] = { + float3(0.015625, 0.000000, 0.017183), + float3(-0.023043, 0.021109, 0.017183), + float3(0.004098, -0.046696, 0.017183), + float3(0.038027, 0.049600, 0.017183), + float3(-0.076931, -0.013608, 0.017183), + float3(0.079102, -0.050318, 0.017182), + float3(-0.028394, 0.105625, 0.017182), + float3(-0.057613, -0.110931, 0.017181), + float3(0.132092, 0.048240, 0.017180), + float3(-0.144429, 0.059618, 0.017178), + float3(0.072849, -0.155673, 0.017175), + float3(0.056116, 0.178906, 0.017172), + float3(-0.175746, -0.101848, 0.017168), + float3(0.213648, -0.046970, 0.017163), + float3(-0.134796, 0.191733, 0.017157), + float3(-0.032128, -0.247927, 0.017149), + float3(0.203110, 0.171181, 0.017140), + float3(-0.281010, 0.011621, 0.017129), + float3(0.210434, -0.209410, 0.017116), + float3(-0.014435, 0.312166, 0.017101), + float3(-0.210233, -0.251929, 0.017084), + float3(0.340680, 0.045838, 0.017063), + float3(-0.294996, 0.205251, 0.017040), + float3(0.082306, -0.365856, 0.017014), + float3(0.194211, 0.338925, 0.016984), + float3(-0.387031, -0.123474, 0.016951), + float3(0.382974, -0.176944, 0.016913), + float3(-0.168902, 0.403582, 0.016871), + float3(-0.153361, -0.426383, 0.016825), + float3(0.414933, 0.218077, 0.016773), + float3(-0.468376, 0.123462, 0.016717), + float3(0.270419, -0.420563, 0.016654), + float3(0.087335, 0.508175, 0.016586), + float3(-0.420019, -0.325286, 0.016512), + float3(0.545008, -0.045153, 0.016431), + float3(-0.381982, 0.412911, 0.016344), + float3(0.002820, -0.578118, 0.016250), + float3(0.398932, 0.439764, 0.016148), + float3(-0.606775, -0.056236, 0.016038), + float3(0.497850, -0.377850, 0.015921), + float3(-0.114661, 0.630280, 0.015795), + float3(-0.349522, -0.555426, 0.015661), + float3(0.647981, 0.177585, 0.015518), + float3(-0.611659, 0.313893, 0.015367), + float3(0.244418, -0.659276, 0.015206), + float3(0.270999, 0.665703, 0.015037), + float3(-0.663622, -0.314503, 0.014857), + float3(0.716710, -0.220969, 0.014669), + float3(-0.387117, 0.660547, 0.014471), + float3(-0.164025, -0.763837, 0.014263), + float3(0.649650, 0.461481, 0.014045), + float3(-0.806263, 0.100483, 0.013819), + float3(0.536765, -0.630614, 0.013582), + float3(0.030749, 0.843190, 0.013337), + float3(-0.603207, -0.612100, 0.013082), + float3(0.873858, 0.044681, 0.012818), + float3(-0.686583, 0.567289, 0.012545), + float3(0.125226, -0.897556, 0.012264), + float3(0.522814, 0.759288, 0.011975), + float3(-0.913626, -0.210223, 0.011678), + float3(0.829278, -0.469836, 0.011373), + float3(-0.298936, 0.921474, 0.011062), + float3(-0.408505, -0.895610, 0.010745), + float3(0.920579, 0.390557, 0.010422) }; -TORQUE_UNIFORM_SAMPLER2D(inputTex0, 0); -TORQUE_UNIFORM_SAMPLER2D(inputTex1, 1); -//uniform float filterRadius; +#elif QUALITY == 2 -float4 main( Conn V_IN ) : TORQUE_TARGET0 +static const int KERNEL_SAMPLES = 32; +static const float3 KERNEL[32] = { + float3(0.031250, 0.000000, 0.034485), + float3(-0.046086, 0.042218, 0.034485), + float3(0.008196, -0.093391, 0.034484), + float3(0.076055, 0.099200, 0.034481), + float3(-0.153861, -0.027216, 0.034475), + float3(0.158204, -0.100637, 0.034464), + float3(-0.056788, 0.211250, 0.034446), + float3(-0.115227, -0.221862, 0.034418), + float3(0.264184, 0.096480, 0.034378), + float3(-0.288858, 0.119236, 0.034321), + float3(0.145697, -0.311346, 0.034245), + float3(0.112231, 0.357812, 0.034146), + float3(-0.351492, -0.203697, 0.034019), + float3(0.427296, -0.093940, 0.033859), + float3(-0.269592, 0.383467, 0.033663), + float3(-0.064255, -0.495854, 0.033424), + float3(0.406220, 0.342362, 0.033139), + float3(-0.562020, 0.023241, 0.032802), + float3(0.420867, -0.418819, 0.032408), + float3(-0.028870, 0.624333, 0.031952), + float3(-0.420465, -0.503858, 0.031431), + float3(0.681360, 0.091676, 0.030841), + float3(-0.589992, 0.410501, 0.030178), + float3(0.164611, -0.731713, 0.029439), + float3(0.388423, 0.677849, 0.028625), + float3(-0.774063, -0.246947, 0.027733), + float3(0.765949, -0.353888, 0.026766), + float3(-0.337803, 0.807164, 0.025725), + float3(-0.306722, -0.852766, 0.024613), + float3(0.829865, 0.436154, 0.023437), + float3(-0.936752, 0.246925, 0.022202), + float3(0.540838, -0.841127, 0.020916) +}; + +#elif QUALITY == 1 + +static const int KERNEL_SAMPLES = 16; +static const float3 KERNEL[16] = { + float3(0.062500, 0.000000, 0.069464), + float3(-0.092171, 0.084436, 0.069456), + float3(0.016392, -0.186782, 0.069422), + float3(0.152110, 0.198400, 0.069329), + float3(-0.307723, -0.054432, 0.069134), + float3(0.316408, -0.201273, 0.068781), + float3(-0.113577, 0.422500, 0.068204), + float3(-0.230454, -0.443724, 0.067328), + float3(0.528368, 0.192959, 0.066073), + float3(-0.577716, 0.238473, 0.064362), + float3(0.291394, -0.622692, 0.062123), + float3(0.224463, 0.715623, 0.059300), + float3(-0.702984, -0.407394, 0.055864), + float3(0.854591, -0.187880, 0.051818), + float3(-0.539184, 0.766934, 0.047209), + float3(-0.128511, -0.991708, 0.042133) +}; + +#elif QUALITY == 0 + +static const int KERNEL_SAMPLES = 9; +static const float3 KERNEL[9] = { + float3( 0, 0, 0.25), + float3( 1, 0, 0.125), + float3( 0, 1, 0.125), + float3(-1, 0, 0.125), + float3( 0,-1, 0.125), + float3( 0.707, 0.707, 0.0625), + float3( 0.707,-0.707, 0.0625), + float3(-0.707,-0.707, 0.0625), + float3(-0.707, 0.707, 0.0625) +}; + +#endif + +TORQUE_UNIFORM_SAMPLER2D(inputTex, 0); +uniform float blurRadius; +uniform int numSteps; +uniform float2 oneOverTargetSize; + +float4 main(PFXVertToPix IN) : TORQUE_TARGET0 { - float x = 1.0f; - float y = 1.0f; + float4 upSample = float4(0, 0, 0, 0); + float radStep = blurRadius / float(numSteps); - 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)); + const float alpha = M_2PI_F / float(numSteps); - 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)); + [unroll] + for (int i=0; i