Jump to content
The Dark Mod Forums

Stair Stepping in Soft Shadows


davyspark343

Recommended Posts

So I was interested in how the soft shadows work in TDM and came across this video. At around 40 minutes in he starts discussing the stair stepping in the soft shadows and supplies a fix. What he does is use bi-linear interpolation on each PCF sample, instead of nearest neighbor. He says it is a hack but the result looks great. I have a AMD RX 580 and using higher settings of soft shadows brings the GPU to its knees. Using soft shadows is a huge performance hit ~25%. Lowering the shadow map resolution to 512 does not help much. But using this method should allow using low soft shadows and low shadow map resolution and still enable smooth transitions from shadow to light.

 

  • Like 1
Link to comment
Share on other sites

TDM uses Percentage-Closer Soft Shadows when shadow maps are enabled. I think the only difference over plain PCF is that softening radius is correctly computed using distance-to-light and distance-to-blocker. Unfortunately, it is rather costly technique: one set of samples is used to determine distance-to-blocker, and one set to actually soften the shadow --- so it is 2 times more costly than PCF without distance-to-blocker estimation.

When stencil shadows are enabled, soft shadows use screen-space blurring of stencil buffer. It is rather hacky technique which shows surprisingly good results. But there is no distance-to-blocker, so there is no contact hardening.

 

Shadow maps use nearest-neighbor filtering, since billinear filtering of shadow maps is not that simple to use. I tried enabling bilinear filtering in various ways, but it made no difference. Because samples are usually far from each other in shadow texture, so if you see separate shadows, filtering cannot do anything with it.

  • Like 3
Link to comment
Share on other sites

That's too bad. I am inexperienced in rendering but am fascinated by the subject. Have you looked at using OpenGL Shadow Samplers when soft shadow quality is set to 0 to help smooth jaggies? I have a second question. Does the dark mod clip the view frustum when looking through visportals? It seems like the game overdraws in places like the streets in The Painters Wife.    

  • Like 2
Link to comment
Share on other sites

5 hours ago, davyspark343 said:

That's too bad. I am inexperienced in rendering but am fascinated by the subject. Have you looked at using OpenGL Shadow Samplers when soft shadow quality is set to 0 to help smooth jaggies?

I think it is what @duzenko did with texture gather. It is only enabled when soft quality is zero, and if GPU supports it.
Unlike what you might expect, it does not remove the stair-like look of shadow boundary. It makes it a bit blurry, but separate texels are still visible pretty well. The same would happen if you decide to blur a low-resolution image rendered without antialiasing using <= 1 pixel blur radius: it will not get antialiased well.

Quote

I have a second question. Does the dark mod clip the view frustum when looking through visportals? It seems like the game overdraws in places like the streets in The Painters Wife.    

Yes, of course. Scissor test is used to achieve it: it allows to limit rendering to axis-aligned rectangle on screen. The rectangle for every visportal area is computed as intersection of all portal windings between the eye and the area. The objects outside the rectangle are completely dropped from rendering.

Also, the engine does "depth prepass", so it does not compute color for occluded pixels.

Unfortunately, visportals are only good in closed areas. They are often rather useless in open areas.

  • Like 2
Link to comment
Share on other sites

I am sorry if my comments are irritating, but it has occurred to me that this topic has come up due to shadow mapping performance issues. If shadow mapping was more performant than I could simply turn up the soft shadow quality or shadow size. Modern games use cascade shadow maps to improve performance. I have noticed that my frame rate will tank when looking down a hallway with lots of shadow casting lights. I was thinking about shadow mapping today and the following occurred to me. Shadow quality should scale with the amount of angular screen space that they take up. I don't know if the dark mod has a way to scale shadow size per light, but some kind of Level of Detail could be used.

For example

  1. Get the max dimension from the bounding box for the light. In the game every light has a bounding box that determines how far away objects are lit and shadows are cast. It would be easy to get the single maximum dimension from the light. max_dimension = max(x, y, z)
  2. Get the players distance from the light using pythagorean theorem. sqrt((x1-x0)^2 + ... etc
  3. (player distance from light)/(max dimension of light) will give you the players distance from the light in units of the light's bounding box
  4. Scale the shadow map size for the light by using the players distance from the light. ( shadow map size ) / ( (player distance from light) / (max dimension of light) )

I believe that this should scale the size of the shadow map relative to angular size of the shadow map in the players field of view.

So a player standing inside the bounding box of a light would cause the light to render the shadow map at the highest resolution. In contrast a player that is four bounding boxes away from a light would cause the shadow map to render at 1/4 resolution. The algorithm should catch edge cases like some lights having bounding boxes that take up large areas still casting high resolution shadows, while nearby lights with small bounding boxes will render low resolution shadows.

If shadow map size cannot be scaled dynamically, than the lights could render at lower resolution and use nearest neighbor filtering to cut down on the rendering time, even if the shadow map size takes up the same space in memory

Edited by davyspark343
  • Like 3
Link to comment
Share on other sites

I did not read the details, but the whole idea of setting map size by targeting some prescribed screen-space size of shadow texels is good, of course. At least for indoor lights with small light radius. I think we had similar ideas when we discussed soft shadows implementation.
The current code already tries to adapt shadow map resolution, but in more naive way. Perhaps it already stores maps in single texture.

 

  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recent Status Updates

    • Ansome

      Finally got my PC back from the shop after my SSD got corrupted a week ago and damaged my motherboard. Scary stuff, but thank goodness it happened right after two months of FM development instead of wiping all my work before I could release it. New SSD, repaired Motherboard and BIOS, and we're ready to start working on my second FM with some added version control in the cloud just to be safe!
      · 0 replies
    • Petike the Taffer  »  DeTeEff

      I've updated the articles for your FMs and your author category at the wiki. Your newer nickname (DeTeEff) now comes first, and the one in parentheses is your older nickname (Fieldmedic). Just to avoid confusing people who played your FMs years ago and remember your older nickname. I've added a wiki article for your latest FM, Who Watches the Watcher?, as part of my current updating efforts. Unless I overlooked something, you have five different FMs so far.
      · 0 replies
    • Petike the Taffer

      I've finally managed to log in to The Dark Mod Wiki. I'm back in the saddle and before the holidays start in full, I'll be adding a few new FM articles and doing other updates. Written in Stone is already done.
      · 4 replies
    • nbohr1more

      TDM 15th Anniversary Contest is now active! Please declare your participation: https://forums.thedarkmod.com/index.php?/topic/22413-the-dark-mod-15th-anniversary-contest-entry-thread/
       
      · 0 replies
    • JackFarmer

      @TheUnbeholden
      You cannot receive PMs. Could you please be so kind and check your mailbox if it is full (or maybe you switched off the function)?
      · 1 reply
×
×
  • Create New...