1
我目前正在学习C++和OpenGL,并想知道下面的代码如何能够将纹理映射到场景中的3D对象。代码目前可行,但我很难理解它。纹理如何映射到3D对象?
//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)));