tonemapping

This commit is contained in:
K4RP4T 2024-01-15 16:36:57 +01:00
parent ecb3a1884b
commit c712f95137
3 changed files with 37 additions and 9 deletions

View File

@ -2,22 +2,37 @@
float AMBIENT = 0.1; float AMBIENT = 0.1;
uniform vec3 color;
uniform vec3 lightPos; uniform vec3 lightPos;
uniform vec3 lightColor;
in vec3 vecNormal; in vec3 vecNormal;
in vec3 worldPos; in vec3 worldPos;
in vec2 vtc; in vec2 vtc;
vec4 textureColor;
out vec4 outColor; out vec4 outColor;
vec3 outputColor;
uniform sampler2D colorTexture; uniform sampler2D colorTexture;
vec3 toneMapping(vec3 color){
float exposure = 0.06;
vec3 mapped = 1 - exp(-color*exposure);
return mapped;
}
void main() void main()
{ {
vec3 lightDir = normalize(lightPos - worldPos); vec3 lightDir = normalize(lightPos - worldPos);
vec3 normal = normalize(vecNormal); vec3 normal = normalize(vecNormal);
float diffuse = max(0, dot(normal, lightDir)); 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); outputColor = toneMapping(outputColor);
outColor = vec4(vec3(textureColor) * min(1, AMBIENT + diffuse), 1.0); outColor = vec4(outputColor , 1.0);
} }

View File

@ -67,7 +67,7 @@ float aspectRatio = 1.77f;
//glm::vec3 shipPos = glm::vec3(-4.f, 0, 0); //glm::vec3 shipPos = glm::vec3(-4.f, 0, 0);
//glm::vec3 shipDir = glm::vec3(1.f, 0.f, 0.f); //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() glm::mat4 createShipMatrix()
@ -128,7 +128,7 @@ glm::mat4 createPerspectiveMatrix()
return perspectiveMatrix; return perspectiveMatrix;
} }
/*
void drawObjectTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint texture) { void drawObjectTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint texture) {
glUseProgram(programTex); glUseProgram(programTex);
Core::SetActiveTexture(texture, "colorTexture", programTex, 0); Core::SetActiveTexture(texture, "colorTexture", programTex, 0);
@ -140,6 +140,19 @@ void drawObjectTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLui
Core::DrawContext(context); Core::DrawContext(context);
glUseProgram(0); 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) { void drawSun(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint texture) {
glUseProgram(programSun); 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))); glm::vec3 cameraSide = glm::normalize(glm::cross(cameraDir, glm::vec3(0.f, 1.f, 0.f)));
float angleSpeed = 0.02f; float angleSpeed = 0.002f;
float moveSpeed = 0.04f; float moveSpeed = 0.004f;
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) { if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
glfwSetWindowShouldClose(window, true); glfwSetWindowShouldClose(window, true);

View File

@ -3,7 +3,7 @@
//#include "imgui.h" //#include "imgui.h"
//#include "imgui_impl_glfw.h" //#include "imgui_impl_glfw.h"
//#include "imgui_impl_opengl3.h" //#include "imgui_impl_opengl3.h"
#include <stdio.h> //#include <stdio.h>
//#define GL_SILENCE_DEPRECATION //#define GL_SILENCE_DEPRECATION
//#if defined(IMGUI_IMPL_OPENGL_ES2) //#if defined(IMGUI_IMPL_OPENGL_ES2)
//#include <GLES2/gl2.h> //#include <GLES2/gl2.h>