Skip to content

Commit

Permalink
feat(rendering): add configSplitDistances to DirectionalShadowCaster
Browse files Browse the repository at this point in the history
This prevents the CSM plugin from overriding user-defined values with defaults
  • Loading branch information
tomas7770 committed Oct 1, 2024
1 parent 52f8e80 commit 4bd089b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ namespace cubos::engine

int configNumSplits = 3; ///< Target number of splits for PSSM/CSM.
int numSplits = 0; ///< Current number of splits for PSSM/CSM.
std::vector<float>
splitDistances; ///< Distance of each split's near plane from 0 to 1 (relative to maxDistance).

std::vector<float> configSplitDistances; ///< Target distance of each split's near plane from 0 to 1 (relative
///< to maxDistance). If the amount of distances doesn't match the
///< number of splits, default values will be used.
std::vector<float> splitDistances; ///< Distance of each split's near plane from 0 to 1.

float maxDistance = 0; ///< Max distance (if 0, uses camera zFar).
float nearDistance = 0.1F; ///< Minimum near plane distance of splits frustum.

Expand Down
27 changes: 16 additions & 11 deletions engine/src/render/cascaded_shadow_maps/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,29 @@ void cubos::engine::cascadedShadowMapsPlugin(Cubos& cubos)
if (caster.size != caster.configSize || caster.numSplits != caster.configNumSplits)

Check warning on line 45 in engine/src/render/cascaded_shadow_maps/plugin.cpp

View check run for this annotation

Codecov / codecov/patch

engine/src/render/cascaded_shadow_maps/plugin.cpp#L45

Added line #L45 was not covered by tests
{
caster.size = caster.configSize;
if (caster.numSplits != caster.configNumSplits)
{
caster.numSplits = caster.configNumSplits;

// Set default split distances
caster.splitDistances.clear();
for (int i = 0; i < caster.numSplits; i++)
{
caster.splitDistances.push_back(float(i) / float(caster.numSplits));
}
}
caster.numSplits = caster.configNumSplits;

Check warning on line 48 in engine/src/render/cascaded_shadow_maps/plugin.cpp

View check run for this annotation

Codecov / codecov/patch

engine/src/render/cascaded_shadow_maps/plugin.cpp#L47-L48

Added lines #L47 - L48 were not covered by tests

for (auto& [camera, shadowMap] : caster.shadowMaps)

Check warning on line 50 in engine/src/render/cascaded_shadow_maps/plugin.cpp

View check run for this annotation

Codecov / codecov/patch

engine/src/render/cascaded_shadow_maps/plugin.cpp#L50

Added line #L50 was not covered by tests
{
shadowMap.resize(window->renderDevice(), caster.size, caster.numSplits);

Check warning on line 52 in engine/src/render/cascaded_shadow_maps/plugin.cpp

View check run for this annotation

Codecov / codecov/patch

engine/src/render/cascaded_shadow_maps/plugin.cpp#L52

Added line #L52 was not covered by tests
}
}

// Set split distances
if (caster.configSplitDistances.size() == static_cast<unsigned long>(caster.numSplits))

Check warning on line 57 in engine/src/render/cascaded_shadow_maps/plugin.cpp

View check run for this annotation

Codecov / codecov/patch

engine/src/render/cascaded_shadow_maps/plugin.cpp#L57

Added line #L57 was not covered by tests
{
caster.splitDistances = caster.configSplitDistances;

Check warning on line 59 in engine/src/render/cascaded_shadow_maps/plugin.cpp

View check run for this annotation

Codecov / codecov/patch

engine/src/render/cascaded_shadow_maps/plugin.cpp#L59

Added line #L59 was not covered by tests
}
else
{
// Set default split distances
caster.splitDistances.clear();
for (int i = 0; i < caster.numSplits; i++)

Check warning on line 65 in engine/src/render/cascaded_shadow_maps/plugin.cpp

View check run for this annotation

Codecov / codecov/patch

engine/src/render/cascaded_shadow_maps/plugin.cpp#L64-L65

Added lines #L64 - L65 were not covered by tests
{
caster.splitDistances.push_back(float(i) / float(caster.numSplits));

Check warning on line 67 in engine/src/render/cascaded_shadow_maps/plugin.cpp

View check run for this annotation

Codecov / codecov/patch

engine/src/render/cascaded_shadow_maps/plugin.cpp#L67

Added line #L67 was not covered by tests
}
}

// Create shadow maps for new cameras
for (auto [entity, camera] : cameras)

Check warning on line 72 in engine/src/render/cascaded_shadow_maps/plugin.cpp

View check run for this annotation

Codecov / codecov/patch

engine/src/render/cascaded_shadow_maps/plugin.cpp#L72

Added line #L72 was not covered by tests
{
Expand Down
2 changes: 1 addition & 1 deletion engine/src/render/shadows/directional_caster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ CUBOS_REFLECT_IMPL(cubos::engine::DirectionalShadowCaster)
return core::ecs::TypeBuilder<DirectionalShadowCaster>("cubos::engine::DirectionalShadowCaster")
.withField("baseSettings", &DirectionalShadowCaster::baseSettings)
.withField("configNumSplits", &DirectionalShadowCaster::configNumSplits)
.withField("splitDistances", &DirectionalShadowCaster::splitDistances)
.withField("configSplitDistances", &DirectionalShadowCaster::configSplitDistances)

Check warning on line 17 in engine/src/render/shadows/directional_caster.cpp

View check run for this annotation

Codecov / codecov/patch

engine/src/render/shadows/directional_caster.cpp#L16-L17

Added lines #L16 - L17 were not covered by tests
.withField("maxDistance", &DirectionalShadowCaster::maxDistance)
.withField("nearDistance", &DirectionalShadowCaster::nearDistance)
.withField("configSize", &DirectionalShadowCaster::configSize)

Check warning on line 20 in engine/src/render/shadows/directional_caster.cpp

View check run for this annotation

Codecov / codecov/patch

engine/src/render/shadows/directional_caster.cpp#L19-L20

Added lines #L19 - L20 were not covered by tests
Expand Down

0 comments on commit 4bd089b

Please sign in to comment.