Question

In computer graphics it's a common technique to apply jittering to sampling positions in order to avoid visible sampling patterns.

What's the proper way to apply jittering to sampl-positions in a fragment shader? One way I could think of would be to feed a noise-texture into the shader, and then depending on the texlvalue of this noise texture alter the sampling-positions of whatever one wants to sample.

Is there a better way of implementing jittering?

Was it helpful?

Solution

The various hardware driver AA schemes usually are jitter-based already -- each vendor has their own favored patterns. And unfortunately the user/player can often mess with the settings and turn things on and off.

This might make you think that there's no "correct" way -- and you'd be right! There are ways, some of which are correct for some tasks. Learn and use what you like.

For surface-texture jittering, you might try something like so:

  1. In photoshop, make a 256x512 rgb image (or 256x511, for some versions of the NVIDIA DDS exporter), fill it ALL with random noise, save as DDS with "use existing mip maps." this will give you roughly-uniform noise regardless of how much the texture is scaled (at least through many useful size ranges).

  2. in your shader, read the noise texture, then apply it to the UVs, and then read your other texture(s), e.g.

    float4 noise = tex2D(noiseSampler,OriginalUV);

    float2 newUV = OriginalUV + someSmallScale*(noise.xy-0.5);

    float4 jitteredColor = tex2D(colorSampler,newUV);

Try other variations as you like. Be aware that strong texture jittering can cause a lot of texture cache misses, which may have a performance cost, and be careful around normal maps, since you are introducing high-frequency components into a signal that's already been filtered.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top