- Registriert
- Okt. 2007
- Beiträge
- 8.643
Ein schöner Beitrag hier auch in Sachen Raytraced Shadows und wie dieses den Konflikt Stencil shadows<>Shadow mapping löst:
Für interessierte:
Stencil shadow shortcomings
In favour of shadow mapping
Apart from being without the limitations I listed specifically for stencil shadows, there are a few extra advantages to shadow mapping:
LG
Zero
YouTube
An dieser Stelle steht ein externer Inhalt von YouTube, der den Forumbeitrag ergänzt. Er kann mit einem Klick geladen und auch wieder ausgeblendet werden.
Ich bin damit einverstanden, dass YouTube-Embeds geladen werden. Dabei können personenbezogene Daten an YouTube übermittelt werden. Mehr dazu in der Datenschutzerklärung.
Für interessierte:
Stencil shadow shortcomings
- Shadows match the shape of the casting mesh. This is very limiting, and is probably the biggest technical reason not to use stencil shadows. Tree leaves, bushes, wire fences, rips in cloth, and other common shadow-casting game elements use alpha transparency to define the shape of the object. But since stencil shadows match the mesh and not strictly the visible parts of the texture on the mesh, they can't be used for such objects. For example, a cluster of leaves in a tree will usually be a texture of a cluster of leaves on a quad. Stencil shadows would only be able to show the shadow of the quad itself (and it'll have problems with that since a quad isn't a closed mesh, but this is a minor detail I'll skip over for this answer, as it's generally able to be worked around).
- Can't do accurate soft shadows. You've pointed out that Doom 3 has been modded to allow soft shadows. This version here, at least, uses shadow mapping for soft shadows. I've also seen screen-space techniques for softening hard shadows, but they're prone to all sorts of problems.
- Can't do shadows on transparent objects. There are workarounds for this -- rendering shadows for transparent objects in separate passes and compositing them afterwards. But besides difficult workarounds, the nature of stencil shadows is such that each pixel on-screen is either in shadow or not. This is also the reason for no soft shadows as mentioned before.
- The generally preferred and most robust implementation of stencil shadows, often called "Carmack's Reverse", is actually patented, as Angew pointed out in the comments. (Not patented by Carmack; he had to work around it for the open source version of Doom 3)
In favour of shadow mapping
Apart from being without the limitations I listed specifically for stencil shadows, there are a few extra advantages to shadow mapping:
- Scalability. While shadow mapping is neither cheap nor perfect (ed: but stencil shadows aren't cheap either), it's relatively easy to trade fidelity for performance by changing the resolution of the shadow maps or changing the filtering for shadows. This makes it relatively easy to tune the shadow quality / performance for different systems. As you've pointed out, this often isn't perfect, but a lot of this will depend on the perceptiveness of the player, and the resolution they're playing at (higher screen resolution will make it easier to see the blockiness of shadow mapping). Some AAA games (like Fracture) do an amazing job with shadow mapping just by picking the right filters and tuning the right knobs, while many just slap it in there and say "good enough".
- Cookies (textured shadows): Add the texture of a spotlight, or stained glass, and you can emulate all sorts of real-world light sources. This is doable with stencil shadows, too, by the way, but involves almost all the setup of shadow mapping anyway (the same projection matrices used for projecting the light's texture on objects are the ones used for shadow mapping).
- Transparent shadows: Most games don't attempt much with this, but transparent shadows are possible with shadow mapping. I don't just mean alpha cutouts like trees and fences like I mentioned before, but I mean partially transparent shadows, like from smoke and dust.
LG
Zero