I'm working on implementing screen space fluid rendering as described in the presentation here. I've implemented the bilateral blur from the paper in HLSL, however there are two issues with the blur:
- Performance, the author states the code is "not optimized". It looks to be similar to SSAO blur algorithms but my math knowledge is limited in this area. Anyone know of similar bilateral blurs that would be faster, i.e. recursive ones?
- Currently, I have a hard-coded fiter radius, which I've set to be half the width of the final rendered pixels of the sprite in question (there are multiple particle sprites being shaded in a full-screen quad post-processing pass). The problem is as the camera moves closer or further from the sprites, the filter width has to be changed to accommodate. I have access to the depth values (non-linear z/w) in the post-processing pass, but I'm not sure the best way to figure out the filter radius based on that. Code below:
float depth = tex2D(depthSampler, texcoord).x;
float sum = 0;
float wsum = 0;
for(float x=-filterRadius; x<=filterRadius; x+=1.0) {
float sample = tex2D(depthSampler, texcoord + x*blurDir).x;
// spatial domain
float r = x * blurScale;
float w = exp(-r*r);
// range domain
float r2 = (sample -depth) * blurDepthFalloff;
float g = exp(-r2*r2);
sum += sample * w * g;
wsum += w * g;
}
if (wsum > 0.0) {
sum /= wsum;
}
return sum;
The author says the filter width should be constant in world space but variable in screen-space. In my world space each sprite is one unit wide and tall. Thanks for any help!