From 30a64ee82ae00fb2ab19224754385932ff4b6bcf Mon Sep 17 00:00:00 2001 From: cody glassman Date: Tue, 24 May 2022 22:30:25 -0700 Subject: [PATCH] move to world space, fix bug with uniform size updates --- components/fx/pass.cpp | 2 +- components/sceneutil/lightmanager.cpp | 18 ++++++++++++------ components/sceneutil/lightmanager.hpp | 7 ++++++- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/components/fx/pass.cpp b/components/fx/pass.cpp index d8fb07efd5..16480128b7 100644 --- a/components/fx/pass.cpp +++ b/components/fx/pass.cpp @@ -86,7 +86,7 @@ int omw_GetPointLightCount() return omw_PointLightsCount; } -vec3 omw_GetPointLightViewPos(int index) +vec3 omw_GetPointLightWorldPos(int index) { return omw_PointLights[(index * 3)].xyz; } diff --git a/components/sceneutil/lightmanager.cpp b/components/sceneutil/lightmanager.cpp index 3092fc6f40..db5fe6b479 100644 --- a/components/sceneutil/lightmanager.cpp +++ b/components/sceneutil/lightmanager.cpp @@ -635,6 +635,9 @@ namespace SceneUtil cv->pushStateSet(stateset); traverse(node, cv); cv->popStateSet(); + + if (node->getPPLightsBuffer() && cv->getCurrentCamera()->getName() == Constants::SceneCamera) + node->getPPLightsBuffer()->updateCount(cv->getTraversalNumber()); } }; @@ -1141,12 +1144,15 @@ namespace SceneUtil if (mPPLightBuffer && it->first->getName() == Constants::SceneCamera) { const auto* light = l.mLightSource->getLight(frameNum); - mPPLightBuffer->setLight(frameNum, light->getPosition() * (*viewMatrix), - light->getDiffuse(), - light->getConstantAttenuation(), - light->getLinearAttenuation(), - light->getQuadraticAttenuation(), - l.mLightSource->getRadius()); + if (light->getDiffuse().x() >= 0.f) + { + mPPLightBuffer->setLight(frameNum, light->getPosition(), + light->getDiffuse(), + light->getConstantAttenuation(), + light->getLinearAttenuation(), + light->getQuadraticAttenuation(), + l.mLightSource->getRadius()); + } } } } diff --git a/components/sceneutil/lightmanager.hpp b/components/sceneutil/lightmanager.hpp index ab48e9a23a..0457dc323e 100644 --- a/components/sceneutil/lightmanager.hpp +++ b/components/sceneutil/lightmanager.hpp @@ -29,7 +29,7 @@ namespace SceneUtil class PPLightBuffer { public: - inline static constexpr auto sMaxPPLights = 30; + inline static constexpr auto sMaxPPLights = 40; inline static constexpr auto sMaxPPLightsArraySize = sMaxPPLights * 3; PPLightBuffer() @@ -75,6 +75,11 @@ namespace SceneUtil mUniformBuffers[frameId]->setElement(i + 2, osg::Vec4f(ac, al, aq, radius)); mIndex[frameId]++; + } + + void updateCount(size_t frame) + { + size_t frameId = frame % 2; mUniformCount[frameId]->set(static_cast(mIndex[frameId])); }