将相机位置传递给着色器 OpenGL
Pass camera position to shader OpenGL
我正在尝试制作一个立方体映射,现在我有这段代码:
顶点着色器
varying vec2 tex_coord;
void main()
{
vec3 v = vec3(gl_ModelViewMatrix * gl_Vertex);
gl_TexCoord[0].stp = normalize(gl_Vertex.xyz);
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
//gl_ModelViewMatrix * gl_Vertex
}
片段着色器
uniform samplerCube _tex;
void main()
{
//gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
gl_FragColor = textureCube(_tex, gl_TexCoord[0].stp);
}
请问如何将相机位置传递给shader
您应该将 uniform vec3 camera_location
传递给着色器
我正在尝试制作一个立方体映射,现在我有这段代码:
顶点着色器
varying vec2 tex_coord;
void main()
{
vec3 v = vec3(gl_ModelViewMatrix * gl_Vertex);
gl_TexCoord[0].stp = normalize(gl_Vertex.xyz);
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
//gl_ModelViewMatrix * gl_Vertex
}
片段着色器
uniform samplerCube _tex;
void main()
{
//gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
gl_FragColor = textureCube(_tex, gl_TexCoord[0].stp);
}
请问如何将相机位置传递给shader
您应该将 uniform vec3 camera_location
传递给着色器