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

Shadow mapping is not supported #84

Closed
9 of 10 tasks
coderbot16 opened this issue Jan 19, 2021 · 2 comments
Closed
9 of 10 tasks

Shadow mapping is not supported #84

coderbot16 opened this issue Jan 19, 2021 · 2 comments
Labels
unimplemented Something isn't implemented yet
Milestone

Comments

@coderbot16
Copy link
Member

coderbot16 commented Jan 19, 2021

Many shaderpacks require this to work properly. They'll run without it, but things won't look right.

  • Ability to orient the camera to point at the player from the current shadow light position
  • Configuring the projection matrix as required by the shaderpack
    • Orthographic projections (SHADOWHPL), used by most shaderpacks
    • Perspective projections (SHADOWFOV), legacy
  • Rendering the world (or parts of it) twice per frame: once for shadows, once normally
    • Ensure that this is implemented in a way that doesn't trip up other mods
    • Open question: should the events in WorldRenderEvents be fired for both the shadowmap rendering and standard world rendering, or only standard world rendering?
      • Canvas does not fire special world events when rendering shadows. This seems like sane behavior to replicate.
    • An initial implementation could focus only on rendering terrain and perhaps the player entity, since those are the most important things for shadows.
  • Render to special shadow render targets and then make the render target content available to other shaders
  • Decent shadow culling
    • I discussed shadow culling with Grondag a while back. Essentially, the only chunks that should be considered for shadow rendering are chunks that are (a) directly visible to the player or (b) potentially occluding (ie, casting shadows on) chunks directly visible to the player from the perspective of the sun / moon
    • Based on the absolutely abysmal performance of shadow rendering with most shaderpacks on OptiFine (some shaderpacks spend 50% of the CPU time on shadow rendering, and probably a bit of GPU time too!), I'm going to guess that it just flat out does not cull anything during shadow rendering. This is likely to solve the "why is the mountain behind me not casting a shadow" problem, but it results in very poor performance.
@coderbot16
Copy link
Member Author

  • Don't cull the sides and bottom of the world in shadow map rendering

While the player normally cannot see these things, the shadow light source definitely can. During the chunk building process, the faces on the sides of chunks on the edge of the world are culled with the expectation that a new chunk will be loaded there, however it would be possible to keep track of all of those culled faces, then render them during shadow map rendering only. This would fix the issue of shadow light seeping into caves that seems to afflict many shaderpacks.

You can see in this image how the shadow map under OptiFine is able to see caves and underground mobs:

2021-02-20_19 19 11

This is a completely dark cave underground, yet it is filled with sun:

image

Some shaderpacks work around this by only applying shadows to faces with a certain sky light value, however this causes problems of its own.

@coderbot16
Copy link
Member Author

Shadows are now available in the latest trunk version.

@coderbot16 coderbot16 unpinned this issue Jun 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unimplemented Something isn't implemented yet
Projects
None yet
Development

No branches or pull requests

1 participant