Search Unity

Post image effect with Single-Pass Stereo Rendering on GearVR

Discussion in 'Daydream' started by Epic_Cube, Nov 7, 2017.

  1. Epic_Cube

    Epic_Cube

    Joined:
    Jul 3, 2012
    Posts:
    100
    Hi all,
    I'm trying to use posto processing with Single-Pass Stereo Rendering on GearVR and DayDream.
    Now using Windows 10 + Unity 2017.2. My mobile device is a Samsung S6.
    My post effect consists of two steps:
    RenderWithShader renders the scene with my very-simple shader that draws everything is visible with White color
    Blit operations to perform more complex operations.
    Now I'm trying to make work the RenderWithShader operation. First of all: is it allowed to use RenderWithShader with single pass stereo rendering, or is there any issue related to its usage? Here it's the script code I use:
    Code (CSharp):
    1. RenderTexture tempRT1 = new RenderTexture( width, height, depth, format );
    2. [...]
    3. MyCamera.targetTexture = tempRT1;
    4. MyCamera.RenderWithShader( drawSimpleShader, "" );
    5. Graphics.Blit( tempRT1, destination );
    6.  
    I added to my shader all the additional instruction described in https://docs.unity3d.com/Manual/Android-SinglePassStereoRendering.html . Here it is the code (anything wrong?):

    Code (CSharp):
    1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
    2. Shader "ShaderTest/DrawSimple SPSR"
    3. {
    4.     Properties {
    5.         _MainTex ("Base (RGB)", 2D) = "" {}
    6.     }
    7.     CGINCLUDE
    8.    
    9.     #include "UnityCG.cginc"
    10.     // FOR SINGLE PASS STEREO RENDERING
    11.     //sampler2D _MainTex;
    12.     UNITY_DECLARE_SCREENSPACE_TEXTURE(_MainTex);
    13.     half4 _MainTex_ST;
    14.     struct appdata
    15.     {
    16.         float4 vertex : POSITION;
    17.         float2 uv : TEXCOORD0;
    18.     };
    19.     struct v2f {
    20.         float2 uv : TEXCOORD0;
    21.         float4 vertex : SV_POSITION;
    22.         UNITY_VERTEX_OUTPUT_STEREO
    23.     };
    24.    
    25.    
    26.    
    27.     v2f vert( appdata v )
    28.     {
    29.         v2f o;
    30.         // FOR SINGLE PASS STEREO RENDERING
    31.         UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
    32.         o.vertex = UnityObjectToClipPos(v.vertex);
    33.         o.uv = TRANSFORM_TEX(v.uv, _MainTex); // v.texcoord.xy;
    34.         return o;
    35.     }
    36.    
    37.     fixed4 frag(v2f i) : SV_Target
    38.     {
    39.         //        return 1-tex2D(_MainTex, i.uv);
    40.         // FOR SINGLE PASS STEREO RENDERING
    41.         UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
    42.         half4 col = tex2D(_MainTex, i.uv);
    43.         half val = col.r + col.g + col.b;
    44.         return (val > 0) ? 1 : 0;
    45.     }
    46.     ENDCG
    47.     Subshader
    48.     {
    49.         Pass
    50.         {
    51.               ZTest Always Cull Off ZWrite Off
    52.               CGPROGRAM
    53.               #pragma vertex vert
    54.               #pragma fragment frag
    55.               ENDCG
    56.         }
    57.     }
    58. }
    When I try to play it in my GearVR, I can see only a dark screen with a lighter blinking screen in the upper right corner of my FOV. I expect to see a full-white moving cube, but it is not visible at all.
    Any project/graphics/camera/anything-else setting missing or wrong?
    Please help.
    Thanks
     
  2. Epic_Cube

    Epic_Cube

    Joined:
    Jul 3, 2012
    Posts:
    100
    no help?
     
  3. scottb

    scottb

    Unity Technologies

    Joined:
    Jan 26, 2016
    Posts:
    13
    Hi, Unfortunately RenderWithShader() isn't currently supported with single-pass mode. We plan to look into it sometime soon, but I'm not sure when it will be resolved.
     
  4. Epic_Cube

    Epic_Cube

    Joined:
    Jul 3, 2012
    Posts:
    100
    Hi @scottb ,
    Thx for your reply. Some other questions please:
    1. Even SetReplacementShader + Render() will not work?
    2. In my post effect (in OnRenderImage) I'm cloning the main camera (with CopyFrom) because I need to render the same scene with a different layer mask, so, what I do is:
    Code (CSharp):
    1.  
    2. Camera OtherCamera.CopyFrom( mainCamera );
    3. [...SOME CAMERA SETUP...]
    4. OtherCamera.targetTexture= tmpRenderTexture; //a Render Texture I use for this camera
    5. OtherCamera.Render();
    6.  
    Then, I do a Blit operation from tmpRenderTexture to destination.
    Cloning and invoking Render() method on the OtherCamera will work or is there any issue?
    3. I made some modification to my shader to make it work in single pass stereo rendering, as I wrote above. Is it needed some modification in my post-image script? (all my work is executed in OnRenderImage)
     
  5. scottb

    scottb

    Unity Technologies

    Joined:
    Jan 26, 2016
    Posts:
    13
    Internally that method uses the same code as RenderWithShader(), so unfortunately it won't work either. One another note: changing render targets in a callback on mobile will eat up a lot of performance and battery, so I highly recommend not doing it.
     
  6. Epic_Cube

    Epic_Cube

    Joined:
    Jul 3, 2012
    Posts:
    100
    Thanks again for your reply @scottb .

    I'm currently modifing my outline system to make it work with single pass stereo rendering, so I really need to render the scene with a clone camera before applying post calculations, but if I cannot call Render() on it, how I can solve this issue?
    Do you know any workaround?

    ps.: I change targetTexture of my camera just once. Is it a problem anyway? Should I place it in a different place?

    thx in advance for your reply
     
  7. nat42

    nat42

    Joined:
    Jun 10, 2017
    Posts:
    353
    It seems that realtime shadow maps are kind of too expensive for GearVR & Daydream right now, and they are rendered at lower than full screen resolution. Maybe the world just isn't ready yet for mobile VR post processed outline rendering?

    Is the draw the geometry with flipped and pushed normals possibly an option? (though I take it that would double the draw calls, but you could use it selectively)
     
  8. Epic_Cube

    Epic_Cube

    Joined:
    Jul 3, 2012
    Posts:
    100
    Hi @nat42 ,
    thx for your reply. When rendering with clone camera, no shadow or light is considered (just because I actually don't need for them).

    Outline effect based on vertex displacement is not actually an outline. Try it on a cube, and you will see the difference :)
     
  9. nat42

    nat42

    Joined:
    Jun 10, 2017
    Posts:
    353
    I was comparing what your effect needs to the "effect" of shadow mapping.

    It's an outline effect - it has limitations/assumptions (I think your point is that it requires "smooth" normals?) I'm not saying it's as good as post process outlines from depth and/or normals, just that it's potentially cheaper on bandwidth.
     
  10. Epic_Cube

    Epic_Cube

    Joined:
    Jul 3, 2012
    Posts:
    100
    What do you mean?


    Thx for your suggest! ;-)
     
  11. pinkwerks

    pinkwerks

    Joined:
    Aug 26, 2014
    Posts:
    5
    I'm doing something very similar. Supposedly Camera.RenderWithShader was fixed for single pass stereo - but I'm not seeing it work for me yet :(

    https://issuetracker.unity3d.com/is...on-slash-offsets-according-to-camera-position

    I used to think I was having blit problems, but supposedly those were fixed too. As I asked about here:

    https://forum.unity.com/threads/2017-2-0f3-single-pass-stereo-blit.501804/#post-3286782

    I've since tried copying my RenderTexture.descriptor to benefit from vrUsage.TwoEyes, but still no luck. The left eye is rendering correctly. However, my right eye is offset.

    Code (CSharp):
    1.  
    2. void OnRenderImage(RenderTexture source, RenderTexture destination)
    3.         {
    4.             RenderTexture intermediateRenderTexture = RenderTexture.GetTemporary(source.descriptor);
    5.  
     
  12. DHARMAKAYA

    DHARMAKAYA

    Joined:
    Dec 1, 2014
    Posts:
    59
    Every person on this thread should open a Github issue about adding single pass stereo support to the Post Processing Stack here:
    https://github.com/Unity-Technologies/PostProcessing

    Thanks in advance. Seems a lazy Unity employee may be the cause, because bizarrely he seems to have been the only Unity employee assigned to make it compatible with single pass stereo...and he seemingly hasn't done much...if anything recently.

    Warning: Be prepared to get some excuses and references to 2017 commits in the replies from that particular employee. Respond by pointing out that those commits are relatively ancient now.
     
  13. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,360
    Hi,

    Any news on the single pass instanced on VR ? I use the things mentioned in the docs

    https://docs.unity3d.com/Manual/SinglePassInstancing.html
    https://docs.unity3d.com/Manual/SinglePassStereoRendering.html

    And the right eye is always black in Single Pass Instanced. I cannot say about simple Single Pass, as i use the MockVR, which for some peculiar reason has not got this emulation mode to test on.

    Thank you in advance for any help on this.

    I use quads to render my image effect and use "UnityStereoTransformScreenSpaceTex" to transform the UVs from vertex shader, plus have added all related directives and pragmas in the shader.