How to accurately sample textures in ComputeShader?

I want to sample a texture in ComputeShader. But the result is always a little different from the original texture. I tried to use my custom TextureSampler and changed the sampling mode, but still could not get the right color. Please help! :rofl:

This is the input texture.

This is the output texture.

By the way, in the latest version of the Playground, I cannot open the Texture Inspector. Just change it to the version 6.49.0.

@Evgeni_Popov Iā€™m sorry to bother you, but do you have a solution?

You should sample at the center of the texel: vec2<f32>(global_id.xy) / dims + vec2<f32>(0.5) / dims.

But you will make your life a lot easier if you use textureLoad instead of textureSampleLevel: let pix : vec4<f32> = textureLoad(src, vec2<u32>(global_id.xy), 0) (you will have to remove all references to the sampler, though).

1 Like

You are great :+1:! I know where the problem lies. Sorry for disturbing you multiple times today.