c++ - OpenGL shading pipeline efficiency with FBOs -


i've been working on implementing deferred shading want have @ least 20 lights in scene. having problems making fast enough (and still am), made change have thought make slower, in fact double frame rate.

initial code:

geometrypassfbo = createfbo(); // position texture, normal texture, colour texture , depth buffer while (1) {     bind geometrypassfbo.     allobjects.draw();      bind systemfbo();     each light         send light info         draw light sphere sampling position, normal , colour textures.      blit depth buffer geometryfbo systemfbo      each light         light.draw(); // draw cube represent light      2dobjects.draw(); // frame rate, etc... } 

i in process of setting stencil test lighting pass if pixel set during geometry pass (ie background normal = 0,0,0 , position = 0,0,0 , colour = 0,0,0.

however having difficulty copying combined depth / stencil buffer default depth / stencil buffer. apparently doesn't work great, don't know format system depth / stencil buffer takes. had read better setup fbo can specify depth / stencil buffer format, render this, , either blit or render screen quad out screen.

so before adding stencil stuff, added new fbo bit working.

my new code looks like:

geometrypassfbo = creategeometryfbo(); // position texture, normal texture, colour texture , depth buffer lightingpassfbo = createlightingfbo(); // colour texture , depth buffer while (1) {     bind geometrypassfbo.     allobjects.draw();      bind lightingpassfbo();     each light         send light info         draw light sphere sampling position, normal , colour textures.      blit depth buffer geometryfbo lightingpassfbo      each light         light.draw(); // draw cube represent light      2dobjects.draw(); // frame rate, etc...      bind systemfbo;     render screen quad sampling colour texture. } 

this works expected. not expected frame rate jumped 25 fps 45 fps.

why this? how can having additional shader pass screen quad more efficient not doing?

quick follow question. more efficient rendering screen quad using simple vertex , fragment shader sample texture based on gl_fragcoord, or blitting colour attachment directly system fbo?

well, it's this:

blit depth buffer geometryfbo lightingpassfbo

as point out, format conversion can slow. since you're defining both input , output buffers blit operation, they're using same depth format. blitting operation may proceed faster.

also, shouldn't blit @ all. attach geometryfbo's depth/stencil buffer lightingpassfbo before render light cubes. remember remove attachment afterward rendering lights (otherwise deferred pass have undefined behavior, assuming you're reading depth buffer in deferred pass).

as question blitting vs. full-screen quad, have better question: why accumulating 20+ lights in scene , not using high-dynamic range lighting? because final pass render screen should use tone-mapping convert hdr image ldr display.

but exact question, blit operation should no slower fsq, assuming there no format conversion going on. if there format conversion happening, more efficient take things vertex shader.


Comments