LWJGL Forum

Programming => OpenGL => Topic started by: MrNoperson on September 01, 2017, 16:52:44

Title: RGBA16F FBO Is Ending Up As All 0s?
Post by: MrNoperson on September 01, 2017, 16:52:44
So I've spent almost 4 days on this. Problem is I don't know what I need to know to know what to look for... o.0

I have a frambuffer which uses an HDR texture attachment created as follows:
Code: [Select]
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, SCR_WID, SCR_HEI, 0, GL_RGBA, GL_FLOAT, NULL);

The issue is that after the second rendering pass (rendering this color attachment texture to a "screen quad") results in a completely black screen.

After days the list of potential solutions I've tried is very long so I'll trim it down to the most relevant:

So at this point I've come to the conclusion that something must be wrong with my HDR FBO specifically the FLOAT flavored color attachment. It seems to simply not render into it? Is this possible/common?
I normally am an advocate for solving one's own problems, however, in this specific case I am quite literally at my wit's end.

Here is how I'm creating the HDR FBO (full source code is attached):
Code: [Select]
int hdrFBO = GL30.glGenFramebuffers();
int colorBuffer = GL11.glGenTextures();
GL11.glBindTexture(GL11.GL_TEXTURE_2D, colorBuffer);
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL30.GL_RGBA16F, SCR_WID, SCR_HEI, 0, GL11.GL_RGBA, GL11.GL_FLOAT, NULL);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
int rboDepth = GL30.glGenRenderbuffers();
GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, rboDepth);
GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL11.GL_DEPTH_COMPONENT, SCR_WID, SCR_HEI);
GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, hdrFBO);
GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, colorBuffer, 0);
GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL30.GL_RENDERBUFFER, rboDepth);
if(GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER) != GL30.GL_FRAMEBUFFER_COMPLETE)
{
System.err.println("Framebuffer check was not GL_FRAMEBUFFER_COMPLETE");
GLFW.glfwTerminate();
return;
}
GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);

Attached you'll find the full self contained source. I apologize for some of the bad practice going on here as I threw this together from my engine-esk source (not reusing some instances and the like were a byproduct of this conversion).


Long story short I'm not even 100% sure what I need to ask. All I know is that it appears that in hdr.frag the sampler2D hdrBuffer is filled with 0s and thus results in a black screen. I'm just trying to understand why and how to fix it. If anyone has any helpful hints or outright knows why this isn't working I would greatly appreciate it and humbly accept any feedback!

Thanks in advance!  :-[

Notes:
Title: Re: RGBA16F FBO Is Ending Up As All 0s?
Post by: spasi on September 01, 2017, 19:21:22
Hey MrNoperson,

The fix is simple, change the location of uvCoord in hdr.vert from 2 to 1.
Title: Re: RGBA16F FBO Is Ending Up As All 0s?
Post by: MrNoperson on September 01, 2017, 19:46:02
Thank you for catching that!

Unfortunately, and embarrassingly enough, that was another byproduct of my conversion to the self contained test.

In my engine there is "Quad" class which has the attributes: position(0), normal(1), texCoords(2), tangent(3), bitangent(4). I forgot to change it back after trying to use that class instead of the quad in the source I have attached.  :-[

I have fixed it and will re-upload my shaders.txt as I am still getting a black screen.

Addendum: I have retested all changes since the aforementioned error was introduced to no avail.
Title: Re: RGBA16F FBO Is Ending Up As All 0s?
Post by: spasi on September 02, 2017, 07:16:57
You're right, I'd done another fix while debugging this that I forgot. You must move the first glClear after glBindFramebuffer(GL_FRAMEBUFFER, hdrFBO).
Title: Re: RGBA16F FBO Is Ending Up As All 0s?
Post by: MrNoperson on September 02, 2017, 17:57:03
Works like a charm! Can't believe I overlooked that! I'm just glad that it wasn't an issue with how floating point fbo textures work!

A million, sincere, thanks spasi!  :)