Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4ffb03fdd5 | |||
| 97fcdb342d | |||
| 949ee76f55 |
@@ -14,14 +14,11 @@ class SSAOPass
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SSAOPass(IRenderer* rendere);
|
SSAOPass(IRenderer* rendere);
|
||||||
~SSAOPass() {
|
~SSAOPass() { };
|
||||||
delete m_DrawBloomPass;
|
|
||||||
};
|
|
||||||
|
|
||||||
void Draw(GLuint depthBuffer, Camera* camera);
|
void Draw(GLuint depthBuffer, Camera* camera);
|
||||||
void Setting(float radius, float bias, float contrast, float intensityScale, int numOfSamples, int NumOfTurns);
|
void Setting(float radius, float bias, float contrast, float intensityScale, int numOfSamples, int NumOfTurns);
|
||||||
void ClearBuffer();
|
void ClearBuffer();
|
||||||
void OnWindowResize();
|
|
||||||
|
|
||||||
//Return the SSAO of the texture sent to Draw
|
//Return the SSAO of the texture sent to Draw
|
||||||
GLuint SSAOTexture() const { return m_DrawBloomPass->GaussianTexture(); }
|
GLuint SSAOTexture() const { return m_DrawBloomPass->GaussianTexture(); }
|
||||||
@@ -34,6 +31,7 @@ private:
|
|||||||
|
|
||||||
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const;
|
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const;
|
||||||
|
|
||||||
|
void ComputeAO(GLuint depthBuffer, Camera* camera);
|
||||||
//void blurHorizontal(GLuint depthBuffer);
|
//void blurHorizontal(GLuint depthBuffer);
|
||||||
//void blurVertical(GLuint depthBuffer);
|
//void blurVertical(GLuint depthBuffer);
|
||||||
|
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ struct LightResult {
|
|||||||
};
|
};
|
||||||
|
|
||||||
float CalcAttenuation(float radius, float dist, float falloff) {
|
float CalcAttenuation(float radius, float dist, float falloff) {
|
||||||
return 1.0 - smoothstep(radius * 0.3, radius, dist);
|
return 1.0 - smoothstep(radius * falloff, radius, dist);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 CalcSpecular(vec4 lightColor, vec4 viewVec, vec4 lightVec, vec4 normal) {
|
vec4 CalcSpecular(vec4 lightColor, vec4 viewVec, vec4 lightVec, vec4 normal) {
|
||||||
@@ -174,7 +174,7 @@ void main()
|
|||||||
sceneColor = vec4(color_result.xyz, clamp(color_result.a, 0, 1));
|
sceneColor = vec4(color_result.xyz, clamp(color_result.a, 0, 1));
|
||||||
color_result += glowTexel*GlowIntensity;
|
color_result += glowTexel*GlowIntensity;
|
||||||
|
|
||||||
bloomColor = vec4(clamp(color_result.xyz - 1.0, 0, 100), 1.0);
|
bloomColor = vec4(clamp(color_result.xyz - 1.0, 0, 100), clamp(color_result.a, 0, 1));
|
||||||
|
|
||||||
//Tiled Debug Code
|
//Tiled Debug Code
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -192,8 +192,10 @@ void DrawFinalPass::Draw(RenderScene& scene, GLuint SSAOTexture)
|
|||||||
state->StencilMask(0x00);
|
state->StencilMask(0x00);
|
||||||
DrawModelRenderQueues(scene.Jobs.OpaqueObjects, scene, SSAOTexture);
|
DrawModelRenderQueues(scene.Jobs.OpaqueObjects, scene, SSAOTexture);
|
||||||
GLERROR("OpaqueObjects");
|
GLERROR("OpaqueObjects");
|
||||||
|
state->BlendFunc(GL_ONE, GL_ONE);
|
||||||
DrawModelRenderQueues(scene.Jobs.TransparentObjects, scene, SSAOTexture);
|
DrawModelRenderQueues(scene.Jobs.TransparentObjects, scene, SSAOTexture);
|
||||||
GLERROR("TransparentObjects");
|
GLERROR("TransparentObjects");
|
||||||
|
state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
DrawSprites(scene.Jobs.SpriteJob, scene);
|
DrawSprites(scene.Jobs.SpriteJob, scene);
|
||||||
GLERROR("SpriteJobs");
|
GLERROR("SpriteJobs");
|
||||||
|
|
||||||
|
|||||||
@@ -21,13 +21,23 @@ void PickingPass::InitializeTextures()
|
|||||||
{
|
{
|
||||||
GenerateTexture(&m_PickingTexture, GL_CLAMP_TO_BORDER, GL_LINEAR,
|
GenerateTexture(&m_PickingTexture, GL_CLAMP_TO_BORDER, GL_LINEAR,
|
||||||
glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RG8, GL_RG, GL_UNSIGNED_BYTE);
|
glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_RG8, GL_RG, GL_UNSIGNED_BYTE);
|
||||||
|
|
||||||
GenerateTexture(&m_DepthBuffer, GL_CLAMP_TO_BORDER, GL_NEAREST,
|
|
||||||
glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PickingPass::InitializeFrameBuffers()
|
void PickingPass::InitializeFrameBuffers()
|
||||||
{
|
{
|
||||||
|
/* glGenRenderbuffers(1, &m_DepthBuffer);
|
||||||
|
glBindRenderbuffer(GL_RENDERBUFFER, m_DepthBuffer);
|
||||||
|
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);*/
|
||||||
|
|
||||||
|
glGenTextures(1, &m_DepthBuffer);
|
||||||
|
|
||||||
|
glBindTexture(GL_TEXTURE_2D, m_DepthBuffer);
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, (int)(m_Renderer->GetViewportSize().Width), (int)(m_Renderer->GetViewportSize().Height), 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, nullptr);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
||||||
|
|
||||||
m_PickingBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_DepthBuffer, GL_DEPTH_ATTACHMENT)));
|
m_PickingBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_DepthBuffer, GL_DEPTH_ATTACHMENT)));
|
||||||
m_PickingBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_PickingTexture, GL_COLOR_ATTACHMENT0)));
|
m_PickingBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_PickingTexture, GL_COLOR_ATTACHMENT0)));
|
||||||
m_PickingBuffer.Generate();
|
m_PickingBuffer.Generate();
|
||||||
@@ -372,6 +382,8 @@ void PickingPass::ClearPicking()
|
|||||||
void PickingPass::OnWindowResize()
|
void PickingPass::OnWindowResize()
|
||||||
{
|
{
|
||||||
InitializeTextures();
|
InitializeTextures();
|
||||||
|
glBindRenderbuffer(GL_RENDERBUFFER, m_DepthBuffer);
|
||||||
|
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height);
|
||||||
m_PickingBuffer.Generate();
|
m_PickingBuffer.Generate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ void Renderer::glfwFrameBufferCallback(GLFWwindow* window, int width, int height
|
|||||||
currentRenderer->m_LightCullingPass->OnWindowResize();
|
currentRenderer->m_LightCullingPass->OnWindowResize();
|
||||||
currentRenderer->m_PickingPass->OnWindowResize();
|
currentRenderer->m_PickingPass->OnWindowResize();
|
||||||
currentRenderer->m_DrawBloomPass->OnWindowResize();
|
currentRenderer->m_DrawBloomPass->OnWindowResize();
|
||||||
currentRenderer->m_SSAOPass->OnWindowResize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::InitializeWindow()
|
void Renderer::InitializeWindow()
|
||||||
@@ -127,7 +126,6 @@ void Renderer::Draw(RenderFrame& frame)
|
|||||||
m_PickingPass->ClearPicking();
|
m_PickingPass->ClearPicking();
|
||||||
m_DrawFinalPass->ClearBuffer();
|
m_DrawFinalPass->ClearBuffer();
|
||||||
m_DrawBloomPass->ClearBuffer();
|
m_DrawBloomPass->ClearBuffer();
|
||||||
m_SSAOPass->ClearBuffer();
|
|
||||||
PerformanceTimer::StopTimer("Renderer-ClearBuffers");
|
PerformanceTimer::StopTimer("Renderer-ClearBuffers");
|
||||||
for (auto scene : frame.RenderScenes) {
|
for (auto scene : frame.RenderScenes) {
|
||||||
PerformanceTimer::StartTimer("Renderer-Depth");
|
PerformanceTimer::StartTimer("Renderer-Depth");
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ SSAOPass::SSAOPass(IRenderer* renderer)
|
|||||||
|
|
||||||
m_ScreenQuad = ResourceManager::Load<Model>("Models/Core/ScreenQuad.mesh");
|
m_ScreenQuad = ResourceManager::Load<Model>("Models/Core/ScreenQuad.mesh");
|
||||||
|
|
||||||
InitializeTexture();
|
|
||||||
InitializeBuffer();
|
InitializeBuffer();
|
||||||
InitializeShaderProgram();
|
InitializeShaderProgram();
|
||||||
Setting(0.1f, 0.012f, 1.0f, 1.0f, 13, 7);
|
Setting(0.1f, 0.012f, 1.0f, 1.0f, 13, 7);
|
||||||
@@ -29,16 +28,16 @@ void SSAOPass::InitializeShaderProgram()
|
|||||||
m_SSAOViewSpaceZProgram->Link();
|
m_SSAOViewSpaceZProgram->Link();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SSAOPass::InitializeTexture() {
|
|
||||||
GenerateTexture(&m_SSAOTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_R8, GL_RED, GL_FLOAT);
|
|
||||||
GenerateTexture(&m_SSAOViewSpaceZTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_R32F, GL_RED, GL_FLOAT);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SSAOPass::InitializeBuffer()
|
void SSAOPass::InitializeBuffer()
|
||||||
{
|
{
|
||||||
|
GenerateTexture(&m_SSAOTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_R8, GL_RED, GL_FLOAT);
|
||||||
|
|
||||||
m_SSAOFramBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_SSAOTexture, GL_COLOR_ATTACHMENT0)));
|
m_SSAOFramBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_SSAOTexture, GL_COLOR_ATTACHMENT0)));
|
||||||
m_SSAOFramBuffer.Generate();
|
m_SSAOFramBuffer.Generate();
|
||||||
|
|
||||||
|
GenerateTexture(&m_SSAOViewSpaceZTexture, GL_CLAMP_TO_EDGE, GL_LINEAR, glm::vec2(m_Renderer->GetViewportSize().Width, m_Renderer->GetViewportSize().Height), GL_R32F, GL_RED, GL_FLOAT);
|
||||||
|
|
||||||
m_SSAOViewSpaceZFramBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_SSAOViewSpaceZTexture, GL_COLOR_ATTACHMENT0)));
|
m_SSAOViewSpaceZFramBuffer.AddResource(std::shared_ptr<BufferResource>(new Texture2D(&m_SSAOViewSpaceZTexture, GL_COLOR_ATTACHMENT0)));
|
||||||
m_SSAOViewSpaceZFramBuffer.Generate();
|
m_SSAOViewSpaceZFramBuffer.Generate();
|
||||||
}
|
}
|
||||||
@@ -46,12 +45,12 @@ void SSAOPass::InitializeBuffer()
|
|||||||
void SSAOPass::ClearBuffer()
|
void SSAOPass::ClearBuffer()
|
||||||
{
|
{
|
||||||
m_SSAOFramBuffer.Bind();
|
m_SSAOFramBuffer.Bind();
|
||||||
glClearColor(1.f, 1.f, 1.f, 1.f);
|
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
m_SSAOFramBuffer.Unbind();
|
m_SSAOFramBuffer.Unbind();
|
||||||
|
|
||||||
m_SSAOViewSpaceZFramBuffer.Bind();
|
m_SSAOViewSpaceZFramBuffer.Bind();
|
||||||
glClearColor(1.f, 1.f, 1.f, 1.f);
|
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
m_SSAOViewSpaceZFramBuffer.Unbind();
|
m_SSAOViewSpaceZFramBuffer.Unbind();
|
||||||
}
|
}
|
||||||
@@ -137,9 +136,6 @@ void SSAOPass::Draw(GLuint depthBuffer, Camera* camera)
|
|||||||
m_DrawBloomPass->Draw(m_SSAOTexture);
|
m_DrawBloomPass->Draw(m_SSAOTexture);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SSAOPass::OnWindowResize() {
|
void ComputeAO(GLuint depthBuffer, Camera* camera) {
|
||||||
m_DrawBloomPass->OnWindowResize();
|
|
||||||
InitializeTexture();
|
|
||||||
m_SSAOFramBuffer.Generate();
|
|
||||||
m_SSAOViewSpaceZFramBuffer.Generate();
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user