Fixed some rendering bugs and some code refactoring
This commit is contained in:
@@ -18,14 +18,16 @@ public:
|
||||
void InitializeFrameBuffers();
|
||||
void InitializeShaderPrograms();
|
||||
void InitializeBuffers();
|
||||
void ClearBuffer();
|
||||
|
||||
void FillGaussianBuffer(FrameBuffer* fb);
|
||||
|
||||
void Draw(GLuint texture);
|
||||
|
||||
//Getters
|
||||
GLuint m_GaussianTexture_horiz;
|
||||
GLuint m_GaussianTexture_vert;
|
||||
//Return the blurred result of the texture that was sent into draw
|
||||
GLuint GaussianTexture() const { return m_GaussianTexture_vert; }
|
||||
|
||||
|
||||
private:
|
||||
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const;
|
||||
@@ -37,6 +39,9 @@ private:
|
||||
//const LightCullingPass* m_LightCullingPass
|
||||
GLuint m_iterations = 9;
|
||||
|
||||
GLuint m_GaussianTexture_horiz;
|
||||
GLuint m_GaussianTexture_vert;
|
||||
|
||||
FrameBuffer m_GaussianFrameBuffer_horiz;
|
||||
FrameBuffer m_GaussianFrameBuffer_vert;
|
||||
|
||||
|
||||
@@ -18,12 +18,12 @@ public:
|
||||
void InitializeFrameBuffers();
|
||||
void InitializeShaderPrograms();
|
||||
void Draw(RenderScene& scene);
|
||||
void ClearBuffer();
|
||||
|
||||
//Todo: Should not be public
|
||||
FrameBuffer m_BloomFrameBuffer;
|
||||
GLuint m_BloomTexture;
|
||||
GLuint m_SceneTexture;
|
||||
GLuint m_DepthBuffer;
|
||||
//Return the texture that is used in later stages to apply the bloom effect
|
||||
GLuint BloomTexture() const { return m_BloomTexture; }
|
||||
//Return the texture with diffuse and lighting of the scene.
|
||||
GLuint SceneTexture() const { return m_SceneTexture; }
|
||||
|
||||
private:
|
||||
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const;
|
||||
@@ -33,6 +33,11 @@ private:
|
||||
Texture* m_BlackTexture;
|
||||
Texture* TEMP_glowTestTexture;
|
||||
|
||||
FrameBuffer m_FinalPassFrameBuffer;
|
||||
GLuint m_BloomTexture;
|
||||
GLuint m_SceneTexture;
|
||||
GLuint m_DepthBuffer;
|
||||
|
||||
const IRenderer* m_Renderer;
|
||||
const LightCullingPass* m_LightCullingPass;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
class DrawFinalPassState : public RenderState
|
||||
{
|
||||
public:
|
||||
DrawFinalPassState();
|
||||
DrawFinalPassState(GLuint frameBuffer);
|
||||
~DrawFinalPassState();
|
||||
private:
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "ImGuiRenderPass.h"
|
||||
#include "Camera.h"
|
||||
#include "../Core/Transform.h"
|
||||
#include "imgui/imgui.h"
|
||||
|
||||
class Renderer : public IRenderer
|
||||
{
|
||||
@@ -45,6 +46,8 @@ private:
|
||||
Model* m_UnitQuad;
|
||||
Model* m_UnitSphere;
|
||||
|
||||
int m_DebugTextureToDraw = 0;
|
||||
|
||||
PickingPass* m_PickingPass;
|
||||
LightCullingPass* m_LightCullingPass;
|
||||
ImGuiRenderPass* m_ImGuiRenderPass;
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef CommonFuntions_h__
|
||||
#define CommonFuntions_h__
|
||||
|
||||
#include "../../Common.h"
|
||||
#include "../../OpenGL.h"
|
||||
#include "../../GLM.h"
|
||||
|
||||
class CommonFuntions
|
||||
{
|
||||
public:
|
||||
CommonFuntions() = delete;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -45,6 +45,19 @@ void DrawBloomPass::InitializeBuffers()
|
||||
m_GaussianFrameBuffer_vert.Generate();
|
||||
}
|
||||
|
||||
|
||||
void DrawBloomPass::ClearBuffer()
|
||||
{
|
||||
m_GaussianFrameBuffer_horiz.Bind();
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
m_GaussianFrameBuffer_horiz.Unbind();
|
||||
m_GaussianFrameBuffer_vert.Bind();
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
m_GaussianFrameBuffer_vert.Unbind();
|
||||
}
|
||||
|
||||
void DrawBloomPass::Draw(GLuint texture)
|
||||
{
|
||||
GLERROR("DrawBloomPass::Draw: Pre");
|
||||
|
||||
@@ -7,8 +7,6 @@ DrawBloomPassState::DrawBloomPassState()
|
||||
Disable(GL_BLEND);
|
||||
Disable(GL_DEPTH_TEST);
|
||||
Disable(GL_CULL_FACE);
|
||||
ClearColor(glm::vec4(0.f / 255, 0.f / 255, 0.f / 255, 0.f));
|
||||
Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
DrawBloomPassState::~DrawBloomPassState()
|
||||
|
||||
@@ -26,7 +26,7 @@ void DrawColorCorrectionPass::Draw(GLuint sceneTexture, GLuint bloomTexture)
|
||||
|
||||
DrawScreenQuadPassState state = DrawScreenQuadPassState();
|
||||
m_ColorCorrectionProgram->Bind();
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glUniform1f(glGetUniformLocation(m_ColorCorrectionProgram->GetHandle(), "Exposure"), m_Exposure);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
@@ -27,10 +27,10 @@ void DrawFinalPass::InitializeFrameBuffers()
|
||||
//GenerateTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->Resolution().Width, m_Renderer->Resolution().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
|
||||
GenerateMipMapTexture(&m_BloomTexture, GL_CLAMP_TO_EDGE, glm::vec2(m_Renderer->Resolution().Width, m_Renderer->Resolution().Height), GL_RGB16F, GL_FLOAT, 4);
|
||||
|
||||
m_BloomFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new RenderBuffer(&m_DepthBuffer, GL_DEPTH_ATTACHMENT)));
|
||||
m_BloomFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_SceneTexture, GL_COLOR_ATTACHMENT0)));
|
||||
m_BloomFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_BloomTexture, GL_COLOR_ATTACHMENT1)));
|
||||
m_BloomFrameBuffer.Generate();
|
||||
m_FinalPassFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new RenderBuffer(&m_DepthBuffer, GL_DEPTH_ATTACHMENT)));
|
||||
m_FinalPassFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_SceneTexture, GL_COLOR_ATTACHMENT0)));
|
||||
m_FinalPassFrameBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_BloomTexture, GL_COLOR_ATTACHMENT1)));
|
||||
m_FinalPassFrameBuffer.Generate();
|
||||
|
||||
}
|
||||
|
||||
@@ -47,9 +47,7 @@ void DrawFinalPass::Draw(RenderScene& scene)
|
||||
{
|
||||
GLERROR("DrawFinalPass::Draw: Pre");
|
||||
|
||||
m_BloomFrameBuffer.Bind(); //in i state
|
||||
|
||||
DrawFinalPassState state;
|
||||
DrawFinalPassState* state = new DrawFinalPassState(m_FinalPassFrameBuffer.GetHandle());
|
||||
|
||||
m_ForwardPlusProgram->Bind();
|
||||
GLuint shaderHandle = m_ForwardPlusProgram->GetHandle();
|
||||
@@ -96,10 +94,19 @@ void DrawFinalPass::Draw(RenderScene& scene)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
m_BloomFrameBuffer.Unbind();
|
||||
m_FinalPassFrameBuffer.Unbind();
|
||||
GLERROR("DrawFinalPass::Draw: END");
|
||||
}
|
||||
|
||||
|
||||
void DrawFinalPass::ClearBuffer()
|
||||
{
|
||||
m_FinalPassFrameBuffer.Bind();
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
m_FinalPassFrameBuffer.Unbind();
|
||||
}
|
||||
|
||||
void DrawFinalPass::GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const
|
||||
{
|
||||
glGenTextures(1, texture);
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#include "Rendering/DrawFinalPassState.h"
|
||||
|
||||
|
||||
DrawFinalPassState::DrawFinalPassState()
|
||||
DrawFinalPassState::DrawFinalPassState(GLuint frameBuffer)
|
||||
{
|
||||
//BindFramebuffer(0);
|
||||
BindFramebuffer(frameBuffer);
|
||||
Enable(GL_BLEND);
|
||||
BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
Enable(GL_DEPTH_TEST);
|
||||
Enable(GL_CULL_FACE);
|
||||
ClearColor(glm::vec4(155.f / 255, 0.f / 255, 155.f / 255, 0.f));
|
||||
ClearColor(glm::vec4(0.f, 0.f, 0.f, 0.f));
|
||||
}
|
||||
|
||||
DrawFinalPassState::~DrawFinalPassState()
|
||||
|
||||
@@ -25,6 +25,7 @@ void DrawScreenQuadPass::Draw(GLuint texture)
|
||||
|
||||
DrawScreenQuadPassState state = DrawScreenQuadPassState();
|
||||
m_DrawQuadProgram->Bind();
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
|
||||
@@ -9,9 +9,7 @@ DrawScreenQuadPassState::DrawScreenQuadPassState()
|
||||
Disable(GL_DEPTH_TEST);
|
||||
Disable(GL_CULL_FACE);
|
||||
Disable(GL_BLEND);
|
||||
glClearColor(0.f, 0.f, 0.f, 1.f);
|
||||
// ClearColor(glm::vec4(255.f / 255, 163.f / 255, 176.f / 255, 0.f));
|
||||
Clear(GL_COLOR_BUFFER_BIT);
|
||||
ClearColor(glm::vec4(0.f));
|
||||
}
|
||||
|
||||
DrawScreenQuadPassState::~DrawScreenQuadPassState()
|
||||
|
||||
@@ -55,45 +55,45 @@ void PickingPass::Draw(RenderScene& scene)
|
||||
if (scene.ClearDepth) {
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
m_Camera = scene.Camera;
|
||||
m_Camera = scene.Camera;
|
||||
|
||||
for (auto &job : scene.ForwardJobs) {
|
||||
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
|
||||
for (auto &job : scene.ForwardJobs) {
|
||||
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
|
||||
|
||||
if (modelJob) {
|
||||
int pickColor[2] = { m_ColorCounter[0], m_ColorCounter[1] };
|
||||
if (modelJob) {
|
||||
int pickColor[2] = { m_ColorCounter[0], m_ColorCounter[1] };
|
||||
|
||||
PickingInfo pickInfo;
|
||||
pickInfo.Entity = modelJob->Entity;
|
||||
pickInfo.World = modelJob->World;
|
||||
pickInfo.Camera = scene.Camera;
|
||||
PickingInfo pickInfo;
|
||||
pickInfo.Entity = modelJob->Entity;
|
||||
pickInfo.World = modelJob->World;
|
||||
pickInfo.Camera = scene.Camera;
|
||||
|
||||
auto color = m_EntityColors.find(std::make_tuple(pickInfo.Entity, pickInfo.World, pickInfo.Camera));
|
||||
if (color != m_EntityColors.end()) {
|
||||
pickColor[0] = color->second[0];
|
||||
pickColor[1] = color->second[1];
|
||||
auto color = m_EntityColors.find(std::make_tuple(pickInfo.Entity, pickInfo.World, pickInfo.Camera));
|
||||
if (color != m_EntityColors.end()) {
|
||||
pickColor[0] = color->second[0];
|
||||
pickColor[1] = color->second[1];
|
||||
} else {
|
||||
m_EntityColors[std::make_tuple(pickInfo.Entity, pickInfo.World, pickInfo.Camera)] = glm::ivec2(pickColor[0], pickColor[1]);
|
||||
if (m_ColorCounter[0] > 255) {
|
||||
m_ColorCounter[0] = 0;
|
||||
m_ColorCounter[1]++;;
|
||||
} else {
|
||||
m_EntityColors[std::make_tuple(pickInfo.Entity, pickInfo.World, pickInfo.Camera)] = glm::ivec2(pickColor[0], pickColor[1]);
|
||||
if (m_ColorCounter[0] > 255) {
|
||||
m_ColorCounter[0] = 0;
|
||||
m_ColorCounter[1]++;;
|
||||
} else {
|
||||
m_ColorCounter[0]++;;
|
||||
}
|
||||
m_ColorCounter[0]++;;
|
||||
}
|
||||
|
||||
m_PickingColorsToEntity[glm::ivec2(pickColor[0], pickColor[1])] = pickInfo;
|
||||
|
||||
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix));
|
||||
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
|
||||
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
|
||||
glUniform2fv(glGetUniformLocation(ShaderHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1])));
|
||||
|
||||
glBindVertexArray(modelJob->Model->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, nullptr, modelJob->StartIndex);
|
||||
}
|
||||
|
||||
m_PickingColorsToEntity[glm::ivec2(pickColor[0], pickColor[1])] = pickInfo;
|
||||
|
||||
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix));
|
||||
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
|
||||
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
|
||||
glUniform2fv(glGetUniformLocation(ShaderHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1])));
|
||||
|
||||
glBindVertexArray(modelJob->Model->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, nullptr, modelJob->StartIndex);
|
||||
}
|
||||
}
|
||||
|
||||
m_PickingBuffer.Unbind();
|
||||
GLERROR("PickingPass Error");
|
||||
|
||||
@@ -76,10 +76,16 @@ void Renderer::Update(double dt)
|
||||
|
||||
void Renderer::Draw(RenderFrame& frame)
|
||||
{
|
||||
glClearColor(255.f / 255, 163.f / 255, 176.f / 255, 0.f);
|
||||
ImGui::Combo("Draw textures", &m_DebugTextureToDraw, "Final\0Scene\0Bloom\0Gaussian\0Picking");
|
||||
//clear buffer 0
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
//Clear other buffers
|
||||
m_PickingPass->ClearPicking();
|
||||
m_DrawFinalPass->ClearBuffer();
|
||||
m_DrawBloomPass->ClearBuffer();
|
||||
|
||||
for (auto scene : frame.RenderScenes){
|
||||
|
||||
SortRenderJobsByDepth(*scene);
|
||||
@@ -88,15 +94,28 @@ void Renderer::Draw(RenderFrame& frame)
|
||||
m_LightCullingPass->FillLightList(*scene);
|
||||
m_LightCullingPass->CullLights(*scene);
|
||||
m_DrawFinalPass->Draw(*scene);
|
||||
//m_DrawScreenQuadPass->Draw(m_DrawFinalPass->m_SceneTexture);
|
||||
//m_DrawScreenQuadPass->Draw(m_DrawFinalPass->m_BloomTexture);
|
||||
m_DrawBloomPass->Draw(m_DrawFinalPass->m_BloomTexture);
|
||||
m_DrawColorCorrectionPass->Draw(m_DrawFinalPass->m_SceneTexture, m_DrawBloomPass->m_GaussianTexture_vert);
|
||||
//m_DrawScreenQuadPass->Draw(m_DrawBloomPass->m_GaussianTexture_vert);
|
||||
//m_DrawScenePass->Draw(rq);
|
||||
|
||||
GLERROR("Renderer::Draw m_DrawScenePass->Draw");
|
||||
}
|
||||
m_DrawBloomPass->Draw(m_DrawFinalPass->BloomTexture());
|
||||
if(m_DebugTextureToDraw == 0) {
|
||||
m_DrawColorCorrectionPass->Draw(m_DrawFinalPass->SceneTexture(), m_DrawBloomPass->GaussianTexture());
|
||||
}
|
||||
if (m_DebugTextureToDraw == 1) {
|
||||
m_DrawScreenQuadPass->Draw(m_DrawFinalPass->SceneTexture());
|
||||
}
|
||||
if (m_DebugTextureToDraw == 2) {
|
||||
m_DrawScreenQuadPass->Draw(m_DrawFinalPass->BloomTexture());
|
||||
}
|
||||
if (m_DebugTextureToDraw == 3) {
|
||||
m_DrawScreenQuadPass->Draw(m_DrawBloomPass->GaussianTexture());
|
||||
}
|
||||
if (m_DebugTextureToDraw == 4) {
|
||||
m_DrawScreenQuadPass->Draw(m_PickingPass->PickingTexture());
|
||||
}
|
||||
|
||||
//m_DrawBloomPass->Draw(m_DrawFinalPass->m_BloomTexture);
|
||||
//m_DrawColorCorrectionPass->Draw(m_DrawFinalPass->m_SceneTexture, m_DrawBloomPass->m_GaussianTexture_vert);
|
||||
|
||||
m_ImGuiRenderPass->Draw();
|
||||
glfwSwapBuffers(m_Window);
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
#include "Rendering/Util/CommonFunctions.h"
|
||||
|
||||
Reference in New Issue
Block a user