opengl - how to do customized stencil test in fragment shader -


in project, used 'discard' call perform customized stencil test, tries draw things on specified area defined stencil texture. here code fragment shader:

//get stencil value texture float value=texture2d( stenciltexture, gl_fragcoord.xy/1024.0).x; //check if value equals desired value, if not draw nothing if(abs(value-desiredvalue)>0.1) {     discard; } 

this code works, suffers performance problem because of 'discard' call. there alternative way through gpu shaders? tell me how.

if access texture, must suffer performance penalties associated accessing texture. in same way, if want stop fragment being rendered, must suffer performance penalties associated stopping fragments being rendered.

this true regardless of how stop fragment. whether it's true stencil test, shader-based discard, or alpha testing, of these encounter same general performance issues (for hardware discard leads significant performance problems, mobile hardware). exception depth test, , that's because of why hardware has problems discard.

for platforms discard has substantial impact in performance, rendering algorithm works optimally if hardware can assume depth final arbiter of whether fragment rendered (and thus, fragment highest/lowest depth wins). therefore, method of culling fragment other depth test interfere optimization.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -