Skip to main content
GameDev.net gamedev.net
🔒 Locked

reflective environment mapping problem

Started by Lord_Evil Jan 24, 2007 at 7:12 AM 2 replies 1.4k views
Original Post
Lord_Evil
Lord_Evil
Hi all. I have some problem with reflective environment mapping in OpenGL (both fixed function + shader). Maybe it's just a matter of misunderstanding, but let me try: I have a simple quad facing along the positive x-axis (normal = (1, 0, 0)). I enabled fixed function environment mapping, since I tend to say my shader could be incorrect, but fixed function should work correctly. My code:

glDisable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_CUBE_MAP);

glBindTexture(&cubemapID);

glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);

glPushMatrix();

glBegin(GL_TRIANGLE_STRIP);
	glNormal3f(1.0f, 0.0f, 0.0f);
	glVertex3f(6.0f,-6.0f,-6.0f);
	glVertex3f(6.0f, 6.0f,-6.0f);
	glVertex3f(6.0f,-6.0f, 6.0f);
	glVertex3f(6.0f, 6.0f, 6.0f);
glEnd();

glPopMatrix();

glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_TEXTURE_GEN_R);

This works, but IMHO uncorrectly: For testing purposes I've disabled backface culling so I would see both sides. Now I'd expect to see a different reflection on both sides ( on one side the left part of the cube, on the other side the right part) as I would see when looking into a 2-sided mirror. Now here's the problem: every side of the quad shows the same reflection. Moreover I tried this with a hard cube (every side having a distinct normal) -> every side showed the same reflection if I was right in front of it and look at its center (same relative position). IMO that's not correct. Using Cg shaders it's the same result. So what went wrong? I'd guess that could be a driver error but I'm rather slow in blaming others. First I'd like to confirm that it's not me ;/. Could anyone provide a simple, running cube environment mapping example in OpenGL that I could test my driver with (preferably prebuilt for Windows ;))?
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
reiko
reiko
I think the problem is that the reflection mapping works in view space, so effectively it's as if the cube is rotating, not your viewpoint. You could correct this by rotating the texture matrix (which is applied post-texgen) by the same amount as the (model)view matrix.
Lord_Evil
Lord_Evil
Ok, fixed that. Thanx.

But why is it that I none of the turials I found don't mention that fact?
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
Lord_Evil
Lord_Evil
Well, it's me again ... still some problems with that reflection.

So far, setting the inverse camera rotation fixes the rotating reflection issue. Now the reflection only changes if the camera moves and the correct portion of the cubemap is displayed.

However, the reflections still aren't correct. They seem to be rotated.
The six sides of the cube are simple textures, labeled "left", "top", etc.
I'd expect the reflection to show the "left" side mirrored horizontally but what I get is a vertical reflection. I could rotate the camera rotation matrix by 180 degrees around the z-axis before inverting, but then I'd have to make GL_TEXTURE_CUBE_MAP_POSITIVE_Y the "bottom" texture for correct reflections.

Maybe I just got a wrong understanding of how the cubemap extension works, but doesn't GL_TEXTURE_CUBE_MAP_POSITIVE_Y specify the top part of the cubemap?
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.