I am trying to render to multiple render targets, I set up a float texture and bound it to COLOR_ATTACHMENT1. This all works well and the buffer is created and bound properly. The buffer is even drawn to if I let all the shaders draw to it (glDrawBuffers(..)
) instead of just the shader I have set up to draw to it (layout (location = 1) out ..
). The issue is the shader that should be altering the values doesn't. I know this using Nsight graphics to preview COLOR_ATTATCHMENT1
:
(note the white pixels on the left are a border from nsight)
As we can see, the buffer has two writes but neither change the buffer at all. The glClear
shouldn't change anything here (I think) because glDrawBuffers
doesn't contain this buffer yet.
This is what COLOR_ATTATCHMENT1
looks like if I let every shader write to it (glDrawBuffers(..) //with both attatchments
):
These shaders don't write to this attatchment at all (layout (location = 0)
no location 1) and work perfectly, but again, the one shader that does write to it doesn't. The crates should be writing white pixels, they can be seen here:
(note: this screenshot has post processing applied)
I don't know it's not writing but every other shader has no problem. The framebuffer is set up properly:
The texture is set up with a format of GL_RGB32F
because I want this to be a float texture with the viewspace normals, but the problem persists if I use GL_RGB
or RGBA
. The framebuffer is multisampled and all the textures are multisampled. This is the creation code (ommited glGen
.....):
glBindFramebuffer(GL_FRAMEBUFFER, fboMultisample);
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, colourTexMs); //..
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, sampleLevel, GL_RGB, windowWidth, windowHeight, GL_FALSE); //..
glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //..
glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //.. magnified ..
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, depthTexMs);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, sampleLevel, GL_DEPTH_COMPONENT32, windowWidth, windowHeight, GL_FALSE); //..
glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //..
glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //..
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, normalTexMs);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, sampleLevel, GL_RGB32F, windowWidth, windowHeight, GL_FALSE); //..
glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //..
glTexParameteri(GL_TEXTURE_2D_MULTISAMPLE, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //..
And this is the attachment code (fboMultisampled
is still bound to GL_FRAMEBUFFER
):
glBindTexture(GL_TEXTURE_2D, 0); //unbind textures for safety
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0); //unbind textures for safety
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, colourTexMs, 0); //attatch textures to the framebuffer
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D_MULTISAMPLE, depthTexMs, 0); //..
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D_MULTISAMPLE, normalTexMs, 0); //.. 0 = mipmap level
And this is the shader that should be writing to COLOR_ATTATCHMENT1
(result
calculation is omitted):
layout (location = 0) out vec4 fragColor;
layout (location = 1) out vec3 viewNorm;
//..
void main()
{
//..
fragColor = vec4(result, 1.0f);
viewNorm = vec3(1.f);
}
So in short I don't understand why the shader isn't writing to COLOR_ATTATCHMENT1
.
note: there aren't any OpenGL errors reported.