Define common limits for light sources count
This commit is contained in:
@@ -16,6 +16,9 @@ inline constexpr float CAMERA_SENSITIVITY = 0.1f;
|
|||||||
inline constexpr float CAMERA_NEAR = 0.1f;
|
inline constexpr float CAMERA_NEAR = 0.1f;
|
||||||
inline constexpr float CAMERA_FAR = 100.0f;
|
inline constexpr float CAMERA_FAR = 100.0f;
|
||||||
|
|
||||||
|
inline constexpr int MAX_POINT_LIGHTS = 32;
|
||||||
|
inline constexpr int MAX_SPOT_LIGHTS = 32;
|
||||||
|
|
||||||
} // namespace Fan
|
} // namespace Fan
|
||||||
|
|
||||||
#endif // FAN_CONFIG_HPP_
|
#endif // FAN_CONFIG_HPP_
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include <iostream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <glad/gl.h>
|
#include <glad/gl.h>
|
||||||
@@ -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.diffuse", env.directional_light.diffuse);
|
||||||
shader->set_vec3("u_directional_light.specular", env.directional_light.specular);
|
shader->set_vec3("u_directional_light.specular", env.directional_light.specular);
|
||||||
|
|
||||||
// Note: current limit is set to MAX_POINT_LIGHT_COUNT (8)
|
if (env.point_lights.size() > MAX_POINT_LIGHTS) {
|
||||||
// TODO: Define this limits in a common header file
|
std::cerr << "WARNING: RENDERER: Maximum number of point lights exceeded"
|
||||||
int point_count = std::min(static_cast<int>(env.point_lights.size()), 8);
|
<< " (" << MAX_POINT_LIGHTS << ")" << std::endl;
|
||||||
|
}
|
||||||
|
int point_count = std::min(static_cast<int>(env.point_lights.size()), MAX_POINT_LIGHTS);
|
||||||
shader->set_int("u_point_light_count", point_count);
|
shader->set_int("u_point_light_count", point_count);
|
||||||
for (int i = 0; i < point_count; ++i) {
|
for (int i = 0; i < point_count; ++i) {
|
||||||
std::string prefix = "u_point_lights[" + std::to_string(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);
|
shader->set_vec3(prefix + "specular", env.point_lights[i].specular);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: current limit is set to MAX_SPOT_LIGHT_COUNT (8)
|
if (env.spot_lights.size() > MAX_SPOT_LIGHTS) {
|
||||||
// TODO: Define this limits in a common header file
|
std::cerr << "WARNING: RENDERER: Maximum number of spot lights exceeded"
|
||||||
int spot_count = std::min(static_cast<int>(env.spot_lights.size()), 8);
|
<< " (" << MAX_POINT_LIGHTS << ")" << std::endl;
|
||||||
|
}
|
||||||
|
int spot_count = std::min(static_cast<int>(env.spot_lights.size()), MAX_SPOT_LIGHTS);
|
||||||
shader->set_int("u_spot_light_count", spot_count);
|
shader->set_int("u_spot_light_count", spot_count);
|
||||||
for (int i = 0; i < spot_count; ++i) {
|
for (int i = 0; i < spot_count; ++i) {
|
||||||
std::string prefix = "u_spot_lights[" + std::to_string(i) + "].";
|
std::string prefix = "u_spot_lights[" + std::to_string(i) + "].";
|
||||||
|
|||||||
@@ -54,11 +54,14 @@ uniform vec3 u_view_pos;
|
|||||||
uniform Material u_material;
|
uniform Material u_material;
|
||||||
|
|
||||||
uniform DirectionalLight u_directional_light;
|
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;
|
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;
|
uniform int u_spot_light_count;
|
||||||
|
|
||||||
vec3 calculate_directional_light(DirectionalLight light, vec3 normal, vec3 view_dir);
|
vec3 calculate_directional_light(DirectionalLight light, vec3 normal, vec3 view_dir);
|
||||||
|
|||||||
Reference in New Issue
Block a user