How to modify the perspective division in OpenGL?

808 views Asked by At

How do you modify or override the perspective division calculation in OpenGL?

Also is it possible to use x, y, z and w as variables in matrices in OpenGL?

1

There are 1 answers

7
datenwolf On

How do you modify or override the perspective division calculation in OpenGL?

You can't. It's one of the few "hardwired" (or actually hardcoded on modern GPUs) things in OpenGL. But that's no problem. Just set gl_Position.w = 1 at the very end of the vertex shader, which will effectively make the perspective division a no-op. However you then also have no perspective, so you'd have to implement that in your vertex shader as well. You could write gl_Position /= gl_Position.w; as the very last statement in the vertex shader to do the perspective divide yourself, and bypass the built-in divide.

Also is it possible to use x, y, z and w as variables in matrices in OpenGL?

I'm not quite sure what you mean by that.