Shader optimization: tradeoff between baking to texture or calculate

Probably best way to measure shader performance is to set some synthetic test shader code is running, like some 8192x8192 image, rendered in 32x32 CPU tile in one thread and a lot of samples.

I know that if the shader is very complex, it runs faster if I bake it to texture. All complex calculation is gone, resolution is limited to textures, ram is wasted and it is then memory bandwidth that limits speed.

I also know that calculation efficiency has improved decades faster than memory access, so it is better to calculate procedual textures than access from memory.

Is there any good best practices to estimate when it is best to bake textures and when to calculate procedually? Obvious optimizations are at least to precalculate some small lookup texture that fits to cache and calculate those “big” textures, or use texture maps and add shader logic to make texture maps to use less memory, like two channel normal mapping, using A channel to something like specular, compress colors to half resolution and so on.

1 Like