opengl - Write to gl_FragDepth. Precision? -


what i'm trying do:

  1. render each mesh of scene in single pass
  2. blend result of each pass final image respect depth of each mesh.

i rendering meshes 1 render pass per mesh, storing color , depth in fbo per mesh. depth component each mesh's fbo has 32 bits.

finally, screen filling quad rendered , color of each fbo written final fbo out vec4 fragcolor , depth gl_fragdepth, layout(depth_any) out float gl_fragdepth. depth func set gl_lequal.

if 2 meshes same, i'd expect see mesh blended last scene because of gl_lequal. noise, fragments of last mesh pass depth test, don't.

basically copying depth values 1 fbo , seems induce errors. accessing depth component tried both, binding texture sampler2d , sampler2dshadow.

as test did following: instead of full screen quad, meshes rendered again depth test color values of surviving fragments of according fbo written final fbo. gives expected result in case 2 meshes same.

where loss of precision come from, when reading depth component texture , writing gl_fragdepth?


edit

full screen quad approach img

this image produced following way:

  1. the gray colored mesh see rendered twice, same shaders , same input model view projection. no other uniforms affect vertex transform. black contour lines can ignored.
  2. both meshes have own fbo (fbo_a , fbo_b) textures output variables color , depth , depth attachment. depth per pixel computed in fragment shader , written 2d texture (with invariant qualifyer), in addition standard depth attachment.
  3. in second step screen filling quad rendered fbo_final. color values of fbo_a written color output , depth values of fbo_a written gl_fragdepth. tried both, taking depth values manually computed output , standard depth attachment.
  4. now post processing done on color of fbo_final, highlight errors lets clear color white. depth of fbo_final not cleared.
  5. the screen filling quad rendered again, time accessing fbo_b in same way in 3.

this result shown in image above. second run of screen filling quad had fragments not passing depth test gl_lequal, gives sight on clear color.

mesh approach img

this image generated in same way in full screen quad approach. difference in step 3. , 5. now, instead of quad original mesh rendered generate fragments access fbo_a , fbo_b.

that means, color written fbo_final fragment shader , depth written automatically pipeline instead of writing gl_fragdepth in fragment shader. result correct.


actually found mesh approach faster , gives expected results. anyway still curious why other approach fails.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -