add emission gbuffer attachment
This commit is contained in:
@@ -8,6 +8,8 @@ using namespace advanced_pipeline;
|
||||
|
||||
static debug::Logger logger("gl-gbuffer");
|
||||
|
||||
// TODO: REFACTOR
|
||||
|
||||
void GBuffer::createColorBuffer() {
|
||||
glGenTextures(1, &colorBuffer);
|
||||
glBindTexture(GL_TEXTURE_2D, colorBuffer);
|
||||
@@ -64,7 +66,7 @@ void GBuffer::createNormalsBuffer() {
|
||||
width,
|
||||
height,
|
||||
0,
|
||||
GL_RGBA,
|
||||
GL_RGB,
|
||||
GL_FLOAT,
|
||||
nullptr
|
||||
);
|
||||
@@ -77,6 +79,29 @@ void GBuffer::createNormalsBuffer() {
|
||||
);
|
||||
}
|
||||
|
||||
void GBuffer::createEmissionBuffer() {
|
||||
glGenTextures(1, &emissionBuffer);
|
||||
glBindTexture(GL_TEXTURE_2D, emissionBuffer);
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_R8,
|
||||
width,
|
||||
height,
|
||||
0,
|
||||
GL_RED,
|
||||
GL_FLOAT,
|
||||
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_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glFramebufferTexture2D(
|
||||
GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_TEXTURE_2D, emissionBuffer, 0
|
||||
);
|
||||
}
|
||||
|
||||
void GBuffer::createDepthBuffer() {
|
||||
glGenRenderbuffers(1, &depthBuffer);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer);
|
||||
@@ -113,16 +138,21 @@ GBuffer::GBuffer(uint width, uint height) : width(width), height(height) {
|
||||
createColorBuffer();
|
||||
createPositionsBuffer();
|
||||
createNormalsBuffer();
|
||||
createEmissionBuffer();
|
||||
|
||||
GLenum attachments[3] = {
|
||||
GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2
|
||||
GLenum attachments[4] = {
|
||||
GL_COLOR_ATTACHMENT0,
|
||||
GL_COLOR_ATTACHMENT1,
|
||||
GL_COLOR_ATTACHMENT2,
|
||||
GL_COLOR_ATTACHMENT3,
|
||||
};
|
||||
glDrawBuffers(3, attachments);
|
||||
glDrawBuffers(4, attachments);
|
||||
|
||||
createDepthBuffer();
|
||||
|
||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||
logger.error() << "gbuffer is not complete!";
|
||||
int status;
|
||||
if ((status = glCheckFramebufferStatus(GL_FRAMEBUFFER)) != GL_FRAMEBUFFER_COMPLETE) {
|
||||
logger.error() << "gbuffer is not complete! (" << status << ")";
|
||||
}
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
@@ -134,8 +164,10 @@ GBuffer::GBuffer(uint width, uint height) : width(width), height(height) {
|
||||
);
|
||||
GLenum ssaoAttachments[1] = {GL_COLOR_ATTACHMENT0};
|
||||
glDrawBuffers(1, ssaoAttachments);
|
||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||
logger.error() << "SSAO framebuffer is not complete!";
|
||||
|
||||
|
||||
if ((status = glCheckFramebufferStatus(GL_FRAMEBUFFER)) != GL_FRAMEBUFFER_COMPLETE) {
|
||||
logger.error() << "SSAO framebuffer is not complete! (" << status << ")";
|
||||
}
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}
|
||||
@@ -144,6 +176,7 @@ GBuffer::~GBuffer() {
|
||||
glDeleteTextures(1, &colorBuffer);
|
||||
glDeleteTextures(1, &positionsBuffer);
|
||||
glDeleteTextures(1, &normalsBuffer);
|
||||
glDeleteTextures(1, &emissionBuffer);
|
||||
glDeleteTextures(1, &ssaoBuffer);
|
||||
glDeleteRenderbuffers(1, &depthBuffer);
|
||||
glDeleteFramebuffers(1, &fbo);
|
||||
@@ -164,6 +197,9 @@ void GBuffer::unbind() {
|
||||
}
|
||||
|
||||
void GBuffer::bindBuffers() const {
|
||||
glActiveTexture(GL_TEXTURE0 + TARGET_EMISSION);
|
||||
glBindTexture(GL_TEXTURE_2D, emissionBuffer);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + TARGET_NORMALS);
|
||||
glBindTexture(GL_TEXTURE_2D, normalsBuffer);
|
||||
|
||||
@@ -227,12 +263,20 @@ void GBuffer::resize(uint width, uint height) {
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, normalsBuffer);
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D, 0, GL_RGB16F, width, height, 0, GL_RGB, GL_FLOAT, nullptr
|
||||
GL_TEXTURE_2D, 0, GL_RGB16F, width, height, 0, GL_RGBA, GL_FLOAT, nullptr
|
||||
);
|
||||
glFramebufferTexture2D(
|
||||
GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, normalsBuffer, 0
|
||||
);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, emissionBuffer);
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D, 0, GL_INTENSITY, width, height, 0, GL_LUMINANCE, GL_FLOAT, nullptr
|
||||
);
|
||||
glFramebufferTexture2D(
|
||||
GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_TEXTURE_2D, emissionBuffer, 0
|
||||
);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ private:
|
||||
uint colorBuffer;
|
||||
uint positionsBuffer;
|
||||
uint normalsBuffer;
|
||||
uint emissionBuffer;
|
||||
uint depthBuffer;
|
||||
uint ssaoFbo;
|
||||
uint ssaoBuffer;
|
||||
@@ -39,6 +40,7 @@ private:
|
||||
void createColorBuffer();
|
||||
void createPositionsBuffer();
|
||||
void createNormalsBuffer();
|
||||
void createEmissionBuffer();
|
||||
void createDepthBuffer();
|
||||
void createSSAOBuffer();
|
||||
};
|
||||
|
||||
@@ -102,6 +102,7 @@ void PostProcessing::configureEffect(
|
||||
if (gbuffer) {
|
||||
shader.uniform1i("u_position", TARGET_POSITIONS);
|
||||
shader.uniform1i("u_normal", TARGET_NORMALS);
|
||||
shader.uniform1i("u_emission", TARGET_EMISSION);
|
||||
}
|
||||
shader.uniform1i("u_noise", TARGET_SSAO); // used in SSAO pass
|
||||
shader.uniform1i("u_ssao", TARGET_SSAO);
|
||||
|
||||
@@ -55,9 +55,10 @@ namespace advanced_pipeline {
|
||||
inline constexpr int TARGET_SKYBOX = 1;
|
||||
inline constexpr int TARGET_POSITIONS = 2;
|
||||
inline constexpr int TARGET_NORMALS = 3;
|
||||
inline constexpr int TARGET_SSAO = 4;
|
||||
inline constexpr int TARGET_SHADOWS0 = 5;
|
||||
inline constexpr int TARGET_SHADOWS1 = 6;
|
||||
inline constexpr int TARGET_EMISSION = 4;
|
||||
inline constexpr int TARGET_SSAO = 5;
|
||||
inline constexpr int TARGET_SHADOWS0 = 6;
|
||||
inline constexpr int TARGET_SHADOWS1 = 7;
|
||||
}
|
||||
|
||||
VC_ENUM_METADATA(CursorShape)
|
||||
|
||||
Reference in New Issue
Block a user