Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement initial cascaded shadow mapping support #3307

Merged
merged 41 commits into from
Aug 27, 2023

Conversation

past-due
Copy link
Member

@past-due past-due commented Jul 15, 2023

Building on top of the new instanced rendering setup, this PR implements an initial attempt at cascaded shadow mapping.

Notes:

  • Shadows are softer than the old stencil shadows, and (generally) more accurate.
  • However, the usual caveats with shadow maps apply. (And we still have visual improvements to make in regards to self-shadowing.)
  • 4096 x 4096 shadow map resolution can use a good chunk of memory.
    • By default, WZ will only default to this high a resolution if it can detect there is >= 4GB of video memory.
    • (On Vulkan, it should always be able to detect this. On OpenGL, there are fewer easy ways to detect this, but WZ takes advantage of vendor-specific extensions when available.)
  • The shaders are not final, and there are several ways we could improve results. Please feel free to play around with the shaders and suggest improvements.
  • For now, only non-terrain meshes are rendered to the shadow map. (i.e. units, structures, etc)

Performance notes:

  • Performance scales dramatically better using shadow mapping than the old stencil shadows.
    • i.e. The more units, and the more polygons (example: lots of ArtRev units on screen), the better shadow mapping will perform over the old stencil shadows.
    • But for an extremely simple scene with almost no units, it's possible that the old stencil shadows will be faster on some systems.
  • Disabling shadows at run-time - whether using the old stencil shadows (fallback) or the new shadow mapping - should eliminate any performance overhead of the shadows.
  • There are several options for configuring shadow mapping quality and visuals:
    • Shadow Resolution:
      (The size of the shadow map buffer.)
      • Normal (2048 x 2048)
      • High (4096 x 4096)
    • Shadow Filtering:
      • Low (3x3)
      • High (5x5)
      • Ultra (7x7)
  • The Script Debugger > Graphics menu offers the ability to change these (and other) settings at run-time, for testing.

Future TODOs:

  • Adjust the bias based on the fragment normal + sun position (or other similar methods to improve results)
  • Fix various classic models (some have holes / are missing sides that weren't normally visible, but this can cause visual issues with the shadow mapping)

Ideas for future improvement:

  • Improve the shadow map cascades calculations (these can definitely be optimized - there are currently various hacks implemented to get something that works decently)
  • Would be great to able to use this for terrain shadows (and self-shadowing terrain)...

@past-due past-due added this to the 4.4.0-beta1 milestone Jul 17, 2023
@KJeff01
Copy link
Member

KJeff01 commented Jul 19, 2023

This post will contain all models that have shadow issues.

Droid components:
- Weapons: Flamer, Seraph, Inferno, Hurricane, Gauss weapons (+fort), Vindicator (dish), Whirlwind, Tornado Flak, Mortar/Incendiary Mortar/EMP Mortar/Howizer/HellStorm/Ground Shaker/Incendiary Howitzer (dark trays), HRA, Twin Assault Gun, Stormbringer (dish), Plasmite Flamer, Twin Assault Cannon.

These all either have holes underneath them or darkness issues. The first slot on the dragon body is good to test with as the weapon is mounted in such a way the turret will cast a longer shadow.

Features:
- Oil Drum
- Crane, Pylon, and water tower have dark scaffolding
- Log cabin 2, log cabin 3 have dark roofs.
- Pipe, pipe1, pipefull, pipeend, pipe collapsed, water building, and wrecked van turn dark

Structures:
- Scavenger specific: Flamer tower, Gun Tower, End Tower, Mortar pit, power Plant, Cannon Tower
- All Command Centers (seems sensor mount is a big cause), big sensor turns dark.
- Lassat antennas are dark.
- Metal scaffolding for the early towers is all dark.
- Look Out tower has a floating box shadow issue.
- Nexus Missile Silo has no shadow (maybe not important)
- Missile Silo
- Nuclear Reactor (dark on parts facing the sky)
- Sensor mount is busting shadows in general for all sensor towers
- Sensor dish is dark on Uplink
- Metal fence on Oil Derrick is dark
- Ultimate Scavenger MG Tower has a dark fence.

So far I'm looking at campaign only and this is still a work in progress. Edit: Done campaign. Need to look at MP specific technology now, plus the body and propulsion components.

@past-due
Copy link
Member Author

First batch of model fixes are in: #3347

past-due and others added 22 commits August 27, 2023 12:21
GL_ATI_meminfo, GL_NVX_gpu_memory_info
@past-due past-due changed the title [WIP] Implement cascaded shadow mapping Implement initial cascaded shadow mapping Aug 27, 2023
@past-due past-due marked this pull request as ready for review August 27, 2023 16:24
@past-due
Copy link
Member Author

Going to merge this shortly, to get some more testing (and make way for additional work that builds on this).

Since the old stencil shadow method still exists, we can always change the default for the next release back to the stencil shadows if we haven't resolved enough additional model issues before then.

@past-due past-due changed the title Implement initial cascaded shadow mapping Implement initial cascaded shadow mapping support Aug 27, 2023
@past-due past-due merged commit f2bce01 into Warzone2100:master Aug 27, 2023
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants