The Industry's Foundation for High Performance Graphics

1. How to draw frustrum in opengl

I want to draw frustrum outlines. What will be my coordinates for these frustrum vertices ?

2. 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?

3. 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.

4. 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.

5. 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 to
Code :
` trans[i]=trans[i]/trans[i].w;`

6. after applying projection matrix, vertices will be in clip coordinate space and not in NDC
Yes, you are correct, I've gotten a bit sloppy with the coordinate spaces
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

7. 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.

Posting Permissions

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