Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix spot light range cutoff when using shadows #1313

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,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())));
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())));
auto proj = glm::perspective(glm::radians(light.spotAngle),
(float(atlas.getSize().x) * slot->size.x) /
(float(atlas.getSize().y) * slot->size.y),
Expand Down
Loading