Implement Shadows #24

Merged
SeanOMik merged 28 commits from feat/shadow-maps into main 2024-08-09 23:10:30 -04:00
Owner

This PR implements shadows for point lights, spot lights, and directional lights. It also has soft shadows with PCF for all light types, and PCSS for directional lights only.

You can modify the light caster settings with an ecs world resource:

world.add_resource(ShadowCasterSettings {
    // Non directional lights ignore this and will fall-back to PCF
    filtering_mode: ShadowFilteringMode::Pcss,
    pcf_samples_num: 25,
    pcss_blocker_search_samples: 25,
    ..Default::default()
});

You can also set specific caster settings on individual lights by adding the same struct as a component to the entity that casts the light:

let mut light_tran = Transform::from_xyz(0.0, 0.0, 0.0);
light_tran.scale = Vec3::new(0.5, 0.5, 0.5);
light_tran.rotate_x(math::Angle::Degrees(-45.0));
light_tran.rotate_y(math::Angle::Degrees(-35.0));
world.spawn((
    //cube_mesh.clone(),
    DirectionalLight {
        enabled: true,
        color: Vec3::new(1.0, 0.95, 0.9),
        intensity: 0.9,
    },
    ShadowCasterSettings {
        filtering_mode: ShadowFilteringMode::Pcss,
        pcf_samples_num: 64,
        pcss_blocker_search_samples: 36,
        constant_depth_bias_scale: 5.0,
        ..Default::default()
    },
    light_tran,
));

By default, all lights cast shadows, #23 will fix that.

This PR implements shadows for point lights, spot lights, and directional lights. It also has soft shadows with PCF for all light types, and PCSS for directional lights only. You can modify the light caster settings with an ecs world resource: ```rust world.add_resource(ShadowCasterSettings { // Non directional lights ignore this and will fall-back to PCF filtering_mode: ShadowFilteringMode::Pcss, pcf_samples_num: 25, pcss_blocker_search_samples: 25, ..Default::default() }); ``` You can also set specific caster settings on individual lights by adding the same struct as a component to the entity that casts the light: ```rust let mut light_tran = Transform::from_xyz(0.0, 0.0, 0.0); light_tran.scale = Vec3::new(0.5, 0.5, 0.5); light_tran.rotate_x(math::Angle::Degrees(-45.0)); light_tran.rotate_y(math::Angle::Degrees(-35.0)); world.spawn(( //cube_mesh.clone(), DirectionalLight { enabled: true, color: Vec3::new(1.0, 0.95, 0.9), intensity: 0.9, }, ShadowCasterSettings { filtering_mode: ShadowFilteringMode::Pcss, pcf_samples_num: 64, pcss_blocker_search_samples: 36, constant_depth_bias_scale: 5.0, ..Default::default() }, light_tran, )); ``` By default, all lights cast shadows, #23 will fix that.
SeanOMik added the
Kind/Feature
Priority
Medium
labels 2024-08-09 22:58:11 -04:00
SeanOMik added 28 commits 2024-08-09 22:58:12 -04:00
3a80c069c9
render: move most of the mesh processing to a MeshPrepare node
Moving that out of the MeshesPass makes the rendering meshes accessible to other passes/nodes. The shadow pass will need access to them which is why this was done now
SeanOMik merged commit 256025849e into main 2024-08-09 23:10:30 -04:00
Sign in to join this conversation.
No reviewers
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: SeanOMik/lyra-engine#24
No description provided.