I have a fbo, with 8 textures in it (g-buffer). What I'm trying to do, is to render all information from opaque objects to first four(color, normal, position, depth), and info from transparent objects to the last four textures. However, openGL seems to only want to render to firs four, no matter what I do. Also, the first frame when the application starts, is form some wierd reason the texture I use for my transparent objects.
Shader that writes to g-buffer:
in vec2 texcoord;
in vec3 worldpos;
in mat3 tbnmatrix;
uniform sampler2d diffuse;
uniform sampler2d normalmap;
uniform sampler2d dispmap;
uniform float dispmapbias;
uniform float dispmapscale;
uniform float specularintensity;
uniform float specularpower;
uniform float opacity;
uniform vec3 c_eyepos;
layout (location = 0) out vec4 diffuseColor;
layout (location = 1) out vec4 normalColor;
layout (location = 2) out vec4 positionColor;
layout (location = 3) out float depthcolor;
layout (location = 4) out vec4 diffuseColorT;
layout (location = 5) out vec4 normalColorT;
layout (location = 6) out vec4 positionColorT;
layout (location = 7) out float depthColorT;
void main(){
//Just calculating displaced texture coordinates vec2 texcoords = calcParallaxTexcoords(dispmap, tbnmatrix, normalize(c_eyepos - worldpos), texcoord, dispmapscale, dispmapbias);
//Calculating normals
vec3 n = normalize(tbnmatrix * (255.0/128.0 * texture(normalmap, texcoords).xyz - 1));
if(opacity == 1){
diffuseColor = vec4(texture(diffuse, texcoords).xyz, 1);
normalColor = vec4(n, specularintensity);
positionColor = vec4(worldpos, specularpower);
depthColor = gl_FragCoord.z;
}
else{
diffuseColorT = vec4(texture(diffuse, texcoords).xyz, opacity);
normalColorT = vec4(n, specularintensity);
positionColorT = vec4(worldpos, specularpower);
depthColorT = gl_FragCoord.z;
}
}
I would post the code that creates my FBO, but it would be very much code, and hard to understand(because my architecture). Here are the values that I am passing in:
//Filters to be used in rendertargets
GLenum filters[8] = { GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_LINEAR,
GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_LINEAR,
GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_LINEAR };
//What I pass in to the third parameter of glTexImage2D
GLenum internalFormats[8] = { GL_RGBA, GL_RGBA16F, GL_RGBA16F, GL_R32F, GL_RGBA, GL_RGBA16F, GL_RGBA16F, GL_R32F };
//Formats, not really important here
GLenum formats[8] = { GL_RGBA, GL_RGBA, GL_RGBA, GL_RGBA, GL_RGBA, GL_RGBA, GL_RGBA, GL_RGBA };
//Attachment to be used in glFramebufferTexture2D (and glDrawBuffers)
GLenum attachments[8] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1,
GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3, GL_COLOR_ATTACHMENT4, GL_COLOR_ATTACHMENT5,
GL_COLOR_ATTACHMENT6, GL_COLOR_ATTACHMENT7 };
GL_MAX_COLOR_ATTACHMENTS
(viaglGetIntegerv
). Lots of hardware only supports a maximum of four simultaneous render targets. – Sean Middleditch Jan 22 at 17:27