Point lights
This commit is contained in:
@@ -61,6 +61,15 @@ update_light_buffer :: () {
|
||||
light_data.light_matrix = light_matrix;
|
||||
|
||||
upload_data_to_buffer(engine.renderer, engine.directional_light_buffer, *light_data, size_of(Directional_Light_Buffer_Data));
|
||||
|
||||
point_light_array: Point_Light_Array;
|
||||
for light: engine.current_scene.by_type._Point_Light {
|
||||
shd_point_light := to_shader_point_light(light);
|
||||
point_light_array.point_lights[point_light_array.num_point_lights] = shd_point_light;
|
||||
point_light_array.num_point_lights += 1;
|
||||
}
|
||||
|
||||
upload_data_to_buffer(engine.renderer, engine.point_light_buffer, *point_light_array, size_of(Point_Light_Array));
|
||||
}
|
||||
|
||||
sync_engine_buffers :: () {
|
||||
|
||||
41
renderer/point_light.jai
Normal file
41
renderer/point_light.jai
Normal file
@@ -0,0 +1,41 @@
|
||||
Point_Light :: struct {
|
||||
using #as entity : Entity;
|
||||
entity.type = Point_Light;
|
||||
|
||||
color: Vector3;
|
||||
intensity: float = 1.0;
|
||||
attenuation_radius: float = 3.0;
|
||||
}
|
||||
|
||||
Point_Light_Shader_Data :: struct {
|
||||
position: Vector4;
|
||||
color: Vector4;
|
||||
attenuation_radius: float;
|
||||
|
||||
pad: Vector3;
|
||||
}
|
||||
|
||||
MAX_POINT_LIGHTS :: 64;
|
||||
|
||||
Point_Light_Array :: struct {
|
||||
point_lights: [MAX_POINT_LIGHTS] Point_Light_Shader_Data;
|
||||
num_point_lights: s32;
|
||||
|
||||
padding: Vector3;
|
||||
}
|
||||
|
||||
init_entity :: (light: *Point_Light) {
|
||||
light.intensity = 1.0;
|
||||
light.color = .{1,1,1};
|
||||
light.attenuation_radius = 3.0;
|
||||
}
|
||||
|
||||
to_shader_point_light :: (point_light: *Point_Light) -> Point_Light_Shader_Data {
|
||||
data : Point_Light_Shader_Data;
|
||||
|
||||
data.position = to_v4(get_position(point_light.transform));
|
||||
data.color = to_v4(point_light.color*point_light.intensity);
|
||||
data.attenuation_radius = point_light.attenuation_radius;
|
||||
|
||||
return data;
|
||||
}
|
||||
Reference in New Issue
Block a user