• Advertisement

Archived

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

Shadow casting on a terrain

This topic is 5711 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

Hi Im currently working on a terrain-engine. At this point I can load and render animated MD3 models and a multitextured terrain. I´ve read a lot of tutorials explaining how to cast shadows on a plane (usally the xz-plane), but I want to cast shadows from my models onto my terrain! Please don´t flame me, just help me :D Best regards Roquqkie

Share this post


Link to post
Share on other sites
Advertisement
Well, there is a tutorial on Nehe about casting shadows, so you could look at that. Also, there are several articles on the nVidia developers site, so that should also be your first port of call.

Death of one is a tragedy, death of a million is just a statistic.

Share this post


Link to post
Share on other sites
Well, if you want to cast shadows on terrain and not onto an even plane you should use shadow mapping or stencil shadow volumes.

Gero

Share this post


Link to post
Share on other sites
Gerogerber... could you describe the theory behind shadow-mapping and stencil shadow volumes???

Thanx m8

-Roq-

[edited by - Roquqkie on May 30, 2002 11:35:19 AM]

Share this post


Link to post
Share on other sites
If you actually bothered to like at the sites I mentioned, you would have found the answers to alot of your questions. There are detailed papers on shadow mapping, so go and have a look, they will tell you much more than what a single person can tell you here.

Death of one is a tragedy, death of a million is just a statistic.

Share this post


Link to post
Share on other sites
Most shadow mapping on terrain (in my experience) is precalculated beforehand, saved as a texture, and multitexture the terrain texture and the shadow map.

Share this post


Link to post
Share on other sites
I think he means for the model to cast a shadow onto the terrain, but you can store static shadows for static objects in the texture. That brings up another point -- how do you avoid adding shodows where there are already shadows? You don''t want a player casting a shadow on the ground if he''s in the shadow of the hill already. Any suggestions on how to avoid that if you have shadows stored in the texture? Motocross Madness 2 avoided overlapping shadows...

Share this post


Link to post
Share on other sites
well, if you are standing in teh shadow of say a hill it implys you are behind the hill, therefore a Ray cast from the light to your postion would conferm this (myabe a couple of them if you want to detect if the head is above or whatever), and then you just turn off or on the shadowing code as needed

Share this post


Link to post
Share on other sites
Well, thx all!
But I´ve sticked to "Shadow Mapping" as Gerogerber and Python_Regious told me to. This technique seems suitable because it is independent of the world around the model that cast the shadow. I just can''t figure out how to implent it...
I have managed to store the depth-buffer from the lights point of view as a texture, but I don''t know what to do next!?
I´ve read that the next step is to test each fragment in the newly created texture againts the vertices in model-space from the cameraes point of view, but Im not sure!?

-Roq-

Share this post


Link to post
Share on other sites
[rant]Why do people bother replying just to post links to sites which MIGHT just possibly have something relevant. The old "There might be something on nehe" response. As the poster said, he'd already found lots of resources on PLANAR shadowing. What he wants help with is _dynamic_ terrain shadow generation (not static shadows, Neosmyle). Banding about terms such as "stencil shadows" without bothering to explain their meaning (probably because you don't know yourself) is also unhelpful.[/rant]

Now, in answer to the original question (now there's an original idea ), I recently found a page linking to several methods, of varying complexity for dynamically shadowing a terrain here. In particular, the terrain self-shadowing method described in this article looks like it would be very effective when used with low res heightmaps.

____________________________________________________________
www.elf-stone.com

[edited by - benjamin bunny on May 31, 2002 8:59:49 PM]

Share this post


Link to post
Share on other sites
shadow texture mapping is probably your best bet. I can't understand why you'd want to read the detph buffer though. Simply render the model without textures (black) on a white background, from the PoV of the light, then copy that image (small) to an existing texture. MUCH faster than either buffer reads/creating the texture.
(that obviosuly has to be done before the terrain is rendererd. You could be clever and fill the texture with all the different models you have, scaled to fit. so when only 1 shadow is drawn, it's really high res, etc. That would be very fast.
Rendering is pretty simple. Just project it onto the small area of terrain under the model, where the shadow will fall, using 'lightmap' style blending. To fix the problem with having a shadow in an already shadowed area, you could store the brightness of each vertex in the alpha component of the vertcies (shadow =0, light=1), since you likly won't be using alpha. You could then use it when rendering the shadows, this way they would automatically fade away as you went into shadow, no CPU hit, or similar, which you'd get from line of sight. And it'd look really nice to boot. (Tribes did projected shadows like this quite well, but it didn't fix the already shadowed problem)

[edited by - RipTorn on June 1, 2002 7:46:14 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by benjamin bunny
[rant]Why do people bother replying just to post links to sites which MIGHT just possibly have something relevant. The old "There might be something on nehe" response. As the poster said, he''d already found lots of resources on PLANAR shadowing. What he wants help with is _dynamic_ terrain shadow generation (not static shadows, Neosmyle). Banding about terms such as "stencil shadows" without bothering to explain their meaning (probably because you don''t know yourself) is also unhelpful.[/rant]



He wanted to know how to make it so his objects cast shadows onto the terrain, not terrain shadowing. Read his post again, and you''ll see that is indeed what he wants. There IS a tutorial on NeHe about stencil shadows, which can be used to do what he asked. I pointed him to places where he can find such information. The nVidia site DOES HAVE VERY RELEVANT information, go there yourself, you will see that I''m right. Don''t post rants about complete nonsense, it isn''t big, and it isn''t smart.

Also, about your view on planar shadowing, I think he means that he has found tutorials on basically "squashing" models into a 2D plane using a projection matrix, like Q3''s hack shadows use.

Death of one is a tragedy, death of a million is just a statistic.

Share this post


Link to post
Share on other sites
I've looked on the nVidia site before for shadow related stuff. There's nothing specifically for shadowing terrain, and most of the methods described will only work on nVidia cards. Given that there are efficient methods specifically for shadowing terrain using standard OpenGL calls, don't you think it would be more useful to post links to those?

____________________________________________________________
www.elf-stone.com

[edited by - benjamin bunny on June 1, 2002 10:03:38 AM]

Share this post


Link to post
Share on other sites
Ok, you are still misinterpreting his post. He doesn''t want nice terrain self-shadowing, he wants to know how to project the shadow of an object onto the terrain, ie, the shadow of a person or something. For this, a shadow mapping technique, or a stencil shadow is needed, both are well documented on the nVidia site.

Shadow mapping only working on nVidia cards? Don''t be silly...

Death of one is a tragedy, death of a million is just a statistic.

Share this post


Link to post
Share on other sites
If you look at the first link I posted, there's a heading entitled Shadows Cast by Objects onto the Terrain . Also, the second link's method could easily be extended to include object shadowing.

____________________________________________________________
www.elf-stone.com

[edited by - benjamin bunny on June 1, 2002 12:46:58 PM]

Share this post


Link to post
Share on other sites
Hi!
I found RipTorns reply very helpful, but Im still not sure how you do it, so I´ve maked some pseudo-code:

glDisable(GL_TEXTURE_2D);
MoveToLightPosition( );
DrawModel( );
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 512, 512, 0); // Save frame-buffer
glClear(Color | Depth);

glEnable(GL_TEXTURE_2D);
MoveToCameraPosition( );
DrawTerrain( );
??? <- What should be here? ProjectFrameTexture( ) ???

if this pseudo-code is correct, what should my ProjectFrameTexture( ) then be?

If it´s not correct, then please write some pseudo-code

Thanx!
-Roq-

Share this post


Link to post
Share on other sites
quote:
Original post by benjamin bunny
If you look at the first link I posted, there''s a heading entitled Shadows Cast by Objects onto the Terrain . Also, the second link''s method could easily be extended to include object shadowing.



Hehe, ok, so we''re both right


Death of one is a tragedy, death of a million is just a statistic.

Share this post


Link to post
Share on other sites
Ah, pants, I guess I was a bit out of line there. I just get pissed off with everyone posting links irrelevant nehe tutorials whenever a question on anything is asked. In your case, I grant you, it was sortof relevant. I had thought the nehe tut was on planar shadows, but it''s not. So, anyway, oops, and sorry about that. I''ll try and be more discriminating in my rants in future (except the indiscriminate ones, that would ruin them).

____________________________________________________________
www.elf-stone.com

Share this post


Link to post
Share on other sites
Yeah, I suppose I over reacted a bit to your original post too...

Death of one is a tragedy, death of a million is just a statistic.

Share this post


Link to post
Share on other sites

  • Advertisement