From 8f05b348ddbbf48a15b36f685cdc48e588aa0768 Mon Sep 17 00:00:00 2001 From: Michael Fabian Dirks Date: Mon, 3 Jul 2017 07:01:23 +0200 Subject: [PATCH] filter-blur: Split into individual files An unknown issue with the OBS effect parser causes it to generate nothing when more than two techniques are in the same file. This works around the issue, but doesn't actually fix it. --- data/filter-blur/box.effect | 49 +++++++++++++++++++ .../{filter.effect => gaussian.effect} | 43 +++------------- 2 files changed, 55 insertions(+), 37 deletions(-) create mode 100644 data/filter-blur/box.effect rename data/filter-blur/{filter.effect => gaussian.effect} (54%) diff --git a/data/filter-blur/box.effect b/data/filter-blur/box.effect new file mode 100644 index 00000000..a1d38965 --- /dev/null +++ b/data/filter-blur/box.effect @@ -0,0 +1,49 @@ +uniform float4x4 ViewProj; +uniform texture2d image; +uniform float2 texel; +uniform int widthHalf; +uniform int width; + +sampler_state textureSampler { + Filter = Point; + AddressU = Clamp; + AddressV = Clamp; +}; + +struct VertDataIn { + float4 pos : POSITION; + float2 uv : TEXCOORD0; +}; + +struct VertDataOut { + float4 pos : POSITION; + float2 uv : TEXCOORD0; +}; + +VertDataOut VSDefault(VertDataIn v_in) +{ + VertDataOut vert_out; + vert_out.pos = mul(float4(v_in.pos.xyz, 1.0), ViewProj); + vert_out.uv = v_in.uv; + return vert_out; +} + +// Box Blur +float4 PSBox(VertDataOut v_in) : TARGET +{ + float4 rgba = float4(0,0,0,0); + for (int k = -widthHalf; k <= widthHalf; k++) { + rgba += image.Sample(textureSampler, v_in.uv + (texel * k)); + } + rgba = rgba / width; + return rgba; +} + +technique Draw +{ + pass + { + vertex_shader = VSDefault(v_in); + pixel_shader = PSBox(v_in); + } +} diff --git a/data/filter-blur/filter.effect b/data/filter-blur/gaussian.effect similarity index 54% rename from data/filter-blur/filter.effect rename to data/filter-blur/gaussian.effect index 2691c6ed..66cd632e 100644 --- a/data/filter-blur/filter.effect +++ b/data/filter-blur/gaussian.effect @@ -1,7 +1,8 @@ uniform float4x4 ViewProj; uniform texture2d image; -uniform int size; uniform float2 texel; +uniform int widthHalf; +uniform int width; sampler_state textureSampler { Filter = Point; @@ -27,32 +28,6 @@ VertDataOut VSDefault(VertDataIn v_in) return vert_out; } -// Box Blur -float4 PSBox(VertDataOut v_in) : TARGET -{ - float4 rgba = float4(0,0,0,0); //image.Sample(textureSampler, v_in.uv); - float trueWidth = 1 + (size * 2); - for (int k = -size; k <= size; k++) { - rgba += image.Sample(textureSampler, v_in.uv + (texel * k)); - } - rgba = rgba / trueWidth; - return rgba; -} - -technique Box -{ - pass Horizontal - { - vertex_shader = VSDefault(v_in); - pixel_shader = PSBox(v_in); - } - pass Vertical - { - vertex_shader = VSDefault(v_in); - pixel_shader = PSBox(v_in); - } -} - // Gaussian Blur float Gaussian(float x, float deviation) { return (1.0 / sqrt(2.0 * 3.141592 * deviation)) * exp(-((x * x) / (2.0 * deviation))); @@ -61,23 +36,17 @@ float Gaussian(float x, float deviation) { float4 PSGaussian(VertDataOut v_in) : TARGET { float4 rgba = float4(0, 0, 0, 0); - float trueWidth = 1.0 + (size * 2); - for (int k = -size; k <= size; k++) { + for (int k = -widthHalf; k <= widthHalf; k++) { float4 smpl = image.Sample(textureSampler, v_in.uv + (texel * k)); - smpl *= Gaussian(k / trueWidth, 1.0); + smpl *= Gaussian(k / width, 1.0); rgba += smpl; } return rgba; } -technique Gaussian +technique Draw { - pass Horizontal - { - vertex_shader = VSDefault(v_in); - pixel_shader = PSGaussian(v_in); - } - pass Vertical + pass { vertex_shader = VSDefault(v_in); pixel_shader = PSGaussian(v_in);