Skip to content

Commit

Permalink
lighting: implement review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
vlj committed Dec 31, 2023
1 parent 0e53192 commit f9c9723
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 38 deletions.
13 changes: 0 additions & 13 deletions data/base/shaders/pointlights.frag
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,3 @@ vec4 processPointLight(vec3 WorldFragPos, vec3 fragNormal, vec3 viewVector, vec4
float pointLightBlinn = pow(clamp(dot(fragNormal, pointLightHalfVec), 0.f, 1.f), 16.f);
return lightColor * pointLightLambert * (albedo + pointLightBlinn * (gloss * gloss));
}

// Unused for now
// vec4 processPointLightScattering(vec3 pointLightWorldPosition, float pointLightEnergy, vec4 pointLightColor)
// {
// // manual integration
// vec3 viewLine = fragPos - cameraPos.xyz;
// vec3 result = vec3(0);
// for (int i = 0; i < 10; i++)
// {
// result += pointLightEnergyAtPosition(fragPos + i * viewLine / 10, pointLightWorldPosition, pointLightEnergy) / 10;
// }
// return vec4(result * pointLightColor.xyz * fogColor.xyz, 1);
// }
13 changes: 0 additions & 13 deletions data/base/shaders/vk/pointlights.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,3 @@ vec4 processPointLight(vec3 WorldFragPos, vec3 fragNormal, vec3 viewVector, vec4
float pointLightBlinn = pow(clamp(dot(fragNormal, pointLightHalfVec), 0.f, 1.f), 16.f);
return lightColor * pointLightLambert * (albedo + pointLightBlinn * (gloss * gloss));
}

// Unused for now
// vec4 processPointLightScattering(vec3 pointLightWorldPosition, float pointLightEnergy, vec4 pointLightColor)
// {
// // manual integration
// vec3 viewLine = fragPos - cameraPos.xyz;
// vec3 result = vec3(0);
// for (int i = 0; i < 10; i++)
// {
// result += pointLightEnergyAtPosition(fragPos + i * viewLine / 10, pointLightWorldPosition, pointLightEnergy) / 10;
// }
// return vec4(result * pointLightColor.xyz * fogColor.xyz, 1);
// }
2 changes: 0 additions & 2 deletions lib/ivis_opengl/culling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
#include <algorithm>
#include <functional>

using BoundinxBox = std::array<glm::vec3, 8>;

BoundinxBox transformBoundingBox(const glm::mat4& worldViewProjectionMatrix, const BoundinxBox& worldSpaceBoundingBox)
{
BoundinxBox bboxInClipSpace;
Expand Down
22 changes: 13 additions & 9 deletions lib/ivis_opengl/pielighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,19 @@ void renderingNew::LightingManager::ComputeFrameData(const LightingData& data, c
for (const auto& light : data.lights)
{
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++)
for (size_t lightIndex = 0; lightIndex < culledLights.size(); lightIndex++)
{
const auto& light = culledLights[lightIndex];
result.positions[lightIndex].x = light.position.x;
Expand All @@ -143,24 +147,24 @@ void renderingNew::LightingManager::ComputeFrameData(const LightingData& data, c
for (int j = 0; j < gfx_api::bucket_dimension; j++)
{
auto frustrum = IntersectionOfHalfSpace{
[&](glm::vec3 in) { return in.x >= -1.f + 2 * static_cast<float>(i) / gfx_api::bucket_dimension; },
[&](glm::vec3 in) { return in.x <= -1.f + 2 * static_cast<float>(i + 1) / gfx_api::bucket_dimension; },
[&](glm::vec3 in) {
[i](glm::vec3 in) { return in.x >= -1.f + 2 * static_cast<float>(i) / gfx_api::bucket_dimension; },
[i](glm::vec3 in) { return in.x <= -1.f + 2 * static_cast<float>(i + 1) / gfx_api::bucket_dimension; },
[j](glm::vec3 in) {
if (gfx_api::context::get().isYAxisInverted())
return -in.y >= -1.f + 2 * static_cast<float>(j) / gfx_api::bucket_dimension;
return in.y >= -1.f + 2 * static_cast<float>(j) / gfx_api::bucket_dimension;
},
[&](glm::vec3 in) {
[j](glm::vec3 in) {
if (gfx_api::context::get().isYAxisInverted())
return -in.y <= -1.f + 2 * static_cast<float>(j + 1) / gfx_api::bucket_dimension;
return in.y <= -1.f + 2 * static_cast<float>(j + 1) / gfx_api::bucket_dimension;
},
[&](glm::vec3 in) { return in.z >= 0; },
[&](glm::vec3 in) { return in.z <= 1; }
[](glm::vec3 in) { return in.z >= 0; },
[](glm::vec3 in) { return in.z <= 1; }
};

int bucketSize = 0;
for (int lightIndex = 0; lightIndex < culledLights.size(); lightIndex++)
size_t bucketSize = 0;
for (size_t lightIndex = 0; lightIndex < culledLights.size(); lightIndex++)
{
if (overallId + bucketSize >= gfx_api::max_indexed_lights)
continue;
Expand Down
2 changes: 1 addition & 1 deletion lib/ivis_opengl/pielighting.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct ILightingManager

virtual void ComputeFrameData(const LightingData& data, const glm::mat4& worldViewProjectionMatrix) = 0;

PointLightBuckets getPointLightBuckets()
PointLightBuckets getPointLightBuckets() const
{
return currentPointLightBuckets;
}
Expand Down

0 comments on commit f9c9723

Please sign in to comment.