This commit is contained in:
Teejoon
2016-02-26 18:01:38 +01:00
parent 62e22d3821
commit b320d8d1e4
9 changed files with 84 additions and 33 deletions
+13 -4
View File
@@ -12,7 +12,7 @@
class DrawBloomPass
{
public:
DrawBloomPass(IRenderer* renderer /* ,Texture or finalpass*/ );
DrawBloomPass(IRenderer* renderer, ConfigFile* config);
~DrawBloomPass() { }
void InitializeTextures();
void InitializeFrameBuffers();
@@ -23,23 +23,32 @@ public:
void FillGaussianBuffer(FrameBuffer* fb);
void Draw(GLuint texture);
void ChangeQuality(int quality);
void OnWindowResize();
//Getters
//Return the blurred result of the texture that was sent into draw
GLuint GaussianTexture() const { return m_GaussianTexture_vert; }
GLuint GaussianTexture() const {
if (m_Quality == 0) {
return m_BlackTexture->m_Texture;
} else {
return m_GaussianTexture_vert;
}
}
private:
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const;
Texture* m_WhiteTexture;
Texture* m_BlackTexture;
Model* m_ScreenQuad;
const IRenderer* m_Renderer;
ConfigFile* m_Config;
//const LightCullingPass* m_LightCullingPass
GLuint m_iterations = 9;
int m_Iterations;
int m_Quality = 0;
GLuint m_GaussianTexture_horiz;
GLuint m_GaussianTexture_vert;
+1
View File
@@ -64,6 +64,7 @@ private:
int m_CubeMapTexture = 0;
bool m_ResizeWindow = false;
int m_SSAO_Quality = 0;
int m_GLOW_Quality = 2;
PickingPass* m_PickingPass;
LightCullingPass* m_LightCullingPass;
+1 -1
View File
@@ -64,7 +64,7 @@ private:
int m_NumOfTurns;
int m_Iterations;
int m_TextureQuality;
int m_Quality;
int m_Quality = 0;
Texture* m_WhiteTexture;
+44 -11
View File
@@ -1,19 +1,39 @@
#include "Rendering/DrawBloomPass.h"
DrawBloomPass::DrawBloomPass(IRenderer* renderer)
DrawBloomPass::DrawBloomPass(IRenderer* renderer, ConfigFile* config)
: m_Renderer(renderer)
, m_Config(config)
{
m_Renderer = renderer;
InitializeTextures();
m_ScreenQuad = ResourceManager::Load<Model>("Models/Core/ScreenQuad.mesh");
ChangeQuality(m_Config->Get<int>("GLOW.Quality", 2));
}
InitializeTextures();
InitializeBuffers();
InitializeShaderPrograms();
void DrawBloomPass::ChangeQuality(int quality)
{
if (m_Quality == quality) {
return;
}
m_Quality = quality;
m_ScreenQuad = ResourceManager::Load<Model>("Models/Core/ScreenQuad.mesh");
if (m_Quality == 0) {
glDeleteTextures(1, &m_GaussianTexture_horiz);
glDeleteTextures(1, &m_GaussianTexture_vert);
return;
}
std::string qStr = std::to_string(m_Quality);
m_Iterations = m_Config->Get<float>("GLOW" + qStr + ".NumIterations", 0);
InitializeBuffers();
InitializeShaderPrograms();
}
void DrawBloomPass::InitializeTextures()
{
m_WhiteTexture = CommonFunctions::LoadTexture("Textures/Core/White.png", false);
m_BlackTexture = CommonFunctions::LoadTexture("Textures/Core/Black.png", false);
}
void DrawBloomPass::InitializeShaderPrograms()
@@ -40,18 +60,24 @@ void DrawBloomPass::InitializeBuffers()
{
GenerateTexture(&m_GaussianTexture_horiz, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
m_GaussianFrameBuffer_horiz.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_GaussianTexture_horiz, GL_COLOR_ATTACHMENT0)));
if (m_GaussianFrameBuffer_horiz.GetHandle() == 0) {
m_GaussianFrameBuffer_horiz.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_GaussianTexture_horiz, GL_COLOR_ATTACHMENT0)));
}
m_GaussianFrameBuffer_horiz.Generate();
GenerateTexture(&m_GaussianTexture_vert, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
m_GaussianFrameBuffer_vert.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_GaussianTexture_vert, GL_COLOR_ATTACHMENT0)));
if (m_GaussianFrameBuffer_vert.GetHandle() == 0) {
m_GaussianFrameBuffer_vert.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_GaussianTexture_vert, GL_COLOR_ATTACHMENT0)));
}
m_GaussianFrameBuffer_vert.Generate();
}
void DrawBloomPass::ClearBuffer()
{
if (m_Quality == 0) {
return;
}
GLERROR("PRE");
m_GaussianFrameBuffer_horiz.Bind();
glClearColor(0.f, 0.f, 0.f, 0.f);
@@ -66,6 +92,9 @@ void DrawBloomPass::ClearBuffer()
void DrawBloomPass::Draw(GLuint texture)
{
if (m_Quality == 0) {
return;
}
GLERROR("DrawBloomPass::Draw: Pre");
DrawBloomPassState state;
@@ -84,7 +113,7 @@ void DrawBloomPass::Draw(GLuint texture)
glDrawElementsBaseVertex(GL_TRIANGLES, m_ScreenQuad->MaterialGroups()[0].material->EndIndex - m_ScreenQuad->MaterialGroups()[0].material->StartIndex +1
, GL_UNSIGNED_INT, 0, m_ScreenQuad->MaterialGroups()[0].material->StartIndex);
//Iterate some times to make it more gaussian.
for (int i = 1; i < m_iterations; i++) {
for (int i = 1; i < m_Iterations; i++) {
//Vertical pass
m_GaussianFrameBuffer_vert.Bind();
m_GaussianProgram_vert->Bind();
@@ -125,6 +154,9 @@ void DrawBloomPass::Draw(GLuint texture)
void DrawBloomPass::OnWindowResize()
{
if (m_Quality == 0) {
return;
}
GenerateTexture(&m_GaussianTexture_vert, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
m_GaussianFrameBuffer_vert.Generate();
GenerateTexture(&m_GaussianTexture_horiz, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RGB16F, GL_RGB, GL_FLOAT);
@@ -133,6 +165,7 @@ void DrawBloomPass::OnWindowResize()
void DrawBloomPass::GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const
{
glDeleteTextures(1, texture);
glGenTextures(1, texture);
glBindTexture(GL_TEXTURE_2D, *texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapping);
+2 -2
View File
@@ -162,14 +162,14 @@ void DrawFinalPass::InitializeShaderPrograms()
m_FillDepthBufferProgram = ResourceManager::Load<ShaderProgram>("#FillDepthBufferProgram");
m_FillDepthBufferProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/FillDepthBuffer.vert.glsl")));
m_FillDepthBufferProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/FillDepthBuffer.frag.glsl")));
//m_FillDepthBufferProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/FillDepthBuffer.frag.glsl")));
m_FillDepthBufferProgram->Compile();
m_FillDepthBufferProgram->Link();
GLERROR("Creating DepthFill program");
m_FillDepthBufferSkinnedProgram = ResourceManager::Load<ShaderProgram>("#FillDepthBufferProgramSkinned");
m_FillDepthBufferSkinnedProgram->AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/FillDepthBufferSkinned.vert.glsl")));
m_FillDepthBufferSkinnedProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/FillDepthBuffer.frag.glsl")));
//m_FillDepthBufferSkinnedProgram->AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/FillDepthBuffer.frag.glsl")));
m_FillDepthBufferSkinnedProgram->Compile();
m_FillDepthBufferSkinnedProgram->Link();
GLERROR("Creating DepthFill program");
@@ -8,6 +8,7 @@ DrawFinalPassState::DrawFinalPassState(GLuint frameBuffer)
Enable(GL_BLEND);
BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Enable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
Enable(GL_CULL_FACE);
Enable(GL_STENCIL_TEST);
StencilFunc(GL_NOTEQUAL, 1, 0xFF);
+7 -1
View File
@@ -4,6 +4,8 @@ std::unordered_map<GLFWwindow*, Renderer*> Renderer::m_WindowToRenderer;
void Renderer::Initialize()
{
m_SSAO_Quality = m_Config->Get<int>("SSAO.Quality", 0);
m_GLOW_Quality = m_Config->Get<int>("GLOW.Quality", 0);
InitializeWindow();
InitializeRenderPasses();
@@ -107,6 +109,7 @@ void Renderer::Update(double dt)
void Renderer::Draw(RenderFrame& frame)
{
GLERROR("PRE");
glBindFramebuffer(GL_FRAMEBUFFER, 0);
ImGui::Combo("Draw textures", &m_DebugTextureToDraw, "Final\0Scene\0Bloom\0SceneLowRes\0BloomLowRes\0Gaussian\0Picking\0Ambient Occlusion");
ImGui::Combo("CubeMap", &m_CubeMapTexture, "Nevada(512)\0Sky(1024)");
if(m_CubeMapTexture == 0) {
@@ -115,7 +118,10 @@ void Renderer::Draw(RenderFrame& frame)
m_CubeMapPass->LoadTextures("Sky");
}
ImGui::SliderInt("SSAO Quality", &m_SSAO_Quality, 0, 3);
ImGui::SliderInt("Glow Quality", &m_GLOW_Quality, 0, 3);
m_SSAOPass->ChangeQuality(m_SSAO_Quality);
m_DrawBloomPass->ChangeQuality(m_GLOW_Quality);
GLERROR("SSAO Settings");
//clear buffer 0
glClearColor(0.f, 0.f, 0.f, 0.f);
@@ -245,7 +251,7 @@ void Renderer::InitializeRenderPasses()
m_SSAOPass = new SSAOPass(this, m_Config);
m_DrawFinalPass = new DrawFinalPass(this, m_LightCullingPass, m_CubeMapPass, m_SSAOPass);
m_DrawScreenQuadPass = new DrawScreenQuadPass(this);
m_DrawBloomPass = new DrawBloomPass(this);
m_DrawBloomPass = new DrawBloomPass(this, m_Config);
m_DrawColorCorrectionPass = new DrawColorCorrectionPass(this);
}
+8 -12
View File
@@ -6,12 +6,7 @@ SSAOPass::SSAOPass(IRenderer* renderer, ConfigFile* config)
{
m_WhiteTexture = CommonFunctions::LoadTexture("Textures/Core/White.png", false);
m_Quality = m_Config->Get<int>("SSAO.Quality", 0);
if (m_Quality == 0) {
return;
}
ChangeQuality(m_Quality);
ChangeQuality(m_Config->Get<int>("SSAO.Quality", 0));
}
@@ -102,33 +97,34 @@ void SSAOPass::InitializeBuffer()
if (m_SSAOFramBuffer.GetHandle() == 0) {
m_SSAOFramBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_SSAOTexture, GL_COLOR_ATTACHMENT0)));
}
m_SSAOFramBuffer.Generate();
m_SSAOFramBuffer.Generate();
if (m_SSAOViewSpaceZFramBuffer.GetHandle() == 0) {
m_SSAOViewSpaceZFramBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_SSAOViewSpaceZTexture, GL_COLOR_ATTACHMENT0)));
}
m_SSAOViewSpaceZFramBuffer.Generate();
m_SSAOViewSpaceZFramBuffer.Generate();
if (m_GaussianFrameBuffer_horiz.GetHandle() == 0) {
m_GaussianFrameBuffer_horiz.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_GaussianTexture_horiz, GL_COLOR_ATTACHMENT0)));
}
m_GaussianFrameBuffer_horiz.Generate();
m_GaussianFrameBuffer_horiz.Generate();
if (m_GaussianFrameBuffer_vert.GetHandle() == 0) {
m_GaussianFrameBuffer_vert.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_GaussianTexture_vert, GL_COLOR_ATTACHMENT0)));
}
m_GaussianFrameBuffer_vert.Generate();
m_GaussianFrameBuffer_vert.Generate();
}
void SSAOPass::ClearBuffer()
{
return;
if (m_Quality == 0) {
return;
}
m_SSAOFramBuffer.Bind();
glClearColor(1.f, 1.f, 1.f, 1.f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+7 -2
View File
@@ -31,22 +31,27 @@ glm::vec3 ScreenCoords::ToWorldPos(glm::vec2 screenCoord, float depth, float scr
ScreenCoords::PixelData ScreenCoords::ToPixelData(float x, float y, FrameBuffer* PickDataBuffer, GLuint DepthBuffer)
{
GLERROR("Pre");
PickDataBuffer->Bind();
unsigned char pdata[3];
glReadPixels(x, y, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &pdata);
GLERROR("glReadPixels(pdata) Error");
PickDataBuffer->Unbind();
glBindFramebuffer(GL_FRAMEBUFFER, DepthBuffer);
glBindFramebuffer(GL_FRAMEBUFFER, DepthBuffer);
GLERROR("glBindFramebuffer(DepthBuffer) Error");
float depthData;
glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depthData);
GLERROR("glReadPixels(depthData) Error");
glBindFramebuffer(GL_FRAMEBUFFER, 0);
GLERROR("glBindFramebuffer(0) Error");
PixelData p;
p.Color[0] = (int)pdata[0];
p.Color[1] = (int)pdata[1];
p.Depth = depthData;
GLERROR("ScreenCoords::ToPixelData Error");
GLERROR("End");
return p;
}