From 1fcd141f10fb04ae8033dae1eec47a3d7055f841 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Tue, 8 Jun 2021 05:48:13 +0200 Subject: [PATCH] filter/blur: Don't pass bool as TEXCOORD1 Using a 'bool' as TEXCOORD1 is undefined behavior, so we should not abuse the intermediate shading storage like this. Fixes #559 --- data/effects/blur/box-linear.effect | 5 ++--- data/effects/blur/gaussian-linear.effect | 8 +++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/data/effects/blur/box-linear.effect b/data/effects/blur/box-linear.effect index fbd35aeb..9ac809e9 100644 --- a/data/effects/blur/box-linear.effect +++ b/data/effects/blur/box-linear.effect @@ -65,20 +65,19 @@ struct VertDataIn { struct VertDataOut { float4 pos : POSITION; float2 uv : TEXCOORD0; - bool is_odd : TEXCOORD1; }; VertDataOut VSDefault(VertDataIn vtx) { VertDataOut vert_out; vert_out.pos = mul(float4(vtx.pos.xyz, 1.0), ViewProj); vert_out.uv = vtx.uv; - vert_out.is_odd = ((int(round(pSize)) % 2) == 1); return vert_out; } // Blur 1 Dimensional float4 PSBlur1D(VertDataOut vtx) : TARGET { float4 final = pImage.Sample(linearSampler, vtx.uv); + bool is_odd = ((int(round(pSize)) % 2) == 1); // y = yes, s = skip, b = break // Size-> | 1| 2| 3| 4| 5| 6| 7| @@ -104,7 +103,7 @@ float4 PSBlur1D(VertDataOut vtx) : TARGET { final += pImage.Sample(linearSampler, vtx.uv + nstep) * 2.; final += pImage.Sample(linearSampler, vtx.uv - nstep) * 2.; } - if (vtx.is_odd) { + if (is_odd) { float2 nstep = (pImageTexel * pStepScale) * pSize; final += pImage.Sample(linearSampler, vtx.uv + nstep); final += pImage.Sample(linearSampler, vtx.uv - nstep); diff --git a/data/effects/blur/gaussian-linear.effect b/data/effects/blur/gaussian-linear.effect index dc46fea8..63c885c5 100644 --- a/data/effects/blur/gaussian-linear.effect +++ b/data/effects/blur/gaussian-linear.effect @@ -71,14 +71,12 @@ struct VertDataIn { struct VertDataOut { float4 pos : POSITION; float2 uv : TEXCOORD0; - bool is_odd : TEXCOORD1; }; VertDataOut VSDefault(VertDataIn vtx) { VertDataOut vert_out; vert_out.pos = mul(float4(vtx.pos.xyz, 1.0), ViewProj); vert_out.uv = vtx.uv; - vert_out.is_odd = ((int(round(pSize)) % 2) == 1); return vert_out; } @@ -89,8 +87,8 @@ float GetKernelAt(int i) { // Blur 1 Dimensional float4 PSBlur1D(VertDataOut vtx) : TARGET { - float4 final = pImage.Sample(linearSampler, vtx.uv) - * GetKernelAt(0); + float4 final = pImage.Sample(linearSampler, vtx.uv) * GetKernelAt(0); + bool is_odd = ((int(round(pSize)) % 2) == 1); // y = yes, s = skip, b = break // Size-> | 1| 2| 3| 4| 5| 6| 7| @@ -118,7 +116,7 @@ float4 PSBlur1D(VertDataOut vtx) : TARGET { final += pImage.Sample(linearSampler, vtx.uv + nstep) * kernel; final += pImage.Sample(linearSampler, vtx.uv - nstep) * kernel; } - if (vtx.is_odd) { + if (is_odd) { float kernel = GetKernelAt(pSize); float2 nstep = (pImageTexel * pStepScale) * pSize; final += pImage.Sample(linearSampler, vtx.uv + nstep) * kernel;