Optimized Gaussian Kernel Generator
Posted: 09 May 2018, 12:21
For my bloom I made a little python2 script which generates an optimized gaussian kernel (using GPU lerping) according to the number of filter taps you specify. It's a bit messy but works fine. Tested with python 2.7.
For anamorphic blur (separate kernel for horizontal and vertical blur) I run it something like this:
And in the bloom shader I use them something like this:
Script as well as a .bat for users to run it and a collection of pre-generated kernels in attachment. Hope it's useful for someone.
For anamorphic blur (separate kernel for horizontal and vertical blur) I run it something like this:
Code: Select all
python gaussianGenerator.py --taps %taps% --notfinal
python gaussianGenerator.py --taps %taps% --prefix gaussianVert --append
Code: Select all
#include "gaussianWeights.fxh"
float4 horizontalGaussian(sampler2D samp, float2 uv, float pixelsize)
{
float4 color = tex2D(samp, uv) * gaussianWeights[0];
for (int i = 1; i < gaussianLoopLength; i++)
{
color += tex2D(tex, uv + float2(gaussianOffsets[i], 0.0) * pixelsize) * gaussianWeights[i];
color += tex2D(tex, uv - float2(gaussianOffsets[i], 0.0) * pixelsize) * gaussianWeights[i];
}
return color;
}
float4 verticalGaussian(sampler2D samp, float2 uv, float pixelsize)
{
float4 color = tex2D(samp, uv) * gaussianVertWeights[0];
for (int i = 1; i < gaussianVertLoopLength; i++)
{
color += tex2D(tex, uv + float2(0.0, gaussianVertOffsets[i]) * pixelsize) * gaussianVertWeights[i];
color += tex2D(tex, uv - float2(0.0, gaussianVertOffsets[i]) * pixelsize) * gaussianVertWeights[i];
}
return color;
}