I’m only just getting into GLSL after coming across from writing pixel shaders in Adobe PixelBender. I have written a few fractal shaders that are just a single quad with the fragment shader doing all the heavy lifting.
There are quite a lot of calculations that are the same for all pixels that I’m currently doing in the fragment shader by assigning local fragment variables (like creating rotation matrices).
Am I right in thinking that all calculations in the fragment shader will be repeated for every pixel, whereas if I were to move the common ones into the vertex shader then they would only be calculated once per vertex?
Thanks for any help, as it’s obvious I am still very new to this
Basically, yes. Fragment shaders are ran for each fragment so its possible that a fragment shader will run more than once for a pixel depending on the rendering technique, scene’s depth complexity, if early-z is enabled, etc.
If something is constant across all fragments, perhaps the rotation matrices you mentioned, you can compute the value once on the CPU and pass it to the shader using a uniform.