Problem with the View Volume?

Good day everyone,

I am having a problem and I was hoping someone could help me. I am on Windows Vista, running OpenGL 3.3, and GLSL 3.3.

I am able to draw lots of different objects, and do things with them in the vertex and fragment shaders.

However, there is still one problem I have that I can not figure out.

Here is the situation:

  • I create a window.
  • I create vertex and fragment shaders that are basically just pass throughs.
  • I then draw a simple square.
  • If I translate the square in the Z direction by 0.5, -0.5, 1.0, or -1.0, the square will still appear in the window.
  • I can translate the square up and down, left and right, and it works as intended.
  • However, if I translate the square by anything more than 1.0 or -1.0 in the Z direction, I no longer see the square.

It seems as if by default, the viewing volume is a 2x2 cube centered on the origin, and only vertex’s falling within this volume will be mapped to the window.

So if there is a vertex that is more then 1.0 units from the origin in the Z-direction, then it gets clipped.

Is this a correct interpretation of the problem?

Also, how do I solve this problem?

Warmest regards,

Shawn

It’s not a problem; it’s just clip space.

Assuming your vertex shader is not doing any perspective projection, your gl_Position W coordinates will be 1.0. So you’re effectively using an orthographic projects. So the object isn’t supposed to appear to move based on the Z.

However, once you exceed the boundaries of clip-space (which is +/- W in all three axes. And since W is 1.0…), the triangle won’t be rendered. None of the triangle is within the clip-space volume, and thus none of it will be visible.

How you “solve the problem” depends entirely on what you want to have happen. Which you have not explained.

[QUOTE=Alfonse Reinheart;1248344]It’s not a problem; it’s just clip space.

Assuming your vertex shader is not doing any perspective projection, your gl_Position W coordinates will be 1.0. So you’re effectively using an orthographic projects. So the object isn’t supposed to appear to move based on the Z.

However, once you exceed the boundaries of clip-space (which is +/- W in all three axes. And since W is 1.0…), the triangle won’t be rendered. None of the triangle is within the clip-space volume, and thus none of it will be visible.

How you “solve the problem” depends entirely on what you want to have happen. Which you have not explained.[/QUOTE]

How do I change the clip-space volume?

For example, if I translate a square to z = -10, I dont want it to disappear.

You don’t change clip space. You create a transformation from your world space to clip space.

If you want your Z extent in your world space to be +/- 100, then you’ll need to multiply all of your Z coordinates by 1/100 before storing them in gl_Position.