Implement the red windows.

This commit is contained in:
Zed A. Shaw 2026-08-30 13:17:35 -04:00
parent 11b7f4a3ed
commit f51df89054
18 changed files with 74 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

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 508 KiB

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.

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

View file

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

View file

@ -2,6 +2,7 @@
#include <stb_image.h>
#include "scene.hpp"
#include "utils.hpp"
void framebuffer_size_callback(GLFWwindow *window, int width, int height);
void init_glfw() {
@ -71,6 +72,12 @@ void process_input(GLFWwindow *window, Scene& scene) {
}
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) {
light.adjust(-0.01f);
}

View file

@ -7,6 +7,15 @@ void Scene::update() {
deltaTime = currentFrame - lastFrame;
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);
}
@ -38,15 +47,6 @@ void Scene::render(GLFWwindow* window) {
shader.setMat4("view", view);
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) {
draw_thing(shader, thing);
}

View file

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

View file

@ -134,9 +134,6 @@ void Shader::apply_lighting(const Lighting& lighting) {
setInt("pointLightCount", lighting.positioned.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++) {
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);
}
// set the first spotlight to the camera light
apply_spot_light(lighting.camera, 0);
// set the first spotlight to the camera light if given
size_t i = 0;
for(size_t i = 0; i < lighting.spot.size(); i++) {
// need to be off by one because the camera is a spot light
apply_spot_light(lighting.spot[i], i+1);
// camera is optional, so only add if used
if(lighting.camera.on) {
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,
"quadratic": 0.0,
"cut_off": 0.0,
"outer_cut_off": 0.0
"outer_cut_off": 0.0,
"on": true
}
],
"positioned": [
@ -31,7 +32,8 @@
"linear": 0.09,
"quadratic": 0.032,
"cut_off": 12.5,
"outer_cut_off": 17.5
"outer_cut_off": 17.5,
"on": true
}
],
"spot": [
@ -47,7 +49,8 @@
"linear": 0.09,
"quadratic": 0.032,
"cut_off": 12.5,
"outer_cut_off": 17.5
"outer_cut_off": 17.5,
"on": true
}
},