summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2025-02-09 18:50:58 +1100
committerquou <quou@disroot.org>2025-02-09 18:51:30 +1100
commit629dc808c595d65cda74a86975ebd780113f3431 (patch)
tree72d0c17600c6420fc2b834529d781dc43cc20317
parent1c86bb51da99df1950124d812eabcfe15af4f771 (diff)
Properly send lights from the CPU
-rw-r--r--Makefile16
-rw-r--r--build.ninja7
-rw-r--r--c2.cpp24
-rw-r--r--configure.lua5
-rw-r--r--intermediate/scene.glbbin0 -> 12360 bytes
-rw-r--r--intermediate/surface.glsl59
-rw-r--r--lighting.cpp54
-rw-r--r--lighting.hpp29
-rw-r--r--model.cpp21
-rw-r--r--model.hpp17
-rw-r--r--scene.cpp3
-rw-r--r--scene.hpp3
-rw-r--r--src/scene.blendbin0 -> 538248 bytes
13 files changed, 200 insertions, 38 deletions
diff --git a/Makefile b/Makefile
index dc60476..2a44434 100644
--- a/Makefile
+++ b/Makefile
@@ -52,6 +52,8 @@ debugdraw.o: debugdraw.cpp
g++ -std=c++20 $(opt_com) $(cflags) -c debugdraw.cpp -o debugdraw.o
editor.o: editor.cpp
g++ -std=c++20 $(opt_com) $(cflags) -c editor.cpp -o editor.o
+lighting.o: lighting.cpp
+ g++ -std=c++20 $(opt_com) $(cflags) -c lighting.cpp -o lighting.o
maths.o: maths.cpp
g++ -std=c++20 $(opt_com) $(cflags) -c maths.cpp -o maths.o
model.o: model.cpp
@@ -68,8 +70,8 @@ video.o: video.cpp
g++ -std=c++20 $(opt_com) $(cflags) -c video.cpp -o video.o
world.o: world.cpp
g++ -std=c++20 $(opt_com) $(cflags) -c world.cpp -o world.o
-c2: app.o asset.o c2.o camera.o debugdraw.o editor.o maths.o model.o physics.o pipeline.o scene.o ui.o video.o world.o libqstd.a
- g++ $(opt_lnk) $(lflags) -o c2 app.o asset.o c2.o camera.o debugdraw.o editor.o maths.o model.o physics.o pipeline.o scene.o ui.o video.o world.o libqstd.a -lX11 -lm
+c2: app.o asset.o c2.o camera.o debugdraw.o editor.o lighting.o maths.o model.o physics.o pipeline.o scene.o ui.o video.o world.o libqstd.a
+ g++ $(opt_lnk) $(lflags) -o c2 app.o asset.o c2.o camera.o debugdraw.o editor.o lighting.o maths.o model.o physics.o pipeline.o scene.o ui.o video.o world.o libqstd.a -lX11 -lm
c2: pack
@@ -114,6 +116,8 @@ data/monkey.mdl: convmodel intermediate/monkey.glb data/debug.csh data/mip_spec.
./convmodel data intermediate/monkey.glb data/monkey.mdl
data/cube.mdl: convmodel intermediate/cube.glb data/debug.csh data/mip_spec.csh data/sky.csh data/surface.csh data/surface_depthonly.csh data/tonemap.csh data/triangle.csh data/ui.csh | data
./convmodel data intermediate/cube.glb data/cube.mdl
+data/scene.mdl: convmodel intermediate/scene.glb data/debug.csh data/mip_spec.csh data/sky.csh data/surface.csh data/surface_depthonly.csh data/tonemap.csh data/triangle.csh data/ui.csh | data
+ ./convmodel data intermediate/scene.glb data/scene.mdl
data/22.tex: convtexture intermediate/22.bmp | data
./convtexture intermediate/22.bmp data/22.tex bc1
@@ -135,16 +139,16 @@ data/plastic.mat: convmaterial intermediate/plastic.mat | data
data/greybox.mat: convmaterial intermediate/greybox.mat | data
./convmaterial intermediate/greybox.mat data/greybox.mat
-pack: packer data/debug.csh data/mip_spec.csh data/sky.csh data/surface.csh data/surface_depthonly.csh data/tonemap.csh data/triangle.csh data/ui.csh data/monkey.mdl data/cube.mdl data/22.tex data/kita.tex data/brick_albedo.tex data/brick_ao.tex data/brick_normal.tex data/sky.tex data/bricks.mat data/plastic.mat data/greybox.mat
- ./packer pack data debug.csh mip_spec.csh sky.csh surface.csh surface_depthonly.csh tonemap.csh triangle.csh ui.csh monkey.mdl cube.mdl 22.tex kita.tex brick_albedo.tex brick_ao.tex brick_normal.tex sky.tex bricks.mat plastic.mat greybox.mat
+pack: packer data/debug.csh data/mip_spec.csh data/sky.csh data/surface.csh data/surface_depthonly.csh data/tonemap.csh data/triangle.csh data/ui.csh data/monkey.mdl data/cube.mdl data/scene.mdl data/22.tex data/kita.tex data/brick_albedo.tex data/brick_ao.tex data/brick_normal.tex data/sky.tex data/bricks.mat data/plastic.mat data/greybox.mat
+ ./packer pack data debug.csh mip_spec.csh sky.csh surface.csh surface_depthonly.csh tonemap.csh triangle.csh ui.csh monkey.mdl cube.mdl scene.mdl 22.tex kita.tex brick_albedo.tex brick_ao.tex brick_normal.tex sky.tex bricks.mat plastic.mat greybox.mat
data:
mkdir -p data
--include qstd/memory.d qstd/plat.d qstd/str.d qstd/pack.d cfg/cfgparse.d sc/sc.d sc/includer.d app.d asset.d c2.d camera.d debugdraw.d editor.d maths.d model.d physics.d pipeline.d scene.d ui.d video.d world.d convtexture.d convmodel.d convmaterial.d packer.d
+-include qstd/memory.d qstd/plat.d qstd/str.d qstd/pack.d cfg/cfgparse.d sc/sc.d sc/includer.d app.d asset.d c2.d camera.d debugdraw.d editor.d lighting.d maths.d model.d physics.d pipeline.d scene.d ui.d video.d world.d convtexture.d convmodel.d convmaterial.d packer.d
clean:
- rm -f qstd/memory.o qstd/plat.o qstd/str.o qstd/pack.o cfg/cfgparse.o sc/sc.o sc/includer.o app.o asset.o c2.o camera.o debugdraw.o editor.o maths.o model.o physics.o pipeline.o scene.o ui.o video.o world.o convtexture.o convmodel.o convmaterial.o packer.o qstd/memory.d qstd/plat.d qstd/str.d qstd/pack.d cfg/cfgparse.d sc/sc.d sc/includer.d app.d asset.d c2.d camera.d debugdraw.d editor.d maths.d model.d physics.d pipeline.d scene.d ui.d video.d world.d convtexture.d convmodel.d convmaterial.d packer.d data/debug.csh data/mip_spec.csh data/sky.csh data/surface.csh data/surface_depthonly.csh data/tonemap.csh data/triangle.csh data/ui.csh data/monkey.mdl data/cube.mdl data/22.tex data/kita.tex data/brick_albedo.tex data/brick_ao.tex data/brick_normal.tex data/sky.tex data/bricks.mat data/plastic.mat data/greybox.mat
+ rm -f qstd/memory.o qstd/plat.o qstd/str.o qstd/pack.o cfg/cfgparse.o sc/sc.o sc/includer.o app.o asset.o c2.o camera.o debugdraw.o editor.o lighting.o maths.o model.o physics.o pipeline.o scene.o ui.o video.o world.o convtexture.o convmodel.o convmaterial.o packer.o qstd/memory.d qstd/plat.d qstd/str.d qstd/pack.d cfg/cfgparse.d sc/sc.d sc/includer.d app.d asset.d c2.d camera.d debugdraw.d editor.d lighting.d maths.d model.d physics.d pipeline.d scene.d ui.d video.d world.d convtexture.d convmodel.d convmaterial.d packer.d data/debug.csh data/mip_spec.csh data/sky.csh data/surface.csh data/surface_depthonly.csh data/tonemap.csh data/triangle.csh data/ui.csh data/monkey.mdl data/cube.mdl data/scene.mdl data/22.tex data/kita.tex data/brick_albedo.tex data/brick_ao.tex data/brick_normal.tex data/sky.tex data/bricks.mat data/plastic.mat data/greybox.mat
rm -f shadercompiler
rmdir data
rm -f c2
diff --git a/build.ninja b/build.ninja
index 06d3b37..86492d1 100644
--- a/build.ninja
+++ b/build.ninja
@@ -18,6 +18,7 @@ build c2.obj: cpp c2.cpp
build camera.obj: cpp camera.cpp
build debugdraw.obj: cpp debugdraw.cpp
build editor.obj: cpp editor.cpp
+build lighting.obj: cpp lighting.cpp
build maths.obj: cpp maths.cpp
build model.obj: cpp model.cpp
build physics.obj: cpp physics.cpp
@@ -26,7 +27,7 @@ build scene.obj: cpp scene.cpp
build ui.obj: cpp ui.cpp
build video.obj: cpp video.cpp
build world.obj: cpp world.cpp
-build c2.exe: link qstd/qstd.lib app.obj asset.obj c2.obj camera.obj debugdraw.obj editor.obj maths.obj model.obj physics.obj pipeline.obj scene.obj ui.obj video.obj world.obj
+build c2.exe: link qstd/qstd.lib app.obj asset.obj c2.obj camera.obj debugdraw.obj editor.obj lighting.obj maths.obj model.obj physics.obj pipeline.obj scene.obj ui.obj video.obj world.obj
libs = user32.lib
build qstd/memory.obj: cpp qstd/memory.c
@@ -85,6 +86,7 @@ build data/ui.csh: shadercompiler intermediate/ui.glsl | shadercompiler.exe
build data/monkey.mdl: convmodel intermediate/monkey.glb | convmodel.exe data/debug.csh data/mip_spec.csh data/sky.csh data/surface.csh data/surface_depthonly.csh data/tonemap.csh data/triangle.csh data/ui.csh
build data/cube.mdl: convmodel intermediate/cube.glb | convmodel.exe data/debug.csh data/mip_spec.csh data/sky.csh data/surface.csh data/surface_depthonly.csh data/tonemap.csh data/triangle.csh data/ui.csh
+build data/scene.mdl: convmodel intermediate/scene.glb | convmodel.exe data/debug.csh data/mip_spec.csh data/sky.csh data/surface.csh data/surface_depthonly.csh data/tonemap.csh data/triangle.csh data/ui.csh
build data/bricks.mat: convmaterial intermediate/bricks.mat | convmaterial.exe
build data/plastic.mat: convmaterial intermediate/plastic.mat | convmaterial.exe
@@ -103,4 +105,5 @@ build data/brick_normal.tex: convtexture intermediate/brick_normal.bmp | convtex
build data/sky.tex: convtexture intermediate/sky.hdr | convtexture.exe
format = rgba16f
-build pack: packer data/debug.csh data/mip_spec.csh data/sky.csh data/surface.csh data/surface_depthonly.csh data/tonemap.csh data/triangle.csh data/ui.csh data/monkey.mdl data/cube.mdl data/bricks.mat data/plastic.mat data/greybox.mat data/22.tex data/kita.tex data/brick_albedo.tex data/brick_ao.tex data/brick_normal.tex data/sky.tex | packer.exe
+build pack: packer data/debug.csh data/mip_spec.csh data/sky.csh data/surface.csh data/surface_depthonly.csh data/tonemap.csh data/triangle.csh data/ui.csh data/monkey.mdl data/cube.mdl data/scene.mdl data/bricks.mat data/plastic.mat data/greybox.mat data/22.tex data/kita.tex data/brick_albedo.tex data/brick_ao.tex data/brick_normal.tex data/sky.tex | packer.exe
+
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::Label>(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);
@@ -739,6 +742,13 @@ struct C2 : public App {
);
}
{
+ auto sun = world->create_entity();
+ auto [light] = world->add<Sun_Light>(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));
box = world->create_entity();
@@ -752,9 +762,13 @@ struct C2 : public App {
);
floor = world->create_entity();
- auto [transf, rbf] = world->add<Transform, Rigidbody>(floor);
+ auto [transf, rbf, modf] = world->add<Transform, Rigidbody, C_Model>(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<Transform>(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);
diff --git a/configure.lua b/configure.lua
index 49ba1f0..cffd61e 100644
--- a/configure.lua
+++ b/configure.lua
@@ -6,6 +6,7 @@ config = {
"camera",
"debugdraw",
"editor",
+ "lighting",
"maths",
"model",
"physics",
@@ -57,7 +58,8 @@ config = {
},
models = {
"monkey",
- "cube"
+ "cube",
+ "scene"
},
textures = {
{ "22", "bmp", "bc1" },
@@ -561,5 +563,6 @@ if system == "windows" then
assets(config.materials, "convmaterial", "mat", "mat")
textures(config.textures, "convtexture")
pack()
+ outfile:write("\n")
end
diff --git a/intermediate/scene.glb b/intermediate/scene.glb
new file mode 100644
index 0000000..5335c55
--- /dev/null
+++ b/intermediate/scene.glb
Binary files differ
diff --git a/intermediate/surface.glsl b/intermediate/surface.glsl
index 0cba7f8..fff15ed 100644
--- a/intermediate/surface.glsl
+++ b/intermediate/surface.glsl
@@ -54,9 +54,24 @@ type: float
name: ao
type: float
[variable]
+name: light_count
+type: int
+[variable]
name: camera_pos
type: vec3
+[struct]
+name: Light
+[variable]
+name: dir
+type: vec3
+[variable]
+name: brightness
+type: float
+[variable]
+name: colour
+type: vec3
+
[cbuffer]
name: c_mvp
type: MVP
@@ -67,6 +82,11 @@ name: material
type: Material
stage: fragment
+[sbuffer]
+name: lights
+type: Light
+stage: fragment
+
[texture]
name: albedo
stage: fragment
@@ -147,6 +167,7 @@ float specular_brdf(vec2 uv, vec3 ref, vec3 l, vec3 v, vec3 n) {
}
void main() {
+ int i;
vec2 uv = interpolator.uv;
vec3 p = interpolator.position.xyz;
@@ -158,29 +179,33 @@ void main() {
else
nrm = normalize(interpolator.tbn * nrm);
- vec3 light_dir = vec3(0, 0, 1);
vec3 col = texture(albedo, uv).rgb * material.albedo;
- float cos_theta_i = max(dot(nrm, light_dir), 0.0);
vec3 view_dir = normalize(material.camera_pos - p);
float met = texture(metal, uv).r * material.metalness;
-
vec3 ref = reflect(-view_dir, nrm);
- vec3 spec_col = texture(env_cube, ref, material.roughness * 8.0).rgb;
- vec3 amb_col = textureLod(env_cube, nrm, 8.0).rgb;
-
- vec3 diffuse =
- diffuse_brdf(uv) *
- (1.0 - met) *
- cos_theta_i;
- vec3 spec =
- mix(spec_col, spec_col * col, met) *
- specular_brdf(uv, ref, light_dir, view_dir, nrm) *
- cos_theta_i;
+ vec3 ref_col = texture(env_cube, ref, material.roughness * 8.0).rgb;
+ vec3 spec_col = mix(ref_col, ref_col * col, met);
+ vec3 amb_col = min(textureLod(env_cube, nrm, 8.0).rgb, 0.05);
vec3 ambient =
- min(amb_col, 0.05) *
+ amb_col *
texture(ao, uv).r * material.ao;
-
- colour = vec4(ambient + diffuse + spec, 1.0);
+
+ vec3 base_diffuse = diffuse_brdf(uv) * (1.0 - met);
+
+ vec3 light = 0.0.xxx;
+ for (i = 0; i < material.light_count; i++) {
+ Light l = lights[i];
+ vec3 light_dir = l.dir;
+ float cos_theta_i = max(dot(nrm, light_dir), 0.0);
+ vec3 diffuse = base_diffuse * cos_theta_i;
+ vec3 spec =
+ spec_col *
+ specular_brdf(uv, ref, light_dir, view_dir, nrm) *
+ cos_theta_i;
+ light += (diffuse + spec) * l.brightness;
+ }
+
+ colour = vec4(ambient + light, 1.0);
}
#endif
diff --git a/lighting.cpp b/lighting.cpp
new file mode 100644
index 0000000..d78ef6e
--- /dev/null
+++ b/lighting.cpp
@@ -0,0 +1,54 @@
+#include "lighting.hpp"
+#include "world.hpp"
+
+extern "C" {
+#include "memory.h"
+#include "plat.h"
+}
+
+/* needs to match surface shader */
+struct GPU_Light {
+ v3f dir;
+ float brightness;
+ v3f colour;
+ float pad;
+};
+
+void Lighting::init(Device* dev) {
+ lights.init(
+ dev,
+ "Light buffer",
+ max_lights * sizeof(GPU_Light),
+ Buffer_Flags::storage_buffer
+ );
+}
+
+void Lighting::destroy(Device* dev) {
+ lights.destroy(dev);
+}
+
+void Lighting::write_buf(void* ptr, World& w) {
+ GPU_Light* dst = (GPU_Light*)ptr;
+ int count = 0;
+ for (auto v : w.view<Sun_Light>()) {
+ GPU_Light gl;
+ Sun_Light& l = v.get<Sun_Light>();
+ if (count >= max_lights) {
+ print_war("Over light limit.\n");
+ return;
+ }
+ gl.brightness = l.brightness;
+ gl.colour = l.colour;
+ gl.dir = l.dir;
+ dst[count++] = gl;
+ }
+ light_count = count;
+}
+
+void Lighting::update(Device* dev, Context& ctx, World& w) {
+ light_count = 0;
+ write_buf(lights.map(dev), w);
+ lights.unmap(dev);
+ lights.update(ctx);
+}
+
diff --git a/lighting.hpp b/lighting.hpp
new file mode 100644
index 0000000..f7708a1
--- /dev/null
+++ b/lighting.hpp
@@ -0,0 +1,29 @@
+#ifndef lighting_hpp
+#define lighting_hpp
+
+#include "maths.hpp"
+#include "video.hpp"
+
+struct Arena;
+struct World;
+
+struct Lighting {
+ static constexpr int max_lights = 128;
+ Staged_Buffer lights;
+ int light_count;
+ void init(Device* dev);
+ void destroy(Device* dev);
+ void update(Device* dev, Context& ctx, World& w);
+ void write_buf(void* ptr, World& w);
+};
+
+struct Light {
+ v3f colour;
+ float brightness;
+};
+
+struct Sun_Light : Light {
+ v3f dir;
+};
+
+#endif
diff --git a/model.cpp b/model.cpp
index 7f2ac7f..e864ff5 100644
--- a/model.cpp
+++ b/model.cpp
@@ -1,4 +1,5 @@
#include "camera.hpp"
+#include "lighting.hpp"
#include "maths.hpp"
#include "model.hpp"
@@ -23,7 +24,8 @@ struct Mat_Cbuffer {
float metalness;
float roughness;
float ao;
- char pad2[8];
+ int light_count;
+ char pad2[4];
float camera_pos[3];
char pad[20];
};
@@ -131,10 +133,12 @@ Asset* Model_Loader::load(
mesh.mvp_binding = shader->descriptor_binding("c_mvp");
mesh.mvp_binding_depth = depth_shader->descriptor_binding("c_mvp");
mesh.mat_binding = shader->descriptor_binding("material");
+ mesh.light_binding = shader->descriptor_binding("lights");
mesh.env_cube_binding = shader->descriptor_binding("env_cube");
mesh.mesh_binding = shader->binding_index("mesh");
assert(mesh.mvp_binding >= 0);
assert(mesh.mat_binding >= 0);
+ assert(mesh.light_binding >= 0);
assert(mesh.mesh_binding >= 0);
assert(mesh.env_cube_binding >= 0);
pack_read(f, &vertex_size, 4);
@@ -296,6 +300,7 @@ void Model_Instance::update() {
void Model_Instance::update_cbuffers(
Device* dev,
+ const Lighting& lighting,
const Camera& cam
) {
int i, c = m->mesh_count;
@@ -322,6 +327,7 @@ void Model_Instance::update_cbuffers(
mat.metalness = sm.metalness;
mat.roughness = sm.roughness;
mat.ao = sm.ao;
+ mat.light_count = lighting.light_count;
mat.camera_pos[0] = cam.position.x;
mat.camera_pos[1] = cam.position.y;
mat.camera_pos[2] = cam.position.z;
@@ -334,6 +340,7 @@ void Model_Instance::render(
Device* dev,
Arena* a,
Render_Pass& pass,
+ const Lighting* lighting,
Texture_Id env_cubemap,
Sampler_Id sampler
) {
@@ -374,6 +381,7 @@ void Model_Instance::render(
} else {
pb.depth(true, false, Depth_Mode::equal);
pb.shader(mesh.shader);
+ pb.sbuffer(mesh.light_binding, lighting->lights.gpuonly);
mesh.material->use(pb, sampler, dev->get_shader(mesh.shader));
pb.cbuffer(
mesh.mat_binding,
@@ -436,12 +444,16 @@ void Model_Scene::uninstantiate(
count = last;
}
-void Model_Scene::update(const Camera& cam, Device* dev) {
+void Model_Scene::update(
+ const Camera& cam,
+ const Lighting& lighting,
+ Device* dev
+) {
int i;
Model_Instance* instance = instances;
for (i = 0; i < count; i++, instance++) {
instance->update();
- instance->update_cbuffers(dev, cam);
+ instance->update_cbuffers(dev, lighting, cam);
}
}
@@ -449,13 +461,14 @@ void Model_Scene::render(
Device* dev,
Arena* a,
Render_Pass& pass,
+ const Lighting* lighting,
Texture_Id env_cubemap,
Sampler_Id sampler
) {
int i;
Model_Instance* instance = instances;
for (i = 0; i < count; i++, instance++)
- instance->render(dev, a, pass, env_cubemap, sampler);
+ instance->render(dev, a, pass, lighting, env_cubemap, sampler);
}
void Model_Scene::destroy(Device* dev) {
diff --git a/model.hpp b/model.hpp
index de9e4d0..d1b9449 100644
--- a/model.hpp
+++ b/model.hpp
@@ -8,6 +8,7 @@
#include <tuple>
struct Camera;
+struct Lighting;
struct Material : public Asset {
float metalness, roughness, ao;
@@ -29,7 +30,7 @@ struct Material : public Asset {
struct Model;
struct Mesh {
int offset, vbo_offset, count;
- int parent, mesh_binding, mvp_binding, mat_binding;
+ int parent, mesh_binding, mvp_binding, mat_binding, light_binding;
int env_cube_binding;
int mvp_binding_depth;
bool world_dirty;
@@ -94,11 +95,16 @@ struct Model_Instance {
void init(Device* dev, Heap* h, Model* model);
void destroy(Device* dev, Heap* h);
void update();
- void update_cbuffers(Device* dev, const Camera& cam);
+ void update_cbuffers(
+ Device* dev,
+ const Lighting& lighting,
+ const Camera& cam
+ );
void render(
Device* dev,
Arena* a,
Render_Pass& pass,
+ const Lighting* lighting,
Texture_Id env_cubemap,
Sampler_Id sampler
);
@@ -115,11 +121,16 @@ struct Model_Scene {
void destroy(Device* dev);
void init(Arena* arena, int max_instances, Sampler_Id s);
- void update(const Camera& cam, Device* dev);
+ void update(
+ const Camera& cam,
+ const Lighting& lighting,
+ Device* dev
+ );
void render(
Device* dev,
Arena* a,
Render_Pass& pass,
+ const Lighting* lighting,
Texture_Id env_cubemap,
Sampler_Id sampler
);
diff --git a/scene.cpp b/scene.cpp
index 89f6f75..d162eda 100644
--- a/scene.cpp
+++ b/scene.cpp
@@ -5,6 +5,7 @@
void update_scene(
Model_Scene& ms,
Device* dev,
+ const Lighting& lighting,
const Camera& cam,
World& w
) {
@@ -13,7 +14,7 @@ void update_scene(
auto& m = v.get<C_Model>();
m.i->transform = t.mat;
}
- ms.update(cam, dev);
+ ms.update(cam, lighting, dev);
}
std::pair<Entity_Id, int> scene_pick(
diff --git a/scene.hpp b/scene.hpp
index 31f1cab..6706899 100644
--- a/scene.hpp
+++ b/scene.hpp
@@ -9,6 +9,7 @@
struct Arena;
struct Camera;
+struct Lighting;
struct Model_Instance;
struct Model_Scene;
struct World;
@@ -24,6 +25,7 @@ struct C_Model {
void update_scene(
Model_Scene& ms,
Device* dev,
+ const Lighting& lighting,
const Camera& cam,
World& w
);
@@ -37,3 +39,4 @@ std::pair<Entity_Id, int> scene_pick(
);
#endif
+
diff --git a/src/scene.blend b/src/scene.blend
new file mode 100644
index 0000000..6342856
--- /dev/null
+++ b/src/scene.blend
Binary files differ