Have the original lighting system back and a little lightbulb model to show where the light is.
This commit is contained in:
parent
3231f747a9
commit
a29494325b
143 changed files with 16360 additions and 9 deletions
104
33-shadow-mapping/src/scene.hpp
Normal file
104
33-shadow-mapping/src/scene.hpp
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
#pragma once
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include "shader.hpp"
|
||||
#include "model.hpp"
|
||||
#include "shader.hpp"
|
||||
#include "model.hpp"
|
||||
#include "camera.hpp"
|
||||
#include "components.hpp"
|
||||
#include "framebuffer.hpp"
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include "config.hpp"
|
||||
#include "text.hpp"
|
||||
|
||||
struct Thing {
|
||||
std::string name;
|
||||
Model& model;
|
||||
Material& material;
|
||||
components::Position position;
|
||||
components::Rotation rotation;
|
||||
float scale;
|
||||
float distance = 0;
|
||||
};
|
||||
|
||||
struct Scene {
|
||||
Shader shader;
|
||||
Shader reflect_shader;
|
||||
Shader skybox_shader;
|
||||
std::vector<std::string> skybox_faces;
|
||||
Screen screen;
|
||||
FrameBuffer framebuffer;
|
||||
|
||||
std::unordered_map<std::string, components::Material> materials;
|
||||
Camera camera;
|
||||
components::Lighting light;
|
||||
std::unordered_map<std::string, Model> models;
|
||||
std::vector<Thing> things;
|
||||
float deltaTime = 0.0f;
|
||||
float lastFrame = 0.0f;
|
||||
unsigned int skyboxVAO = UINT_MAX;
|
||||
unsigned int skyboxVBO = UINT_MAX;
|
||||
unsigned int skybox_texture_id = UINT_MAX;
|
||||
bool reflect_on = false;
|
||||
|
||||
Scene(components::Scene& config):
|
||||
shader{config.shader},
|
||||
reflect_shader{config.reflect_shader},
|
||||
skybox_shader{config.skybox_shader},
|
||||
skybox_faces{config.skybox_faces},
|
||||
screen{.shader={config.screen_shader}},
|
||||
materials{config.materials},
|
||||
camera{
|
||||
.position=config.camera.position,
|
||||
.front=config.camera.front,
|
||||
.up=config.camera.up,
|
||||
.direction=config.camera.direction,
|
||||
.movement_speed=config.camera.movement_speed,
|
||||
},
|
||||
light{config.light}
|
||||
{
|
||||
for(auto& [name, model] : config.models) {
|
||||
models.try_emplace(name, model.directory, model.model_path);
|
||||
}
|
||||
|
||||
for(auto& thing : config.things) {
|
||||
things.emplace_back(
|
||||
thing.model,
|
||||
models.at(thing.model),
|
||||
materials.at(thing.material),
|
||||
thing.position,
|
||||
thing.rotation,
|
||||
thing.scale);
|
||||
}
|
||||
|
||||
glGenVertexArrays(1, &skyboxVAO);
|
||||
glGenBuffers(1, &skyboxVBO);
|
||||
glGenTextures(1, &skybox_texture_id);
|
||||
|
||||
shader.use();
|
||||
shader.setInt("texture1", 0);
|
||||
shader.apply_lighting(light);
|
||||
|
||||
skybox_shader.use();
|
||||
skybox_shader.setInt("skybox", 0);
|
||||
|
||||
framebuffer.init();
|
||||
screen.init();
|
||||
init_skybox();
|
||||
}
|
||||
|
||||
void update();
|
||||
void draw_thing(Shader& with_shader, Thing& thing);
|
||||
void render(GLFWwindow* window);
|
||||
void cleanup();
|
||||
void init_skybox();
|
||||
void load_skybox_textures();
|
||||
void render_skybox(const glm::mat4& projection);
|
||||
void spawn(const std::string& name);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue