diff --git a/imgui.ini b/imgui.ini index afa3344..6bd5573 100644 --- a/imgui.ini +++ b/imgui.ini @@ -4,7 +4,7 @@ Size=400,400 Collapsed=0 [Window][Object Modifier] -Pos=182,52 +Pos=59,22 Size=925,127 Collapsed=0 diff --git a/res/shaders/light.frag b/res/shaders/light.frag index 3f731aa..ecb438c 100644 --- a/res/shaders/light.frag +++ b/res/shaders/light.frag @@ -2,6 +2,8 @@ layout(location = 0) out vec4 f_color; +uniform vec3 v_lightColor; + void main() { - f_color = vec4(1.0f); + f_color = vec4(v_lightColor, 1.0f); } diff --git a/src/Controller.cpp b/src/Controller.cpp index e25d398..dbb7a7a 100644 --- a/src/Controller.cpp +++ b/src/Controller.cpp @@ -97,7 +97,7 @@ void Controller::run() { lightSource.translate(glm::vec3(-5.0f, 1.0f, 0.0f)); lightSource.setScale(0.2f); //plant.setScale(5.0f); - dragon.setScale(0.2f); + //dragon.setScale(0.2f); World world(&shaderProgram); world.addEntity(dragon); @@ -116,7 +116,12 @@ void Controller::run() { float radius = 4.0; glm::vec3 newPos = glm::vec3(cos(glfwGetTime()*0.2), 0.f, sin(glfwGetTime()*0.2)) * radius; world.getEntities()->operator[](1).setPosition(newPos); - world.updatePointLight(0, true, world.getEntities()->operator[](1).getPosition(), glm::vec3(1.0f)); + static glm::vec3 lightColor = glm::vec3(1.f); + world.updatePointLight(0, true, world.getEntities()->operator[](1).getPosition(), lightColor); + world.updateDirectionalLight(true, glm::vec3(1.0f), lightColor); + lightProgram.bind(); + lightProgram.setUniform("v_lightColor", lightColor); + lightProgram.unbind(); // Render and buffer swap glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -127,7 +132,7 @@ void Controller::run() { world.draw(camera->getViewProj(), camera->getPosition()); #ifdef _DEBUG - renderImGui(world.getEntities()); + renderImGui(world.getEntities(), &lightColor); #endif glfwSwapBuffers(gameWindow->getGLFWwindow()); @@ -181,7 +186,7 @@ void Controller::updateWindowSize() { } #ifdef _DEBUG -void Controller::renderImGui(std::vector *entites) { +void Controller::renderImGui(std::vector *entites, glm::vec3 *lightColor) { ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplGlfw_NewFrame(); ImGui::NewFrame(); @@ -194,14 +199,19 @@ void Controller::renderImGui(std::vector *entites) { ImGui::SliderFloat("Rotation", &rotation, 0, 2 * M_PI); static float translation[] = {0.0f, 0.0f}; ImGui::SliderFloat2("Position", translation, -4.0, 4.0); - static float color[4] = {1.0f, 1.0f, 1.0f, 1.0f}; + static float scale = 0.2f; + ImGui::SliderFloat("Scale", &scale, 0.02, 2.0); entites->operator[](0).setPosition(glm::vec3(translation[0], 0.0f, translation[1])); entites->operator[](0).setRotation(glm::vec3(0.f,1.0f,0.f) * rotation); - //entity->setRotation() + entites->operator[](0).setScale(scale); // color picker + static float color[4] = {1.0f, 1.0f, 1.0f, 1.0f}; ImGui::ColorEdit3("Color", color); + lightColor->x = color[0]; + lightColor->y = color[1]; + lightColor->z = color[2]; ImGui::End(); diff --git a/src/Controller.h b/src/Controller.h index 833ad2c..8755b37 100644 --- a/src/Controller.h +++ b/src/Controller.h @@ -27,7 +27,7 @@ private: void updateWindowSize(); - void renderImGui(std::vector *entites); + void renderImGui(std::vector *entites, glm::vec3 *lightColor); Window *gameWindow; EventHandler *gameEventHandler; diff --git a/src/Entity.cpp b/src/Entity.cpp index 81452fe..fe0bb8f 100644 --- a/src/Entity.cpp +++ b/src/Entity.cpp @@ -16,7 +16,6 @@ void Entity::draw(glm::mat4 viewProjMatrix, glm::vec3 viewPosition) { glm::mat4 modelViewProj = viewProjMatrix * modelMatrix; shaderProgram->setUniform("u_modelViewProjMatrix", modelViewProj); - shaderProgram->setUniform("u_modelMatrix", modelMatrix); glm::mat3 normalMatrix = glm::mat3(modelMatrix); diff --git a/src/Light.cpp b/src/Light.cpp index 8c745ef..3b5339c 100644 --- a/src/Light.cpp +++ b/src/Light.cpp @@ -11,6 +11,11 @@ PointLight::PointLight(ShaderProgram *shaderProgram) void PointLight::update() { + // Only temp + glm::vec3 diffuseColor = lightColor * glm::vec3(1.0f); + glm::vec3 ambientColor = diffuseColor * glm::vec3(0.1f); + glm::vec3 specularColor = lightColor * glm::vec3(1.0f); + shaderProgram->bind(); shaderProgram->setUniform((_getStructMemberName() + "isActive").c_str(), isActive); @@ -41,6 +46,11 @@ DirectionalLight::DirectionalLight(ShaderProgram *shaderProgram) void DirectionalLight::update() { + // Only temp + glm::vec3 diffuseColor = lightColor * glm::vec3(1.0f); + glm::vec3 ambientColor = diffuseColor * glm::vec3(0.1f); + glm::vec3 specularColor = lightColor * glm::vec3(1.0f); + shaderProgram->bind(); shaderProgram->setUniform("u_directionalLight.isActive", isActive); diff --git a/src/Light.h b/src/Light.h index f633c8c..31558b2 100644 --- a/src/Light.h +++ b/src/Light.h @@ -36,10 +36,10 @@ protected: bool isActive = false; // Color - glm::vec3 lightColor = glm::vec3(1.0f, 1.0f, 1.0f); - glm::vec3 diffuseColor = lightColor * glm::vec3(1.0f); - glm::vec3 ambientColor = diffuseColor * glm::vec3(0.1f); - glm::vec3 specularColor = glm::vec3(1.0f); + glm::vec3 lightColor; + glm::vec3 diffuseColor; + glm::vec3 ambientColor; + glm::vec3 specularColor; }; diff --git a/src/Window.cpp b/src/Window.cpp index 8d4aa3d..e5a95d9 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -9,7 +9,7 @@ Window::Window() { width = INIT_WINDOW_WIDTH; height = INIT_WINDOW_HEIGHT; - window = glfwCreateWindow(width, height, "OpenGL", NULL, NULL); + window = glfwCreateWindow(width, height, "Fall-Fever", NULL, NULL); if(!window) { std::cout << "Failed to create window" << std::endl; } diff --git a/src/World.cpp b/src/World.cpp index 8c3053e..0b7becd 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -48,6 +48,13 @@ void World::updatePointLight(unsigned int lightId, bool active, glm::vec3 positi pointLights[lightId].setColor(color); } +void World::updateDirectionalLight(bool active, glm::vec3 direction, glm::vec3 color) { + directionalLight.setActive(active); + directionalLight.setDirection(glm::vec3(-0.2f, -1.0f, -0.3f)); + //directionalLight.setDirection(direction); + directionalLight.setColor(color); +} + void World::draw(glm::mat4 viewProjMatrix, glm::vec3 viewPosition) { for(auto it = entities.begin(); it != entities.end(); it++) { diff --git a/src/World.h b/src/World.h index 4bd6e0f..811365f 100644 --- a/src/World.h +++ b/src/World.h @@ -17,6 +17,7 @@ public: void removeEntity(uint32_t id); void updatePointLight(unsigned int lightId, bool active, glm::vec3 position, glm::vec3 color); + void updateDirectionalLight(bool active, glm::vec3 direction, glm::vec3 color); std::vector * getEntities() { return &entities; }