Archived

This topic is now archived and is closed to further replies.

Proposed Light and Shadow method

This topic is 5983 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve been mulling over ways to efficiently render lighting and shadows for a somewhat special-purpose 3d engine I''m developing (which specialization shouldn''t differentiate the usefulness of this from any run-of-the-mill first person shooter). Here''s what I''ve come up with. Different rendering techniques are used for terrain (walls, floors, ceilings-- this is an indoor engine) and things. A thing is a character, a desk, or any non-terrain polygonal object which is not terrain. Terrain is lit using Quake-style light maps. These are precomputed before the level is presented, and may incorporate radiosity. In addition, a global ambient level is chosen for lighting in shadowed areas. This level should not be greater than the minimul light map value in any shadow-recieving area. Terrain may recieve shadows from Things. Here''s the procedure for each polygon of terrain. 0. Render all terrain normally, including Z-buffering. 1. For each Thing, see whether that Thing''s bounding box intersects a pyramid with the base being that terrain''s polygon and the apex being the point light source (in the case of point lights) or whether the bounding box intersects a prism with the base being the terrain and the extrusion parallel to the light vector to an altitude comfortably above the top of all Things (in the case of directional lights). 2. If an intersection is found, project the Thing onto the plane, using either an orthographic projection (for directional lights) or a perspective projection from the light source (for point lights). Note: if Things with multiple levels of detail (LODs) are used, this may be done with a very low vertex mesh regardless of what mesh is to be actually rendered. Texture coordinates for the vertices are also changed to equal the coordinates of the surface it is projected onto. 3. Render the projected mesh with the texture of the surface. Instead of rendering with the lightmap, however, render with the global ambient level factored in. This rendering is also Z-buffered, with a positive bias (i.e., it is rendered over the surface but under any other surfaces in front of that surface). 4. Render all Things normally. This approach has multiple disadvantages, most of which I enumerate here, with ideas on how to minimize their impact: 1. Things and terrain may not shadow Things. This can be somewhat faked with lights that project textures during scene presentation (remember that, since lightmaps are precomputed, this does not have to affect the appearances of any terrain). 2. Any meshes that shadow terrain must be rendered twice, albeit the second time with no need for any more than cursory light calculations. For complex meshes, this problem can be alleviated with the use of low-poly meshes for shadows, or (in the case of directional lights) precalculating and preculling shadow meshes. Without having actually implemented it, it seems like this method could be significantly more efficient than the use of a second, light-originated Z-buffer. Does anyone have questions, comments, criticism, or suggestions for improving the efficiency of the technique?

Share this post


Link to post
Share on other sites
One more caveat, that I forgot to put up there: If I don''t miss my guess, using this method with multiple light sources would be freakishly complex. I''ll have to mull it over some more, tho.

Share this post


Link to post
Share on other sites
Well, it sure does sound like a standard projective shadow algorithm. The tricky part is when you say: "Project the Thing onto the plane". But well, you know, generally your Thing will not fall on a single triangle, but a set of terrain triangles that are not in the same plane.

I also think you can run into artifacts (maybe you can live with it?) when a Thing shadow will be projected into a shadow of the terrain; the terrain will then be darkened twice..

Y.

Share this post


Link to post
Share on other sites
quote:
Original post by Ysaneya
Well, it sure does sound like a standard projective shadow algorithm.



Of course. The real updates I''ve made are in non-obscuration culling, and the use of ambient lighting.

quote:
The tricky part is when you say: "Project the Thing onto the plane". But well, you know, generally your Thing will not fall on a single triangle, but a set of terrain triangles that are not in the same plane.



By terrain, I''m referring usually to flat floors or walls; as I said, it is an indoor engine. It is perfectly possible, too, for multiple planes to exist.

quote:
I also think you can run into artifacts (maybe you can live with it?) when a Thing shadow will be projected into a shadow of the terrain; the terrain will then be darkened twice..


This does not occur, because the target terrain is not darkened from the light map; instead it is redrawn at a flat ambient level. So, yes, overdraw might occur if two objects shadowed the same area (or if a suffciently complex object shadowed the area), but this shouldn''t be a major performance hit, and definitely wouldn''t be visible as degradation.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
> By terrain, I''m referring usually to flat floors or walls; as I said, it is an indoor engine. It is perfectly possible, too, for multiple planes to exist.

This will work, but will be very slow, if the object is projected onto several triangles with different planes (as in a complex terrain), as it will have to be projected and render several times.

I just had an idea, it might be weird, but hmmm, don''t know...

Say you have an object floating above a plane. OK, to get the shadow you project the object onto that plane using perspective projection for point lights and orthographic for directional lights.

Now, let''s say that the object is floating above a perfect sphere. Would it be possible to modify the projection equation, so that the object''s projection is pre-distorted to the shape of the sphere ? I presume, it would be possible. So that you could directly render the projected object on the surface of the sphere in a single pass.

Now, instead of the sphere, we have a highly tesselated mesh (terrain or whatever). Could one pre-calculate some form of ''pre-distortion map'' of the terrain, that would modify the object''s projection to conform with the terrain''s shape ? Something like ''implosion-maps'' used in reflection rendering on complex curved reflectors, but for shadow projections ?

Just some weird idea...

-AH

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Anonymous Poster
> By terrain, I''m referring usually to flat floors or walls; as I said, it is an indoor engine. It is perfectly possible, too, for multiple planes to exist.

This will work, but will be very slow, if the object is projected onto several triangles with different planes (as in a complex terrain), as it will have to be projected and render several times.

I just had an idea, it might be weird, but hmmm, don''t know...

Say you have an object floating above a plane. OK, to get the shadow you project the object onto that plane using perspective projection for point lights and orthographic for directional lights.

Now, let''s say that the object is floating above a perfect sphere. Would it be possible to modify the projection equation, so that the object''s projection is pre-distorted to the shape of the sphere ? I presume, it would be possible. So that you could directly render the projected object on the surface of the sphere in a single pass.

Now, instead of the sphere, we have a highly tesselated mesh (terrain or whatever). Could one pre-calculate some form of ''pre-distortion map'' of the terrain, that would modify the object''s projection to conform with the terrain''s shape ? Something like ''implosion-maps'' used in reflection rendering on complex curved reflectors, but for shadow projections ?

Just some weird idea...

-AH



Ahh... cute!

The math behind projections is fairly simple, especially for orthographic lights, and thus could probably be applied to smooth curves in normal form, or even splines, maybe, with a minimum of difficulty. I''ll sit down with the tricky algebra tonight.... but it really seems like you have something here.

IIRC, Thief 2 levels were supposed to use some sort of modeling technique that relied purely on geometric primitives such as wedges, spheres, and boxes. I wonder if this sort of stuff was used to advantage there.

I wonder, too, if for complex terrains some projections could be re-used, perhaps with a minimal amount of recalculation (scaling or transforming) or even blitting. Oragnizationally that''s kind of scary, but perhaps it could help with the complex surface problems you mention.

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
> By terrain, I''m referring usually to flat floors or walls; as I said, it is an indoor engine. It is perfectly possible, too, for multiple planes to exist.

This will work, but will be very slow, if the object is projected onto several triangles with different planes (as in a complex terrain), as it will have to be projected and render several times.

I just had an idea, it might be weird, but hmmm, don''t know...

Say you have an object floating above a plane. OK, to get the shadow you project the object onto that plane using perspective projection for point lights and orthographic for directional lights.

Now, let''s say that the object is floating above a perfect sphere. Would it be possible to modify the projection equation, so that the object''s projection is pre-distorted to the shape of the sphere ? I presume, it would be possible. So that you could directly render the projected object on the surface of the sphere in a single pass.

Now, instead of the sphere, we have a highly tesselated mesh (terrain or whatever). Could one pre-calculate some form of ''pre-distortion map'' of the terrain, that would modify the object''s projection to conform with the terrain''s shape ? Something like ''implosion-maps'' used in reflection rendering on complex curved reflectors, but for shadow projections ?

Just some weird idea...

-AH



Ahh... cute!

The math behind projections is fairly simple, especially for orthographic lights, and thus could probably be applied to smooth curves in normal form, or even splines, maybe, with a minimum of difficulty. I''ll sit down with the tricky algebra tonight.... but it really seems like you have something here.

IIRC, Thief 2 levels were supposed to use some sort of modeling technique that relied purely on geometric primitives such as wedges, spheres, and boxes. I wonder if this sort of stuff was used to advantage there.

I wonder, too, if for complex terrains some projections could be re-used, perhaps with a minimal amount of recalculation (scaling or transforming) or even blitting. Oragnizationally that''s kind of scary, but perhaps it could help with the complex surface problems you mention.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
OK, I think I have a form of the projection equation for the perfect sphere, this was quite easy. But it''s not with more complex meshes that can''t be described by simple mathematical expressions

I''ll reread some stuff about explosion maps, there was some interesting info about them in the last Siggraph notes, I think they might be usefull for this type of problem, since they give a mathematical approximation of complex meshes.

-AH

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
>I''ll reread some stuff about explosion maps

pffff I meant implosion maps, ofcourse, it''s getting late

-AH

Share this post


Link to post
Share on other sites