From 03cf7710d0fbf011dba7cefbd0ee1e98a0deb3d2 Mon Sep 17 00:00:00 2001 From: Nissim Hadar Date: Thu, 28 Dec 2017 09:34:55 -0800 Subject: [PATCH] Ambient light inheritance --- .../src/RenderableZoneEntityItem.cpp | 27 ++++++++++++------- .../src/RenderableZoneEntityItem.h | 3 ++- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp index e6af7bcdd0..6e6b87a6e5 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp @@ -165,14 +165,14 @@ void ZoneEntityRenderer::doRender(RenderArgs* args) { if (_visible) { // Finally, push the light visible in the frame - if (_keyLightMode == COMPONENT_MODE_DISABLED && sunOnIndex == NO_STORED_VALUE) { + if (_keyLightMode == COMPONENT_MODE_DISABLED && _sunOnIndex == NO_STORED_VALUE) { // Just turned off, store previous value before changing - sunOnIndex = _sunIndex; + _sunOnIndex = _sunIndex; _sunIndex = _stage->getSunOffLight(); - } else if (_keyLightMode == COMPONENT_MODE_ENABLED && sunOnIndex != NO_STORED_VALUE) { + } else if (_keyLightMode == COMPONENT_MODE_ENABLED && _sunOnIndex != NO_STORED_VALUE) { // Just turned on, restore previous value before clearing stored value - _sunIndex = sunOnIndex; - sunOnIndex = NO_STORED_VALUE; + _sunIndex = _sunOnIndex; + _sunOnIndex = NO_STORED_VALUE; } if (_keyLightMode != COMPONENT_MODE_INHERIT) { @@ -180,10 +180,19 @@ void ZoneEntityRenderer::doRender(RenderArgs* args) { } // The ambient light only if it has a valid texture to render with - if (_validAmbientTexture || _validSkyboxTexture) { - if (_ambientLightMode != COMPONENT_MODE_INHERIT) { - _stage->_currentFrame.pushAmbientLight(_ambientIndex); - } + if (_ambientLightMode == COMPONENT_MODE_DISABLED && _ambientOnIndex == NO_STORED_VALUE) { + // Just turned off, store previous value before changing + _ambientOnIndex = _ambientIndex; + _ambientIndex = _stage->getAmbientOffLight(); + } + else if (_ambientLightMode == COMPONENT_MODE_ENABLED && _ambientOnIndex != NO_STORED_VALUE) { + // Just turned on, restore previous value before clearing stored value + _ambientIndex = _ambientOnIndex; + _ambientOnIndex = NO_STORED_VALUE; + } + + if (_ambientLightMode != COMPONENT_MODE_INHERIT && (_validAmbientTexture || _validSkyboxTexture)) { + _stage->_currentFrame.pushAmbientLight(_ambientIndex); } // The background only if the mode is not inherit diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.h b/libraries/entities-renderer/src/RenderableZoneEntityItem.h index f7473f1898..f753d39b97 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.h +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.h @@ -96,7 +96,8 @@ private: indexed_container::Index _ambientIndex{ LightStage::INVALID_INDEX }; const int NO_STORED_VALUE { -1 }; - indexed_container::Index sunOnIndex { NO_STORED_VALUE }; + indexed_container::Index _sunOnIndex { NO_STORED_VALUE }; + indexed_container::Index _ambientOnIndex { NO_STORED_VALUE }; BackgroundStagePointer _backgroundStage; BackgroundStage::Index _backgroundIndex{ BackgroundStage::INVALID_INDEX };