Search Unity

Configuring AR Foundation 3.0.0-preview to work with LWRP or URP

Discussion in 'Handheld AR' started by todds_unity, Aug 29, 2019.

  1. todds_unity

    todds_unity

    Unity Technologies

    Joined:
    Aug 1, 2018
    Posts:
    46
    With AR Foundation 3.0.0-preview, we are supporting Lightweight Render Pipeline (LWRP) or Universal Render Pipeline (URP).

    AR Foundation supports the two scriptable render pipelines:
    • Lightwight Render Pipeline (LWRP) - supported versions 5.7.2 or later
    • Universal Render Pipeline (URP) - supported versions 7.0.0 or later
    Note: Projects made using LWRP or URP are not compatible with the High Definition Render Pipeline or the built-in Unity rendering pipeline. Before you start development, you must decide which render pipeline to use in your Project.


    Basic Configuration for SRP with AR Foundation
    1. In the project's Assets folder, create a new folder named "Rendering".

    2. In the Assets > Rendering folder, create a "ForwardRenderer" for your SRP.
      create-forward-renderer.png
      • For LWRP, choose Create > Rendering > Lightweight Render Pipeline > Forward Renderer.
      • For URP, choose Create > Rendering > Universal Render Pipeline > Forward Renderer.
    3. In the Inspector with the Forward Renderer selected, add a "ARBackgroundRendererFeature" to the list of Renderer Features.
      add-renderer-feature.png

    4. In the Assets > Rendering folder, create a "PipelineAsset" for your SRP.
      create-pipeline-asset.png
      • For LWRP, choose Create > Rendering > Lightweight Render Pipeline > Pipeline Asset.
      • For URP, choose Create > Rendering > Universal Render Pipeline > Pipeline Asset.
    5. In the Inspector with the Pipeline Asset selected, add the Forward Renderer.
      set-renderer-data.png
      1. Switch the Renderer Type to Custom.
      2. Select the Forward Renderer that you created for the Render Type > Data field.
    6. In Project Settings > Graphics, select the Pipeline Asset for the Scriptable Render Pipeline Settings field.
      set-pipeline-asset.png
     
    Last edited: Aug 29, 2019
  2. Blarp

    Blarp

    Joined:
    May 13, 2014
    Posts:
    188
    THX TODDS
     
    todds_unity likes this.
  3. erfan_unity

    erfan_unity

    Joined:
    Apr 9, 2018
    Posts:
    2
    Thanks!
     
    todds_unity and Blarp like this.
  4. olemidt1

    olemidt1

    Joined:
    Mar 22, 2018
    Posts:
    3
    Amazing. Thanks, I look forward to testing this
     
  5. Saicopate

    Saicopate

    Joined:
    Sep 25, 2017
    Posts:
    58
    Anyone got it to work with 2019.3.0b1 + AR Foundation 3.0? I'm getting blue screen.

    EDIT: OK. I got it to work on a fresh project. However I have a problem converting from a existing one. Any tips to look for?
     
    Last edited: Sep 3, 2019
  6. Saicopate

    Saicopate

    Joined:
    Sep 25, 2017
    Posts:
    58
    Ok I got it to work. The problem was that the Canvas was displayed in "Screen Space - Camera" mode with a separate camera. After switching to "Overlay" all is fine.
    Would be nice of you guys to place a simple warning on this post that it does not work when there is a second camera e.g. for canvas rendering. This would spare me and future users a few hours of battling as it doesn't throw any warnings nor errors.

    On a side - LWRP is great (thanks for finally integrating it with ARF), but still we should have an option for a separate canvas camera to e.g. to render 3D objects.
     
  7. JohnKP-Mindshow

    JohnKP-Mindshow

    Joined:
    Oct 25, 2017
    Posts:
    23
    While easy to set up, a little frustrating we have to do this and doesn't work for our LWRP use case. We are using a custom SRP in the project folder (it's a very slight modification of the LWRP), so even though the fix should still be relevant to our SRP, its not working since it is looking for shaders hardcoded to a path in the package manager :(


    Trying to figure out the least hackiest work around, but any suggestions from the LWRP or ARFoundation devs would help
     
  8. MF_Danny

    MF_Danny

    Joined:
    Sep 4, 2019
    Posts:
    5
    Just updated to this, I seem to be coming across a gamma issue. My project is linear but my camera feed is definitely having gamma applied to it. Any help would be greatly appreciated - I'm a colossal noob at all of this stuff
     
  9. Blarp

    Blarp

    Joined:
    May 13, 2014
    Posts:
    188
    Click the "custom background" checkbox on the AR component.
    Add a material that has this linear shader:

    https://forum.unity.com/threads/linear-color-space-for-camera-background.537262/#post-4136656

    Camera will be crisp again
     
    MF_Danny likes this.
  10. gfellisch

    gfellisch

    Joined:
    Sep 2, 2019
    Posts:
    2
    I do not get the option to add "AR Background Renderer Feature" to the Renderer Features of my ForwardRenderer. The Project was created with LWRP and the ARFoundation Package ist installed.

    Any idea how I can fix that?
     
  11. gfellisch

    gfellisch

    Joined:
    Sep 2, 2019
    Posts:
    2
    Just found it. The project still loaded v2 instead of v3-preview.
     
  12. MF_Danny

    MF_Danny

    Joined:
    Sep 4, 2019
    Posts:
    5
    Blarp likes this.
  13. TapUp

    TapUp

    Joined:
    Oct 17, 2016
    Posts:
    2
    Hi. When creating a build for Android (ARCore), the camera background is always black. I managed to solve this problem by replacing the shader.


    Code (CSharp):
    1. Shader "ALEXWICK/ARCore/ARBackground(Linear)"
    2. {
    3.     Properties {
    4.         _MainTex ("Texture", 2D) = "white" {}
    5.         _UvTopLeftRight ("UV of top corners", Vector) = (0, 1, 1, 1)
    6.         _UvBottomLeftRight ("UV of bottom corners", Vector) = (0 , 0, 1, 0)
    7.     }
    8.  
    9.     // For GLES3
    10.     SubShader
    11.     {
    12.         Pass
    13.         {
    14.             ZWrite Off
    15.  
    16.             GLSLPROGRAM
    17.  
    18.             #pragma only_renderers gles3
    19.  
    20.             #ifdef SHADER_API_GLES3
    21.             #extension GL_OES_EGL_image_external_essl3 : require
    22.             #endif
    23.  
    24.             uniform vec4 _UvTopLeftRight;
    25.             uniform vec4 _UvBottomLeftRight;
    26.  
    27.             #ifdef VERTEX
    28.  
    29.             varying vec2 textureCoord;
    30.  
    31.             void main()
    32.             {
    33.                 #ifdef SHADER_API_GLES3
    34.                 vec2 uvTop = mix(_UvTopLeftRight.zy, _UvTopLeftRight.xw, gl_MultiTexCoord0.y);
    35.                 vec2 uvBottom = mix(_UvBottomLeftRight.zy, _UvBottomLeftRight.xw, gl_MultiTexCoord0.y);
    36.                 textureCoord = mix(uvTop, uvBottom, gl_MultiTexCoord0.x);
    37.  
    38.                 gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    39.                 #endif
    40.             }
    41.  
    42.             #endif
    43.  
    44.             #ifdef FRAGMENT
    45.             varying vec2 textureCoord;
    46.             uniform samplerExternalOES _MainTex;
    47.  
    48.             void main()
    49.             {
    50.                 #ifdef SHADER_API_GLES3
    51.                 gl_FragColor = texture(_MainTex, textureCoord);
    52.                 //gamma to linear conversion
    53.         gl_FragColor.rgb = pow(gl_FragColor.rgb, vec3(2.2));
    54.                 #endif
    55.             }
    56.  
    57.             #endif
    58.  
    59.             ENDGLSL
    60.         }
    61.     }
    62.  
    63.   Subshader
    64.   {
    65.     Pass
    66.     {
    67.       ZWrite Off
    68.  
    69.       CGPROGRAM
    70.  
    71.       #pragma exclude_renderers gles3
    72.       #pragma vertex vert
    73.       #pragma fragment frag
    74.  
    75.       #include "UnityCG.cginc"
    76.  
    77.       uniform float4 _UvTopLeftRight;
    78.       uniform float4 _UvBottomLeftRight;
    79.  
    80.       struct appdata
    81.       {
    82.         float4 vertex : POSITION;
    83.         float2 uv : TEXCOORD0;
    84.       };
    85.  
    86.       struct v2f
    87.       {
    88.         float2 uv : TEXCOORD0;
    89.         float4 vertex : SV_POSITION;
    90.       };
    91.  
    92.       v2f vert(appdata v)
    93.       {
    94.         float2 uvTop = lerp(_UvTopLeftRight.zy, _UvTopLeftRight.xw, v.uv.y);
    95.         float2 uvBottom = lerp(_UvBottomLeftRight.zy, _UvBottomLeftRight.xw, v.uv.y);
    96.  
    97.         v2f o;
    98.         o.vertex = UnityObjectToClipPos(v.vertex);
    99.         o.uv = lerp(uvTop, uvBottom, v.uv.x);
    100.  
    101.         // Instant preview's texture is transformed differently.
    102.         o.uv = o.uv.yx;
    103.         //o.uv.x = 1.0 - o.uv.x;
    104.         //o.uv.y = 1.0 - o.uv.y;
    105.         return o;
    106.       }
    107.  
    108.       sampler2D _MainTex;
    109.  
    110.       fixed4 frag(v2f i) : SV_Target
    111.       {
    112.            return tex2D(_MainTex, i.uv);
    113.       }
    114.       ENDCG
    115.     }
    116.   }
    117.  
    118.   FallBack Off
    119. }
     
    MF_Danny and Blarp like this.