Shadows
This commit is contained in:
69
module.jai
69
module.jai
@@ -104,79 +104,12 @@ coven_run :: (game_update_proc: (float), game_update_post_physics_proc: (float))
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
update_light_buffer :: () {
|
||||
scene := current_scene;
|
||||
light_data : Directional_Light_Buffer_Data;
|
||||
light_data.direction = scene.directional_light.direction;
|
||||
light_data.color_and_intensity = scene.directional_light.color_and_intensity;
|
||||
|
||||
dir := to_v3(scene.directional_light.direction);
|
||||
|
||||
z_near := 1.0;
|
||||
z_far := 50.5;
|
||||
width := 10.0;
|
||||
light_projection := orthographic_lh_projection_matrix(-width, width, -width, width, z_near, z_far);
|
||||
light_view : Matrix4;
|
||||
eye := scene.directional_light.view_position - dir * 30.0;
|
||||
|
||||
m := look_at_lh(eye, eye + dir * 5.0, .{0,1,0});
|
||||
|
||||
light_view = m;
|
||||
|
||||
light_data.light_matrix = light_projection * light_view;
|
||||
|
||||
upload_data_to_buffer(renderer, directional_light_buffer, *light_data, size_of(Directional_Light_Buffer_Data));
|
||||
}
|
||||
|
||||
sync_engine_buffers :: () {
|
||||
update_light_buffer();
|
||||
// Camera buffer
|
||||
camera := *current_scene.camera;
|
||||
|
||||
camera_data : Camera_Data;
|
||||
camera_data.projection_matrix = camera.projection_matrix;
|
||||
camera_data.view_matrix = camera.view_matrix;
|
||||
camera_data.position = to_v4(camera.position);
|
||||
upload_data_to_buffer(renderer, camera_buffer, *camera_data, size_of(Camera_Data));
|
||||
|
||||
shader_time : Shader_Time;
|
||||
shader_time.time = time;
|
||||
upload_data_to_buffer(renderer, time_buffer, *shader_time, size_of(Shader_Time));
|
||||
|
||||
// Sync entity transforms
|
||||
for current_scene.entities {
|
||||
if it.flags & .RENDERABLE {
|
||||
if it.renderable.type == {
|
||||
case .MODEL; {
|
||||
for n, i: it.renderable.model.nodes {
|
||||
if n.meshes.count > 0 {
|
||||
node_data := *it.renderable.nodes[i];
|
||||
upload_data_to_buffer(renderer, node_data.transform_buffer, *node_data.transform.world_matrix, size_of(Matrix4));
|
||||
|
||||
if node_data.num_bones > 0 {
|
||||
for handle, mesh_index: n.meshes {
|
||||
m := parray_get(*renderer.meshes, handle);
|
||||
bones : [MAX_BONES] Matrix4;
|
||||
for bone_index: 0..m.num_bones-1 {
|
||||
bone := *it.renderable.nodes[m.bone_indices[bone_index]];
|
||||
bones[bone_index] = bone.transform.world_matrix * m.bone_matrices[bone_index];
|
||||
}
|
||||
upload_data_to_buffer(renderer, node_data.bone_buffers[mesh_index], bones.data, size_of(Matrix4) * m.num_bones);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if NETWORKING {
|
||||
#load "networking/networking.jai";
|
||||
}
|
||||
|
||||
#load "input/input.jai";
|
||||
#load "renderer/engine_buffers.jai";
|
||||
#load "renderer/renderer.jai";
|
||||
#load "windowing/window.jai";
|
||||
#load "physics/physics.jai";
|
||||
|
||||
Reference in New Issue
Block a user