Skip to content

Custom directional shadow maps#24936

Open
mate-h wants to merge 2 commits into
bevyengine:mainfrom
mate-h:m/custom-shadows
Open

Custom directional shadow maps#24936
mate-h wants to merge 2 commits into
bevyengine:mainfrom
mate-h:m/custom-shadows

Conversation

@mate-h

@mate-h mate-h commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Objective

While I was working on terrain rendering, I realized that I needed to make use of custom shadow maps that raymarches the heightfield towards the light. For the terrain material I use apply_pbr_lighting. Using this approach, we better support custom shadow maps while still being able to use the pbr lighting code.

Use cases:

  • terrain rendering system optimized shadowing
  • cloud shadowing in outdoor scenes

Solution

  • pbr_input now includes a new field called directional_shadow_factor which defaults to 1.0
  • In the custom material code the user would:

Given some function terrain_shadow_factor that samples a custom shadow map.

var pbr_input: PbrInput = pbr_input_new();
// ...

// set a custom shadow factor
pbr_input.directional_shadow_factor = terrain_shadow_factor(world_position.xyz);

vec4 out_color = apply_pbr_lighting(pbr_input);

Testing


Showcase

Screenshot 2026-07-09 at 5 09 48 PM

Context: the custom shadow map translates to a texture binding in my material, output of a compute pass that ray-marches the terrain heightmap towards the light centered on the camera, where R is the highest occluding elevation and G is ray length. and at fragment shade time the shadow factor value is computed to get cheap penumbras on the terrain.
At first I tried wiring it into the regular cascaded shadow maps but that resulted in quite a bad performance so this is essentially an optimization. This technique based on the Red Dead Redemption 2 Siggraph talk from 2019.

Custom shadow map example:
terrain_shadow_map

@mate-h mate-h added A-Rendering Drawing game state to the screen D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jul 10, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in Rendering Jul 10, 2026

@kfc35 kfc35 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi main has the fix for the ci error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Rendering Drawing game state to the screen D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

2 participants