From 589bcc19ce9b841b91a487f069b35fa5136a95e6 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Fri, 19 May 2017 17:50:19 -0700 Subject: [PATCH] Refining the shader for key and testing removing completely the code dealing with Zone lighting in the ENtityTreeREnderer --- .../src/EntityTreeRenderer.cpp | 26 +++++++++---------- .../src/EntityTreeRenderer.h | 8 +++--- .../src/DeferredLightingEffect.cpp | 7 +++-- .../render-utils/src/zone_drawKeyLight.slf | 3 ++- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 1de476c825..de7fa43026 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -141,7 +141,7 @@ void EntityTreeRenderer::clear() { // reset the zone to the default (while we load the next scene) _layeredZones.clear(); - applyZoneAndHasSkybox(nullptr); + // applyZoneAndHasSkybox(nullptr); OctreeRenderer::clear(); } @@ -198,11 +198,11 @@ void EntityTreeRenderer::update() { // If we haven't already updated and previously attempted to load a texture, // check if the texture loaded and apply it - if (!updated && + /* if (!updated && ((_pendingAmbientTexture && (!_ambientTexture || _ambientTexture->isLoaded())) || (_pendingSkyboxTexture && (!_skyboxTexture || _skyboxTexture->isLoaded())))) { applySkyboxAndHasAmbient(); - } + }*/ // Even if we're not moving the mouse, if we started clicking on an entity and we have // not yet released the hold then this is still considered a holdingClickOnEntity event @@ -371,7 +371,7 @@ bool EntityTreeRenderer::applyLayeredZones() { return true; } - +/* bool EntityTreeRenderer::applyZoneAndHasSkybox(const std::shared_ptr& zone) { auto textureCache = DependencyManager::get(); auto scene = DependencyManager::get(); @@ -427,8 +427,8 @@ bool EntityTreeRenderer::applyZoneAndHasSkybox(const std::shared_ptr& zone) { assert(zone); @@ -483,8 +483,8 @@ bool EntityTreeRenderer::layerZoneAndHasSkybox(const std::shared_ptr(); auto scene = DependencyManager::get(); @@ -539,7 +539,7 @@ bool EntityTreeRenderer::applySkyboxAndHasAmbient() { } return isAmbientSet; -} +}*/ const FBXGeometry* EntityTreeRenderer::getGeometryForEntity(EntityItemPointer entityItem) { const FBXGeometry* result = NULL; @@ -1169,7 +1169,7 @@ std::pair EntityTreeRenderer:: void EntityTreeRenderer::LayeredZones::apply() { assert(_entityTreeRenderer); - applyPartial(begin()); + // applyPartial(begin()); } void EntityTreeRenderer::LayeredZones::update(std::shared_ptr zone) { @@ -1211,11 +1211,11 @@ void EntityTreeRenderer::LayeredZones::update(std::shared_ptr zo } if (shouldUpdate) { - applyPartial(layer); + // applyPartial(layer); } } } - +/* void EntityTreeRenderer::LayeredZones::applyPartial(iterator layer) { bool hasSkybox = false; _skyboxLayer = end(); @@ -1243,7 +1243,7 @@ void EntityTreeRenderer::LayeredZones::applyPartial(iterator layer) { _skyboxLayer = layer; } - +*/ bool EntityTreeRenderer::LayeredZones::contains(const LayeredZones& other) { bool result = std::equal(other.begin(), other._skyboxLayer, begin()); if (result) { diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.h b/libraries/entities-renderer/src/EntityTreeRenderer.h index f4717dca51..92235b1a00 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.h +++ b/libraries/entities-renderer/src/EntityTreeRenderer.h @@ -147,9 +147,9 @@ private: void addEntityToScene(EntityItemPointer entity); bool findBestZoneAndMaybeContainingEntities(QVector* entitiesContainingAvatar = nullptr); - bool applyZoneAndHasSkybox(const std::shared_ptr& zone); - bool layerZoneAndHasSkybox(const std::shared_ptr& zone); - bool applySkyboxAndHasAmbient(); + // bool applyZoneAndHasSkybox(const std::shared_ptr& zone); + // bool layerZoneAndHasSkybox(const std::shared_ptr& zone); + // bool applySkyboxAndHasAmbient(); bool applyLayeredZones(); void checkAndCallPreload(const EntityItemID& entityID, bool reload = false, bool unloadFirst = false); @@ -223,7 +223,7 @@ private: std::shared_ptr getZone() { return empty() ? nullptr : begin()->zone; } private: - void applyPartial(iterator layer); + // void applyPartial(iterator layer); std::map _map; iterator _skyboxLayer{ end() }; diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index b799a7c49e..e1042912aa 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -160,8 +160,11 @@ void DeferredLightingEffect::init() { lp->setAmbientIntensity(0.5f); - lp->setAmbientMap(_defaultSkyboxAmbientTexture); - + lp->setAmbientMap(_defaultSkyboxAmbientTexture); + auto irradianceSH = _defaultSkyboxAmbientTexture->getIrradiance(); + if (irradianceSH) { + lp->setAmbientSphere((*irradianceSH)); + } } void DeferredLightingEffect::setupKeyLightBatch(gpu::Batch& batch, int lightBufferUnit, int ambientBufferUnit, int skyboxCubemapUnit) { diff --git a/libraries/render-utils/src/zone_drawKeyLight.slf b/libraries/render-utils/src/zone_drawKeyLight.slf index cc60979605..e96239b6dc 100644 --- a/libraries/render-utils/src/zone_drawKeyLight.slf +++ b/libraries/render-utils/src/zone_drawKeyLight.slf @@ -45,7 +45,8 @@ void main(void) { vec3 inSpherePos = normalize(vec3(inSphereUV, sqrt(1.0 - dot(inSphereUV.xy, inSphereUV.xy)))); vec3 inNormal = vec3(getViewInverse() * vec4(inSpherePos, 0.0)); - color += lightIrradiance * vec3(dot(-lightDirection, inNormal)); + vec3 marbleColor = max(lightIrradiance * vec3(dot(-lightDirection, inNormal)), vec3(0.01)); + color += marbleColor; } color = color * 1.0 - base.w + base.xyz * base.w;