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

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

  • In the project's Assets folder, create a new folder named "Rendering".

  • In the Assets > Rendering folder, create a "ForwardRenderer" for your SRP.
    4911686--475520--create-forward-renderer.png

  • For LWRP, choose Create > Rendering > Lightweight Render Pipeline > Forward Renderer.

  • For URP, choose Create > Rendering > Universal Render Pipeline > Forward Renderer.

  • In the Inspector with the Forward Renderer selected, add a "ARBackgroundRendererFeature" to the list of Renderer Features.
    4911686--475517--add-renderer-feature.png

  • In the Assets > Rendering folder, create a "PipelineAsset" for your SRP.
    4911686--475523--create-pipeline-asset.png

  • For LWRP, choose Create > Rendering > Lightweight Render Pipeline > Pipeline Asset.

  • For URP, choose Create > Rendering > Universal Render Pipeline > Pipeline Asset.

  • In the Inspector with the Pipeline Asset selected, add the Forward Renderer.
    4911686--475532--set-renderer-data.png

  • Switch the Renderer Type to Custom.

  • Select the Forward Renderer that you created for the Render Type > Data field.

  • In Project Settings > Graphics, select the Pipeline Asset for the Scriptable Render Pipeline Settings field.
    4911686--475529--set-pipeline-asset.png

17 Likes

THX TODDS

1 Like

Thanks!

2 Likes

Amazing. Thanks, I look forward to testing this

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?

1 Like

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.

1 Like

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

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

[quote=“MF_Danny”, post:8, topic: 756403]
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
[/quote]

Click the “custom background” checkbox on the AR component.
Add a material that has this linear shader:

https://discussions.unity.com/t/705802/8

Camera will be crisp again

1 Like

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?

[quote]
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?
[/quote]

Just found it. The project still loaded v2 instead of v3-preview.

2 Likes

[quote=“Blarp”, post:9, topic: 756403]
Click the “custom background” checkbox on the AR component.
Add a material that has this linear shader:

https://discussions.unity.com/t/705802/8

Camera will be crisp again
[/quote]

Bloody legend, thank you very much!

1 Like

Hi. When creating a build for Android (ARCore), the camera background is always black. I managed to solve this problem by replacing the shader.

Shader "ALEXWICK/ARCore/ARBackground(Linear)"
{
    Properties {
        _MainTex ("Texture", 2D) = "white" {}
        _UvTopLeftRight ("UV of top corners", Vector) = (0, 1, 1, 1)
        _UvBottomLeftRight ("UV of bottom corners", Vector) = (0 , 0, 1, 0)
    }

    // For GLES3
    SubShader
    {
        Pass
        {
            ZWrite Off

            GLSLPROGRAM

            #pragma only_renderers gles3

            #ifdef SHADER_API_GLES3
            #extension GL_OES_EGL_image_external_essl3 : require
            #endif

            uniform vec4 _UvTopLeftRight;
            uniform vec4 _UvBottomLeftRight;

            #ifdef VERTEX

            varying vec2 textureCoord;

            void main()
            {
                #ifdef SHADER_API_GLES3
                vec2 uvTop = mix(_UvTopLeftRight.zy, _UvTopLeftRight.xw, gl_MultiTexCoord0.y);
                vec2 uvBottom = mix(_UvBottomLeftRight.zy, _UvBottomLeftRight.xw, gl_MultiTexCoord0.y);
                textureCoord = mix(uvTop, uvBottom, gl_MultiTexCoord0.x);

                gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
                #endif
            }

            #endif

            #ifdef FRAGMENT
            varying vec2 textureCoord;
            uniform samplerExternalOES _MainTex;

            void main()
            {
                #ifdef SHADER_API_GLES3
                gl_FragColor = texture(_MainTex, textureCoord);
                //gamma to linear conversion
        gl_FragColor.rgb = pow(gl_FragColor.rgb, vec3(2.2));
                #endif
            }

            #endif

            ENDGLSL
        }
    }

  Subshader
  {
    Pass
    {
      ZWrite Off

      CGPROGRAM

      #pragma exclude_renderers gles3
      #pragma vertex vert
      #pragma fragment frag

      #include "UnityCG.cginc"

      uniform float4 _UvTopLeftRight;
      uniform float4 _UvBottomLeftRight;

      struct appdata
      {
        float4 vertex : POSITION;
        float2 uv : TEXCOORD0;
      };

      struct v2f
      {
        float2 uv : TEXCOORD0;
        float4 vertex : SV_POSITION;
      };

      v2f vert(appdata v)
      {
        float2 uvTop = lerp(_UvTopLeftRight.zy, _UvTopLeftRight.xw, v.uv.y);
        float2 uvBottom = lerp(_UvBottomLeftRight.zy, _UvBottomLeftRight.xw, v.uv.y);

        v2f o;
        o.vertex = UnityObjectToClipPos(v.vertex);
        o.uv = lerp(uvTop, uvBottom, v.uv.x);

        // Instant preview's texture is transformed differently.
        o.uv = o.uv.yx;
        //o.uv.x = 1.0 - o.uv.x;
        //o.uv.y = 1.0 - o.uv.y;
        return o;
      }

      sampler2D _MainTex;

      fixed4 frag(v2f i) : SV_Target
      {
           return tex2D(_MainTex, i.uv);
      }
      ENDCG
    }
  }

  FallBack Off
}
3 Likes

Does ARFoundation support having no graphics pipeline set? The ARFoundation sample project did not have any render pipeline assigned. I'm getting a bunch of shader errors, and I'm getting a pink screen on my iPad. Please help.

Hi @_Daniel ,

  • What is the exact version of Unity?
  • What version of AR Foundation package?
  • What version of ARKit package?
  • What is the full version of Xcode including the build ID? E.g. "11.1 (11A1025)"
  • What is the full version of iOS are you using? Tap the short version value under Settings > About > SoftwareVersion, and it will shift to appear something like "13.1.2 (16A860)".
  • What is the model of device are you using? Tap the model number value under Settings > About > ModelNumber, and it will shift to appear something like "A1904".

Todd


2019.2.7f2

3.0.0 Preview 3

3.0.0 Preview 3

Version 11.0 (11A420a)

13.1 (17A844)

A2152

The default pipeline, the Legacy Render Pipeline, is what is used when the ProjectSettings > Graphics > ScriptableRenderPipelineSettings is set to None.

This is the state of the arfoundation-samples project in the master branch. It uses the Legacy RP.

What changes have you made to the arfoundation-samples project? Which of the sample scenes are you building?

Would you try pulling down a fresh copy of the arfoundation-samples project and building the SimpleAR scene with no project or scene modifications?

Todd


Ok, I didn't touch it or any settings. The only modification I made to the project was I enabled the HumanBodyTracking3D scene. I assumed I had to turn at least 1 scene on.


Ok, I did exactly that, and it crashes immediately. Please see attached screenshot of Xcode for more details.

5029370--492908--Screen Shot 2019-10-03 at 9.17.05 PM.jpg

on macOS Mojave 10.14.6 I always get this error:

Library/PackageCache/com.unity.xr.arsubsystems@3.0.0-preview.3/Runtime/XRSubsytstem.cs(50,40): error CS0115: 'XRSubsystem.OnDestroy()': no suitable method found to override

and I dont have a clue how to fix it.

1 Like

[quote=“enslaved2die”, post:19, topic: 756403]
on macOS Mojave 10.14.6 I always get this error:

Library/PackageCache/com.unity.xr.arsubsystems@3.0.0-preview.3/Runtime/XRSubsytstem.cs(50,40): error CS0115: ‘XRSubsystem.OnDestroy()’: no suitable method found to override

and I dont have a clue how to fix it.
[/quote]

Look what I´ve done here:

https://discussions.unity.com/t/756302 page-2#post-5028170

just change

#if UNITY_2019_3_OR_NEWER
protected sealed override void OnDestroy()
#else
public sealed override void Destroy()
#endif

to

#if UNITY_2019_3_OR_NEWER
public sealed override void Destroy()
#else
public sealed override void Destroy()
#endif

2 Likes