Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Reversing perspective foreshortening.

Threaded View

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2004

    Reversing perspective foreshortening.

    Hi. I have a 3D scene that I am rendering in a perspective projection. I have a camera that I use to orbit around the scene, always looking at the origin. In addition the scene itself can translate and rotate. In my scene I have 3D objects that get smaller as they get farther away from the camera as you would expect in a perspective projection. I want some 3D objects to remain the same size regardless of where they are in the scene. In a GLSL vertex shader I managed to linearize gl_Position.z and then reverse the foreshortening by doing the following...

    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    gl_Position.z = (gl_Position.z / 40.0) * gl_Position.w; // Linearize depth. 40 is the far plane.
    gl_Position.w = 1.000;

    Unfortunately now my 3D objects are in the wrong place in the scene. I suspect I may need to do something with gl_Position.x and gl_Position.y?

    Any help would be appreciated.

    At the top of the projection matrix I have glFrustum while at the top of the modelview matrix I have gluLookAt followed by the scene.

    Last edited by JMSDKS; 08-15-2013 at 12:42 PM. Reason: More information.

Tags for this Thread

Posting Permissions

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