opengl es - Stencil buffer clear values not 0? -
opengl es - Stencil buffer clear values not 0? -
ive been trying understand / debug problem stencil buffer. dont understand how works versus how think works. have scene render solid objects , assign them stencil value of 1. go through same scene again, sec time render transparent objects , give them stencil value of 2. in final step have screen quad draws scene texture. want utilize stencil buffer draw final quad stencil bits set 1 or 2. in code:
// first enable stencil buffer gl.enable( gl.stencil_test ); gl.clearstencil( 0 ); gl.clear(gl.stencil_buffer_bit); // presumably clears buffer 0? // ...for solid meshes gl.stencilfunc( gl.always, 1, 0xffffffff ); // pass stencil gl.stencilop( gl.replace, gl.replace, gl.replace ); // replace stencil value ref=1 // ...for transparent meshes gl.stencilfunc( gl.always, 2, 0xffffffff ); // pass stencil gl.stencilop( gl.replace, gl.replace, gl.replace ); // replace stencil value ref=2 // ...for final screen quad gl.stencilfunc( gl.gequal, 1, 0xffffffff ); // draw bits higher 1 (so 1 , 2 should included) gl.stencilop( gl.keep, gl.keep, gl.keep); // dont touch stencil values in buffer
however never seems work. tests seems though stencil values set 0xffffffff before assign them values. makes gequal test pointless buffer values greater 0.
i created js fiddle demo mean. draw little square , assign values 4. draw bigger square , test gequal 5. have thought bigger square fail. passes. when test using gl.stencilfunc( gl.gequal, 4, 0xffffffff ); see right little square only. when test gl.stencilfunc( gl.gequal, 0xffffff, 0xffffffff ); looks correct. me says stencil buffer not set 0?
http://jsfiddle.net/90af0rov/
im confused , appreciate pointers on <:(
you getting gequal operation wrong way around in stencilfunc. see documentation here: https://www.opengl.org/sdk/docs/man2/xhtml/glstencilfunc.xml
gl_gequal passes if ( ref & mask ) >= ( stencil & mask ).
so in code example, draw when ref (which 1) greater equal value in stencil buffer. if alter to:
gl.stencilfunc( gl.less, 0, 0xffffffff );
then should prepare it, pass if ref of 0 less value in stencil buffer. utilize notequal instead of less in case.
opengl-es webgl
Comments
Post a Comment