View Full Version : Get the polygon from the shadow

rbalaji

04-12-2001, 11:05 AM

Hi,

I have a 3D mesh object and projecting the shadow of it in a plane. Please tell me how do I get the XY coord of the points of the 2D polygon that represents the boundary of the shadow plane.

Rob The Bloke

04-13-2001, 06:20 PM

Originally posted by rbalaji:

Hi,

I have a 3D mesh object and projecting the shadow of it in a plane. Please tell me how do I get the XY coord of the points of the 2D polygon that represents the boundary of the shadow plane.

First, your 3D mesh object will be held as a bunch of vertex co-ords, you'll then use your glRotate*() etc to position the model in the correct place. This is where you encounter problem number 1.

Your light source will (probably) be held in world co-ordinates, to project a shadow, you'll have to know the object's world co-ordinates so that both light and mesh are using the same co-ordinate system. This entails not using glRotate*(), glTranslate*() etc, and you'd have to calculate using a lot of vector & matrix math to put all the vertices in the correct co-ordinate system. A lot of processing. Luckily there is a quicker way, in-stead of transforming the mesh, we could apply the inverse of the mesh's transformation, on the light source position. This would put the light into object space co-ords. The advantage of this is that you only need to do one transformation.

once you have the light's position, there are about three ways you can do the shadows.

1. Simple:

to project the shadow onto a plane where y=0 ( presuming y is up ), calculate the vector from the light to the vertex and NORMALISE it(call it lv, & dont forget to normalise it!!). The shadow position is then given by,

Shadow pos x = vertex.x + lv.x * (vertex.y/lv.y)

Shadow pos y = 0

Shadow pos z = vertex.z + lv.z * (vertex.y/lv.y)

Basically this uses similar triangles, draw it on some paper and prove it to yourself. You can also do the same thing using a projection matrix (if only a single directional light is used that is of infinate distance from the camera)

2. projecting onto a plane of any orientation

calculate the plane equation in the form ax^3 + by^2 + cz + d = 0,

the normal to the plane(N) is then (a,b,c).

To calculate the shadow position,

ShadowPos = vertex - lv *((N dot vertex)+d)/(N dot lv)

couple of dot products and thats about it,

3. Use shadow volumes & the stencil buffer

The best resource for this is to look at nvidia.com and a few other places to find some examples.

Whatever method you use, you should ensure that culling is reversed when drawing the shadows, knowledge of the stencil buffer is also a good idea.

hope that helps

rbalaji

04-16-2001, 08:35 AM

Hi,

Thanks for your kind reply. Yes, I was thinking in the same line

as yourself. After getting all the mesh points in the plane of the projection

Ax + By + Cz + D = 0

after doing some matrix transormation, I was not able to get the polygon that

represents the shadow boundary of the projected points in the plane.

I was even thinking of getting the polygon vertices from the projected points

in the plane thru some algo. But it seems it also involves the hidden surface removal

of the actual mesh object as some of the vertices points in the mesh object

may be hiiden in the ray of the source.

Do you have any idea how to go about it?

Thanx for your response,

R.B

Michael Steinberg

04-16-2001, 08:46 AM

Do you try to get the silhouette on the plane?

I think this could be possible:

Test wether any face faces the light source. Then test any faces adjacent to it. If they point away and the first face points towards, or vice versa, the edge is on the silhouette. But you could get lines which actually are inside the silhouette as well.

rbalaji

04-16-2001, 08:52 AM

Yes, exactly I want the coordinate points from the silhoutte on the shadow plane, since the silhouutte is caused by a triangular mesh.

Michael Steinberg

04-16-2001, 08:56 AM

So you know which point make the silhouette? Then the easiest approach would be to cast rays from the light source through the points and let them intersect with the plane.

There are however faster algo's I guess...

rbalaji

04-16-2001, 09:26 AM

I get only the silhoute image on the plane, ie pixel based shadow image?

How do I get the vertices from it?

Michael Steinberg

04-16-2001, 09:33 AM

Huh???

You have the vertices of the silhouette of the object, haven't you? With these it is trivial to project THEM to the plane of choice.

What do you mean by pixel-based?

rbalaji

04-16-2001, 09:41 AM

Input: Mesh object, light source definition and projection plane.

Output I need: Shadow vertices of the mesh object on the shadow plane.

Reason is that I want to send this output of the shadow vertex to another app where

it takes the input as polygon points to draw the outline of the shadow.

Problem in my opengl thing is that I have got the shadow thing (as pixel image) defined in the plane but not the shadow boudary point coord.

Michael Steinberg

04-16-2001, 09:44 AM

Then, you must find the silhouette of your 3d mesh in regards to the position of the light (look above for an easy approach), and project this silhouette to whatever plane which lies behind the mesh.

Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.