init of hdr buffer

This commit is contained in:
natnow45 2024-01-17 15:09:32 +01:00
parent 74ffe6d81a
commit ec77d99b0e

View File

@ -15,12 +15,10 @@
#include <assimp/postprocess.h>
#include <string>
namespace models {
Core::RenderContext testContext;
}
namespace texture {
GLuint earth;
GLuint clouds;
@ -76,10 +74,11 @@ glm::vec3 lightColor = glm::vec3(20.f, 20.f, 20.f);
unsigned int depthMapFBO;
unsigned int depthMap;
const unsigned int SHADOW_WIDTH = 1024, SHADOW_HEIGHT = 1024;
unsigned int hdrFBO;
unsigned int colorBuffers[2];
const unsigned int HDR_WIDTH = 1024, HDR_HEIGHT = 1024;
glm::mat4 createCameraMatrix()
@ -139,12 +138,35 @@ glm::mat4 createPerspectiveMatrix()
return perspectiveMatrix;
}
void initHDR() {
glGenFramebuffers(1, &hdrFBO);
glBindFramebuffer(GL_FRAMEBUFFER, hdrFBO);
glGenTextures(2, colorBuffers);
for (unsigned int i = 0; i < 2; i++) {
glBindTexture(GL_TEXTURE_2D, colorBuffers[i]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F,
HDR_WIDTH, HDR_HEIGHT, 0, GL_RGBA, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, colorBuffers[i], 0);
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
}
unsigned int attachments[2] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 };
glDrawBuffers(2, attachments);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
void initDepthMap() {
glGenFramebuffers(1, &depthMapFBO);
glGenTextures(1, &depthMap);
glBindTexture(GL_TEXTURE_2D, depthMap);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT,
SHADOW_WIDTH, SHADOW_HEIGHT, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
HDR_WIDTH, HDR_HEIGHT, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
@ -156,15 +178,17 @@ void initDepthMap() {
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
void renderShadowapSun() {
int WIDTH = 500, HEIGHT = 500;
void renderShadowapSun(GLFWwindow* window) {
int width = 500, height = 500;
glfwGetWindowSize(window, &width, &height);
float time = glfwGetTime();
glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
glViewport(0, 0, HDR_WIDTH, HDR_HEIGHT);
//uzupelnij o renderowanie glebokosci do tekstury
glUseProgram(programDepth);
//ustawianie przestrzeni rysowania
glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
glViewport(0, 0, HDR_WIDTH, HDR_HEIGHT);
//bindowanie FBO
glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
//czyszczenie mapy głębokości
@ -265,9 +289,6 @@ void renderScene(GLFWwindow* window)
glm::mat4 transformation;
float time = glfwGetTime();
//shadowmap, poki co nie pozwala na skalowanie okna dlatego zakomentowane
//renderShadowapSun();
glm::mat4 sunScale = glm::scale(glm::vec3(1.75));
glm::mat4 mercuryScale = glm::scale(glm::vec3(0.24));
@ -294,12 +315,6 @@ void renderScene(GLFWwindow* window)
glm::mat4 shipRotate = createShipMatrix();
glm::mat4 shipTranslate = glm::translate(shipPos);
//glUseProgram(program);
//glUniform3f(glGetUniformLocation(program, "lightPos"), 0.0, 0.0, 0.0);
//glUseProgram(0);
drawSun(sphereContext, sunScale, texture::sun);
drawObjectTexture(sphereContext, mercuryRotate * mercuryTranslate * mercuryScale, texture::mercury); //mercury
@ -314,16 +329,6 @@ void renderScene(GLFWwindow* window)
drawObjectTexture(shipContext, shipTranslate * shipRotate * shipScale, texture::ship); //ship
/*
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(programTest);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, depthMap);
Core::DrawContext(models::testContext);
*/
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);
@ -360,7 +365,8 @@ void init(GLFWwindow* window)
glEnable(GL_DEPTH_TEST);
initDepthMap();
//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");