init hdr buffer

This commit is contained in:
Natalia Nowakowska 2024-01-17 22:01:14 +01:00
parent 1a1441e98a
commit 92af34a58d
2 changed files with 18 additions and 81 deletions

View File

@ -3,42 +3,21 @@
float AMBIENT = 0.1;
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);
<<<<<<<< HEAD:grk/cw 6/shaders/shader_sun.frag
//float diffuse = max(0, dot(normal, lightDir));
vec4 textureColor = texture2D(colorTexture, vtc);
outColor = vec4(vec3(textureColor) * 1.5, 1.0);
========
float diffuse = max(0, dot(normal, lightDir));
textureColor = texture2D(colorTexture, vtc);
vec3 distance = lightColor/(lightPos - worldPos)*(lightPos - worldPos);
outputColor = vec3(textureColor) * min(1, AMBIENT + diffuse)* distance;
//gamma correction
//outputColor = pow(outputColor, vec3(1.0/2.2));
outputColor = toneMapping(outputColor);
outColor = vec4(outputColor , 1.0);
>>>>>>>> hdr:grk/cw 6/shaders/shader_5_1_tex.frag
}

View File

@ -50,7 +50,6 @@ GLuint program;
GLuint programSun;
GLuint programDepth;
GLuint programTex;
GLuint programTest;
Core::Shader_Loader shaderLoader;
@ -66,7 +65,14 @@ GLuint VAO, VBO;
float aspectRatio = 1.77f;
float aspectRatio = 1.f;
unsigned int hdrFBO;
unsigned int colorBuffers[2];
unsigned int depthMap;
unsigned int depthMapFBO;
int HDR_WIDTH = 1024;
int HDR_HEIGHT = 1024;
glm::vec3 lightColor = glm::vec3(50, 50, 50);
@ -170,29 +176,6 @@ void initDepthMap() {
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
void renderShadowapSun(GLFWwindow* window) {
int width = 500, height = 500;
glfwGetWindowSize(window, &width, &height);
float time = glfwGetTime();
glViewport(0, 0, HDR_WIDTH, HDR_HEIGHT);
//uzupelnij o renderowanie glebokosci do tekstury
glUseProgram(programDepth);
//ustawianie przestrzeni rysowania
glViewport(0, 0, HDR_WIDTH, HDR_HEIGHT);
//bindowanie FBO
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
//czyszczenie mapy głębokości
glClear(GL_DEPTH_BUFFER_BIT);
//ustawianie programu
glUseProgram(programDepth);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
//glViewport(0, 0, WIDTH, HEIGHT);
}
void drawObjectTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint texture) {
glUseProgram(programTex);
@ -231,18 +214,6 @@ void drawObjectColor(Core::RenderContext& context, glm::mat4 modelMatrix, glm::v
glUseProgram(0);
}
void drawObjectDepth(Core::RenderContext& context, glm::mat4 viewProjection, glm::mat4 modelMatrix) {
glUseProgram(programDepth);
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
glm::mat4 transformation = viewProjectionMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(programDepth, "viewProjectionMatrix"), 1, GL_FALSE, (float*)&viewProjectionMatrix);
glUniformMatrix4fv(glGetUniformLocation(programDepth, "modelMatrix"), 1, GL_FALSE, (float*)&modelMatrix);
Core::DrawContext(context);
glUseProgram(0);
}
void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec3 color, float roughness, float metallic) {
glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix();
@ -272,7 +243,7 @@ void drawObjectPBR(Core::RenderContext& context, glm::mat4 modelMatrix, glm::vec
Core::DrawContext(context);
}
*/
void renderScene(GLFWwindow* window)
{
@ -302,9 +273,9 @@ void renderScene(GLFWwindow* window)
glm::mat4 marsRotate = glm::rotate(time * 1.8f, glm::vec3(0, 1, 0));
glm::mat4 marsTranslate = glm::translate(glm::vec3(0, 0, -9));
glm::mat4 shipScale = glm::scale(glm::vec3(0.3));
glm::mat4 shipRotate = createShipMatrix();
glm::mat4 shipTranslate = glm::translate(shipPos);
//glm::mat4 shipScale = glm::scale(glm::vec3(0.3));
//glm::mat4 shipRotate = createShipMatrix();
//glm::mat4 shipTranslate = glm::translate(shipPos);
//glUseProgram(program);
//glUniform3f(glGetUniformLocation(program, "lightDir"), 1.0, -1.0, 0.0);
@ -313,6 +284,7 @@ void renderScene(GLFWwindow* window)
//glUniform3f(glGetUniformLocation(program, "lightPos"), 0.0, 0.0, 0.0);
//glUseProgram(0);
drawObjectColor(sphereContext, sunScale, glm::vec3(0.9, 0.9, 0.2)); //sun
drawObjectTexture(sphereContext, mercuryRotate * mercuryTranslate * mercuryScale, texture::mercury); //mercury
@ -343,16 +315,6 @@ void renderScene(GLFWwindow* window)
drawObjectTexture(sphereContext, planetTranslate * planetRotate * planetScale, texture::earth);
glm::mat4 lightVP = glm::ortho(-10.f, 10.f, -10.f, 10.f, 1.0f, 30.0f) * glm::lookAt(sunPos, sunPos - sunDir, glm::vec3(0, 1, 0));
drawObjectDepth(sphereContext, lightVP, sunScale);
drawObjectDepth(sphereContext, lightVP, mercuryRotate * mercuryTranslate * mercuryScale);
drawObjectDepth(sphereContext, lightVP, venusRotate * venusTranslate * venusScale);
drawObjectDepth(sphereContext, lightVP, earthRotate * earthTranslate * earthScale);
drawObjectDepth(sphereContext, lightVP, marsRotate * marsTranslate * marsScale);
drawObjectDepth(sphereContext, lightVP, shipTranslate * shipRotate * shipScale);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glUseProgram(0);
glfwSwapBuffers(window);
}
@ -383,12 +345,8 @@ void init(GLFWwindow* window)
//initDepthMap();
initHDR();
program = shaderLoader.CreateProgram("shaders/shader_5_1.vert", "shaders/shader_5_1.frag");
programTex = shaderLoader.CreateProgram("shaders/shader_5_1_tex.vert", "shaders/shader_5_1_tex.frag");
programDepth = shaderLoader.CreateProgram("shaders/shader_smap.vert", "shaders/shader_smap.frag");
//programTest = shaderLoader.CreateProgram("shaders/test.vert", "shaders/test.frag");
programSun = shaderLoader.CreateProgram("shaders/shader_5_sun.vert", "shaders/shader_5_sun.frag");
program = shaderLoader.CreateProgram("shaders/shader.vert", "shaders/shader.frag");
programTex = shaderLoader.CreateProgram("shaders/shader_tex.vert", "shaders/shader_tex.frag");
programSun = shaderLoader.CreateProgram("shaders/shader_sun.vert", "shaders/shader_sun.frag");
@ -410,8 +368,8 @@ void processInput(GLFWwindow* window)
{
glm::vec3 cameraSide = glm::normalize(glm::cross(cameraDir, glm::vec3(0.f, 1.f, 0.f)));
float angleSpeed = 0.002f;
float moveSpeed = 0.004f;
float angleSpeed = 0.02f;
float moveSpeed = 0.04f;
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
glfwSetWindowShouldClose(window, true);