Optimized Gaussian Kernel Generator

share shaders here
Post Reply
  • Author
  • Message
Offline
User avatar
Posts: 99
Joined: 11 May 2014, 10:48

Optimized Gaussian Kernel Generator

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.
Attachments
Gaussian Generator.zip
(6.91 KiB) Downloaded 168 times
_________________
Reforged ENB for Dragon's Dogma, The Witcher 2, Kingdom Come: Deliverance

Offline
User avatar
Posts: 56
Joined: 02 Aug 2017, 13:30

Re: Optimized Gaussian Kernel Generator

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
Attachments
enbbloom.fx
(8.88 KiB) Downloaded 151 times

Offline
User avatar
*blah-blah-blah maniac*
Posts: 530
Joined: 30 Jan 2012, 13:18

Re: Optimized Gaussian Kernel Generator

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.

Offline
User avatar
Posts: 99
Joined: 11 May 2014, 10:48

Re: Optimized Gaussian Kernel Generator

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.
_________________
Reforged ENB for Dragon's Dogma, The Witcher 2, Kingdom Come: Deliverance
Post Reply