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

    • taffernicus

      i am so euphoric to see new FMs keep coming out and I am keen to try it out in my leisure time, then suddenly my PC is spouting a couple of S.M.A.R.T errors...
      tbf i cannot afford myself to miss my network emulator image file&progress, important ebooks, hyper-v checkpoint & hyper-v export and the precious thief & TDM gamesaves. Don't fall yourself into & lay your hands on crappy SSD
       
      · 1 reply
    • OrbWeaver

      Does anyone actually use the Normalise button in the Surface inspector? Even after looking at the code I'm not quite sure what it's for.
      · 7 replies
    • Ansome

      Turns out my 15th anniversary mission idea has already been done once or twice before! I've been beaten to the punch once again, but I suppose that's to be expected when there's over 170 FMs out there, eh? I'm not complaining though, I love learning new tricks and taking inspiration from past FMs. Best of luck on your own fan missions!
      · 4 replies
    • The Black Arrow

      I wanna play Doom 3, but fhDoom has much better features than dhewm3, yet fhDoom is old, outdated and probably not supported. Damn!
      Makes me think that TDM engine for Doom 3 itself would actually be perfect.
      · 6 replies
    • Petike the Taffer

      Maybe a bit of advice ? In the FM series I'm preparing, the two main characters have the given names Toby and Agnes (it's the protagonist and deuteragonist, respectively), I've been toying with the idea of giving them family names as well, since many of the FM series have named protagonists who have surnames. Toby's from a family who were usually farriers, though he eventually wound up working as a cobbler (this serves as a daylight "front" for his night time thieving). Would it make sense if the man's popularly accepted family name was Farrier ? It's an existing, though less common English surname, and it directly refers to the profession practiced by his relatives. Your suggestions ?
      · 9 replies
×
×
  • Create New...