Basic Cubemapping

I’m trying to get a cubemap to work with only some luck, I can visible see parts of the image on the cube map but when I rotate it, it starts to distort and becomes a mess. There seems to be a lot of threads pertaining to cubemaps but I haven’t seem to found any sort of solution. Any help or link to good examples would be appreciated.

vertex:

uniform vec3 eyePosition;

varying vec3 reflection;

void main(void)
{
   gl_Position = ftransform();
   
   vec3 normal = normalize(gl_NormalMatrix * gl_Normal);
   vec3 direction = normalize(eyePosition.xyz - gl_Position.xyz);
   reflection = normalize(reflect(direction, normal));
}

frag:

varying vec3 reflection;

void main(void)
{
   gl_FragColor = textureCube(texCube, reflection);
}

Try it with just the normal. That is, pass “normal” as “reflection”. This should have the object rendered such that the direction of each vertex is mapped to an area on the cubemap. If it doesn’t, then there’s a good chance your normals are bad or your normal matrix is wrong. Or that your cubemap wasn’t uploaded correctly.

Also, you should be drawing a simple shape, like a sphere.

I am using a sphere and the cubemap seems to be correct along with the normals, it shows up fine when I pass normal as reflection.

normalize(eyePosition.xyz - gl_Position.xyz);

Are these two vectors in the same space? gl_Position is usually in model space. Is eyePosition in model space?

That seemed to be the problem I had them in different spaces which seemed to be causing the distortion that I was getting, thanks.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.