Sign in to follow this  
Grizwald

HLSL Gaussian blur help

Recommended Posts

How do I effective sample neighboring pixels and weigh them? I've been doing a simple average the pixels (8 of them) around the point, but since I can't get too accurate, I get ghosting with large blur areas. Is there a better way to blur in a pixel shader? I want to weigh the pixels with the gaussian function, maybe even the separated function (x blur, then y blur) but I want to know how to effectively sample neighboring pixels first.

Share this post


Link to post
Share on other sites
Ok
what if I passed the dimensions of the texture to the pixel shader, multiply the tex coords (u,v) by the dimension vector(w,h), and then subtract (1,1), and re-divide by the dimenion vector(w,h).

That would give me the difference in texture space between the texel and its neighbors, and multiplying this number by root-2 would give me the diagnols.

this seems like a lot of work though...
darn it

i'll have to do x passes of 8 pixel samples to get a good blur

and screw using gauss's weighing :D

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I never did this before but it seems like multipass would be a good solution if you render to texture the first pass and use that texture in the second pass it would seem the screen cords and tex cords would be the same thing allowing you to tex look ups based on relative position to the current point. for example take a screen cord add some number to it's x and y then sample your texture at this new cord.

Share this post


Link to post
Share on other sites
In the RenderMonkey examples they do a blur by rendering to a texture in one pass and them using that texture, in a second pass, on a screen aligned quad. In the second pass they can sample as they please on the texture that is the pre rendered screen. It is worth a look. Seems like with this method yoy could do a great number of 2d raster like operations.

Share this post


Link to post
Share on other sites
Quote:
I've been doing a simple average the pixels (8 of them) around the point, but since I can't get too accurate


how do u mean accurate? U can be accurate down to 1 texel:

1 texel left = Current_coord.x - (1/texture_width)
(y is same)

similarly for 1 texel up:
Current_coord.y - (1/texture_height)


Also if you're trying to average everything in pass thats a bad idea, it's better to use a separable filter (do search on google for separable gaussian kernel). Basically blur horizontally first, then take the blurred texture and blur it vertically. Unfortunately this only works on ps_2_0 cards.. (or ur limited to 4 samples per pass for which u can use the linear sampler instead).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this