This tutorial is about using an amazing Spatial Augmented Reality SDK called Immersal in Unity, combining ARFoundation and ARKit or ARCore.

Now Immersal offers a free commercial license for developers.

Pricing: 0 EUR/month

Mapping capacity

  • up to 300 images / map
  • up to 1000 maps / month

Cloud features

  • 300,000 on-server localizations / month
  • unlimited on-device localizations
  • 100,000 map downloads / month
A great work created by BitCrushingCog using ARKit+Immersal in Unity
  1. Create an account in Immersal Developer Portal: https://developers.immersal.com/
  2. Follow the offical video tutorial below to scan the space with Immersal App (iOS download from here, Android download from here), and after you successfully scan and upload, you might see map data in Immersal Developer Portal>Jobs, and you can get BYTES file in Downloadable files which is your own Map Data to use in Unity.
  1. Create a project in Unity 2019.4 or above
  2. Import ImmersalSDKv1_11_1.unitypackage (download from here)
  3. Delete Main Camera in the default scene and create XR>AR Session Origin and AR Session by right click in Hierarchy, and make sure the tag of AR Session Origin>AR Camera is set to MainCamera (which is the default ARFoundation settings can be found in any ARFoundation tutorial, tutorials in chinese recommend: iOS https://blog.csdn.net/yolon3000/article/details/93405795 Android https://blog.csdn.net/yolon3000/article/details/93061181)
  4. Go to Edit -> Project Settings -> Player -> Other Settings
  • Turn off the Auto Graphics API.
  • For Windows:
    • Set primary API to OpenGLES3
  • For iOS:
    • Set Graphics API to Metal.
    • Set Target Minimum Version to 11.3.
  • For Android:
    • Set Graphics API to OpenGLES3.
    • Set Minimum API Level to 26.
  1. Drag and drop ImmersalSDK from project>Assets>ImmersalSDK>Core>Prefabs into the scene.
  1. Add component AR Locailzer in ImmersalSDK
  1. Create Empty in Hierarchy named AR Space, drag and drop AR Space script from project>Assets>ImmersalSDK>Core>Scripts>AR.
  2. Create Empty as child of AR Space, named AR Map, drag and drop AR Map script from project>Assets>ImmersalSDK>Core>Scripts>AR.
  1. In Inspector of AR Map, drag and drop BYTES files download from Immersal Developer Portal into ARMap(Scripts)>Map File, and create a material using the shader below, you might see visualized spatial cloud data in the Scene.
Shader "Immersal/pointcloud3d"
{
	Properties
	{
        _PointSize("Point Size", Float) = 0.003
	}

		SubShader
	{
		Tags{ "RenderType" = "Opaque" }

		Pass
		{
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag

            #pragma multi_compile_fog

			#include "UnityCG.cginc"

			half _PointSize;

			struct Vertex
			{
				float3 vertex : POSITION;
				fixed4 color : COLOR;
			};

			struct VertexOut
			{
				fixed4 color : COLOR;
				float psize : PSIZE;
				UNITY_FOG_COORDS(0)
			};

			VertexOut vert(Vertex vertex, out float4 outpos : SV_POSITION)
			{
				VertexOut o;
				outpos = UnityObjectToClipPos(vertex.vertex);
				o.color = vertex.color;
				o.psize = _PointSize / outpos.w * _ScreenParams.y;
				UNITY_TRANSFER_FOG(o, outpos);
				return o;
			}
            
			fixed4 frag(VertexOut i, UNITY_VPOS_TYPE vpos : VPOS) : SV_Target
			{
				fixed4 c = fixed4(i.color);
				UNITY_APPLY_FOG(input.fogCoord, c);
				return c;
			}
			ENDCG
		}
	}
}
  1. Now you can put any content into the scene (I create an empty named Spatial Content as the child of AR Space and put all content in), and make the spatial augmented reality experience works.
  2. One more thing: there is a strange error when building in Xcode, called “Permission denied”, but it can be easily solved by typing “chmod -R 777 (your_file_name)” in terminal(终端).

发表评论