documentation

Universal Render Pipeline Support
URP_Banner.png

VisionLib can be used seamlessly in Unity projects that make use of the Universal Render Pipeline.

Using the VisionLib in a new URP project scene

Create a new Unity Project using the Universal Render Pipeline template.

URP_Template_selection.png

Open the Unity Package Manager to install the package VisionLib.SDK.Unity.X.Y.Z.tgz from the root folder in the current VisionLib.SDK.Unity release. See also Install VisionLib Packages in Unity.

After that, import the Unity example from VisionLib.SDK.Examples-Unity.X.Y.Z.unitypackage in the Extensions folder.

Now, open any of the scenes in Assets > VisionLib Examples > Scenes.

Read UnitySDK Quick Start, for more details on that.

Adding URP support to an existing VisionLib scene

Follow the official Unity guide to convert your existing project to use Universal Render Pipeline.

Furthermore, the default shader used as the init pose guide doesn't work with URP and can't be automatically converted, so it has to be exchanged manually with an URP-compatible shader. The DifferentAugmentation and the TrackingOccluder scene use this shader and therefore cannot be correctly started on URP.

You can use the following shader to replace the old shader located at Packages/VisionLib SDK/Core/Materials/Shaders/transparentWithDepthPass. It mimics the behaviour of the default (non-URP) shader:

Shader "VisionLib/Transparent Lambert with Z Pass (URP)"
{
Properties
{
_Color ("Main Color", Color) = (1,1,1,0.5)
_BaseMap("Texture", 2D) = "white"
_LightDir("Light Direction", Vector) = (-1,0.5,0.5,1)
}
SubShader
{
Tags
{
"RenderType"="Transparent" "Queue"="Transparent" "IgnoreProjector"="True"
}
// Render backfaces. Could be disabled if the models are apropriate
Cull Off
// "Pre-Z" depth pass
// This is to avoid rendering faces behind each other. In this pass the depth buffer is set to the face in front,
// in the next pass only the face with exactly this depth is rendered
Pass
{
Tags { "LightMode"="SRPDefaultUnlit" }
ZWrite On
// Only write depth, no color
ColorMask 0
}
// Color pass
Pass
{
Tags { "LightMode"="UniversalForwardOnly" }
// Only render fragments with the exact depth determined in the depth prepass
ZTest Equal
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
// Make inputs accessible to shader
TEXTURE2D(_BaseMap);
SAMPLER(sampler_BaseMap);
CBUFFER_START(UnityPerMaterial)
// The _ST suffix is necessary for tiling and offset to work.
float4 _BaseMap_ST;
half4 _Color;
float4 _LightDir;
CBUFFER_END
struct VertInputs
{
float4 positionOS : POSITION;
float3 normal : NORMAL;
float2 uv : TEXCOORD0;
};
struct VertOutputs
{
float4 position : SV_POSITION;
float3 normal : TEXCOORD1;
float2 uv : TEXCOORD0;
};
// Vertex shader
VertOutputs vert(VertInputs inVert)
{
VertOutputs outVert;
outVert.position = TransformObjectToHClip(inVert.positionOS.xyz);
outVert.normal = mul(unity_ObjectToWorld, float4(inVert.normal.xyz, 1.0));
outVert.uv = TRANSFORM_TEX(inVert.uv, _BaseMap);
return outVert;
}
// Fragment shader
half4 frag(VertOutputs i) : SV_Target
{
// Simple lambert lighting calculation
float intensity = dot(_LightDir, i.normal);
// Clamp light intensity from -1:1 to 0.15:0.95 to avoid clipping out any detail on the opposing side of the light
// These values were chosen arbitrarily to show enough detail in both dark and light areas
intensity = intensity / 2.5 + 0.55;
half4 baseColor = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, i.uv) * _Color;
half4 outColor = baseColor * half4(intensity, intensity, intensity, 1);
return outColor;
}
ENDHLSL
}
}
}