mirror of
https://github.com/lubosz/overte.git
synced 2025-04-24 00:13:53 +02:00
FOund 2 bugs causing the empty clusters. now back to working
This commit is contained in:
parent
3d99179e3f
commit
567adf651a
7 changed files with 74 additions and 13 deletions
|
@ -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]);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Config>(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);
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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<Shadow>(light));
|
||||
_descs[lightIndex].shadowId = shadowId;
|
||||
}
|
||||
return shadowId;
|
||||
}
|
||||
|
||||
LightStage::LightPointer LightStage::removeLight(Index index) {
|
||||
LightPointer removed = _lights.freeElement(index);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue