PDA

View Full Version : Basic Cubemapping



xerzi
06-05-2011, 11:50 PM
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);
}

Alfonse Reinheart
06-06-2011, 12:55 AM
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.

xerzi
06-06-2011, 09:09 AM
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.

Alfonse Reinheart
06-06-2011, 09:57 AM
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?

xerzi
06-06-2011, 11:23 AM
That seemed to be the problem I had them in different spaces which seemed to be causing the distortion that I was getting, thanks.