HLSL Gaussian blur help

Started by
3 comments, last by dhanji 19 years, 7 months ago
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.
I love me and you love you.
Advertisement
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
I love me and you love you.
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.
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.
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).
________________
"I'm starting to think that maybe it's wrong to put someone who thinks they're a Vietnamese prostitute on a bull"       -- Stan from South Park
Lab74 Entertainment | Project Razor Online: the Future of Racing (flashsite preview)

This topic is closed to new replies.

Advertisement