🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Downsampling Image in Compute Shader

Started by
1 comment, last by MJP 3 years, 2 months ago

This is more of a sanity check question. Suppose I have a 512x512 image. I dispatch a down sampling compute shader with 256x256 threads total. I want to use hardware bilinear filtering, so for each thread with indices threadXY, I compute:

float2 uv = (threadXY*2 + 1) / 512;
float4 downsampledValue = tex.SampleLevel(linearSampler, uv, 0.0f);

I just want to make sure the +1 is correct, and not +0.5. The idea is if the image was 2x2, only one thread with indices (0,0) would get kicked off, and uv = (0.5, 0.5), which would be in the center of the 4 neighbor texels.

Advertisement

Yes, that's correct given the sizes you mentioned. The other way you an think about it (and what I would do personally, since I think it makes more sense) is compute your UV based on the output texel coordinate instead of the input texture. This would be uv = (threadXY + 0.5) / 256, since texel centers are located at 0.5. Doing it that way will make your shader work correctly even if the input size is not exactly 2x the output size.

This topic is closed to new replies.

Advertisement