From 5bbff74f8cd1686cc51fd28b0be156b05a1b6f12 Mon Sep 17 00:00:00 2001 From: sasankasa Date: Mon, 22 Jan 2024 16:54:33 +0100 Subject: [PATCH] zmiany na cw 22-01-2024 --- grk/cw 6/shaders/shader_FBO.frag | 3 ++- grk/cw 6/shaders/shader_bloom.frag | 1 + grk/cw 6/src/Planet.hpp | 24 ++++++++++++------------ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/grk/cw 6/shaders/shader_FBO.frag b/grk/cw 6/shaders/shader_FBO.frag index a5c0dcb..c3ceeb1 100644 --- a/grk/cw 6/shaders/shader_FBO.frag +++ b/grk/cw 6/shaders/shader_FBO.frag @@ -17,5 +17,6 @@ void main() float exposure = 0.8f; vec3 toneMapped = vec3(1.0f) - exp(-color * exposure); - FragColor.rgb = pow(toneMapped, vec3(1.0f / gamma)); + toneMapped = pow(toneMapped, vec3(1.0f / gamma)); + FragColor = vec4(toneMapped, 1.0); } \ No newline at end of file diff --git a/grk/cw 6/shaders/shader_bloom.frag b/grk/cw 6/shaders/shader_bloom.frag index 6cb67d8..130f7ba 100644 --- a/grk/cw 6/shaders/shader_bloom.frag +++ b/grk/cw 6/shaders/shader_bloom.frag @@ -53,5 +53,6 @@ void main() result += texture(screenTexture, texCoords - vec2(0.0, tex_offset.y * i)).rgb * weights[i]; } } + result = vec3(0, 1, 0); FragColor = vec4(result, 1.0f); } \ No newline at end of file diff --git a/grk/cw 6/src/Planet.hpp b/grk/cw 6/src/Planet.hpp index a6ef138..c816a6f 100644 --- a/grk/cw 6/src/Planet.hpp +++ b/grk/cw 6/src/Planet.hpp @@ -191,14 +191,7 @@ void drawObjectTexture(Core::RenderContext& context, glm::mat4 modelMatrix, GLui glUniform3f(glGetUniformLocation(programTex, "lightPos"), sunPosition.x, sunPosition.y, sunPosition.z); glUniform3f(glGetUniformLocation(programTex, "lightColor"), lightColor.x, lightColor.y, lightColor.z); - /* glUseProgram(programFramebuffer); - glUniform1i(glGetUniformLocation(programFramebuffer, "screenTexture"), 0); - glUniform1i(glGetUniformLocation(programFramebuffer, "bloomTexture"), 1); - glUniform1f(glGetUniformLocation(programFramebuffer, "gamma"), gamma); - - glUseProgram(programBlur); - glUniform1i(glGetUniformLocation(programBlur, "screenTexture"), 0); - */ + Core::DrawContext(context); @@ -218,8 +211,10 @@ void drawSun(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint texture } void drawObjectBloom(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint texture, int amount, bool horizontal, bool first_iteration) { + + glUseProgram(programBlur); - Core::SetActiveTexture(texture, "colorTexture", programTex, 0); + glUniform1i(glGetUniformLocation(programBlur, "screenTexture"), 0); glm::mat4 viewProjectionMatrix = createPerspectiveMatrix() * createCameraMatrix(); glm::mat4 transformation = viewProjectionMatrix * modelMatrix; @@ -250,6 +245,11 @@ void drawObjectBloom(Core::RenderContext& context, glm::mat4 modelMatrix, GLuint // Switch between vertical and horizontal blurring horizontal = !horizontal; } + glBindFramebuffer(GL_FRAMEBUFFER, 0); + glUseProgram(programFramebuffer); + glUniform1i(glGetUniformLocation(programFramebuffer, "screenTexture"), 0); + glUniform1i(glGetUniformLocation(programFramebuffer, "bloomTexture"), 1); + glUniform1f(glGetUniformLocation(programFramebuffer, "gamma"), gamma); glUseProgram(0); } @@ -317,11 +317,11 @@ void renderScene(GLFWwindow* window) glm::mat4 planetTranslate = glm::translate(glm::vec3(0, 0, 0)); // zostaje na domyślnej pozycji drawObjectTexture(sphereContext, planetTranslate * planetRotate * planetScale, texture::earth); - /* + glBindFramebuffer(hdrFBO, 0); glUseProgram(programBlur); - drawObjectBloom(sphereContext, planetTranslate * planetRotate * planetScale, texture::earth, 2, true, true); - */ + drawObjectBloom(sphereContext, planetTranslate * planetRotate * planetScale, texture::earth, 10, true, true); + glfwSwapBuffers(window);