Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

setContext, shaders, draw order advice/question (bug perhaps?)

edited February 2014 in Shaders Posts: 49

In my ongoing quest to learn the ins and outs of glsl shaders stepping from a single image to a 2D scene took a little learning about frame buffers and setContext(). Drawing the scene off camera to apply the shader to the entire scene works fine for simple 2D but provides strange effects in 3D space. It seems that it has to do with the draw order of the objects. When drawing a 2D game, the order of the object change what will go behind what, but in 3D the draw order is handled by the device with things like depth buffers and math way over my head. This seams to be ignored when using setContext()


W/ ripple shader on Feb 25, 5 34 54 PM.mp4

W/ shader off Feb 25, 5 51 39 PM.mp4

Images Feb 25, 5 51 47 PM.png Feb 25, 5 52 43 PM.png

This might be a question that can be quickly explained with a "no" but I thought I might try:
Is there a way to solve this draw order problem?



  • IgnatzIgnatz Mod
    Posts: 5,396

    @1980geeksquad - the 3D depth setting does not work with setContext. The next version will hopefuly solve that.

  • Posts: 372

    There's a workaround for that though...

    Use this extension in the fragment shader

    #extension GL_EXT_shader_framebuffer_fetch : require

    And then use "gl_LastFragData[0].x" to get the depth of previous fragment.
    Found it useful while creating depth maps for shadowing.

    Here's the link to the post by space monkey who uses it for depth maps.

  • @Ignats - I sure hope so. I don't plan on using this idea right away, but in the future, it would be nice to have the option for some neat effects.

    @Saurabh - I'm not sure that is really helps my problem. A depthmap would be useful, but how would I pass that into the draw order and get rid of the oddities that I showed?

    Thanks for the help @Ignatz and @Saurabh. ;;)

  • edited February 2014 Posts: 372

    Double post

  • Posts: 372

    @1980geeksquad It should probably work this way....

    In the fragment shader,

    If (last depth > current depth) 
    Gl_FragColor = vColor

    I haven't tried it, but it should work.

  • Posts: 80

    I just saw this on codea commits Runtime - JohnTLL - Added depth attachment to setContext. :)

Sign In or Register to comment.