Page 1 of 1

Optimized Gaussian Kernel Generator

Posted: 09 May 2018, 12:21
by SandvichDISH
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:

Code: Select all

python gaussianGenerator.py --taps %taps% --notfinal
python gaussianGenerator.py --taps %taps% --prefix gaussianVert --append
And in the bloom shader I use them something like this:

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;
}
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.

Re: Optimized Gaussian Kernel Generator

Posted: 10 May 2018, 21:22
by Adyss
Made a little bloom file out of it :3 tested on SSE. Your Generator works like a charm ;) Thanks for sharing. (i am not really a coder i am just trying around till it works so forgive my coding mess in that bloom)
Thats a test image with it ;)
Imageenb2018_5_10_22_29_34

Re: Optimized Gaussian Kernel Generator

Posted: 11 May 2018, 14:02
by Marty McFly
Interesting! I liked how you made use of linear sampling so no more taps on each Texel like a lot of other filters. Although a python script is a little overkill imho :D computing the offsets inline is much more flexible and considering how fast arithmetics are these days, there's not much performance gain. The expensive part that determines the final sample coordinates can be replaced by just plainly sample between texels 50/50, makes not much of a difference.

Re: Optimized Gaussian Kernel Generator

Posted: 15 May 2018, 19:26
by SandvichDISH
Interesting! I liked how you made use of linear sampling so no more taps on each Texel like a lot of other filters. Although a python script is a little overkill imho :D computing the offsets inline is much more flexible and considering how fast arithmetics are these days, there's not much performance gain. The expensive part that determines the final sample coordinates can be replaced by just plainly sample between texels 50/50, makes not much of a difference.
Ha, thanks for letting me know! I'm using ENB as a platform to learn shader programming right now so there's definitely much to learn.