EEVEE-Next: Improve shadow bias #121088

Merged
Clément Foucault merged 13 commits from fclem/blender:eevee-next-shadow-bias-improved into main 2024-04-27 14:31:02 +02:00

The goal of this PR is to remove any user facing parameter
bias that fixes issues that are caused by inherent nature of
the shadow map (aliasing or discretization).

Compute shadow bias in the normal direction to avoid
both shadow leaking at certain angles or shadow
acnee.

This bias is computed automatically based on the minimum
bias amount required to remove all errors. The render
setting is removed as of no use for now.

Normal bias

We do the bias in world space instead of shadow space
for speed and simplicity. This requires us to bias using
the upper bound of biases for the same location in space
(using biggest texel world radius instead of UVZ bias).
This isn't much of an issue since the bias is still less
than 2 texel. The bias is still modulated by facing
ratio to the light so surfaces facing the light have no
biase.

This fixes both self shadowing and flat occluders aliasing
artifacts at the cost of moving the shadow a bit on the
side. This is the blue arrow in the diagram.

We always bias toward the normal direction instead of the
light direction. This is alike Cycles geometric offset for
the shadow terminator fix. This is better since it does'nt
modify the shading at all.

Slope bias

To avoid aliasing issue on zero slope receiver, we still
have to use the slope bias with a size of 1 pixel.

No bias 1px Slope Bias 1px Normal Bias Combined

PCF filtering

We now parametrize the filter around the normal instead of
using the shadow map local space. This requires to use
a disk filter instead of box, which is also more pleasant
for most light shapes (all except rectangle lights).

Setting the filter around normal avoid overshadowing from
zero slope occluders. This cannot be fixed by more slope bias
in light space PCF. We could fix it in light space by projecting
onto the normal plane but that gives an unbounded bias when N.L
is near 0 which causes either missing shadows or self shadow if
using an arbitrary max offset value.

Light PCF Light PCF + Slope Bias Normal PCF

To avoid overshadowing from any surface behind the shading
point, we reflect the offset to always face the light.
Doing so instead of using the perpendicular direction
is better for very sharp geometric angles, has less
numerical precision issue, is symetrical and is cheaper.

Normal PCF Normal PCF + Reflect

To avoid any self shadowing artifact on zero slope receivers
with angled neighbors (like a wall and the floor), we have
to increase the slope bias according to the filter size.
This might be overkill in most situation but I don't feel
this should become a setting and should be kept in sync
with the filter. If it has to become an option, it should
simply a factor between unbiased filter and best bias.

Normal PCF + Reflect Normal PCF + Slope bias Normal PCF + Reflect + Slope bias

Shadow terminator

The remaining artifacts are all related to shadow terminator
one way or another. It is always caused by the shading
normal we use for biasing and visibility computation not
being aligned with the geometric normal.

This is still something we need a setting for somewhere.

The goal of this PR is to remove any user facing parameter bias that fixes issues that are caused by inherent nature of the shadow map (aliasing or discretization). Compute shadow bias in the normal direction to avoid both shadow leaking at certain angles or shadow acnee. This bias is computed automatically based on the minimum bias amount required to remove all errors. The render setting is removed as of no use for now. ![](https://projects.blender.org/attachments/12998611-2b81-48f1-83fb-338dd74d66f9) #### Normal bias We do the bias in world space instead of shadow space for speed and simplicity. This requires us to bias using the upper bound of biases for the same location in space (using biggest texel world radius instead of UVZ bias). This isn't much of an issue since the bias is still less than 2 texel. The bias is still modulated by facing ratio to the light so surfaces facing the light have no biase. This fixes both self shadowing and flat occluders aliasing artifacts at the cost of moving the shadow a bit on the side. This is the blue arrow in the diagram. We always bias toward the normal direction instead of the light direction. This is alike Cycles geometric offset for the shadow terminator fix. This is better since it does'nt modify the shading at all. #### Slope bias To avoid aliasing issue on zero slope receiver, we still have to use the slope bias with a size of 1 pixel. | No bias | 1px Slope Bias | 1px Normal Bias | Combined | | -------- | -------- | -------- | -------- | | <img src="https://projects.blender.org/attachments/1bbab178-7064-4fd9-b82e-47dc11c423a4" width="200"> | <img src="https://projects.blender.org/attachments/140e4a84-4c77-4b6c-bfc6-b035efd32329" width="200"> |<img src="https://projects.blender.org/attachments/17b8e914-fa46-4639-8e46-bbd8d01d00c1" width="200"> |<img src="https://projects.blender.org/attachments/6ed2bfd4-83e1-441a-88a2-4e1ea736e1e6" width="200"> | #### PCF filtering We now parametrize the filter around the normal instead of using the shadow map local space. This requires to use a disk filter instead of box, which is also more pleasant for most light shapes (all except rectangle lights). Setting the filter around normal avoid overshadowing from zero slope occluders. This cannot be fixed by more slope bias in light space PCF. We could fix it in light space by projecting onto the normal plane but that gives an unbounded bias when `N.L` is near 0 which causes either missing shadows or self shadow if using an arbitrary max offset value. | Light PCF | Light PCF + Slope Bias | Normal PCF | | -------- | -------- | -------- | |<img src="https://projects.blender.org/attachments/2f67cc52-5479-4595-8230-c73b0aaf4266" width="200"> |<img src="https://projects.blender.org/attachments/aa6e565f-11b1-460c-8725-24f7db8c4bf4" width="200"> |<img src="https://projects.blender.org/attachments/489e7a59-16e5-4c14-adbe-9da256d31bce" width="200"> | To avoid overshadowing from any surface behind the shading point, we reflect the offset to always face the light. Doing so instead of using the perpendicular direction is better for very sharp geometric angles, has less numerical precision issue, is symetrical and is cheaper. | Normal PCF | Normal PCF + Reflect | | -------- | -------- | |<img src="https://projects.blender.org/attachments/489e7a59-16e5-4c14-adbe-9da256d31bce" width="200"> |<img src="https://projects.blender.org/attachments/18737ed8-47d2-4f3f-91ab-66e9cf570f4f" width="200"> | To avoid any self shadowing artifact on zero slope receivers with angled neighbors (like a wall and the floor), we have to increase the slope bias according to the filter size. This might be overkill in most situation but I don't feel this should become a setting and should be kept in sync with the filter. If it has to become an option, it should simply a factor between unbiased filter and best bias. | Normal PCF + Reflect | Normal PCF + Slope bias | Normal PCF + Reflect + Slope bias | | -------- | -------- | -------- | |<img src="https://projects.blender.org/attachments/18737ed8-47d2-4f3f-91ab-66e9cf570f4f" width="200"> |<img src="https://projects.blender.org/attachments/6cac3096-fc81-4754-b2e7-28d1f0d92001" width="200"> |<img src="https://projects.blender.org/attachments/8caded22-abd2-4ec4-b84a-f2ae8b5242f8" width="200"> | #### Shadow terminator The remaining artifacts are all related to shadow terminator one way or another. It is always caused by the shading normal we use for biasing and visibility computation not being aligned with the geometric normal. This is still something we need a setting for somewhere.
Clément Foucault added this to the 4.2 LTS milestone 2024-04-25 19:08:02 +02:00
Clément Foucault added the
Interest
EEVEE
label 2024-04-25 19:08:02 +02:00
Clément Foucault added 1 commit 2024-04-25 19:08:13 +02:00
b58e9459fe EEVEE-Next: Improve shadow bias
Compute shadow bias in the normal direction to avoid
both shadow leaking at certain angles or shadow
acnee.

This bias is computed automatically based on the minimum
bias amount required to remove all errors.

We do the bias in world space instead of shadow space
for speed and simplicity. This requires us to bias using
the upper bound of biases for the same location in space
(using biggest texel world radius instead of UVZ bias).
This isn't much of an issue since the bias is still less
than 2 texel. The bias is still modulated by facing
ratio to the light so surfaces facing the light have no
biases.

We always bias toward the normal direction instead of the
light direction. This is alike Cycles geometric offset for
the shadow terminator fix. This is better since it does'nt
modify the shading at all.

This changes the PCF filtering to only filter after the
the "safe" zone where we cannot have any shadow acnee.
This introduces bias in this regard since we move the
shadow map center away from the surface.

This removes the geometric offset inside the shadow surface
shader as we already account for that at sampling time.
Clément Foucault added 5 commits 2024-04-26 18:53:02 +02:00
Clément Foucault added 3 commits 2024-04-26 22:50:43 +02:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
2b03ad5a2d
Merge branch 'main' into eevee-next-shadow-bias-improved
Author
Member

@blender-bot build

@blender-bot build
Clément Foucault changed title from WIP: EEVEE-Next: Improve shadow bias to EEVEE-Next: Improve shadow bias 2024-04-26 23:46:25 +02:00
Clément Foucault added 1 commit 2024-04-26 23:46:34 +02:00
buildbot/vexp-code-patch-lint Build done. Details
buildbot/vexp-code-patch-linux-x86_64 Build done. Details
buildbot/vexp-code-patch-darwin-x86_64 Build done. Details
buildbot/vexp-code-patch-windows-amd64 Build done. Details
buildbot/vexp-code-patch-darwin-arm64 Build done. Details
buildbot/vexp-code-patch-coordinator Build done. Details
4778d53bc8
Remove shadow normal offset
Author
Member

@blender-bot build

@blender-bot build
Clément Foucault added 2 commits 2024-04-27 11:11:31 +02:00
Clément Foucault added 1 commit 2024-04-27 14:06:05 +02:00
Clément Foucault merged commit bb44bce95c into main 2024-04-27 14:31:02 +02:00
Clément Foucault deleted branch eevee-next-shadow-bias-improved 2024-04-27 14:31:05 +02:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#121088
No description provided.