Mixing Deferred and Forward rendering
- TODO: fix Skybox affected by lighting pass
This commit is contained in:
parent
2dcc3f1803
commit
3a9c07aff9
@ -23,29 +23,12 @@ namespace YoggieEngine {
|
||||
|
||||
|
||||
// Create a depth buffer
|
||||
glGenTextures(1, &DepthAttachment);
|
||||
glBindTexture(GL_TEXTURE_2D, DepthAttachment);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, width, height, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, DepthAttachment, 0);
|
||||
|
||||
|
||||
/*
|
||||
* // Render buffer
|
||||
glGenRenderbuffers(1, &DepthAttachment);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, DepthAttachment);
|
||||
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 800, 600);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, DepthAttachment);
|
||||
|
||||
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||
|
||||
glFramebufferRenderbuffer(GL_RENDERBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, DepthAttachment);
|
||||
|
||||
*/
|
||||
|
||||
if (!glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE)
|
||||
{
|
||||
|
@ -6,8 +6,6 @@
|
||||
#include "../Graphics/Memory/VertexArray.h"
|
||||
#include "../Graphics/Primitives/DrawCommand.h"
|
||||
|
||||
#define FORWARD 1
|
||||
#define DEFERRED 0
|
||||
|
||||
extern YoggieEngine::Camera cam;
|
||||
namespace YoggieEngine {
|
||||
@ -72,7 +70,6 @@ Renderer::Renderer(RendererConfig& config)
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
#if DEFERRED
|
||||
// Deferred Rendering
|
||||
glGenFramebuffers(1, &gBuffer);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, gBuffer);
|
||||
@ -117,7 +114,6 @@ Renderer::Renderer(RendererConfig& config)
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
std::vector<std::string> faces{
|
||||
"build/Debug/skybox/Open_Water/right.jpg",
|
||||
@ -196,9 +192,6 @@ void Renderer::Submit( Render3DComponent& renderComponent, TransformComponent& t
|
||||
|
||||
void Renderer::GeometryPass() {
|
||||
// 1.0 Geometry pass
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, gBuffer);
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
gBufferShader.Use();
|
||||
|
||||
for (const DrawCommand& command : commands)
|
||||
@ -246,8 +239,14 @@ void Renderer::SkyboxPass() {
|
||||
void Renderer::lightingPass(Scene& scene){
|
||||
|
||||
// 2.0 Lighting Pass
|
||||
|
||||
// configure shader
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer.GetId());
|
||||
|
||||
lightingPassShader.Use();
|
||||
lightingPassShader.setUniformInt("gPosition", 0);
|
||||
lightingPassShader.setUniformInt("gNormal", 1);
|
||||
lightingPassShader.setUniformInt("gColorSpec", 2);
|
||||
|
||||
// Bind all Gbuffer textures
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
@ -305,34 +304,25 @@ void Renderer::lightingPass(Scene& scene){
|
||||
|
||||
void Renderer::Render(Scene& scene)
|
||||
{
|
||||
#if DEFERRED
|
||||
// configure shader
|
||||
lightingPassShader.Use();
|
||||
lightingPassShader.setUniformInt("gPosition", 0);
|
||||
lightingPassShader.setUniformInt("gNormal", 1);
|
||||
lightingPassShader.setUniformInt("gColorSpec", 2);
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, gBuffer);
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
SkyboxPass();
|
||||
|
||||
GeometryPass();
|
||||
|
||||
lightingPass(scene);
|
||||
|
||||
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, gBuffer);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_framebuffer.GetId());
|
||||
glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_DEPTH_BUFFER_BIT, GL_NEAREST);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#if FORWARD
|
||||
// Forward rendering approach
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer.GetId());
|
||||
|
||||
glClearColor(m_clearColor.r, m_clearColor.g, m_clearColor.b, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
|
||||
|
||||
SkyboxPass();
|
||||
|
||||
|
||||
for (const DrawCommand& command : commands)
|
||||
{
|
||||
glBindVertexArray(command.VAO_identifier);
|
||||
@ -372,7 +362,6 @@ void Renderer::Render(Scene& scene)
|
||||
|
||||
*/
|
||||
|
||||
#endif
|
||||
|
||||
commands.clear();
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user