Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 3 123 LastLast
Results 1 to 10 of 28

Thread: cubemap reflection not perspective correct

  1. #1
    Intern Newbie
    Join Date
    May 2001
    Posts
    39

    cubemap reflection not perspective correct

    From the posts I saw on this forum, I've implemented my own reflection texture-mappping using the GL_TEXTURE_CUBE_MAP_ARB extension. It's working great for me except for one thing: The reflection does not get rendered perspective-correct (regular texture mapping modes are working fine). Is this a limitation of the technique or is there something extra I must do when using a cubemap to render reflections?

    I've looked at Nutty's demo and source code where he's doing the same thing, and I see his reflections have the same problem, which leads me to believe it's just a limitation I have to live with. (Thanks Nutty for your demos)

    See these images for clarification, which are just simple cubes with 2 tris/face:

    Correctly rendered cube with a simple checkerboard pattern http://home.columbus.rr.com/bpainte/cube3.jpg

    Incorrectly rendered cube with reflection mapping (nevermind that the reflection does not include the ground in the scene, I'm not dynamically updating the cubemap texture) http://home.columbus.rr.com/bpainte/cube1.jpg

    Of course, I'll post code if people feel it will help.

    (Edited to add extra info.)
    Oh yes, hw is Geforce4 Ti 4200, with 30.72 drivers.

    [This message has been edited by painterb (edited 11-27-2002).]

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    2,704

    Re: cubemap reflection not perspective correct

    That doesn't look like a perspective correction problem; it looks like a cube map image problem. If you use those same images as a sky box, does it look seamless or does it show the same discontinuities at the seams?
    "If you can't afford to do something right,
    you'd better make sure you can afford to do it wrong!"

  3. #3
    Intern Newbie
    Join Date
    May 2001
    Posts
    39

    Re: cubemap reflection not perspective correct

    When used as a skybox, the textures look fine together.

    Just to be sure we're looking at the same thing, here's one more image ... the flawed areas are highlighted in yellow (it's where the 2 tris of one face meet). This type of distortion doesn't occur on my skybox. http://home.columbus.rr.com/bpainte/cube2.jpg

    And, here's a link to Nutty's demo exhibiting the same flaw. (Look for the demo "Dynamic Cubemap Demo") http://romka.demonews.com/opengl/demos/texture_eng.htm

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Feb 2001
    Location
    Switzerland
    Posts
    1,840

    Re: cubemap reflection not perspective correct

    tesselate it higher..

    you do per vertex generate reflection coords, but per triangle, you will map planar onto the surface.. it looks like you have smooth normals, on wich you reflect at?

    at least, its a texcoord problem. nothing else..
    http://davepermen.net - if i could stay true to my heart, i would feel totally free

  5. #5
    Junior Member Regular Contributor
    Join Date
    Dec 2001
    Location
    London, England
    Posts
    163

    Re: cubemap reflection not perspective correct

    How are you computing the texture coordinates to use for the cube mapping? I had this problem once when creating the reflection vectors in a vertex program since I was normalizong them per vertex. Interpolating normalized vectors does not give the correct results.
    If you are using REFLECTION_MAP however, it should not be doing this normalisation. Just make sure you have unit normals on your cube.

  6. #6
    Intern Newbie
    Join Date
    May 2001
    Posts
    39

    Re: cubemap reflection not perspective correct

    Originally posted by davepermen:
    tesselate it higher..
    I realize this would help. But the problem would still exist, just at a level where it won't be terribly noticable.

    And I'm surprised, is this really the only way to solve? Because when applying a texture normally (GL_TEXTURE_2D mode, not CUBE_MAP) say in decal mode, this flaw is not present.

    Sorry I left out some useful data ... I am using glTexGen to generate the tex coords:
    glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_REFLECTION_M AP_ARB);
    glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_REFLECTION_M AP_ARB);
    glTexGeni(GL_R,GL_TEXTURE_GEN_MODE,GL_REFLECTION_M AP_ARB);

    bakery2k, ok, I will double check to make sure my normals are of unit length.

    I admit, I have trouble with the more complex texture-mapping methods, so you guys no doubt are smarter than me, but from what I've read it certainly looks like a perspective-correction issue. I will see if I can put together an executable for you to run.

    Thanks all.

  7. #7
    Junior Member Regular Contributor
    Join Date
    Jan 2001
    Posts
    238

    Re: cubemap reflection not perspective correct

    One thing that will help debug this for you is to try outputting those texture coords as colors. This can show you if the coordintes are showing a discontinuity there. I imagine the problem you are having is with the texture matrix.

    -Evan

    BTW, Go Bucks!

  8. #8
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    4,388

    Re: cubemap reflection not perspective correct

    Does this help:

    glTexGeni(GL_Q,GL_TEXTURE_GEN_MODE,GL_REFLECTION_M AP_ARB);

    Just a guess really.

  9. #9
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    2,704

    Re: cubemap reflection not perspective correct

    Okay, I'm also convinced it's a triangle edge issue now.

    I'd bet a donut that Dorbies suggestion is on the right track.
    "If you can't afford to do something right,
    you'd better make sure you can afford to do it wrong!"

  10. #10
    Junior Member Regular Contributor
    Join Date
    Dec 2001
    Location
    London, England
    Posts
    163

    Re: cubemap reflection not perspective correct

    Quote from the OpenGL 1.4 specs:

    "Calling TexGen with a coord of Q when pname indicates REFLECTION_MAP generates the error INVALID_ENUM"

    That's not it...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •