Re: Still working on shadows...

New Message Reply Date view Thread view Subject view Author view

Angus Dorbie (dorbie++at++bitch.reading.sgi.com)
Sat, 18 Jan 1997 20:44:28 +0000


On Jan 18, 1:11pm, Thom DeCarlo wrote:
> Subject: Still working on shadows...
> Some time ago I wrote asking if anyone had any experience trying
> to render shadows cast by the sun in a large area sim. I haven't
> seen a responce, but several people have emailed me to ask if I
> have solved the problem. Well, since I haven't found a solution
> I thought I should try restating the question.
>
> I assume that I would need an infinite, rather than local, light
> source to achieve the correct effect. Am I right, or is there some
> other way to do this? Perhaps if I attach a local light to the
> observer's DCS? But then it would still need to be very far away
> and not rotate when the observer changes orientation.
>
> Has anyone out there come up with a workable solution?

I'm surprised nobody has been able to help you with this.

There's depth mapped shadows but this is impractical
for most visual simulation due to the rendering overhead,
even with the reduced number of passes required on iR.

Another method is to render the projected shadow volume, outside
then inside, to the stencil planes while zbuffering. With a
stencil increment on the outside and decrement on the inside you
end up with stencil == 1 where the shadow projects onto surfaces.
Exactly the same method can be used for per-pixel spotlights. You
then re-render the lit or shadowed surfaces with or without light with
a stencil operation which only writes to stencil == 1 for your final
effect. This is also multi-pass so for most Vis Sim it's
not appropriate.

It sounds like what you need is yer standard flat plane
shadows projection, made famous by the "Ideas in Motion" demo.
As this demo shows, it's possible to project geometry from the
light source position onto a plane, and the light source can even
be a local one.

You can use the geometry of the object casting the shadow for
this but it's probably wiser to use a very simplified
representation of the object casting the shadow.
You place the simplified object below a DCS which has the
transformation required to project it onto the ground plane.
For this to work you will have to work around zfighting issues,
you should also use a black geostate and a stipple pattern or
multisample transparency for the shadow contribution.

So the only tricky part is figuring out how to produce the projective
matrix required for the shadow. Thankfully I don't have to work this
out because Thant Tessman has already described this in an IRIS Universe
Programmers Corner, way back when that publication was usefull.
Plagerising shamelessly from this article, here's how it's done for
a infinite light source. I've adjusted the sums for Performers
coordinate system:

The equation to project to the ground where z==0 is as follows.
Where, lx, ly, lz are the light vector and mx, my, mz are the model
coordinates and sx, sy, sz are shadow coordinates.

sx = mx + mz * lx/lz
sy = my + mz * ly/lz
sz = 0

So you now have to build a 4x4 matrix to set in a DCS which will apply
this transformation to the model coordinates.

[ 1.0 0.0 0.0 0.0 ]
[ 0.0 1.0 0.0 0.0 ]
[ lx/lz ly/lz 0.0 0.0 ]
[ 0.0 0.0 0.0 1.0 ]

In code this might look like:

if ((root = pfdLoadFile(argv[arg])) != NULL)
{
  pfMatrix *doomed;
  // create a DCS shadow casting
  pfDCS *shadow = new pfDCS();
  // build the matrix with projection onto horizontal z=0 plane
  shadow->setMat( * (doomed = new pfMatrix (
                                  1.0f, 0.0f, 0.0f, 0.0f,
                                  0.0f, 1.0f, 0.0f, 0.0f,
                                  lx/lz, ly/lz, 0.0f, 0.0f,
                                  0.0f, 0.0f, 0.0f, 1.0f,
                                           ))
               );
  delete doomed;
  shadow->addChild(root);
  scene->addChild(shadow);
}

Attached is a small gif of a test of this shadows method in
performer using the above code by loading a duplicate flt file
which has been made black in the modelling tool.

For other horizontal planes you can very simply introduce the delta
values in the arithmetic. Non horizontal planes and local light
sources are more difficult to figure but can be done. If you want
me to go over the local light source stuff in Thant's article I
will.

Cheers,
Angus.



New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:54:22 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.