Skip to main content
GameDev.net gamedev.net
🔒 Locked

Shadows

Started by spek Jan 13, 2007 at 12:04 PM 7 replies 1.3k views
Original Post
spek
spek
Hi, I'm looking for a way to add shadows to my game. The static part is already using lightMapping, so it's only for dynamic objects such as characters and boxes. I already tried stencil shadows in the past. That worked, but as you probably know, they have these sharp edges. I know there are soft shadowing techniques, but I believe they are relative heavy to perform. And it still looks kinda fake, unless you do it real high quality. I noticed that Halflife2 used another way of shadows. A little bit pixelated, but they had smoother edges. How is that technique called, and is it really faster than stencil shadows? Or are there any other techniques? Greetings, Rick
SimmerD
SimmerD
What they do, afaik, is to render their chars in black to a white texture, blur it, then blend this on over the lighting. It works well for outdoor scenarios, but is fast, cheap, and solves the main goal of shadows, which is to help place items in the scene visually.

I used to use a similar technique in my engine. It's great if you have only a single light render pass.

If you want distinct per-light shadows, then you would have to do this per-light source, or use some other technique.
spek
spek
My objects pick 1 or 2 nearby lightsources. So I need 1 or 2 shadows as well (but maybe only 1 for lower-end cards), and the lightSource(s) can change when the objects moves around.

I think I understand the background rendering part. But how to apply that texture on the scene, or maybe even on other objects?

By the way, isn't this technique called "shadow mapping"? I remember that I tried that a long time ago. One problem that I had, was with very far way lightSources (the sun). Because the further the light, the lower resolution the shadow was (resulting in very pixelated shadows). Is there a trick to reduce that?

greetings,
rick
SimmerD
SimmerD
If you do per-object shadow maps, you can get the resolution pretty good, assuming the shadow casting object is near the shadow receiving object ( usually the ground or nearby geometry ).

Check my journal for some info about my implementation of per-object shadow maps.
Schrompf
Schrompf
Shadow Mapping is a technique that renders the scene depth from the light's point of view into a texture and then compares the depth against the scene's depth while rendering the scene.

This depth comparision isn't needed for simple shadows. If you have distinct shadow casters (a character) and shadow receivers (ground), you can simply render a black silhouette of the character into a small texture on white background and project that texture onto the ground. This method is the oldest of all shadow methods (apart from blob shadows :-)) and is called "Projected Shadows" for some reason. It is similar to Shadow Mapping in the sense that you render the object into a texture. But instead of comparing depth you rely on the distinction of shadow casters and shadow receivers, which simplifies the per-pixel-work and makes this method suitable for even the oldest gfx board. Including mainboards with integrated graphics. Simply draw the black/white texture alpha-blended over the scene in a second pass and you're done.

The last popular game that I know doing shadows this way was Half Life II, but I guess alot of casual games use this method as well as they are usually targetted on lower spec hardware.

Bye, Thomas
----------
Gonna try that "Indie" stuff I keep hearing about. Let's start with Splatter.
Ashkan
Ashkan
Quote:
This depth comparision isn't needed for simple shadows. If you have distinct shadow casters (a character) and shadow receivers (ground), you can simply render a black silhouette of the character into a small texture on white background and project that texture onto the ground. This method is the oldest of all shadow methods (apart from blob shadows :-)) and is called "Projected Shadows" for some reason. It is similar to Shadow Mapping in the sense that you render the object into a texture. But instead of comparing depth you rely on the distinction of shadow casters and shadow receivers, which simplifies the per-pixel-work and makes this method suitable for even the oldest gfx board. Including mainboards with integrated graphics. Simply draw the black/white texture alpha-blended over the scene in a second pass and you're done.


Would you please elaborate more on this technique? I used to think projected shadows are usually created by multiplying the geometry by some shadow matrix (which is actually nothing more than a projection matrix) + using stencil buffers to prevent double blending.

PS. do we have support for render to texture on older FFP cards?

Thank you.
Matt Aufderheide
Matt Aufderheide
Render-to-texture has been around for awhile .. i think cards like GeForce 256 had it.
Schrompf
Schrompf
Projected Shadows are nothing new or magical. They're around for quite a while now. The Unreal2-Engine uses them, just like most of the other Engines of that age as well.

First step: Draw every shadow caster into a texture. You can use separate textures per object or one texture for everything. Older RTS games did use the latter option for unit/tree/object shadows. Clear the texture to (0, 0, 0, 1) and render the objects so that they write maybe( 0, 0, 0, 0) to all occupied pixels.

Second step: Project that texture to your scene. If you have separate textures for objects, first determine what scene parts are influenced by that projection. Then redraw that parts (or all of the shadow receiving scene) with the projected texture and modulative Alpha Blending. The result is that pixels on screen in shadow are darkened and pixels outside of the shadow are left unchanged.

Advanteges:
- Supported by all gfx boards with Render-To-Texture support. That means every gfxboard since maybe 2000.
- Quite fast
- Texture coord generation can be accelerated by Hardware T&L
- can easily be blurred, faded in and out etc.

Disadvanteges:
- Needs second pass, means more CPU processing demand and fillrate consumption
- Shadow casters and shadow receivers have to be distinct objects. No self-shadowing.

That's all about it. Propably easier set up than Shadow Maps. After all, this is no new technique or something. I mentioned it mainly to correct the assumption that this is Shadow Mapping.

[edit]
Quote:

One problem that I had, was with very far way lightSources (the sun). Because the further the light, the lower resolution the shadow was (resulting in very pixelated shadows). Is there a trick to reduce that?


That's another topic, and quite a difficult one. Google for "Trapezoidal Shadow Mapping", "Light Space Perspective Shadow Mapping" or have a look at http://www.gamedev.net/community/forums/topic.asp?topic_id=405955&whichpage=1 where another technique is described that I use to counter this problem.

Bye, Thomas
----------
Gonna try that "Indie" stuff I keep hearing about. Let's start with Splatter.
spek
spek
Good help, as usual here. Thanks guys! I'm going to look into it.

greetings,
Rick

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.