I have to develop a visualization toolkit and know I search the best way to implement.
My idea is to take a FBO and render all the needed scenes (the main scene, depth map, normal map, color picking, …) and store them in the different color attachments. Than I want to work with the different attachments.
My first question: Is this a good approach for such a project?
I want to use shader for lighting, depth map, color picking etc.
Is it possible and efficient to render the scene once with one glDrawElements or glDrawArray and create the different scene/maps with different shader? I ask because I’m relative new in shader technique and I don’t want to waste time trying to implement an impossible technique.
My last to question:
Has anyone examples for render different texture/color attachments with multiple shader?
And is it possible to copy a color attachment into the frontbuffer to display the scene in the window? Or do I have to a quad in the viewport an map the color attachment as texture?
Use deferred shading as it separates the shaders for rendering the geometry from the shaders used by the lighting phase. This makes shader writing simpler and more elegant.
Deferred rendering is a multi-pass algorithum; geometry pass to write to scene depth (buffer), colour and normal. Deferred shadow pass to perform shadow map calulations; Lighting pass to perform lighting calculations (and apply shadow maps); and in your case a colour-picking pass.
The geometry phase of deferred shading will render all your opague objects to the framebuffer (bound with it’s colour attachments) and will output to the depth, albedo and normal attachments.
I’d suggest you switch shaders and then rendder the scene again using the color picking shader - outputting to the color picking attachment.
It is possible with glFrameBufferBlit. However you’d probably find is better to use a quad and render the ‘final’ FBO texture to the main window. This has the advantage that you can apply post-processing effects such as bloom, blur, tone mapping or anything else you can imagine.
There are plenty of examples out there of FBO attachments and getting a shader to write to the colour attachment(s).
If your using compatability profile then glDrawBuffers sets up the FBO with the colour buffers; and in the shader instead of glFragcolor use glFragData[n] to output to the nth colour attachment specified with glDrawBuffers.