From 629dc808c595d65cda74a86975ebd780113f3431 Mon Sep 17 00:00:00 2001 From: quou Date: Sun, 9 Feb 2025 18:50:58 +1100 Subject: Properly send lights from the CPU --- c2.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'c2.cpp') diff --git a/c2.cpp b/c2.cpp index c98f5b9..d1aa36a 100644 --- a/c2.cpp +++ b/c2.cpp @@ -2,6 +2,7 @@ #include "camera.hpp" #include "debugdraw.hpp" #include "editor.hpp" +#include "lighting.hpp" #include "model.hpp" #include "physics.hpp" #include "scene.hpp" @@ -639,6 +640,7 @@ struct C2 : public App { Texture_Id default_texture; Entity_Id monkey, monkey2, box, floor; Model_Scene scene; + Lighting lighting; Orbit_Cam camera; Fullscreen_Quad quad; Sky sky; @@ -718,6 +720,7 @@ struct C2 : public App { ui->layout(w, h); fps_label = ui->create_element(ui->root, ""); scene.init(&scene_arena, 32, clamped_linear); + lighting.init(dev); sky.init(dev, &assets); eprobe.init(dev, &assets, 256); tonemap.init(dev, &assets); @@ -738,6 +741,13 @@ struct C2 : public App { (Model*)assets.load("monkey.mdl") ); } + { + auto sun = world->create_entity(); + auto [light] = world->add(sun); + light.colour = v3f(1.0f); + light.dir = v3f(0.57f, 0.57f, 0.57f); + light.brightness = 1.0f; + } { box_col = make_box(&asset_arena, v3f(1.0f, 1.0f, 1.0f)); floor_col = make_box(&asset_arena, v3f(10.0f, 0.1f, 10.0f)); @@ -752,9 +762,13 @@ struct C2 : public App { ); floor = world->create_entity(); - auto [transf, rbf] = world->add(floor); + auto [transf, rbf, modf] = world->add(floor); transf.mat = m4f::identity(); rbf.init(floor_col, v3f(0.0f), quat::identity(), 0.0f); + modf.i = scene.instantiate( + dev, + (Model*)assets.load("scene.mdl") + ); } world->get(monkey).mat = m4f::translate( m4f::identity(), @@ -877,13 +891,14 @@ struct C2 : public App { camera.asp = (float)bb.w / (float)bb.h; camera.update_orbit(*this); camera.update(); - update_scene(scene, dev, camera, *world); + lighting.update(dev, ctx, *world); + update_scene(scene, dev, lighting, camera, *world); ctx.debug_push("scene"); ctx.debug_push("depth prepass"); - scene.render(dev, &frame_arena, depth_prepass, 0, clamped_linear); + scene.render(dev, &frame_arena, depth_prepass, &lighting, 0, clamped_linear); ctx.debug_pop(); ctx.debug_push("forward"); - scene.render(dev, &frame_arena, pass2, eprobe.get_cubemap(), clamped_linear); + scene.render(dev, &frame_arena, pass2, &lighting, eprobe.get_cubemap(), clamped_linear); ctx.debug_pop(); ctx.debug_pop(); @@ -984,6 +999,7 @@ struct C2 : public App { quad.destroy(dev); scene.destroy(dev); sky.destroy(dev); + lighting.destroy(dev); lr.destroy(dev); eprobe.destroy(dev); tonemap.destroy(dev); -- cgit v1.2.3-54-g00ecf