openspades
openspades copied to clipboard
Option to use stencil shadows (aka shadow volumes) instead of a shadowmap for player shadows.
It would look quite a lot crisper, and it has the potential to actually be faster than the PSSM currently used, since the players are fairly low poly count.
One way to make this somewhat fast is use a geometry shader to compute the shadow volumes, and render them to the stencil buffer or a texture (after the depth pre-pass of course), then render the sun lighting as usual in the same sunlight pass as the block shadows, but now use the stencil test (or conditional/multiply on the texture). Basically the same number of actual passes done.
Does the sunlight pass also do the "ambient" light as well? That would either require a separate pass for the ambient or to use a texture instead of a stencil test. A texture could also be slightly blurred to get rid of aliasing (fxaa) or have a lot more sampling done to it to create soft shadows.
Any thoughts? I might have a go at it at some point.
One of the biggest issues regarding stencil shadows is its fill-rate requirement, but it should not be a problem in the case of dynamic models (players, grenades, falling blocks, e.t.c.). An extra full-screen pass might be problematic on the lowest end of integrated GPUs, though.
I would imagine handling the case where the camera is inside a shadow volume would be difficult without infringing Creative Labs' patent. Is there any better way?
One way to make this somewhat fast is use a geometry shader to compute the shadow volumes,
Maybe we do not need geometry shader at all. The shape of silhouette edge changes depending on the light direction relative to the model axes. For general models, there are (practically) infinite patterns of such shapes, hence a geometry shader is needed. But in the case of voxel models, there are only up to 26 patterns possible.
That said, geometry shader is still be useful for, like, extruding silhouette edges to form shadow volumes. This would reduce the vertex buffer size by half.
the PSSM currently used
No, the default algorithm is sparse shadow maps, (maybe?) similar to Resolution Matched Shadow Maps
Does the sunlight pass also do the "ambient" light as well?
Yep, like old times. Fewer passes = less bandwidth.
That would either require a separate pass for the ambient or to use a texture instead of a stencil test. A texture could also be slightly blurred to get rid of aliasing (fxaa) or have a lot more sampling done to it to create soft shadows.
We could apply a screen-space technique (basically depth-aware blur without or with anisotropy) to create soft shadows, but since there is no way we can obtain the distance to the blocker in the case of stencil shadows, we will have to pick a constant penumbra size in screen-space or world-space.
I have only heard of a handful of games/engines using a screen-space technique to create soft shadows:
- Wolfenstein (2009) - stencil shadows + screen-space soft shadows (with depth-aware Gaussian blur, constant kernel size in screen-space)
- My own no-longer-under-development engine - CSM + not-widely-known screen-space soft shadows algorithm + Temporal AA. A screen shot is shown below:
Some artifacts are visible where multiple blockers with different penumbra sizes overlap, but screen-space solutions appear to be robust as long as penumbra is small enough.
Additional Bonus 1: Stencil shadows could be applicable to the terrain, not just dynamic models. This means #622 can be addressed at the same time, but at cost of tremendous overdraw.
Additional Bonus 2: Shadow volumes potentially can be utilized to accelerate the rendering of volumetric shadow. NVIDIA GameWorks analytically computes the effect of participating media using shadow volumes derived from shadow maps. You can see this in action in Fallout 4, Far Cry 4, and The Elder Scrolls V: Skyrim Special Edition.
Fallout 4:
Far Cry 4:
I'm not sure if this is applicable to Ace of Spades's physically incorrect fog.
Even if we cant get around the licensing issue for depth-fail, we can still use them for volumetrics. I came up with a method that should work moderately well, and may be faster than the current raymarching-a-shadowmap method that is used. I will write something with more detail up later.
So the method I came up with depended on writing to a texture while reading from it... It might still work, due to the nature of the writes, but I will have to write a small program to test it first.
I am also working on another method, but it is an approximation and might be hard to get "accurate" density and scattering. Should still look pretty, but might not be suitable for OS.
The cases when the camera is inside the volume still need to be addressed even for volumetrics. GameWorks renders a full-screen quad in such cases, but the method to detect such cases is not explained.
Even without this or depth-fail, maybe we could clip the shadow volume against the near clip plane using a geometry shader.
So the method I came up with depended on writing to a texture while reading from it...
I think that will result in an undefined behavior, unless writing is done by image store operation, not via a framebuffer attachment.
And I think now I know why most game devs don’t favor screen-space soft shadows:
I would imagine handling the case where the camera is inside a shadow volume would be difficult without infringing Creative Labs' patent. Is there any better way?
I realize this issue is super old, but I stumbled across it while researching stencil shadow volumes. So, apologies for the necro-post, but you'll be happy to know the patent expired in 2019.