I have a situation where I need the distance between to the camera and I also need the normalize the vector. This is my current code:
vec3 view_dir = camera_pos - world_pos;
float d = length(view_dir);
view_dir *= 1.0 / d;
I’m wondering if this code is any different performance wise than if I just use view_dir /= d
. Does the right side of the *=
happen for each component or is it just calculated once?