Lets assume that we have several vector variables (f. e. light direction, camera direction and vertex normals) in the vertex shader that we want to pass through the fragment shader.
I know that shader vector variables should be normalized before using them for further calculation. Especially vectors, like vertex normals, that could change per fragment should be normalized in the vertex shader first.
I want to know which variables neednt to be normalized in the fragment shader, so that i can save some calculations.
I'm trying to give a general answer to that somewhat vague question.
You will of course have to normalize any vector which you need to have unit length for further calculation. In the context of classical phong-based lighting calculations, these includes all direction vectors, since what really is to be calculated are the cosines of the angles between the directions, which will equal the dot product of unit-lenght vectors.
In this context, it is worth noting that the interpolation of the variables for each fragment will not preserve vector lengths. So you have to renormalize the vectors in the fragment shader, even if the vertex shader outputs were already normalized. And you can't save that per-vertex normalization step either: If you interploate vectors of different length, you'll introduce some kind of weighting, increasing the influence of the longer vector. So you'll have to make sure that your vertex shader outputs are normalized, and have to renormalize them again in the fragment shader.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With