From 567adf651a9c747c676a422783515b26b62bedb9 Mon Sep 17 00:00:00 2001 From: sam Date: Fri, 7 Oct 2016 05:02:04 -0700 Subject: [PATCH] FOund 2 bugs causing the empty clusters. now back to working --- .../src/DeferredLightingEffect.cpp | 1 + libraries/render-utils/src/LightClusters.cpp | 13 +++++---- libraries/render-utils/src/LightClusters.h | 19 ++++++++---- libraries/render-utils/src/LightStage.cpp | 10 +++++++ libraries/render-utils/src/LightStage.h | 5 ++++ .../render/src/render/IndexedContainer.h | 10 +++++-- .../utilities/render/lightClustering.qml | 29 +++++++++++++++++++ 7 files changed, 74 insertions(+), 13 deletions(-) diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 084ec0e746..0524466412 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -139,6 +139,7 @@ void DeferredLightingEffect::init() { // Add the global light to the light stage (for later shadow rendering) _globalLights.push_back(_lightStage->addLight(lp)); + _lightStage->addShadow(_globalLights[0]); } diff --git a/libraries/render-utils/src/LightClusters.cpp b/libraries/render-utils/src/LightClusters.cpp index dd7897b23e..7cfd609f1e 100644 --- a/libraries/render-utils/src/LightClusters.cpp +++ b/libraries/render-utils/src/LightClusters.cpp @@ -174,9 +174,7 @@ void LightClusters::updateLightFrame(const LightStage::Frame& lightFrame, bool p auto& srcPointLights = lightFrame._pointLights; auto& srcSpotLights = lightFrame._spotLights; int numPointLights = (int)srcPointLights.size(); - // int offsetPointLights = 0; int numSpotLights = (int)srcSpotLights.size(); - // int offsetSpotLights = numPointLights; _visibleLightIndices.resize(numPointLights + numSpotLights + 1); @@ -367,10 +365,8 @@ glm::ivec3 LightClusters::updateClusters() { continue; } - // CLamp the z range zMin = std::max(0, zMin); - // zMax = std::min(zMax, theFrustumGrid.dims.z); auto xLeftDistance = radius - distanceToPlane(eyeOri, _gridPlanes[0][0]); auto xRightDistance = radius + distanceToPlane(eyeOri, _gridPlanes[0].back()); @@ -389,8 +385,9 @@ glm::ivec3 LightClusters::updateClusters() { int yMax { theFrustumGrid.dims.y - 1 }; float radius2 = radius * radius; - auto eyeOriH = eyeOri; - auto eyeOriV = eyeOri; + + auto eyeOriH = glm::vec3(eyeOri); + auto eyeOriV = glm::vec3(eyeOri); eyeOriH.y = 0.0f; eyeOriV.x = 0.0f; @@ -490,6 +487,7 @@ glm::ivec3 LightClusters::updateClusters() { } } + // Encode the cluster grid: [ ContentOffset - 16bits, Num Point LIghts - 8bits, Num Spot Lights - 8bits] _clusterGrid[i] = (uint32_t)((0xFF000000 & (numLightsSpot << 24)) | (0x00FF0000 & (numLightsPoint << 16)) | (0x0000FFFF & offset)); @@ -553,6 +551,9 @@ void LightClusteringPass::run(const render::SceneContextPointer& sceneContext, c output = _lightClusters; auto config = std::static_pointer_cast(renderContext->jobConfig); + config->numSceneLights = lightStage->getNumLights(); + config->numFreeSceneLights = lightStage->getNumFreeLights(); + config->numAllocatedSceneLights = lightStage->getNumAllocatedLights(); config->setNumInputLights(clusteringStats.x); config->setNumClusteredLights(clusteringStats.y); config->setNumClusteredLightReferences(clusteringStats.z); diff --git a/libraries/render-utils/src/LightClusters.h b/libraries/render-utils/src/LightClusters.h index bb2bf47295..57acc74121 100644 --- a/libraries/render-utils/src/LightClusters.h +++ b/libraries/render-utils/src/LightClusters.h @@ -120,6 +120,11 @@ class LightClusteringPassConfig : public render::Job::Config { Q_PROPERTY(int numClusteredLightReferences MEMBER numClusteredLightReferences NOTIFY dirty) Q_PROPERTY(int numInputLights MEMBER numInputLights NOTIFY dirty) Q_PROPERTY(int numClusteredLights MEMBER numClusteredLights NOTIFY dirty) + + Q_PROPERTY(int numSceneLights MEMBER numSceneLights NOTIFY dirty) + Q_PROPERTY(int numFreeSceneLights MEMBER numFreeSceneLights NOTIFY dirty) + Q_PROPERTY(int numAllocatedSceneLights MEMBER numAllocatedSceneLights NOTIFY dirty) + public: LightClusteringPassConfig() : render::Job::Config(true){} float rangeNear{ 0.1f }; @@ -131,14 +136,18 @@ public: bool freeze{ false }; - - void setNumClusteredLightReferences(int numRefs) { numClusteredLightReferences = numRefs; emit dirty(); } - int numClusteredLightReferences { 0 }; - void setNumInputLights(int numLights) { numInputLights = numLights; emit dirty(); } + int numClusteredLightReferences { 0 }; int numInputLights { 0 }; - void setNumClusteredLights(int numLights) { numClusteredLights = numLights; emit dirty(); } int numClusteredLights { 0 }; + + void setNumClusteredLightReferences(int numRefs) { numClusteredLightReferences = numRefs; emit dirty(); } + void setNumInputLights(int numLights) { numInputLights = numLights; emit dirty(); } + void setNumClusteredLights(int numLights) { numClusteredLights = numLights; emit dirty(); } + + int numSceneLights { 0 }; + int numFreeSceneLights { 0 }; + int numAllocatedSceneLights { 0 }; signals: void dirty(); diff --git a/libraries/render-utils/src/LightStage.cpp b/libraries/render-utils/src/LightStage.cpp index 8c6e6d96a4..66a9797d3c 100644 --- a/libraries/render-utils/src/LightStage.cpp +++ b/libraries/render-utils/src/LightStage.cpp @@ -123,6 +123,16 @@ LightStage::Index LightStage::addLight(const LightPointer& light) { } } +LightStage::Index LightStage::addShadow(Index lightIndex) { + auto light = getLight(lightIndex); + Index shadowId = INVALID_INDEX; + if (light) { + shadowId = _shadows.newElement(std::make_shared(light)); + _descs[lightIndex].shadowId = shadowId; + } + return shadowId; +} + LightStage::LightPointer LightStage::removeLight(Index index) { LightPointer removed = _lights.freeElement(index); diff --git a/libraries/render-utils/src/LightStage.h b/libraries/render-utils/src/LightStage.h index 34575596dd..c2293ac099 100644 --- a/libraries/render-utils/src/LightStage.h +++ b/libraries/render-utils/src/LightStage.h @@ -80,11 +80,16 @@ public: Index findLight(const LightPointer& light) const; Index addLight(const LightPointer& light); + + Index addShadow(Index lightIndex); + LightPointer removeLight(Index index); bool checkLightId(Index index) const { return _lights.checkIndex(index); } Index getNumLights() const { return _lights.getNumElements(); } + Index getNumFreeLights() const { return _lights.getNumFreeIndices(); } + Index getNumAllocatedLights() const { return _lights.getNumAllocatedIndices(); } LightPointer getLight(Index lightId) const { return _lights.get(lightId); diff --git a/libraries/render/src/render/IndexedContainer.h b/libraries/render/src/render/IndexedContainer.h index 6250d4f4f1..bb1a9b72b7 100644 --- a/libraries/render/src/render/IndexedContainer.h +++ b/libraries/render/src/render/IndexedContainer.h @@ -31,6 +31,8 @@ namespace indexed_container { bool checkIndex(Index index) const { return ((index >= 0) && (index < _nextNewIndex)); } Index getNumIndices() const { return _nextNewIndex - (Index) _freeIndices.size(); } + Index getNumFreeIndices() const { return (Index) _freeIndices.size(); } + Index getNumAllocatedIndices() const { return _nextNewIndex; } Index allocateIndex() { if (_freeIndices.empty()) { @@ -74,12 +76,14 @@ namespace indexed_container { bool checkIndex(Index index) const { return _allocator.checkIndex(index); }; Index getNumElements() const { return _allocator.getNumIndices(); } + Index getNumFreeIndices() const { return _allocator.getNumFreeIndices(); } + Index getNumAllocatedIndices() const { return _allocator.getNumAllocatedIndices(); } Index newElement(const Element& e) { Index index = _allocator.allocateIndex(); if (index != INVALID_INDEX) { if (index < (Index) _elements.size()) { - _elements.emplace(_elements.begin() + index, e); + _elements[index] = e; } else { assert(index == _elements.size()); _elements.emplace_back(e); @@ -113,12 +117,14 @@ namespace indexed_container { bool checkIndex(Index index) const { return _allocator.checkIndex(index); }; Index getNumElements() const { return _allocator.getNumIndices(); } + Index getNumFreeIndices() const { return _allocator.getNumFreeIndices(); } + Index getNumAllocatedIndices() const { return _allocator.getNumAllocatedIndices(); } Index newElement(const ElementPtr& e) { Index index = _allocator.allocateIndex(); if (index != INVALID_INDEX) { if (index < (Index) _elements.size()) { - _elements.emplace(_elements.begin() + index, e); + _elements[index] = e; } else { assert(index == (Index) _elements.size()); _elements.emplace_back(e); diff --git a/scripts/developer/utilities/render/lightClustering.qml b/scripts/developer/utilities/render/lightClustering.qml index a9ca05dff8..4db7aa8c39 100644 --- a/scripts/developer/utilities/render/lightClustering.qml +++ b/scripts/developer/utilities/render/lightClustering.qml @@ -60,6 +60,35 @@ Column { ] } + PlotPerf { + title: "Scene Lights" + height: 80 + object: Render.getConfig("LightClustering") + valueUnit: "" + valueScale: 1 + valueNumDigits: "0" + plots: [ + { + object: Render.getConfig("LightClustering"), + prop: "numSceneLights", + label: "current", + color: "#00B4EF" + }, + { + object: Render.getConfig("LightClustering"), + prop: "numFreeSceneLights", + label: "free", + color: "#1AC567" + }, + { + object: Render.getConfig("LightClustering"), + prop: "numAllocatedSceneLights", + label: "allocated", + color: "#9495FF" + } + ] + } + ConfigSlider { label: qsTr("Range Near [m]") integral: false