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

Make SSAO optional #1397

Merged
merged 1 commit into from
Dec 14, 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed

- Make SSAO optional (#1396, **@tomas7770**).

## [v0.5.0] - 2024-12-01

### Added
Expand Down
3 changes: 2 additions & 1 deletion engine/assets/render/deferred_shading.fs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ layout(std140) uniform PerScene
uint numSpotLights;

int directionalLightWithShadowsId; // index of directional light that casts shadows, or -1 if none
int useSSAO;
};

layout(location = 0) out vec3 color;
Expand Down Expand Up @@ -318,7 +319,7 @@ void main()
{
vec3 albedo = texture(albedoTexture, uv).rgb;
vec3 position = texture(positionTexture, uv).xyz;
float ssao = texture(ssaoTexture, uv).r;
float ssao = useSSAO == 1 ? texture(ssaoTexture, uv).r : 1.0;

// Calculate lighting from each light source.
vec3 lighting = ambientLight.rgb * ssao;
Expand Down
7 changes: 5 additions & 2 deletions engine/include/cubos/engine/render/defaults/target.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
#include <cubos/engine/render/tone_mapping/fxaa.hpp>
#include <cubos/engine/render/tone_mapping/tone_mapping.hpp>


// Export types so that code using the engine shared library can share reflection data,
// otherwise we may end up with e.g. a Opt<cubos::engine::SplitScreen> type in the engine
// and another one in the external code.
namespace cubos::core::memory
{
CUBOS_ENGINE_EXTERN template class CUBOS_ENGINE_API Opt<cubos::engine::SplitScreen>;
CUBOS_ENGINE_EXTERN template class CUBOS_ENGINE_API Opt<cubos::engine::Bloom>;
CUBOS_ENGINE_EXTERN template class CUBOS_ENGINE_API Opt<cubos::engine::SSAO>;
} // namespace cubos::core::memory

namespace cubos::engine
Expand Down Expand Up @@ -56,7 +59,7 @@ namespace cubos::engine
GBufferRasterizer gBufferRasterizer{};

/// @brief SSAO component.
SSAO ssao{};
core::memory::Opt<SSAO> ssao{SSAO{}};

/// @brief Tone Mapping component.
ToneMapping toneMapping{};
Expand Down
6 changes: 5 additions & 1 deletion engine/src/render/defaults/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
.add(entity, defaults.picker)
.add(entity, defaults.depth)
.add(entity, defaults.gBufferRasterizer)
.add(entity, defaults.ssao)
.add(entity, defaults.toneMapping)
.add(entity, defaults.fxaa)
.add(entity, defaults.deferredShading);
Expand All @@ -88,6 +87,11 @@
{
cmds.add(entity, defaults.bloom.value());
}

if (defaults.ssao)
{
cmds.add(entity, defaults.ssao.value());

Check warning on line 93 in engine/src/render/defaults/plugin.cpp

View check run for this annotation

Codecov / codecov/patch

engine/src/render/defaults/plugin.cpp#L93

Added line #L93 was not covered by tests
}
}
});
}
1 change: 1 addition & 0 deletions engine/src/render/defaults/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

template class cubos::core::memory::Opt<cubos::engine::SplitScreen>;
template class cubos::core::memory::Opt<cubos::engine::Bloom>;
template class cubos::core::memory::Opt<cubos::engine::SSAO>;

CUBOS_REFLECT_IMPL(cubos::engine::RenderTargetDefaults)
{
Expand Down
13 changes: 11 additions & 2 deletions engine/src/render/deferred_shading/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
glm::uint numSpotLights{0};

int directionalLightWithShadowsId;
int useSSAO;
};

struct State
Expand Down Expand Up @@ -218,7 +219,7 @@
directionalLights,
Query<const LocalToWorld&, const PointLight&, Opt<const PointShadowCaster&>> pointLights,
Query<const LocalToWorld&, const SpotLight&, Opt<const SpotShadowCaster&>> spotLights,
Query<Entity, const HDR&, const GBuffer&, const SSAO&, DeferredShading&> targets,
Query<Entity, const HDR&, const GBuffer&, Opt<const SSAO&>, DeferredShading&> targets,
Query<Entity, const LocalToWorld&, const Camera&, const DrawsTo&> cameras) {
auto& rd = window->renderDevice();

Expand Down Expand Up @@ -441,7 +442,15 @@
state.positionBP->bind(gBuffer.position);
state.normalBP->bind(gBuffer.normal);
state.albedoBP->bind(gBuffer.albedo);
state.ssaoBP->bind(ssao.blurTexture);
if (ssao.contains())
{
state.ssaoBP->bind(ssao.value().blurTexture);
perScene.useSSAO = 1;

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

View check run for this annotation

Codecov / codecov/patch

engine/src/render/deferred_shading/plugin.cpp#L447-L448

Added lines #L447 - L448 were not covered by tests
}
else
{
perScene.useSSAO = 0;

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

View check run for this annotation

Codecov / codecov/patch

engine/src/render/deferred_shading/plugin.cpp#L452

Added line #L452 was not covered by tests
}
state.spotShadowAtlasBP->bind(spotShadowAtlas.atlas);
state.pointShadowAtlasBP->bind(pointShadowAtlas.atlas);
// directionalShadowMap needs to be bound even if it's null, or else errors may occur on some GPUs
Expand Down
Loading