I'm currently learning C++ and OpenGL and was wondering how the below code is able to map a texture to a 3D object within a scene. The code currently works, but I'm struggling to understand it.
//In the Pixel Shader. float pi = 3.14159265359; vec3 N = normalize (Normal); vec3 L = normalize (vec3 (EyeSpaceLightPosition - EyeSpacePosition)); vec3 R = reflect (L, N); vec3 V = normalize (vec3 (EyeSpacePosition) - vec3 (0, 0, 0)); //Specifically these parts here. float theta = acos (dot ( N, L )) / pi; float phi = acos (dot ( -R, V )) / pi; fragColor = vec4 (texture (texture1, vec2 ( theta, phi )));