diff --git a/grk/cw 6/shaders/shader_tex.frag b/grk/cw 6/shaders/shader_tex.frag index 4f8d13e..22d6d31 100644 --- a/grk/cw 6/shaders/shader_tex.frag +++ b/grk/cw 6/shaders/shader_tex.frag @@ -2,22 +2,37 @@ float AMBIENT = 0.1; +uniform vec3 color; uniform vec3 lightPos; +uniform vec3 lightColor; in vec3 vecNormal; in vec3 worldPos; in vec2 vtc; - +vec4 textureColor; out vec4 outColor; +vec3 outputColor; uniform sampler2D colorTexture; +vec3 toneMapping(vec3 color){ + float exposure = 0.06; + vec3 mapped = 1 - exp(-color*exposure); + return mapped; +} + + void main() { vec3 lightDir = normalize(lightPos - worldPos); vec3 normal = normalize(vecNormal); float diffuse = max(0, dot(normal, lightDir)); + textureColor = texture2D(colorTexture, vtc); + vec3 distance = lightColor/pow(length(lightPos - worldPos), 2.0) * 200; + outputColor = vec3(textureColor) * min(1, AMBIENT + diffuse)* distance; + //gamma correction + //outputColor = pow(outputColor, vec3(1.0/2.2)); - vec4 textureColor = texture2D(colorTexture, vtc); - outColor = vec4(vec3(textureColor) * min(1, AMBIENT + diffuse), 1.0); -} + outputColor = toneMapping(outputColor); + outColor = vec4(outputColor , 1.0); +} \ No newline at end of file diff --git a/grk/cw 6/src/Planet.hpp b/grk/cw 6/src/Planet.hpp index b41eaf9..18c03fe 100644 --- a/grk/cw 6/src/Planet.hpp +++ b/grk/cw 6/src/Planet.hpp @@ -67,7 +67,7 @@ float aspectRatio = 1.77f; //glm::vec3 shipPos = glm::vec3(-4.f, 0, 0); //glm::vec3 shipDir = glm::vec3(1.f, 0.f, 0.f); -//glm::vec3 lightColor = glm::vec3(0.9, 0.7, 0.8); +glm::vec3 lightColor = glm::vec3(50, 50, 50); /* glm::mat4 createShipMatrix() @@ -128,7 +128,7 @@ glm::mat4 createPerspectiveMatrix() return perspectiveMatrix; } - +/* void drawObjectTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint texture) { glUseProgram(programTex); Core::SetActiveTexture(texture, "colorTexture", programTex, 0); @@ -140,6 +140,19 @@ void drawObjectTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLui Core::DrawContext(context); glUseProgram(0); } +*/ +void drawObjectTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint texture) { + glUseProgram(programTex); + Core::SetActiveTexture(texture, "colorTexture", programTex, 0); + glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix(); + glm::mat4 transformation = viewProjectionMatrix * modelMatrix; + glUniformMatrix4fv(glGetUniformLocation(programTex, "transformation"), 1, GL_FALSE, (float*)&transformation); + glUniformMatrix4fv(glGetUniformLocation(programTex, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix); + glUniform3f(glGetUniformLocation(programTex, "lightPos"), sunPosition.x, sunPosition.y, sunPosition.z); + glUniform3f(glGetUniformLocation(programTex, "lightColor"), lightColor.x, lightColor.y, lightColor.z); + Core::DrawContext(context); + glUseProgram(0); +} void drawSun(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint texture) { glUseProgram(programSun); @@ -281,8 +294,8 @@ void processInput(GLFWwindow* window) { glm::vec3 cameraSide = glm::normalize(glm::cross(cameraDir, glm::vec3(0.f, 1.f, 0.f))); - float angleSpeed = 0.02f; - float moveSpeed = 0.04f; + float angleSpeed = 0.002f; + float moveSpeed = 0.004f; if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) { glfwSetWindowShouldClose(window, true); diff --git a/grk/cw 6/src/main.cpp b/grk/cw 6/src/main.cpp index 1ad5fe6..1bc2357 100644 --- a/grk/cw 6/src/main.cpp +++ b/grk/cw 6/src/main.cpp @@ -3,7 +3,7 @@ //#include "imgui.h" //#include "imgui_impl_glfw.h" //#include "imgui_impl_opengl3.h" -#include +//#include //#define GL_SILENCE_DEPRECATION //#if defined(IMGUI_IMPL_OPENGL_ES2) //#include