From 1703ead546b8c5433ecc787018c26a4062142e45 Mon Sep 17 00:00:00 2001 From: Cristian Gora Date: Sun, 27 Sep 2026 03:34:20 +0200 Subject: [PATCH] Define common limits for light sources count --- src/config.hpp | 3 +++ src/renderer.cpp | 17 +++++++++++------ src/shaders/default.frag | 11 +++++++---- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/config.hpp b/src/config.hpp index 7fd5d5c..ded59b0 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -16,6 +16,9 @@ inline constexpr float CAMERA_SENSITIVITY = 0.1f; inline constexpr float CAMERA_NEAR = 0.1f; inline constexpr float CAMERA_FAR = 100.0f; +inline constexpr int MAX_POINT_LIGHTS = 32; +inline constexpr int MAX_SPOT_LIGHTS = 32; + } // namespace Fan #endif // FAN_CONFIG_HPP_ diff --git a/src/renderer.cpp b/src/renderer.cpp index bc6ba8e..e0691a4 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -64,9 +65,11 @@ void Renderer::draw_scene(const Scene& scene, const Camera& camera, shader->set_vec3("u_directional_light.diffuse", env.directional_light.diffuse); shader->set_vec3("u_directional_light.specular", env.directional_light.specular); - // Note: current limit is set to MAX_POINT_LIGHT_COUNT (8) - // TODO: Define this limits in a common header file - int point_count = std::min(static_cast(env.point_lights.size()), 8); + if (env.point_lights.size() > MAX_POINT_LIGHTS) { + std::cerr << "WARNING: RENDERER: Maximum number of point lights exceeded" + << " (" << MAX_POINT_LIGHTS << ")" << std::endl; + } + int point_count = std::min(static_cast(env.point_lights.size()), MAX_POINT_LIGHTS); shader->set_int("u_point_light_count", point_count); for (int i = 0; i < point_count; ++i) { std::string prefix = "u_point_lights[" + std::to_string(i) + "]."; @@ -81,9 +84,11 @@ void Renderer::draw_scene(const Scene& scene, const Camera& camera, shader->set_vec3(prefix + "specular", env.point_lights[i].specular); } - // Note: current limit is set to MAX_SPOT_LIGHT_COUNT (8) - // TODO: Define this limits in a common header file - int spot_count = std::min(static_cast(env.spot_lights.size()), 8); + if (env.spot_lights.size() > MAX_SPOT_LIGHTS) { + std::cerr << "WARNING: RENDERER: Maximum number of spot lights exceeded" + << " (" << MAX_POINT_LIGHTS << ")" << std::endl; + } + int spot_count = std::min(static_cast(env.spot_lights.size()), MAX_SPOT_LIGHTS); shader->set_int("u_spot_light_count", spot_count); for (int i = 0; i < spot_count; ++i) { std::string prefix = "u_spot_lights[" + std::to_string(i) + "]."; diff --git a/src/shaders/default.frag b/src/shaders/default.frag index 13ba102..a002483 100644 --- a/src/shaders/default.frag +++ b/src/shaders/default.frag @@ -54,11 +54,14 @@ uniform vec3 u_view_pos; uniform Material u_material; uniform DirectionalLight u_directional_light; -#define MAX_POINT_LIGHT_COUNT 8 -uniform PointLight u_point_lights[MAX_POINT_LIGHT_COUNT]; + +#define MAX_POINT_LIGHTS 32 +#define MAX_SPOT_LIGHTS 32 + +uniform PointLight u_point_lights[MAX_POINT_LIGHTS]; uniform int u_point_light_count; -#define MAX_SPOT_LIGHT_COUNT 8 -uniform SpotLight u_spot_lights[MAX_SPOT_LIGHT_COUNT]; + +uniform SpotLight u_spot_lights[MAX_SPOT_LIGHTS]; uniform int u_spot_light_count; vec3 calculate_directional_light(DirectionalLight light, vec3 normal, vec3 view_dir);