Skip to content

Commit

Permalink
fix(rendering): fix spot light range cutoff when using shadows
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas7770 committed Sep 16, 2024
1 parent 5eb8282 commit 251653b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Spot light angle mismatch between light and shadows (#1310, **@tomas7770**).
- Spot shadows cause light range cutoff (#1312, **@tomas7770**).

## [v0.3.0] - 2024-08-02

Expand Down
5 changes: 3 additions & 2 deletions engine/src/render/deferred_shading/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,9 @@ void cubos::engine::deferredShadingPlugin(Cubos& cubos)
auto slot = shadowAtlas.slotsMap.at(caster.value().baseSettings.id);

// The light is actually facing the direction opposite to what's visible, so rotate it.
auto lightView = glm::inverse(
glm::rotate(lightLocalToWorld.mat, glm::radians(180.0F), glm::vec3(0.0F, 1.0F, 0.0F)));
auto lightView = glm::inverse(glm::scale(
glm::rotate(lightLocalToWorld.mat, glm::radians(180.0F), glm::vec3(0.0F, 1.0F, 0.0F)),
glm::vec3(1.0F / lightLocalToWorld.worldScale())));

Check warning on line 262 in engine/src/render/deferred_shading/plugin.cpp

View check run for this annotation

Codecov / codecov/patch

engine/src/render/deferred_shading/plugin.cpp#L260-L262

Added lines #L260 - L262 were not covered by tests
auto lightProj = glm::perspective(glm::radians(light.spotAngle),
(float(shadowAtlas.getSize().x) * slot->size.x) /
(float(shadowAtlas.getSize().y) * slot->size.y),
Expand Down
5 changes: 3 additions & 2 deletions engine/src/render/shadow_atlas_rasterizer/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ void cubos::engine::shadowAtlasRasterizerPlugin(Cubos& cubos)

// Send the PerScene data to the GPU.
// The light is actually facing the direction opposite to what's visible, so rotate it.
auto view =
glm::inverse(glm::rotate(localToWorld.mat, glm::radians(180.0F), glm::vec3(0.0F, 1.0F, 0.0F)));
auto view = glm::inverse(
glm::scale(glm::rotate(localToWorld.mat, glm::radians(180.0F), glm::vec3(0.0F, 1.0F, 0.0F)),
glm::vec3(1.0F / localToWorld.worldScale())));

Check warning on line 171 in engine/src/render/shadow_atlas_rasterizer/plugin.cpp

View check run for this annotation

Codecov / codecov/patch

engine/src/render/shadow_atlas_rasterizer/plugin.cpp#L169-L171

Added lines #L169 - L171 were not covered by tests
auto proj = glm::perspective(glm::radians(light.spotAngle),
(float(atlas.getSize().x) * slot->size.x) /
(float(atlas.getSize().y) * slot->size.y),
Expand Down

0 comments on commit 251653b

Please sign in to comment.