Now have multiple lights.
This commit is contained in:
parent
a1d2c7768d
commit
1b7066757a
63 changed files with 13886 additions and 17 deletions
|
|
@ -24,19 +24,6 @@ struct Config {
|
|||
Shader shader;
|
||||
Shader lightShader;
|
||||
|
||||
Light light{
|
||||
.position={1.2f, 1.0f, 2.0f},
|
||||
.direction={-0.2f, -1.0f, -0.3f},
|
||||
.ambient={0.2f, 0.2f, 0.2f},
|
||||
.diffuse={0.8f, 0.8f, 0.8f},
|
||||
.specular={1.0f, 1.0f, 1.0f},
|
||||
.constant=1.0f,
|
||||
.linear=0.09f,
|
||||
.quadratic=0.032f,
|
||||
.cutOff=12.5f,
|
||||
.outerCutOff=17.5f,
|
||||
};
|
||||
|
||||
glm::vec3 cubePos{2.0f, 0.0f, 0.0f};
|
||||
Camera camera{.movementSpeed=2.0f};
|
||||
|
||||
|
|
@ -243,15 +230,15 @@ void draw_cube(size_t pos, Config& config, glm::mat4& projection, glm::mat4& vie
|
|||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||
}
|
||||
|
||||
void draw_light(Config& config, glm::mat4& projection, glm::mat4& view) {
|
||||
void draw_light(Config& config, Light& light, glm::mat4& projection, glm::mat4& view) {
|
||||
config.lightShader.use();
|
||||
|
||||
config.lightShader.applyLight(config.light);
|
||||
config.lightShader.setVec3(light.diffuse);
|
||||
config.lightShader.setMat4("projection", projection);
|
||||
config.lightShader.setMat4("view", view);
|
||||
|
||||
glm::mat4 model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, config.light.position);
|
||||
model = glm::translate(model, light.position);
|
||||
model = glm::scale(model, glm::vec3(0.2f));
|
||||
config.lightShader.setMat4("model", model);
|
||||
|
||||
|
|
@ -276,7 +263,9 @@ void render(GLFWwindow* window, Config& config) {
|
|||
// fov, aspect, near plane, far plane
|
||||
projection = glm::perspective(glm::radians(config.camera.fov), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
|
||||
|
||||
// draw_light(config, projection, view);
|
||||
for(auto& light : config.light.positioned) {
|
||||
draw_light(config, light, projection, view);
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < CUBE_COUNT; i++) {
|
||||
draw_cube(i, config, projection, view);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue