feat(editor): persist graphics settings and shadow overrides
This commit is contained in:
@@ -1,11 +1,20 @@
|
||||
#include "Components/LightComponent.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace Components {
|
||||
|
||||
namespace {
|
||||
|
||||
float SanitizeNonNegativeFinite(float value, float fallback) {
|
||||
return std::isfinite(value) && value >= 0.0f ? value : fallback;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void LightComponent::SetIntensity(float value) {
|
||||
m_intensity = std::max(0.0f, value);
|
||||
}
|
||||
@@ -18,6 +27,51 @@ void LightComponent::SetSpotAngle(float value) {
|
||||
m_spotAngle = std::clamp(value, 1.0f, 179.0f);
|
||||
}
|
||||
|
||||
void LightComponent::SetDirectionalShadowSamplingSettings(
|
||||
const Rendering::DirectionalShadowSamplingSettings& value) {
|
||||
SetDirectionalShadowReceiverDepthBias(value.receiverDepthBias);
|
||||
SetDirectionalShadowNormalBiasScale(value.normalBiasScale);
|
||||
SetDirectionalShadowStrength(value.shadowStrength);
|
||||
}
|
||||
|
||||
void LightComponent::SetDirectionalShadowCasterBiasSettings(
|
||||
const Rendering::DirectionalShadowCasterBiasSettings& value) {
|
||||
SetDirectionalShadowDepthBiasFactor(value.depthBiasFactor);
|
||||
SetDirectionalShadowDepthBiasUnits(value.depthBiasUnits);
|
||||
}
|
||||
|
||||
void LightComponent::SetDirectionalShadowReceiverDepthBias(float value) {
|
||||
const Rendering::DirectionalShadowSamplingSettings defaults = {};
|
||||
m_directionalShadowSampling.receiverDepthBias =
|
||||
SanitizeNonNegativeFinite(value, defaults.receiverDepthBias);
|
||||
}
|
||||
|
||||
void LightComponent::SetDirectionalShadowNormalBiasScale(float value) {
|
||||
const Rendering::DirectionalShadowSamplingSettings defaults = {};
|
||||
m_directionalShadowSampling.normalBiasScale =
|
||||
SanitizeNonNegativeFinite(value, defaults.normalBiasScale);
|
||||
}
|
||||
|
||||
void LightComponent::SetDirectionalShadowStrength(float value) {
|
||||
if (!std::isfinite(value)) {
|
||||
const Rendering::DirectionalShadowSamplingSettings defaults = {};
|
||||
m_directionalShadowSampling.shadowStrength = defaults.shadowStrength;
|
||||
return;
|
||||
}
|
||||
|
||||
m_directionalShadowSampling.shadowStrength = std::clamp(value, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
void LightComponent::SetDirectionalShadowDepthBiasFactor(float value) {
|
||||
const Rendering::DirectionalShadowCasterBiasSettings defaults = {};
|
||||
m_directionalShadowCasterBias.depthBiasFactor =
|
||||
SanitizeNonNegativeFinite(value, defaults.depthBiasFactor);
|
||||
}
|
||||
|
||||
void LightComponent::SetDirectionalShadowDepthBiasUnits(int value) {
|
||||
m_directionalShadowCasterBias.depthBiasUnits = std::max(0, value);
|
||||
}
|
||||
|
||||
void LightComponent::Serialize(std::ostream& os) const {
|
||||
os << "type=" << static_cast<int>(m_lightType) << ";";
|
||||
os << "color=" << m_color.r << "," << m_color.g << "," << m_color.b << "," << m_color.a << ";";
|
||||
@@ -25,6 +79,12 @@ void LightComponent::Serialize(std::ostream& os) const {
|
||||
os << "range=" << m_range << ";";
|
||||
os << "spotAngle=" << m_spotAngle << ";";
|
||||
os << "shadows=" << (m_castsShadows ? 1 : 0) << ";";
|
||||
os << "overrideDirectionalShadowSettings=" << (m_overrideDirectionalShadowSettings ? 1 : 0) << ";";
|
||||
os << "directionalShadowReceiverDepthBias=" << m_directionalShadowSampling.receiverDepthBias << ";";
|
||||
os << "directionalShadowNormalBiasScale=" << m_directionalShadowSampling.normalBiasScale << ";";
|
||||
os << "directionalShadowStrength=" << m_directionalShadowSampling.shadowStrength << ";";
|
||||
os << "directionalShadowDepthBiasFactor=" << m_directionalShadowCasterBias.depthBiasFactor << ";";
|
||||
os << "directionalShadowDepthBiasUnits=" << m_directionalShadowCasterBias.depthBiasUnits << ";";
|
||||
}
|
||||
|
||||
void LightComponent::Deserialize(std::istream& is) {
|
||||
@@ -56,6 +116,18 @@ void LightComponent::Deserialize(std::istream& is) {
|
||||
SetSpotAngle(std::stof(value));
|
||||
} else if (key == "shadows") {
|
||||
m_castsShadows = (std::stoi(value) != 0);
|
||||
} else if (key == "overrideDirectionalShadowSettings") {
|
||||
m_overrideDirectionalShadowSettings = (std::stoi(value) != 0);
|
||||
} else if (key == "directionalShadowReceiverDepthBias") {
|
||||
SetDirectionalShadowReceiverDepthBias(std::stof(value));
|
||||
} else if (key == "directionalShadowNormalBiasScale") {
|
||||
SetDirectionalShadowNormalBiasScale(std::stof(value));
|
||||
} else if (key == "directionalShadowStrength") {
|
||||
SetDirectionalShadowStrength(std::stof(value));
|
||||
} else if (key == "directionalShadowDepthBiasFactor") {
|
||||
SetDirectionalShadowDepthBiasFactor(std::stof(value));
|
||||
} else if (key == "directionalShadowDepthBiasUnits") {
|
||||
SetDirectionalShadowDepthBiasUnits(std::stoi(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
42
engine/src/Rendering/GraphicsSettingsState.cpp
Normal file
42
engine/src/Rendering/GraphicsSettingsState.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "Rendering/GraphicsSettingsState.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace Rendering {
|
||||
|
||||
GraphicsSettingsState& GetGraphicsSettingsState() {
|
||||
static GraphicsSettingsState s_state;
|
||||
return s_state;
|
||||
}
|
||||
|
||||
void GraphicsSettingsState::SetManagedRenderPipelineBridge(
|
||||
std::shared_ptr<const Pipelines::ManagedRenderPipelineBridge> bridge) {
|
||||
m_managedRenderPipelineBridge = std::move(bridge);
|
||||
++m_managedRenderPipelineBridgeGeneration;
|
||||
BumpEnvironmentGeneration();
|
||||
}
|
||||
|
||||
void GraphicsSettingsState::ClearManagedRenderPipelineBridge() {
|
||||
m_managedRenderPipelineBridge.reset();
|
||||
++m_managedRenderPipelineBridgeGeneration;
|
||||
BumpEnvironmentGeneration();
|
||||
}
|
||||
|
||||
void GraphicsSettingsState::SetRenderPipelineAssetDescriptor(
|
||||
const Pipelines::ManagedRenderPipelineAssetDescriptor& descriptor) {
|
||||
m_renderPipelineAssetDescriptor = descriptor;
|
||||
BumpEnvironmentGeneration();
|
||||
}
|
||||
|
||||
void GraphicsSettingsState::ClearRenderPipelineAssetDescriptor() {
|
||||
m_renderPipelineAssetDescriptor = {};
|
||||
BumpEnvironmentGeneration();
|
||||
}
|
||||
|
||||
void GraphicsSettingsState::BumpEnvironmentGeneration() {
|
||||
++m_environmentGeneration;
|
||||
}
|
||||
|
||||
} // namespace Rendering
|
||||
} // namespace XCEngine
|
||||
Reference in New Issue
Block a user