vram-guild / canvas

Shader-Based Minecraft Renderer for Fabric
GNU Lesser General Public License v3.0
415 stars 40 forks source link

Shadow experiments in the config #383

Closed spiralhalo closed 2 years ago

spiralhalo commented 2 years ago

This sub-project adds a few debug options as well as improve the current ones for shadow rendering. The Configurator class is referenced directly where they apply, as these are meant for development therefore scoping is made simpler albeit chaotic. Despite that, these options should have low impact on production performance.

List of changes

Shadow Priming Strategy

IMPROVED "padded" method. It now simply primes the view distance edge, one region before it, as well as 4 regions away from the camera. The two first ones seem to solve disappearing shadows as the player approaches the light source. The last one simply ensure that nearby objects cast shadow faster since chunk loading starts from the camera. With this, the padded strategy is currently the preferred/recommended option.

Shadow Render Distance

IMPROVED: previously only affects shadow priming distance. Now also affects occlusion maximum distance, as well as the shadow matrix boundaries. Eventually, this option is meant to become the distance config for the 0th cascade, which should be implemented as optional and falls back to maximum render distance.

Shadow Face Culling

Choose between Back face (default), Front face, and None.

Shadow Centering Factor

The center of the shadow map is set to the approximated centroid of the camera frustum. This option allows the user to interpolate this center between this and the camera. Setting the center to simply be the camera seem to reduce clipping artifact, as shown in the video below:

https://user-images.githubusercontent.com/8444172/175876494-c4b5a68c-636a-4172-933b-7a2c94a29abf.mp4

Disable Shadow Self-Occlusion

This option makes it so that shadow culling only relies on the "target" occluder rather than the shadow occluder. This works around the current issue of non-renderable occlusion volumes occluding renderable geometry, causing massive gaps. A proper solution will be made eventually.

Observations

Currently, the best shadow map outcome is achieved by these settings:

The necessity to disable face culling and self-occlusion are related. Therefore once a proper solution is made, these will be unnecessary.

As for centering the shadow to the camera instead of the frustum centroid, I'm not really sure the implications of this. Gotta ask Grondag.

For priming strategy, padded might just be the permanent solution, but the option remains to make further experiments easier.