Welcome to the Oculus Developer Forums!

Your participation on the forum is subject to the Oculus Code of Conduct.

In general, please be respectful and kind. If you violate the Oculus Code of Conduct, your access to the developer forums may be revoked at the discretion of Oculus staff.

some question for Blend Render Compositor layer( OvrOverlay ) with Opaque & Transparent model

wangxiaoganganwangxiaogangan Posts: 21
Brain Burst
First of all, Compositor layer contain two type, called them  Overlay and Underlay. i have readed the post https://forums.oculusvr.com/developer/discussion/comment/536880#Comment_536880 which talk about how the 3d model correctly show or hide while using Compositor layer. 

i want ask a extra qustion to confirm my assumption for using Compositor layer right.

Is Oculus Gear vr home app using "Underlay" to Render Ui Panel ?

oculus staff said "we do use overlay in Gear VR home,  and the fact is that everything is made by overlay in gear VR home", while gear controller & its white laser can display in front of ui panel shown below.

if gear home using "Overlay" not "Underlay" to render ui panel into cylinder, i do not figure out a valid method to render controller & its laser in front of ui panel, because of "Overlay" blend with eye buffer using Overlay Rt's alpha value. while "Underlay" blend using eye buffer's alpha value.

using Overlay Rt's alpha value for blend and "Overlay" render in front of all things, make the "Overlay" layer can not leak a hole to show the controller.

consider what i assume is right, there must be "Underlay". so gear vr home need "poke a hole" for eye buffer while shader the hole's alpha = 0, which ui panel can blend into eye buffer correctly. 

Finally, the render action list for using Compositor layer combine with controller & room shown below:

1. render cinema and some opaque things  except gear controller

2. render some transparent things except gear controller laser

3. in simple, clear total eye buffer alpha into 0

4. render controller & laser, write them alpha to corresponding  location

4. Underlay ui panel blend with eye buffer, leave eye buffer alpha = 1 not blend

so, Is it right render order for gear vr home ?  but the method above can not handle the situation while gear controller behind the UI panel render using "Underlay" because their alpha already = 1.

Or there contian other method to use"Overlay" render ui and make contrller render right? thanks for your time





Comments

  • wangxiaoganganwangxiaogangan Posts: 21
    Brain Burst
    edited June 2018
    After some experiment,i should post some detail information for "Overlay" & "Underlay".

    1. If using "Underlay" to render something, in ther first we should know that "Underlays depend on the alpha channel of the render target.", which render target is eye buffer. 

      base on this rule, if we want render a ui panel ( panel contian white background and 3 image )  shown belown with "Underlay", we should clear eye buffer's alpha = 0, so ui panel can blend with eye buffer.

    the easy  way to clear alpha in the demo is draw a black quad with shader "Underlay Impostor" in the same position of "underlay" quad. 


    2. what make me feel very odd is the blend formula for "Underlay" & eye buffer.

        if i change the black quad, which clear alpha = 0 & shader using "Underlay Impostor", make its color into green,

        i found that even though green quad's alpha =0, underlay still can blend its color with green quad.

        this confirm the blend formula is not in the default way, which is 

        eye.Color * eye.Alpha + underlay.Color * (1 - eye.Alpha)

        SO, event eye buffer aplha = 0, i still found no way to just show ui panel's color. that is very unreasonable for the situation using "Underlay" to draw a panel.

    ( in addition, i know "overlay" can blend very well because its using "overlay" rt's alpha, but "overlay" can not handle 3d model in front of panel. For example in the pic, white ball will always hide behind overlay panel ) 


    3. Could oculus staff give a function to change the blend formula in the later version? i need this default blend method very much to draw ui panel using "underlay"  

  • vrdavebvrdaveb Posts: 1,596 Oculus Staff
    Is Oculus Gear vr home app using "Underlay" to Render Ui Panel ?
    Yes, Oculus Home has 4 layers, which are rendered in the following order:
    1. Cubemap background
    2. Cylinder panel (tile grid)
    3. Cursor
    4. Eye buffers (controller geometry)
    Each layer is blended on top of the previous ones using src.a * src.rgb + (1-src.a) * dst.rgb. So we set a=0 in each layer to "poke a hole" for the previously-rendered layer(s) to show through. In Unity, you can use the "Underlay Impostor" shader to poke a hole for OVROverlay underlays. Sorry this isn't in the documentation yet, we're updating it. For performance reasons, we can't easily change the blending formula, but you can change the compositing order by activating your OVROverlay instances in a different order. "Underlay" layers simply composite before the eye buffers and "overlay" layers composite after them.
  • wangxiaoganganwangxiaogangan Posts: 21
    Brain Burst
    I'm truly grateful for your help. And the render order your listed above is very clear to let "underlay" render right.

    but i think there are some bugs for "underlay" tech because the rules you mentioned contradict with render result using unity 2017.3.1 & sdk-1.25. 

      1."Each layer is blended on top of the previous ones using src.a * src.rgb + (1-src.a) * dst.rgb." 
      2."Underlay" layers simply composite before the eye buffers"

    first, there is a scene looks like  below:


    plane impostor using shader "Underlay Impostor" to clear alpha = 0, which "poke a hole" for the previously-rendered layer(s) to show through.

    plane overlay at same position with plane impostor, "plane overlay" render a underlay quad

    the bug appears step by step.

    1.  underlay quad panel render first, texture like below   

    2.  blend eyebuffer with 1 result 

    while doing blend operation with already rendered "underlay",  if using src.a * src.rgb + (1-src.a) * dst.rgb." ,
    (first we should agree on the src.a means eyebuffer.alpha not 1's alpha in this situation )

    we using "plane imposter" to poke the hole which size equals "plane imposter".

    src.a( hole alpha = 0 ) * src.rgb + (1 - src.a) * dest.rgb = dest.rgb,

    which means the "hole's" render result should be only the underlay's color = dest,rgb

    but the result is:


    the render result shows that: 
    even though the hole's alpha = 0, underlay still blend with eyebuffer( underlay render first, then the eyebuffer which contian a hole). Is it a bug for alpha = 0 and  still blend two textures color not just dest.rgb?  or unity sdk behaivor diff with oculus home app which develop from native framework?

    you can find the scene from UnderlayExample.unitypackage at underlayquad.scene~~ change 
    plane imposter material's color to confirm what i said.
  • wangxiaoganganwangxiaogangan Posts: 21
    Brain Burst
    vrdaveb said:
    Each layer is blended on top of the previous ones using src.a * src.rgb + (1-src.a) * dst.rgb. 
    is any update to explain the above phenomenon?
  • vrdavebvrdaveb Posts: 1,596 Oculus Staff
    edited July 2018
    Sorry for the confusion and delay here. Our Underlay_Impostor shader is based on Unity's Standard Shader, which doesn't have the alpha behavior you are looking for. I would recommend using Oculus/Unlit Transparent Color for your your object.
  • wangxiaoganganwangxiaogangan Posts: 21
    Brain Burst
    thank you very much, i can not blend right without your help!!!!
  • wangxiaoganganwangxiaogangan Posts: 21
    Brain Burst
    edited January 13
    if you  want render something infront of Compositor layer something like 3d mesh, the layer must be underlay.
    the blend forumla is not the default one --  eye.Color * eye.Alpha + underlay.Color * (1 - eye.Alpha)

    the blend formula  should be eye.Color + underlay.Color * (1 - eye.Alpha) or
                                                  eye.Color * eye.Alpha + underlay.Color 

    i forgot which one is correct, you could try both.

    so, if you want blend right, the hole you render in unity should multi alpha in frag shader first when formula is
    eye.Color + underlay.Color * (1 - eye.Alpha) 

    the  Compositor layer kills performance in android device develop by unity, which using a lot of blit operations. you could add native plugin to save blit operation by tex getnativeptr & opengl code, which direct render into overlay


Sign In or Register to comment.