HDR causing X-Ray effect...

Started by
4 comments, last by JackOfAllTrades 12 years, 8 months ago
When I create a texture using GL_RGBA16F and bind it to my frame buffer it appears as though the polygons are semi transparent to each other when I render my scene to it. Here is how I create the texture:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, Width, Height, 0, GL_RGBA, GL_FLOAT, NULL);

Any ideas what could be causing this? Even though I don't think it's enabled could it be something to do with the stencil buffer maybe?
Advertisement
When I create a texture using GL_RGBA16F and bind it to my frame buffer it appears as though the polygons are semi transparent to each other when I render my scene to it. Here is how I create the texture:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, Width, Height, 0, GL_RGBA, GL_FLOAT, NULL);

Any ideas what could be causing this? Even though I don't think it's enabled could it be something to do with the stencil buffer maybe?


Most likely your shaders and/or blend functions are causing values to go below zero. Floating point targets are not clamped, ensure you do a max(0, value) at the end of your shaders unless you are intentionally allowing negative values.

[quote name='SteveDeFacto' timestamp='1313218284' post='4848534']When I create a texture using GL_RGBA16F and bind it to my frame buffer it appears as though the polygons are semi transparent to each other when I render my scene to it. Here is how I create the texture:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, Width, Height, 0, GL_RGBA, GL_FLOAT, NULL);

Any ideas what could be causing this? Even though I don't think it's enabled could it be something to do with the stencil buffer maybe?


Most likely your shaders and/or blend functions are causing values to go below zero. Floating point targets are not clamped, ensure you do a max(0, value) at the end of your shaders unless you are intentionally allowing negative values.
[/quote]

I added this to the end of all my fragment shaders:

Out.color = max(float4(0.0, 0.0, 0.0, 1.0), Out.color);

But it still happens...

Code I'm using to initialize the frame buffer and texture:
glGenFramebuffers(1, &rendertarget->frameBuffer);
glBindFramebuffer(GL_FRAMEBUFFER, rendertarget->frameBuffer);
glGenRenderbuffers(1, &rendertarget->depthBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, rendertarget->depthBuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rendertarget->depthBuffer);
glGenTextures(1, &rendertarget->BaseTexture);
glBindTexture(GL_TEXTURE_2D, rendertarget->BaseTexture);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top, 0, GL_RGBA, GL_FLOAT, NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rendertarget->BaseTexture, 0);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(status != GL_FRAMEBUFFER_COMPLETE)
{
OutputDebugString( L"Unable to create frame buffer" );
}


Code I'm using to initialize the frame buffer and texture:
snip



What are you using for your clear colour / clear depth, and what blend functions are you using? I don't see anything out of the ordinary with your framebuffer construction.

[quote name='SteveDeFacto' timestamp='1313223994' post='4848551']
Code I'm using to initialize the frame buffer and texture:
snip



What are you using for your clear colour / clear depth, and what blend functions are you using? I don't see anything out of the ordinary with your framebuffer construction.
[/quote]

I figured it out. It was not that the alpha was going below zero but that it was over 1.

This topic is closed to new replies.

Advertisement