Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.