I want to draw a frustum using GL_LINE_STRIP
. What will be my coordinates for these frustum vertices? I have model view and projection matrices. Is it possible to calculate coordinates in shader itself using these matrices?
If you want the world space coordinates for the frustum corners, all you need to do is project the 8 corner points from NDC space (which is going from -1 to 1 in every dimension, so the corner points are easy to enumerate) back to world space. But do not forget that you have to divide by w
:
c_world = inverse(projection * view) * vec4(c_ncd, 1);
c_world = c_world*1.0/c_world.w;
While I wrote this in GLSL syntax, this is meant as pseudocode only. You can do it in the shader, but that means that this has to be calculated many times (depending on which shader stage you put this into). It is typically much faster to at least pre-calculate that inverted matrix on the CPU.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With