1
\$\begingroup\$

I'm trying to do cube mapping. Problem is that I'm getting this: Wrong cube mapping This is what I get when I rotate it: Wrong cube mapping rotated

But it should look like this right cube mapping

Here is code for vertex shader

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 
}

fragment shader

uniform samplerCube _tex;
void main()
{
 //gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
 gl_FragColor = textureCube(_tex, gl_TexCoord[0].stp);
}

Could you please tell me what am I doing wrong?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$
gl_TexCoord[0].stp = normalize(gl_Vertex.xyz);

Is your problem, I believe you need:

gl_TexCoord[0].stp = normalize(gl_Normal.xyz * gl_ModelViewMatrix);

Possibly without the matrix multiplier -- I'm a bit rusty.

Note that the meaning of 'normal' can be a bit confusing here -- The 'vertex normal' (gl_Normal) is a vector pointing directly 'away' from the vertex -- it's the direction you'll want the reflection to come from on the cubemap. The 'normalize()' function takes a vector, and returns a vector with the equivalent direction, but a length of 1 (which is what you want, because texture coords go from 0 to 1).

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .