I want to draw frustrum outlines. What will be my coordinates for these frustrum vertices ?
I want to draw frustrum outlines. What will be my coordinates for these frustrum vertices ?
Last edited by debonair; 06-06-2014 at 10:21 AM.
They are trivial in NDC (normalized device coordinates): there the frustum becomes a cube with coordinates (-1, -1, -1) (1, 1, 1). By applying e.g. the inverse projection transformation you can bring these points back to eye space.
However, you are at best going to see lines along the edge of your screen, because that is where by definition these points project. Perhaps you want something different?
I want light frustrum. here is my code of geometry shader:
Code :vec4 vertices[]={ {-1, -1, -1, 1}, { 1, -1, -1, 1}, { 1, 1, -1, 1}, {-1, 1, -1, 1}, {-1, -1, 1, 1}, { 1, -1, 1, 1}, { 1, 1, 1, 1}, {-1, 1, 1, 1} }; mat4 inverse1; inverse1=inverse(LightWorldViewProjection); vec4 trans[8]; int i; for(i=0;i<8;i++) { trans[i]=vertices[i]*inverse1; trans[i]=trans[i]/trans[i].w; } gl_Position=trans[0]; data.color=vec3(1.0,0.0,0.0); EmitVertex(); gl_Position=trans[1]; data.color=vec3(1.0,0.0,0.0); EmitVertex(); gl_Position=trans[2]; data.color=vec3(1.0,0.0,0.0); EmitVertex(); gl_Position=trans[3]; data.color=vec3(1.0,0.0,0.0); EmitVertex(); gl_Position=trans[4]; data.color=vec3(1.0,0.0,0.0); EmitVertex(); gl_Position=trans[5]; data.color=vec3(1.0,0.0,0.0); EmitVertex(); gl_Position=trans[6]; data.color=vec3(1.0,0.0,0.0); EmitVertex(); gl_Position=trans[7]; data.color=vec3(1.0,0.0,0.0); EmitVertex(); EndPrimitive();
It does not draw anything.
Last edited by debonair; 06-06-2014 at 01:17 PM.
Hmm, shouldn't the vertices (after transforming from light source NDC to world coords) undergo the normal modelview and projection of your camera?
Also, is all your code set up to adhere to the vertex * matrix convention, because IIRC that influences the order in which the various transformations apply.
Thanks a lot. I forgot to apply camera transformation.
It works now
One doubt, after applying projection matrix, vertices will be in clip coordinate space and not in NDC right? but we are taking NDC as input. Also can you please explain why need toCode :trans[i]=trans[i]/trans[i].w;
Last edited by debonair; 06-06-2014 at 03:04 PM.
Yes, you are correct, I've gotten a bit sloppy with the coordinate spacesafter applying projection matrix, vertices will be in clip coordinate space and not in NDC
The difference between clip space and NDC is the perspective division, which you also have to account for when transforming back, hence the division by .w
I am still confused with how it works. Initially we are taking normalized coordinates and multiplying it with inverse projection matrix to get coordinates into view space, but in the reverse step ( converting view space to NDC) we multiply it with projection matrix and then divide by 'w' which is not the same while going NDC to view space.
Can you please explain how it works?
Thanks.