See the former post about ARFoundation working on LWRP 3.3.0 for context.
TLDR: “lwrp-support” branch on arfoundation-samples repo has been updated to support the latest LWRP 4.8.0-preview.
The “lwrp-support” branch has a folder called LWRPSupport that has all the files needed. If you want to see a starter project that works with LWRP, open SampleLWRPScene using Unity 2018.3 and build it to your device - it should just work!
To make it work with an existing project, follow these steps:
You must change your whole project to use LWRP. See https://blogs.unity3d.com/2018/02/2...er-pipeline-optimizing-real-time-performance/ (or for TLDR: create a LightweightRenderpipelineAsset and set it to the Renderpipeline parameter in Graphics settings).This might cause some of your existing materials to not work (even if you attempted to upgrade them). Fix these materials by replacing them with new materials that support LWRP. There is a folder called LWRPSupport in the root. This contains all the components needed to support LWRP for ARFoundation background rendering.
Next, locate your ARCamera game object which lives under the ARSessionOrigin game object, and examine it in the Inspector. Note the ARCameraBackground component. ARFoundation has the concept of a CustomRenderAsset which you can enable on your ARCameraBackground component. Check the “Use Custom Renderer Asset” on the component, which should reveal the “Custom Renderer Asset” parameter. Into this parameter, drag the LWRPBackgroundRendererAsset asset from the LWRPSupport folder.
This should setup everything you need to make your app render the scene properly with LWRP. For more information on how this works, you can look at the source files in the LWRPSupport folder. There is some functionality in ARFoundation that was added to change the background renderer from the default behavior to use the CustomRendererAsset specified one.
LWRPSupport folder contains shaders, materials and scripts that support the renderer above. It also contains a LWRPBackgroundRendererAsset that is used to provide the renderer and its settings to ARFoundation. To create one of these assets, select Assets>Create>XR>LWRPBackgroundRendererAsset which should create the asset in your project folder. In order for the background rendering shaders to be included when building your project, it needs to be referenced from somewhere, and this asset also allows you to reference the materials that use those shaders so that they are included.
If you want to take advantage of the shader graph you will need to make sure to import the same version as the LWRP you’re using. To do this open the package manager and click Advanced → Show preview packages, next locate Shader Graph and select the version number in the upper corner. Under All versions locate 4.8.0-preview and click Install.
Please watch the arfoundation-samples project for future examples that include shader graphs. And enjoy making cool new content with ARFoundation and LWRP!
We are working on AR car project with lwrp using AR foundation…
We experience some problems with consistency of the appearance when we build it for iOS… even without AR
Sorry to hijack, But I’m having the below trouble with ARFoundation and the LWRP.
As you can see, initially the camera works, but as soon as we see the AR content, (either the cube or the plane mesh) the background disappears.
I’ve followed the above instructions to get the LWRPSupport folder and added the LWRPBackgroundRendererAsset to the camera. (Which fixed an earlier all black screen issue I had been having.)
I’m using unity 2018.3.2f1, ARFoundation preview 22, ARCore preview 24, ARKit preview 23, and LWRP 4.8.0.
I have an issue that appeared after upgrading our project in using LWRP. Before the upgrade, I was able to access the Camera.main.activeTexture. However, now Camera.main.activeTexture appears to be null.
To work around this issue, I have attempted assigning a render texture to the camera’s target texture, and access the targetTexture instead such as:
RenderTexture = new RenderTexture(Screen.width, Screen.height, 24, RenderTextureFormat.ARGB32);
Camera.main.targetTexture = RenderTexture;
However, it doesn’t look like LWRP likes the camera having a targetTexture assigned to the camera.
The above is all happening in OnPostRender() which is listening for RenderPipeline_beginFrameRendering:
If you are doing anything fancy with customizing the rendering as you appear to be doing, you will need to look at how LWRP works now - it throws out the legacy render pipeline and rejiggers it to do it differently. So you will have to redo your rendering to work within the process of LWRP. If its just a post processing effect you want, you might be able to achieve it via PostFx v2 which should be supported by LWRP: https://blogs.unity3d.com/2018/06/11/postfx-v2-amazing-visuals-upgraded/
I would like to grab the camera’s activeTexture.GetNativeTexturePtr() and pass it to another client so it can render the camera on the client side. Since Camera.activeTexture is null after the LWRP upgrade, how would I go about in accessing the active camera texture?
Read that the following might work, but its still rendering a black screen for me:
var rt = RenderTexture.GetTemporary(Screen.width, Screen.height, 24);
Texture2D actual = null;
try
{
Camera.main.targetTexture = rt;
Camera.main.Render();
Camera.main.targetTexture = null;
actual = new Texture2D(Screen.width, Screen.height, TextureFormat.ARGB32, false);
RenderTexture.active = rt;
actual.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
RenderTexture.active = null;
actual.Apply();
// At this stage, the texture "actual" can be read form the CPU and contains what the camera sees.
m_androidJavaObjectRenderCallback.Call("onFrameResolved", actual.GetNativeTexturePtr().ToInt32());
}
finally
{
RenderTexture.ReleaseTemporary(rt);
if (actual != null)
UnityEngine.Object.Destroy(actual);
}
Thanks for the prompt response jimmya. The link looks like a way to “Accessing the Camera Image on the CPU”. However, I need to access the camera image on the GPU. I have tried the code in the link and the rendering is very laggy and distortioned, not exactly what I am looking for. I should have mentioned I am trying to access the AR camera image (using the latest ARFoundation XR Preview 22 and ARCore Preview 24).
Before the LWRP update I was able to access it by simply doing Camera.main.activeTexture.
After LWRP, Camera.main.activeTexture is always NULL.
Isn’t there a simple way to access the AR camera image using LWRP?
This is not possible in LWRP atm. The reason is that, although the camera target texture is available, it’s only exposed as an opaque handle, not the actual RenderTexture.
We plan to move away from CommandBuffer.GetTemporaryRT to an alternative that allow us non opaque handles. Then with that we can expose this to you.
I understand that, however although “actual” contains the texture, it is still outputting a black screen. I’ve try removing the code within “finally” where it destroys “actual” to no avail.
Must also add that I am looking for a solution where it doesnt need to manually readpixels every frame, rather set it up like a render texture where it assigns the texture to the camera’s targetTexture, and then pass a reference of this texture to another client for it to render the Unity camera (or even better, pass the reference to the camera’s activeTexture, but apparently this is not possible).
Thanks phil_lira, it sounds like there is no way to achieve this using LWRP.
EDIT: It appears the problem lies on LWRP & ARFoundation which forces you to “Use Custom Renderer Asset”. If this field is left unchecked, it works as expected. So the issue exists only when using both LWRP in conjunction with ARFoundation.
Just updated my project from LWRP 3.3.0 to 4.8.0 and now getting an error:
LWRPBeforeCameraRender.cs error CS0246: The type or namespace name ‘IBeforeRender’ could not be found
That usually means that your Package Cache may need to be cleared out. Go to your <PROJECT_FOLDER>/Library/PackageCache/ folder and delete all the folders there and then restart Unity and load your project.
I am getting this error while building in XCode. Can you please help me to resolve this problem.
Undefined symbols for architecture arm64:
"_UnityARKit_FaceProvider_TryGetFaceMeshIndices", referenced from:
_ARKitFaceSubsystem_UnityARKit_FaceProvider_TryGetFaceMeshIndices_m7A6FE458C958BF11AE24CA3274F463FD49C09BA2 in Bulk_Unity.XR.ARKit.FaceTracking_0.o
_ARKitFaceSubsystem_TryGetNativeFaceMeshIndices_m8378B9A3DF4C4ED0CFEA79A47DA170DCB2141785 in Bulk_Unity.XR.ARKit.FaceTracking_0.o
(maybe you meant: _ARKitFaceSubsystem_UnityARKit_FaceProvider_TryGetFaceMeshIndices_m7A6FE458C958BF11AE24CA3274F463FD49C09BA2)
"_UnityARKit_FaceProvider_TryGetFaceMeshVertices", referenced from:
_ARKitFaceSubsystem_UnityARKit_FaceProvider_TryGetFaceMeshVertices_mDB45907AF6B2DAC520DDAB919E284C17811C9735 in Bulk_Unity.XR.ARKit.FaceTracking_0.o
_ARKitFaceSubsystem_TryGetNativeFaceMeshVertices_m905544AB03379E3DF56E27ABB45416E4D032D866 in Bulk_Unity.XR.ARKit.FaceTracking_0.o
(maybe you meant: _ARKitFaceSubsystem_UnityARKit_FaceProvider_TryGetFaceMeshVertices_mDB45907AF6B2DAC520DDAB919E284C17811C9735)
"_UnityARKit_FaceProvider_Stop", referenced from:
_ARKitFaceSubsystem_UnityARKit_FaceProvider_Stop_m954FB8F865E3061633A492C20A8B428BCB36F51B in Bulk_Unity.XR.ARKit.FaceTracking_0.o
_ARKitFaceSubsystem_Stop_m1AAF46F54485390743C94368A40483C989F780A6 in Bulk_Unity.XR.ARKit.FaceTracking_0.o
(maybe you meant: _ARKitFaceSubsystem_UnityARKit_FaceProvider_Stop_m954FB8F865E3061633A492C20A8B428BCB36F51B)
"_UnityARKit_FaceProvider_Start", referenced from:
_ARKitFaceSubsystem_UnityARKit_FaceProvider_Start_mC62F8D50FCF282BE1305CB02D2058473A2EB7CBD in Bulk_Unity.XR.ARKit.FaceTracking_0.o
_ARKitFaceSubsystem_Start_mB474E9813C911E7B3464E3256A322DAEC2717D01 in Bulk_Unity.XR.ARKit.FaceTracking_0.o
(maybe you meant: _ARKitFaceSubsystem_UnityARKit_FaceProvider_Start_mC62F8D50FCF282BE1305CB02D2058473A2EB7CBD)
"_UnityARKit_FaceProvider_TryGetAllFaces", referenced from:
_ARKitFaceSubsystem_UnityARKit_FaceProvider_TryGetAllFaces_m020D1DDA108F03FE88F5ADB91D71F7BE25DF2C21 in Bulk_Unity.XR.ARKit.FaceTracking_0.o
_ARKitFaceSubsystem_TryGetNativeAllFaces_mE0E1C845A424571DE67EABF45FEA4DB941120B4D in Bulk_Unity.XR.ARKit.FaceTracking_0.o
(maybe you meant: _ARKitFaceSubsystem_UnityARKit_FaceProvider_TryGetAllFaces_m020D1DDA108F03FE88F5ADB91D71F7BE25DF2C21)
"_UnityARKit_FaceProvider_TryGetFaceMeshUVs", referenced from:
_ARKitFaceSubsystem_UnityARKit_FaceProvider_TryGetFaceMeshUVs_m98966A83FEE4630DE054B1BFB64ABE0C40EB5DA4 in Bulk_Unity.XR.ARKit.FaceTracking_0.o
_ARKitFaceSubsystem_TryGetNativeFaceMeshUVs_m82A19E753759869AECD51161E253A603DF88BED5 in Bulk_Unity.XR.ARKit.FaceTracking_0.o
(maybe you meant: _ARKitFaceSubsystem_UnityARKit_FaceProvider_TryGetFaceMeshUVs_m98966A83FEE4630DE054B1BFB64ABE0C40EB5DA4)
"_UnityARKit_FaceProvider_Shutdown", referenced from:
_ARKitFaceSubsystem_UnityARKit_FaceProvider_Shutdown_mC8D639F7AEBDED8A050942382892B17D4740EA9E in Bulk_Unity.XR.ARKit.FaceTracking_0.o
_ARKitFaceSubsystem_Destroy_m745B75DAD42DF40450B3CBA8FB33A87C087ABC86 in Bulk_Unity.XR.ARKit.FaceTracking_0.o
(maybe you meant: _ARKitFaceSubsystem_UnityARKit_FaceProvider_Shutdown_mC8D639F7AEBDED8A050942382892B17D4740EA9E)
"_UnityARKit_FaceProvider_SetFaceAnchorCallbacks", referenced from:
_ARKitFaceSubsystem_UnityARKit_FaceProvider_SetFaceAnchorCallbacks_m951AB71674E37F07CF5D28697F4A712F069236CC in Bulk_Unity.XR.ARKit.FaceTracking_0.o
(maybe you meant: _ARKitFaceSubsystem_UnityARKit_FaceProvider_SetFaceAnchorCallbacks_m951AB71674E37F07CF5D28697F4A712F069236CC)
"_UnityARKit_FaceProvider_Initialize", referenced from:
_ARKitFaceSubsystem__ctor_mC6439CD04A82E490E6463EC32FC4AE2317744054 in Bulk_Unity.XR.ARKit.FaceTracking_0.o
_ARKitFaceSubsystem_UnityARKit_FaceProvider_Initialize_m6D6491C57F7AB25359EE5D12F1BDACDA1F9B2636 in Bulk_Unity.XR.ARKit.FaceTracking_0.o
(maybe you meant: _ARKitFaceSubsystem_UnityARKit_FaceProvider_Initialize_m6D6491C57F7AB25359EE5D12F1BDACDA1F9B2636)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Hi all,
having a strange problem with rendering shadows in my scene. I have tried adjusting LWRP settings but with no luck. Maybe you might be able to suggest a solution.
Here is a iOS device screenshot, and editor screenshot as to how it should look.
It looks almost like the shadows have been inverted.
The problem persists with and without PostProcessing activated.
These are the shadow settings in LWRP Asset:
Shadow distance 250
4 Cascades
Depth Bias 1
Normal Bias 1
I also tried:
varying the depth bias.
disabling and enabling MSAA in the LWRP settings. (HDR and MSAA are off on the camera)
There is a single directional light in the scene, and I tried varying light estimation on and off.
My Setup:
MacOS
Unity 2018.3.0f2
ARFoundation 1.0.0.preview.22
ARKit XR Plugin 1.0.0-preview.23
Lightweight RP 4.9.0-preview