Compare commits

...

2 commits

Author SHA1 Message Date
Zed A. Shaw
c32e7bd00d 19/20 is done so setup for day 21. 2026-08-30 13:51:01 -04:00
Zed A. Shaw
f51df89054 Implement the red windows. 2026-08-30 13:17:35 -04:00
213 changed files with 15363 additions and 36 deletions

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

View file

Before

Width:  |  Height:  |  Size: 457 KiB

After

Width:  |  Height:  |  Size: 457 KiB

Before After
Before After

File diff suppressed because one or more lines are too long

Binary file not shown.

View file

Before

Width:  |  Height:  |  Size: 195 KiB

After

Width:  |  Height:  |  Size: 195 KiB

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

File diff suppressed because one or more lines are too long

Binary file not shown.

View file

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB

Before After
Before After

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.

View file

@ -16,7 +16,7 @@
"specularMap": 0 "specularMap": 0
}, },
"shiny": { "shiny": {
"ambient": [0.5, 0.25, 0.31], "ambient": [0.5, 0.5, 0.5],
"shininess": 10000.0, "shininess": 10000.0,
"diffuseMap": 0, "diffuseMap": 0,
"specularMap": 0 "specularMap": 0
@ -34,6 +34,10 @@
"grass": { "grass": {
"directory": "assets", "directory": "assets",
"model_path": "grass.glb" "model_path": "grass.glb"
},
"window": {
"directory": "assets",
"model_path": "window.glb"
} }
}, },
"things": [ "things": [
@ -41,9 +45,9 @@
"rotation": {"angle": 0.0, "axes": [1.0, 1.0, 1.0]}, "rotation": {"angle": 0.0, "axes": [1.0, 1.0, 1.0]},
"scale": 1.0, "scale": 1.0,
"material": "default"}, "material": "default"},
{"model": "marble_cube", "position": [2.0, 0.0, 0.0], {"model": "marble_cube", "position": [1.5, 0.0, 1.0],
"rotation": {"angle": 0.0, "axes": [1.0, 1.0, 1.0]}, "rotation": {"angle": 0.0, "axes": [1.0, 1.0, 1.0]},
"scale": 1.0, "scale": 2.0,
"material": "default"}, "material": "default"},
{"model": "metal_floor", "position": [0.0, 0.0, 0.0], {"model": "metal_floor", "position": [0.0, 0.0, 0.0],
"rotation": {"angle": 0.0, "axes": [1.0, 1.0, 1.0]}, "rotation": {"angle": 0.0, "axes": [1.0, 1.0, 1.0]},
@ -52,7 +56,15 @@
{"model": "grass", "position": [0.5, 0.13, 0.0], {"model": "grass", "position": [0.5, 0.13, 0.0],
"rotation": {"angle": 90.0, "axes": [1.0,0.0,0.0]}, "rotation": {"angle": 90.0, "axes": [1.0,0.0,0.0]},
"scale": 1.0, "scale": 1.0,
"material": "default"} "material": "default"},
{"model": "window", "position": [1.75, 0.25, 0.25],
"rotation": {"angle": 90.0, "axes": [1.0,0.0,0.0]},
"scale": 1.0,
"material": "shiny"},
{"model": "window", "position": [1.5, 0.25, 0.0],
"rotation": {"angle": 90.0, "axes": [1.0,0.0,0.0]},
"scale": 1.0,
"material": "shiny"}
], ],
"camera": { "camera": {
"position": [0.0, 0.1, 3.0], "position": [0.0, 0.1, 3.0],
@ -73,7 +85,8 @@
"linear": 0.0, "linear": 0.0,
"quadratic": 0.0, "quadratic": 0.0,
"cut_off": 0.0, "cut_off": 0.0,
"outer_cut_off": 0.0 "outer_cut_off": 0.0,
"on": true
} }
], ],
"positioned": [ "positioned": [
@ -87,7 +100,8 @@
"linear": 0.09, "linear": 0.09,
"quadratic": 0.032, "quadratic": 0.032,
"cut_off": 12.5, "cut_off": 12.5,
"outer_cut_off": 17.5 "outer_cut_off": 17.5,
"on": true
} }
], ],
"spot": [ "spot": [
@ -102,7 +116,8 @@
"linear": 0.09, "linear": 0.09,
"quadratic": 0.032, "quadratic": 0.032,
"cut_off": 12.5, "cut_off": 12.5,
"outer_cut_off": 17.5 "outer_cut_off": 17.5,
"on": true
} }
} }
} }

View file

Before

Width:  |  Height:  |  Size: 58 KiB

After

Width:  |  Height:  |  Size: 58 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 181 KiB

After

Width:  |  Height:  |  Size: 181 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 457 KiB

After

Width:  |  Height:  |  Size: 457 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 141 KiB

After

Width:  |  Height:  |  Size: 141 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

Before After
Before After

View file

@ -2,7 +2,7 @@
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <vector> #include <vector>
#include <map> #include <unordered_map>
#include "json.hpp" #include "json.hpp"
const unsigned int SCR_WIDTH = 800; const unsigned int SCR_WIDTH = 800;
@ -34,6 +34,7 @@ namespace components {
float quadratic=0.0f; float quadratic=0.0f;
float cut_off=0.0f; float cut_off=0.0f;
float outer_cut_off=0.0f; float outer_cut_off=0.0f;
bool on=true;
void adjust(float amount) { void adjust(float amount) {
ambient += amount; ambient += amount;
@ -46,7 +47,7 @@ namespace components {
position, direction, position, direction,
ambient, diffuse, specular, ambient, diffuse, specular,
constant, linear, quadratic, constant, linear, quadratic,
cut_off, outer_cut_off); cut_off, outer_cut_off, on);
struct Lighting { struct Lighting {
std::vector<Light> directional; std::vector<Light> directional;
@ -102,8 +103,8 @@ namespace components {
struct Scene { struct Scene {
components::Shader shader; components::Shader shader;
components::Shader light_shader; components::Shader light_shader;
std::map<std::string, Material> materials; std::unordered_map<std::string, Material> materials;
std::map<std::string, Model> models; std::unordered_map<std::string, Model> models;
std::vector<Thing> things; std::vector<Thing> things;
Camera camera; Camera camera;
Lighting light; Lighting light;

View file

@ -2,6 +2,7 @@
#include <stb_image.h> #include <stb_image.h>
#include "scene.hpp" #include "scene.hpp"
#include "utils.hpp" #include "utils.hpp"
void framebuffer_size_callback(GLFWwindow *window, int width, int height); void framebuffer_size_callback(GLFWwindow *window, int width, int height);
void init_glfw() { void init_glfw() {
@ -71,6 +72,12 @@ void process_input(GLFWwindow *window, Scene& scene) {
} }
if(glfwGetKey(window, GLFW_KEY_L) == GLFW_PRESS) { if(glfwGetKey(window, GLFW_KEY_L) == GLFW_PRESS) {
scene.light.camera.on = !scene.light.camera.on;
scene.shader.apply_lighting(scene.light);
}
if(glfwGetKey(window, GLFW_KEY_O) == GLFW_PRESS) {
for(auto& light : scene.light.directional) { for(auto& light : scene.light.directional) {
light.adjust(-0.01f); light.adjust(-0.01f);
} }

View file

@ -7,6 +7,15 @@ void Scene::update() {
deltaTime = currentFrame - lastFrame; deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame; lastFrame = currentFrame;
// for now just detect the camera moved and do spotlight update
if(camera.dirty) {
light.camera.position = camera.position;
light.camera.direction = camera.front;
// just update the camera's light
shader.apply_spot_light(light.camera, 0);
camera.dirty = false;
}
camera.update(deltaTime); camera.update(deltaTime);
} }
@ -38,15 +47,6 @@ void Scene::render(GLFWwindow* window) {
shader.setMat4("view", view); shader.setMat4("view", view);
shader.setMat4("projection", projection); shader.setMat4("projection", projection);
// for now just detect the camera moved and do spotlight update
if(camera.dirty) {
light.camera.position = camera.position;
light.camera.direction = camera.front;
// just update the camera's light
shader.apply_spot_light(light.camera, 0);
camera.dirty = false;
}
for(auto& thing : things) { for(auto& thing : things) {
draw_thing(shader, thing); draw_thing(shader, thing);
} }

View file

@ -12,6 +12,7 @@
#include "camera.hpp" #include "camera.hpp"
#include "components.hpp" #include "components.hpp"
#include <vector> #include <vector>
#include <unordered_map>
struct Thing { struct Thing {
std::string name; std::string name;
@ -20,16 +21,17 @@ struct Thing {
components::Position position; components::Position position;
components::Rotation rotation; components::Rotation rotation;
float scale; float scale;
float distance = 0;
}; };
struct Scene { struct Scene {
Shader shader; Shader shader;
Shader light_shader; Shader light_shader;
std::map<std::string, components::Material> materials; std::unordered_map<std::string, components::Material> materials;
Camera camera; Camera camera;
components::Lighting light; components::Lighting light;
std::map<std::string, Model> models; std::unordered_map<std::string, Model> models;
std::vector<Thing> things; std::vector<Thing> things;
float deltaTime = 0.0f; float deltaTime = 0.0f;

View file

@ -134,9 +134,6 @@ void Shader::apply_lighting(const Lighting& lighting) {
setInt("pointLightCount", lighting.positioned.size()); setInt("pointLightCount", lighting.positioned.size());
setInt("dirLightCount", lighting.directional.size()); setInt("dirLightCount", lighting.directional.size());
// need +1 for the camera spot light
setInt("spotLightCount", lighting.spot.size() + 1);
for(size_t i = 0; i < lighting.directional.size(); i++) { for(size_t i = 0; i < lighting.directional.size(); i++) {
apply_dir_light(lighting.directional[i], i); apply_dir_light(lighting.directional[i], i);
} }
@ -145,13 +142,25 @@ void Shader::apply_lighting(const Lighting& lighting) {
apply_point_light(lighting.positioned[i], i); apply_point_light(lighting.positioned[i], i);
} }
// set the first spotlight to the camera light // set the first spotlight to the camera light if given
apply_spot_light(lighting.camera, 0); size_t i = 0;
for(size_t i = 0; i < lighting.spot.size(); i++) { // camera is optional, so only add if used
// need to be off by one because the camera is a spot light if(lighting.camera.on) {
apply_spot_light(lighting.spot[i], i+1); apply_spot_light(lighting.camera, 0);
i++;
} }
// gross but that's fine for now
for(; i < lighting.spot.size(); i++) {
// need to be off by one because the camera is a spot light
if(lighting.spot[i].on) {
apply_spot_light(lighting.spot[i], i+1);
}
}
// need +1 for the camera spot light
setInt("spotLightCount", (int)i);
} }

View file

@ -17,7 +17,8 @@
"linear": 0.0, "linear": 0.0,
"quadratic": 0.0, "quadratic": 0.0,
"cut_off": 0.0, "cut_off": 0.0,
"outer_cut_off": 0.0 "outer_cut_off": 0.0,
"on": true
} }
], ],
"positioned": [ "positioned": [
@ -31,7 +32,8 @@
"linear": 0.09, "linear": 0.09,
"quadratic": 0.032, "quadratic": 0.032,
"cut_off": 12.5, "cut_off": 12.5,
"outer_cut_off": 17.5 "outer_cut_off": 17.5,
"on": true
} }
], ],
"spot": [ "spot": [
@ -47,7 +49,8 @@
"linear": 0.09, "linear": 0.09,
"quadratic": 0.032, "quadratic": 0.032,
"cut_off": 12.5, "cut_off": 12.5,
"outer_cut_off": 17.5 "outer_cut_off": 17.5,
"on": true
} }
}, },

Some files were not shown because too many files have changed in this diff Show more