Skip to content

Commit

Permalink
Clamping of ambient light intensity
Browse files Browse the repository at this point in the history
  • Loading branch information
ssell committed Sep 22, 2016
1 parent 45f71ef commit 817adc5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
41 changes: 40 additions & 1 deletion OcularCore/include/Scene/Light/LightManager.hpp
Expand Up @@ -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
{
Expand All @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion OcularCore/src/Scene/Light/LightManager.cpp
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions OcularEditor/src/Widgets/ScenePropertiesDialog.cpp
Expand Up @@ -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<float>(m_AmbientIntensity), sizeof(float));
}
}
}

0 comments on commit 817adc5

Please sign in to comment.