Skip to content

Commit

Permalink
lighting: Proper pre-culling.
Browse files Browse the repository at this point in the history
  • Loading branch information
vlj committed Dec 31, 2023
1 parent 56f592d commit 0681e26
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions lib/ivis_opengl/pielighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,39 @@ void renderingNew::LightingManager::ComputeFrameData(const LightingData& data, c
WZ_PROFILE_SCOPE("LightingManager_ComputeFrameData");
PointLightBuckets result;

// Pick the firsts lights in the scene
// TODO: Be smarter, culling light outside the scene before
for (int lightIndex = 0; lightIndex < std::min(gfx_api::max_lights, data.lights.size()); lightIndex++)
// Pick the first lights inside the view frustrum
auto viewFrustrum = IntersectionOfHalfSpace{
[](glm::vec3 in) { return in.x >= -1.f; },
[](glm::vec3 in) { return in.x <= 1.f; },
[](glm::vec3 in) {
if (gfx_api::context::get().isYAxisInverted())
return -in.y >= -1.f ;
return in.y >= -1.f ;
},
[](glm::vec3 in) {
if (gfx_api::context::get().isYAxisInverted())
return -in.y <= 1.f;
return in.y <= 1.f;
},
[](glm::vec3 in) { return in.z >= 0; },
[](glm::vec3 in) { return in.z <= 1; }
};

std::vector<LIGHT> culledLights;
for (const auto& light : data.lights)
{
const auto& light = data.lights[lightIndex];
if (culledLights.size() >= gfx_api::max_lights)
break;
auto clipSpaceBoundingBox = transformBoundingBox(worldViewProjectionMatrix, getLightBoundingBox(light));
if (!isBBoxInClipSpace(viewFrustrum, clipSpaceBoundingBox))
continue;
culledLights.push_back(light);
}


for (int lightIndex = 0; lightIndex < culledLights.size(); lightIndex++)
{
const auto& light = culledLights[lightIndex];
result.positions[lightIndex].x = light.position.x;
result.positions[lightIndex].y = light.position.y;
result.positions[lightIndex].z = light.position.z;
Expand Down Expand Up @@ -102,11 +130,11 @@ void renderingNew::LightingManager::ComputeFrameData(const LightingData& data, c
};

int bucketSize = 0;
for (int lightIndex = 0; lightIndex < std::min(gfx_api::max_lights, data.lights.size()); lightIndex++)
for (int lightIndex = 0; lightIndex < culledLights.size(); lightIndex++)
{
if (overallId + bucketSize >= gfx_api::max_indexed_lights)
continue;
const auto& light = data.lights[lightIndex];
const auto& light = culledLights[lightIndex];
auto clipSpaceBoundingBox = transformBoundingBox(worldViewProjectionMatrix, getLightBoundingBox(light));

if (isBBoxInClipSpace(frustrum, clipSpaceBoundingBox))
Expand Down

0 comments on commit 0681e26

Please sign in to comment.