3d - OpenGL depth sorting fails on single mesh, when rendering to framebuffer instead of screen -


as simple demonstration of problem, trying render large simple mesh texture used later, strangely enough, further-away-from-the-camera parts of mesh displayed in front of closer-to-the-camera parts, when viewed specific angle. despite undeniable fact beyond doubt use depth testing:

glenable(gl_depth_test); gldepthfunc(gl_less);  

as example, trying render subdivided grid (on xz plane) centered on origin, smooth "hill" in middle of grid.

when rendered screen no errors occur , mesh looks (rendered using orthographic projection, , greyscale color representing depth, no error furthermore occur if mesh viewed side):

rendering directly screen, no errors occur, when mesh rotated

rendering screen of course done making sure framebuffer set 0 (glbindframebuffer(gl_framebuffer, 0);), need render scene framebuffer not screen, in order use render texture.
have set framebuffer, , output texture, , redering scene framebuffer (with absolutely nothing changed, except framebuffer , viewport size, set match output texture). purpose of demonstrating error, experiancing, then rendering rendered texture, onto plane displayed on screen.

when mesh rotated seen positive x axis, , rotated around y axis, centered on origin between -0.5 π rad , 0.5 π rad, rendered texture looks identical result when rendering screen, seen on image above.

however when rotation around y axis greater 0.5 π rad or less -0.5 π rad closer-to-the-camera hill rendered behind further-away-from-the-camera plane (the fact hill closer camera can proven looking @ color, represents debth):

enter image description here

(whoops got title wrong on window, ignore that)

in borderregions rotation around y axis of close 0.5 π rad or -0.5 π rad scene looks this.

enter image description here

(whoops got title wrong on window again, ignore again)

to recap. error depth sorting happens when rendering texture using framebuffer, , when object viewed specific angle. when object rendered directly screen, no error occurs. question therefor: why happen, , how (if @ all) can avoid avoid it.

if problem happens when you're rendering texture framebuffer, don't have depth attachment linked it.

make sure during fbo init linking depth texture well. there's example of how here.

also, check of matrices you're using render -- i've had several cases in past improper matrices have thrown off depth calculations.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -