From 817adc5691a806dcb3ad18f271c04290a11ab605 Mon Sep 17 00:00:00 2001 From: Steven Sell Date: Thu, 22 Sep 2016 00:16:35 -0400 Subject: [PATCH] Clamping of ambient light intensity --- .../include/Scene/Light/LightManager.hpp | 41 ++++++++++++++++++- OcularCore/src/Scene/Light/LightManager.cpp | 2 +- .../src/Widgets/ScenePropertiesDialog.cpp | 3 ++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/OcularCore/include/Scene/Light/LightManager.hpp b/OcularCore/include/Scene/Light/LightManager.hpp index 4007753..dd45990 100644 --- a/OcularCore/include/Scene/Light/LightManager.hpp +++ b/OcularCore/include/Scene/Light/LightManager.hpp @@ -46,6 +46,22 @@ namespace Ocular { /** * \class LightManager + * + * Handles updating the GPU light buffer with current scene's lighting. + * All light sources are uploaded as instances of the GPULight structures. + * + * Ambient lighting is always passed over in the buffers 0 index, with the + * number of lights recorded in it's light type property (Buffer[0].parameters.z). + * + * Culling of visible lights is done using simple frustum culling against + * bounding volumes generated by the light's properties (bounding spheres + * for point lights). + * + * Directional and ambient lights are not culled as they affect the entire + * scene by their very definition. + * + * In Direct3D, the light structured buffer is passed over register t8. + * See LightManager::LightBufferSlot */ class LightManager { @@ -56,15 +72,38 @@ namespace Ocular LightManager(); ~LightManager(); + /** + * Updates the GPU light buffer. + * + * For Direct3D, this buffer is passed over register t8. + * + * \param[in] cullVisible If TRUE, only visible lights will be passed to the GPU. + */ void updateLights(bool cullVisible = true); + /** + * Sets the ambient light color. + * \param[in] color + */ void setAmbientLightColor(Color const& color); + + /** + * \return The current ambient light color. + */ Color getAmbientLightColor() const; + /** + * Sets the ambient light intensity. Intensity is clamped to [0,1]. + * \param[in] intensity + */ void setAmbientLightIntensity(float intensity); + + /** + * \return The currently ambient light intensity. + */ float getAmbientLightIntensity() const; - static const uint32_t LightBufferSlot; // The GPUBuffer slot used by the LightManager to pass light data + static const uint32_t LightBufferSlot; ///< The GPUBuffer slot used by the LightManager to pass light data protected: diff --git a/OcularCore/src/Scene/Light/LightManager.cpp b/OcularCore/src/Scene/Light/LightManager.cpp index 8a73462..0756a87 100644 --- a/OcularCore/src/Scene/Light/LightManager.cpp +++ b/OcularCore/src/Scene/Light/LightManager.cpp @@ -79,7 +79,7 @@ namespace Ocular void LightManager::setAmbientLightIntensity(float const intensity) { - m_GPUAmbientLight.parameters.x = intensity; + m_GPUAmbientLight.parameters.x = Math::Clamp(intensity); } float LightManager::getAmbientLightIntensity() const diff --git a/OcularEditor/src/Widgets/ScenePropertiesDialog.cpp b/OcularEditor/src/Widgets/ScenePropertiesDialog.cpp index 01a07fe..f4c2b12 100644 --- a/OcularEditor/src/Widgets/ScenePropertiesDialog.cpp +++ b/OcularEditor/src/Widgets/ScenePropertiesDialog.cpp @@ -214,6 +214,9 @@ namespace Ocular OcularLights->setAmbientLightColor(m_AmbientColor); OcularLights->setAmbientLightIntensity(m_AmbientIntensity); + + m_AmbientIntensity = Math::Clamp(m_AmbientIntensity); + m_AmbientIntensityProperty->setValue(void_cast(m_AmbientIntensity), sizeof(float)); } } } \ No newline at end of file