order - OpenGL sprite scene, using z-buffer with perspective projection and without distortion. Possible? -



order - OpenGL sprite scene, using z-buffer with perspective projection and without distortion. Possible? -

i'm working on sprite based games. z-ordering sprites there alternatives 1) draw in right order - can troublesome batching 2) utilize orthographic projection , depth testing - can troublesome translucency favoring 2) maintain perspective projection allow easy 3d animations. cards beingness flipped in 3d etc. if that, z-buffer differences may/will result in scaling of sprites, since objects @ different distances camera. thought scaling sprites based on distance undo projection. interference 3d animated objects on top of "non-flat" 2d scene. guess sane way is, go orthographic 2d scene , rare 3d animations in sec step "cloned" objects on top of it. maybe has different idea?

mikkokoos reply led solution. via additional depth value vertex shader can adjust z coords of vertices in clip space force them different depth layers. real 3d coords can remain @ z=0. changing in clip space eliminates perspective problems, perspective projection can used in scene. allow different photographic camera angles perpendicular sprite plane, instead of pushing sprite vertices fixed layers should adjusted "layeroffset * layeridx". every layer vertex gets pushed 1 step closer camera. note: fixed layers can tricky find out right clip space coordinates, since xy plane not in center. open questions: resolution of clip space? smallest coord difference in clip space? possible interference between pushed sprites , real 3d elements? prevent plane sprites overdrawing 3d objects, non-sprite-plane-objects should pushed maximum used layer offset. calculating layer offset available space in front end of photographic camera idea. achieved: sprites organized on 2d plane in perspective projected 3d scene. sprites occluded based on fragment depth, calculated in shaders. drawing can still done in texture batches. note2: still consider doing 2 batched draw runs. 1st 1 2d sprites adjusted depth, 2nd 1 sprites or objects not "attached" sprite plane. clearing depth buffer inbetween , adding invisible sprite plane clipping. (if no objects behind stage allowed) pics: http://www.imagebam.com/image/109f6e356918267 http://www.imagebam.com/image/a2085f356918275

you utilize perspective projection render sprites , have uniform float "depth" each substitute gl_position.z @ end of vertex shader:

gl_position.z=(u_zoffset-1.0)*gl_position.w;

this "flatten" mesh, if meshes more complex , depending on used depthfunc, might want have range instead. (visible range -1 1):

gl_position.z=((1.0+(gl_position.z/gl_position.w))*u_zrange+u_zoffset-1.0)*gl_position.w;

where u_zrange 2f/(number_of_layers) , u_zoffset u_zrange*layer_id. layer 0 closest.

edit: summary: set through mvp matrix @ same distance camera, modify z value in vertex shader order them on screen.

order opengl-es-2.0 sprite perspective depth-buffer

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -