I'm currently implementing skeletal animation in my deferred rendering pipeline. Since each vertex in a rigged mesh will take at least an extra 32 bytes (due to the bone's vertex IDs & weights), I thought it would be a good idea to make a different shader that will be in charge of drawing animated meshes.
That being said, I have a simple geometry buffer (framebuffer) that has 4 color attachments. These color attachments will be written to using my static geometry shader. C++ code looks like:
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glBindFramebuffer(GL_FRAMEBUFFER, gID); // Bind FBO
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(staticGeometryShaderID); // Bind static geometry shader
// Pass uniforms & draw static meshes here
glBindFramebuffer(GL_FRAMEBUFFER, 0); // Unbind FBO
The code above functions correctly. The issue is when I try to add my animation shader into the mix. The following code is what I am currently using:
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glBindFramebuffer(GL_FRAMEBUFFER, gID); // Bind FBO
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(staticGeometryShaderID); // Bind static geometry shader
// Pass uniforms & draw static meshes here
glUseProgram(animationShaderID); // Bind animated geometry shader
// Pass uniforms & draw animated meshes here
glBindFramebuffer(GL_FRAMEBUFFER, 0); // Unbind FBO
The above example is the same as the last, except another shader is bound after the static geometry is drawn, which attempts to draw the animated geometry. Keep in mind that the static geometry shader and animated geometry shader are the EXACT SAME (besides the animated vertex shader which transforms vertices based on bone transforms).
The result of this code is my animated meshes are being drawn, not only for the current frame, but for all previous frames as well. The result looks something like this: https://gyazo.com/fef2faccbfd03377c0ffab3f9a8cb8ec
My initial thought when writing this code was that the things drawn using the animated shader will simply just overwrite the previous data (assuming that the depth is lower) since I'm not clearing the depth or color buffers. This obviously isn't the case.
If anyone has an idea as to how to fix this, that would be great!
Turns out that I wasn't clearing my vector of render submissions, so I was adding a new mesh to draw every frame.