4 Commits

Author SHA1 Message Date
Jedd Morgan 3d541484c7 Merge pull request #1 from specklesystems/Licence
Added licence
2023-09-11 18:27:29 +01:00
Jedd Morgan 7518b16c0e Add files via upload 2023-09-11 17:07:28 +01:00
Jedd Morgan 40ea10de36 Update README.md 2023-09-11 17:05:58 +01:00
Jedd Morgan fb44c40b9d Update README.md 2023-09-07 14:07:18 +01:00
54 changed files with 448 additions and 4984 deletions
-9
View File
@@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: 02185835049d6f84f8312b9e1b780ce8
folderAsset: yes
timeCreated: 1582138081
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
-9
View File
@@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: 85bec33395c45964c80151f894391ad1
folderAsset: yes
timeCreated: 1594311982
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
-9
View File
@@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: e4adc2a19e3e56947a59564eb243231e
folderAsset: yes
timeCreated: 1594311982
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
Binary file not shown.
@@ -1,69 +0,0 @@
fileFormatVersion: 2
guid: 4263a2cc16309384dbc7348be390b0eb
timeCreated: 1595528355
licenseType: Free
PluginImporter:
serializedVersion: 1
iconMap: {}
executionOrder: {}
isPreloaded: 0
isOverridable: 0
platformData:
Android:
enabled: 0
settings:
CPU: ARMv7
Any:
enabled: 1
settings:
Exclude Android: 1
Exclude Editor: 0
Exclude Linux: 0
Exclude Linux64: 0
Exclude LinuxUniversal: 0
Exclude OSXIntel: 0
Exclude OSXIntel64: 0
Exclude OSXUniversal: 0
Exclude Win: 1
Exclude Win64: 0
Editor:
enabled: 1
settings:
CPU: x86_64
DefaultValueInitialized: true
OS: Windows
Linux:
enabled: 1
settings:
CPU: None
Linux64:
enabled: 1
settings:
CPU: x86_64
LinuxUniversal:
enabled: 1
settings:
CPU: AnyCPU
OSXIntel:
enabled: 1
settings:
CPU: None
OSXIntel64:
enabled: 1
settings:
CPU: AnyCPU
OSXUniversal:
enabled: 1
settings:
CPU: AnyCPU
Win:
enabled: 0
settings:
CPU: None
Win64:
enabled: 1
settings:
CPU: AnyCPU
userData:
assetBundleName:
assetBundleVariant:
-9
View File
@@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: 5ed6ade9042a478f898fa6838de4c6e1
folderAsset: yes
timeCreated: 1510156134
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
-9
View File
@@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: 4d3ab40d452541f488a3aff2f1262b36
folderAsset: yes
timeCreated: 1510156134
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -1,90 +0,0 @@
Shader "Hidden/LIV_ClipPlaneComplex"
{
Properties{
_LivClipPlaneHeightMap("Clip Plane Height Map", 2D) = "black" {}
}
SubShader
{
Tags { "Queue" = "Overlay" "LightMode" = "Always" "IgnoreProjector" = "True" "ForceNoShadowCasting" = "True"}
Pass {
Name "CLIP_PLANE_COMPLEX"
Cull Off
ZWrite On
Blend Off
Fog{ Mode Off }
ColorMask[_LivColorMask]
CGPROGRAM
#pragma target 4.6
#pragma vertex TessellationVertexProgram
#pragma fragment FragmentProgram
#pragma hull HullProgram
#pragma domain DomainProgram
#include "UnityCG.cginc"
sampler2D _LivClipPlaneHeightMap;
float _LivTessellation;
struct VertexData {
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct TessellationFactors {
float edge[4] : SV_TessFactor;
float inside[2] : SV_InsideTessFactor;
};
struct TessellationControlPoint {
float4 vertex : INTERNALTESSPOS;
float2 uv : TEXCOORD0;
};
[domain("quad")]
[outputcontrolpoints(4)]
[outputtopology("triangle_cw")]
[partitioning("fractional_odd")]
[patchconstantfunc("PatchConstantFunction")]
TessellationControlPoint HullProgram(InputPatch<TessellationControlPoint, 4> patch, uint id : SV_OutputControlPointID) {
return patch[id];
}
TessellationFactors PatchConstantFunction(InputPatch<TessellationControlPoint, 4> patch) {
TessellationFactors f;
float t = _LivTessellation;
f.edge[0] = f.edge[1] = f.edge[2] = f.edge[3] = f.inside[0] = f.inside[1] = t;
return f;
}
[domain("quad")]
VertexData DomainProgram(TessellationFactors factors, OutputPatch<TessellationControlPoint, 4> patch, float2 uv : SV_DomainLocation) {
VertexData data;
data.uv = lerp(lerp(patch[0].uv, patch[1].uv, uv.x), lerp(patch[3].uv, patch[2].uv, uv.x), uv.y);
float4 vertex = lerp(lerp(patch[0].vertex, patch[1].vertex, uv.x), lerp(patch[3].vertex, patch[2].vertex, uv.x), uv.y);
vertex.z += tex2Dlod(_LivClipPlaneHeightMap, float4(data.uv, 0, 0)).r;
data.vertex = UnityObjectToClipPos(vertex);
return data;
}
TessellationControlPoint TessellationVertexProgram(VertexData v) {
TessellationControlPoint p;
p.vertex = v.vertex;
p.uv = v.uv;
return p;
}
fixed4 FragmentProgram(TessellationControlPoint i) : SV_Target{
return fixed4(0, 0, 0, 0);
}
ENDCG
}
}
}
@@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: 569a95a794f4c0f41a495cf572cb294a
timeCreated: 1510156263
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -1,120 +0,0 @@
Shader "Hidden/LIV_ClipPlaneComplexDebug"
{
Properties{
_LivClipPlaneHeightMap("Clip Plane Height Map", 2D) = "black" {}
}
SubShader
{
Tags { "Queue" = "Background" "LightMode" = "Always" "IgnoreProjector" = "True" "ForceNoShadowCasting" = "True"}
Pass {
Name "CLIP_PLANE_COMPLEX_DEBUG"
Cull Off ZWrite On
Fog{ Mode Off }
CGPROGRAM
#pragma target 4.6
#pragma vertex TessellationVertexProgram
#pragma fragment FragmentProgram
#pragma hull HullProgram
#pragma domain DomainProgram
#pragma geometry GeometryProgram
#include "UnityCG.cginc"
sampler2D _LivClipPlaneHeightMap;
float _LivTessellation;
struct VertexData {
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float4 worldPos : TEXCOORD1;
};
struct GeomToFragData {
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float3 barycentric : TEXCOORD1;
};
struct TessellationFactors {
float edge[4] : SV_TessFactor;
float inside[2] : SV_InsideTessFactor;
};
struct TessellationControlPoint {
float4 vertex : INTERNALTESSPOS;
float2 uv : TEXCOORD0;
};
[domain("quad")]
[outputcontrolpoints(4)]
[outputtopology("triangle_cw")]
[partitioning("fractional_odd")]
[patchconstantfunc("PatchConstantFunction")]
TessellationControlPoint HullProgram(InputPatch<TessellationControlPoint, 4> patch, uint id : SV_OutputControlPointID) {
return patch[id];
}
TessellationFactors PatchConstantFunction(InputPatch<TessellationControlPoint, 4> patch) {
TessellationFactors f;
float t = _LivTessellation;
f.edge[0] = f.edge[1] = f.edge[2] = f.edge[3] = f.inside[0] = f.inside[1] = t;
return f;
}
[domain("quad")]
VertexData DomainProgram(TessellationFactors factors, OutputPatch<TessellationControlPoint, 4> patch, float2 uv : SV_DomainLocation) {
VertexData data;
data.uv = lerp(lerp(patch[0].uv, patch[1].uv, uv.x), lerp(patch[3].uv, patch[2].uv, uv.x), uv.y);
float4 vertex = lerp(lerp(patch[0].vertex, patch[1].vertex, uv.x), lerp(patch[3].vertex, patch[2].vertex, uv.x), uv.y);
vertex.z += tex2Dlod(_LivClipPlaneHeightMap, float4(data.uv, 0, 0)).r;
data.vertex = UnityObjectToClipPos(vertex);
data.worldPos = mul(unity_ObjectToWorld, vertex);
return data;
}
TessellationControlPoint TessellationVertexProgram(VertexData v) {
TessellationControlPoint p;
p.vertex = v.vertex;
p.uv = v.uv;
return p;
}
[maxvertexcount(3)]
void GeometryProgram(triangle VertexData p[3], inout TriangleStream<GeomToFragData> triStream) {
GeomToFragData pIn;
pIn.vertex = p[0].vertex;
pIn.uv = p[0].uv;
pIn.barycentric.xyz = float3(1.0, 0, 0);
triStream.Append(pIn);
pIn.vertex = p[1].vertex;
pIn.uv = p[1].uv;
pIn.barycentric.xyz = float3(0, 1.0, 0);
triStream.Append(pIn);
pIn.vertex = p[2].vertex;
pIn.uv = p[2].uv;
pIn.barycentric.xyz = float3(0, 0, 1.0);
triStream.Append(pIn);
}
fixed4 FragmentProgram(GeomToFragData i) : SV_Target {
float3 barys;
barys.xy = i.barycentric;
barys.z = 1 - barys.x - barys.y;
barys = smoothstep(0.0, 0.0 + fwidth(barys), barys);
return lerp(float4(0.0, 0.0, 0.0, 0.5), float4(0.0, 1.0, 0.0, 0.5), min(barys.x, min(barys.y, barys.z)));
}
ENDCG
}
}
}
@@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: d62b3c83b832fe7479f1593441176199
timeCreated: 1510156263
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -1,47 +0,0 @@
Shader "Hidden/LIV_ClipPlaneSimple"
{
SubShader
{
Tags { "Queue" = "Overlay" "LightMode" = "Always" "IgnoreProjector" = "True" "ForceNoShadowCasting" = "True"}
Pass {
Name "CLIP_PLANE_SIMPLE"
Cull Off
ZWrite On
Blend Off
Fog{ Mode Off }
ColorMask[_LivColorMask]
CGPROGRAM
#pragma target 4.6
#pragma vertex VertexProgram
#pragma fragment FragmentProgram
#include "UnityCG.cginc"
struct VertexData {
float4 vertex : POSITION;
};
struct VertexToFragData {
float4 vertex : POSITION;
};
VertexToFragData VertexProgram(VertexData v)
{
VertexToFragData o;
o.vertex = UnityObjectToClipPos(v.vertex);
return o;
}
fixed4 FragmentProgram(VertexToFragData i) : SV_Target
{
return fixed4(0, 0, 0, 0);
}
ENDCG
}
}
}
@@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: 6b34d6785f929904683c682139c8450f
timeCreated: 1510156263
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -1,79 +0,0 @@
Shader "Hidden/LIV_ClipPlaneSimpleDebug"
{
SubShader
{
Tags { "Queue" = "Overlay" "LightMode" = "Always" "IgnoreProjector" = "True" "ForceNoShadowCasting" = "True"}
Pass {
Name "CLIP_PLANE_SIMPLE_DEBUG"
Cull Off
ZWrite On
Fog{ Mode Off }
CGPROGRAM
#pragma target 4.6
#pragma vertex VertexProgram
#pragma fragment FragmentProgram
#pragma geometry GeometryProgram
#include "UnityCG.cginc"
struct VertexData {
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct VertexToGeomData {
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct GeomToFragData {
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float3 barycentric : TEXCOORD1;
};
VertexToGeomData VertexProgram(VertexData v)
{
VertexToGeomData o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
[maxvertexcount(3)]
void GeometryProgram(triangle VertexToGeomData p[3], inout TriangleStream<GeomToFragData> triStream) {
GeomToFragData pIn;
pIn.vertex = p[0].vertex;
pIn.uv = p[0].uv;
pIn.barycentric.xyz = float3(1.0, 0, 0);
triStream.Append(pIn);
pIn.vertex = p[1].vertex;
pIn.uv = p[1].uv;
pIn.barycentric.xyz = float3(0, 1.0, 0);
triStream.Append(pIn);
pIn.vertex = p[2].vertex;
pIn.uv = p[2].uv;
pIn.barycentric.xyz = float3(0, 0, 1.0);
triStream.Append(pIn);
}
fixed4 FragmentProgram(GeomToFragData i) : SV_Target
{
float3 barys;
barys.xy = i.barycentric;
barys.z = 1 - barys.x - barys.y;
barys = smoothstep(0.0, 0.0 + fwidth(barys), barys);
return lerp(float4(0.0, 0.0, 0.0, 0.5), float4(0.0, 1.0, 0.0, 0.5), min(barys.x, min(barys.y, barys.z)));
}
ENDCG
}
}
}
@@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: d07d4a88aeeb21e45abfc07016386fa9
timeCreated: 1510156263
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -1,58 +0,0 @@
Shader "Hidden/LIV_CombineAlpha"
{
Properties
{
_MainTex ("Texture", 2D) = "black" {}
}
SubShader
{
Tags { "Queue" = "Overlay" "LightMode" = "Always" "IgnoreProjector" = "True" "ForceNoShadowCasting" = "True"}
Pass
{
Name "COMBINE_ALPHA"
Blend One OneMinusSrcAlpha
Ztest Always
Zwrite Off
Cull Off
ColorMask[_LivColorMask]
Fog{ Mode Off }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
return tex2D(_MainTex, i.uv).a;
}
ENDCG
}
}
}
@@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: 91bc0cbe8a9c17349bfae83f6b078472
timeCreated: 1599242616
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -1,47 +0,0 @@
Shader "Hidden/LIV_ForceForwardRendering"
{
SubShader
{
Tags { "Queue" = "Geometry" "LightMode" = "Always" "IgnoreProjector" = "True" "ForceNoShadowCasting" = "True"}
Pass
{
Name "FORCE_FORWARD_RENDERING"
ZTest Always ZWrite Off ColorMask 0
Fog{ Mode Off }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
};
struct v2f
{
float4 vertex : SV_POSITION;
};
sampler2D _MainTex;
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
return o;
}
fixed4 frag(v2f i) : SV_Target
{
return 1;
}
ENDCG
}
}
}
@@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: 45e8bd30c7e403247b1a77b8589b16dd
timeCreated: 1510156263
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -1,55 +0,0 @@
Shader "Hidden/LIV_Write"
{
Properties
{
_MainTex("Texture", 2D) = "black" {}
}
SubShader
{
Tags { "Queue" = "Background" "LightMode" = "Always" "IgnoreProjector" = "True" "ForceNoShadowCasting" = "True"}
Pass
{
Name "WRITE"
ZTest Always ZWrite Off
ColorMask [_LivColorMask]
Fog{ Mode Off }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
};
sampler2D _MainTex;
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
fixed4 frag(v2f i) : SV_Target
{
return tex2D(_MainTex, i.uv);
}
ENDCG
}
}
}
@@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: cfc3b5575e59a5f49958e7a512225457
timeCreated: 1510156263
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -1,47 +0,0 @@
Shader "Hidden/LIV_WriteOpaqueToAlpha"
{
SubShader
{
Tags { "Queue" = "Overlay" "LightMode" = "Always" "IgnoreProjector" = "True" "ForceNoShadowCasting" = "True"}
Pass {
Name "CLIP_PLANE_FIX_ALPHA"
Blend Off
ZTest Greater
ZWrite Off
Cull Off
ColorMask A
Fog{ Mode Off }
CGPROGRAM
#pragma target 4.6
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f
{
float4 vertex : SV_POSITION;
};
v2f vert(appdata_base v)
{
v2f o;
o.vertex.xy = v.vertex.xy * 2.0;
o.vertex.z = 0;
o.vertex.w = 1;
return o;
}
fixed4 frag(v2f i) : SV_Target
{
return 1;
}
ENDCG
}
}
}
@@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: f84923ec31d58c44d8834c9f9fc31fef
timeCreated: 1510156263
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
-9
View File
@@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: b50ccc67bb7f02a479899aa023692115
folderAsset: yes
timeCreated: 1509714021
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
-9
View File
@@ -1,9 +0,0 @@
fileFormatVersion: 2
guid: 1129c286d231cee4cae55654016cf0f9
folderAsset: yes
timeCreated: 1594120584
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
-278
View File
@@ -1,278 +0,0 @@
using UnityEngine;
using UnityEditor;
using UnityEditorInternal;
namespace LIV.SDK.Unity
{
[CustomEditor(typeof(LIV))]
public class LIVEditor : Editor
{
const string EXCLUDE_BEHAVIOURS_FOLDOUT_KEY = "liv_excludeBehavioursfoldout";
const string STAGE_PROPERTY = "_stage";
const string STAGE_TRANSFORM_PROPERTY = "_stageTransform";
const string HMD_CAMERA_PROPERTY = "_HMDCamera";
const string MR_CAMERA_PREFAB_PROPERTY = "_MRCameraPrefab";
const string DISABLE_STANDARD_ASSETS_PROPERTY = "_disableStandardAssets";
const string SPECTATOR_LAYER_MASK_PROPERTY = "_spectatorLayerMask";
const string EXCLUDE_BEHAVIOURS_PROPERTY = "_excludeBehaviours";
const string FIX_POST_EFFECTS_ALPHA_PROPERTY = "_fixPostEffectsAlpha";
static GUIContent REQUIRED_FOLDOUT_GUICONTENT = new GUIContent("Required");
static GUIContent OPTIONAL_FOLDOUT_GUICONTENT = new GUIContent("Optional");
static GUIContent STAGE_GUICONTENT = new GUIContent("Stage");
static GUIContent STAGE_INFO_GUICONTENT = new GUIContent(
"The origin of tracked space.\n" +
"This is the object that you use to move the player around."
);
static GUIContent STAGE_TRANSFORM_GUICONTENT = new GUIContent("Stage Transform");
static GUIContent STAGE_TRANSFORM_INFO_GUICONTENT = new GUIContent(
"This transform defines the stage transform."
);
static GUIContent HMD_CAMERA_GUICONTENT = new GUIContent("HMD Camera");
static GUIContent HMD_CAMERA_INFO_GUICONTENT = new GUIContent(
"Set this to the camera used to render the HMD's point of view."
);
static GUIContent MR_CAMERA_PREFAB_GUICONTENT = new GUIContent("MR Camera Prefab");
static GUIContent MR_CAMERA_PREFAB_INFO_GUICONTENT = new GUIContent(
"Set custom camera prefab."
);
static GUIContent DISABLE_STANDARD_ASSETS_GUICONTENT = new GUIContent("Disable Standard Assets");
static GUIContent DISABLE_STANDARD_INFO_ASSETS_GUICONTENT = new GUIContent(
"If you're using Unity's standard effects and they're interfering with MR rendering, check this box."
);
static GUIContent SPECTATOR_LAYER_MASK_GUICONTENT = new GUIContent("Spectator Layer Mask");
static GUIContent SPECTATOR_LAYER_MASK_INFO_GUICONTENT = new GUIContent(
"By default, we'll show everything on the spectator camera. If you want to disable certain objects from showing, update this mask property."
);
static GUIContent FIX_POST_EFFECTS_ALPHA_GUICONTENT = new GUIContent("Fix Post-Effects alpha channel");
static GUIContent FIX_POST_EFFECTS_ALPHA_INFO_GUICONTENT = new GUIContent(
"Some post-effects corrupt the alpha channel, this fix tries to recover it."
);
static GUIContent EXCLUDE_BEHAVIOURS_GUICONTENT = new GUIContent("Exclude Behaviours");
static GUIStyle VERSION_STYLE {
get {
GUIStyle g = new GUIStyle(EditorStyles.label);
g.alignment = TextAnchor.LowerLeft;
g.normal.textColor = Color.white;
g.fontStyle = FontStyle.Bold;
return g;
}
}
static GUIStyle LIV_BUTTON_STYLE {
get {
GUIStyle g = new GUIStyle();
return g;
}
}
static Color darkBGColor {
get {
if (EditorGUIUtility.isProSkin)
{
return new Color(0f, 0f, 0f, 0.5f);
} else
{
return new Color(1f, 1f, 1f, 0.5f);
}
}
}
static Color lightRedBGColor {
get {
return new Color(1f, 0.5f, 0.5f, 1f);
}
}
static Color lightBGColor {
get {
return new Color(1f, 1, 1, 1f);
}
}
ReorderableList excludeBehavioursList;
static bool excludeBehavioursFoldoutValue {
get {
if (!EditorPrefs.HasKey(EXCLUDE_BEHAVIOURS_FOLDOUT_KEY)) return false;
return EditorPrefs.GetBool(EXCLUDE_BEHAVIOURS_FOLDOUT_KEY);
}
set {
EditorPrefs.SetBool(EXCLUDE_BEHAVIOURS_FOLDOUT_KEY, value);
}
}
SerializedProperty stageProperty = null;
SerializedProperty stageTransformProperty = null;
SerializedProperty hmdCameraProperty = null;
SerializedProperty mrCameraPrefabProperty = null;
SerializedProperty disableStandardAssetsProperty = null;
SerializedProperty SpectatorLayerMaskProperty = null;
SerializedProperty ExcludeBehavioursProperty = null;
SerializedProperty FixPostEffectsAlphaProperty = null;
static Texture2D _livLogo;
void OnEnable()
{
string[] livLogoGUID = AssetDatabase.FindAssets("LIVLogo t:texture2D");
if (livLogoGUID.Length > 0)
{
_livLogo = AssetDatabase.LoadAssetAtPath<Texture2D>(AssetDatabase.GUIDToAssetPath(livLogoGUID[0]));
}
stageProperty = serializedObject.FindProperty(STAGE_PROPERTY);
stageTransformProperty = serializedObject.FindProperty(STAGE_TRANSFORM_PROPERTY);
hmdCameraProperty = serializedObject.FindProperty(HMD_CAMERA_PROPERTY);
mrCameraPrefabProperty = serializedObject.FindProperty(MR_CAMERA_PREFAB_PROPERTY);
disableStandardAssetsProperty = serializedObject.FindProperty(DISABLE_STANDARD_ASSETS_PROPERTY);
SpectatorLayerMaskProperty = serializedObject.FindProperty(SPECTATOR_LAYER_MASK_PROPERTY);
ExcludeBehavioursProperty = serializedObject.FindProperty(EXCLUDE_BEHAVIOURS_PROPERTY);
FixPostEffectsAlphaProperty = serializedObject.FindProperty(FIX_POST_EFFECTS_ALPHA_PROPERTY);
excludeBehavioursList = new ReorderableList(serializedObject, ExcludeBehavioursProperty, true, true, true, true);
excludeBehavioursList.drawElementCallback = DrawListItems;
excludeBehavioursList.headerHeight = 2;
}
void DrawListItems(Rect rect, int index, bool isActive, bool isFocused)
{
EditorGUI.PropertyField(rect, excludeBehavioursList.serializedProperty.GetArrayElementAtIndex(index), new GUIContent(""), false);
}
void DrawList(SerializedProperty property, GUIContent guiContent)
{
EditorGUILayout.PropertyField(property, guiContent);
while (true)
{
if(!property.Next(true))
{
break;
}
EditorGUILayout.PropertyField(property);
}
}
void DrawProperty(SerializedProperty property, GUIContent label, GUIContent content, Color color)
{
Color lastAccentColor = GUI.color;
GUI.color = darkBGColor;
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
GUI.color = lastAccentColor;
GUILayout.Space(2);
EditorGUILayout.PropertyField(property, label);
Color lastBackgroundColor = GUI.backgroundColor;
GUI.backgroundColor = color;
EditorGUILayout.LabelField(content, EditorStyles.helpBox);
GUI.backgroundColor = lastBackgroundColor;
EditorGUILayout.EndVertical();
}
void RenderStageField()
{
Color color = lightBGColor;
GUIContent content = new GUIContent(STAGE_INFO_GUICONTENT);
if (stageProperty.objectReferenceValue == null)
{
color = lightRedBGColor;
content.text += "\nThe stage has to be set!";
content.image = EditorGUIUtility.IconContent("console.erroricon").image;
}
DrawProperty(stageProperty, STAGE_GUICONTENT, content, color);
}
void RenderHMDField()
{
Color color = lightBGColor;
GUIContent content = new GUIContent(HMD_CAMERA_INFO_GUICONTENT);
if (hmdCameraProperty.objectReferenceValue == null)
{
color = lightRedBGColor;
content.text += "\nThe camera has to be set!";
content.image = EditorGUIUtility.IconContent("console.erroricon").image;
}
DrawProperty(hmdCameraProperty, HMD_CAMERA_GUICONTENT, content, color);
}
void RenderSpectatorLayerMaskField()
{
Color color = lightBGColor;
GUIContent content = new GUIContent(SPECTATOR_LAYER_MASK_INFO_GUICONTENT);
if (SpectatorLayerMaskProperty.intValue == 0)
{
color = lightRedBGColor;
content.text += "\nAre you sure you want to render nothing?";
content.image = EditorGUIUtility.IconContent("console.warnicon").image;
}
DrawProperty(SpectatorLayerMaskProperty, SPECTATOR_LAYER_MASK_GUICONTENT, content, color);
}
public override void OnInspectorGUI()
{
serializedObject.Update();
if (_livLogo != null)
{
Color lastBackgroundColor = GUI.color;
GUI.color = new Color(0f, 0f, 0f, 0.5f);
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
GUI.color = lastBackgroundColor;
Rect originalRect = EditorGUILayout.GetControlRect(GUILayout.Height(_livLogo.height));
Rect imageRect = originalRect;
imageRect.x = (originalRect.width - _livLogo.width);
imageRect.width = _livLogo.width;
GUI.DrawTexture(imageRect, _livLogo);
GUI.Label(originalRect, "v" + SDKConstants.SDK_VERSION, VERSION_STYLE);
if(GUI.Button(originalRect, new GUIContent(), LIV_BUTTON_STYLE)) {
Application.OpenURL("https://liv.tv/");
}
EditorGUILayout.EndVertical();
}
EditorGUILayout.LabelField(REQUIRED_FOLDOUT_GUICONTENT, EditorStyles.boldLabel);
RenderStageField();
RenderHMDField();
DrawProperty(disableStandardAssetsProperty, DISABLE_STANDARD_ASSETS_GUICONTENT, DISABLE_STANDARD_INFO_ASSETS_GUICONTENT, lightBGColor);
RenderSpectatorLayerMaskField();
Color lastAccentColor = GUI.color;
GUI.color = darkBGColor;
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
GUI.color = lastAccentColor;
EditorGUI.indentLevel++;
excludeBehavioursFoldoutValue = EditorGUILayout.Foldout(excludeBehavioursFoldoutValue, EXCLUDE_BEHAVIOURS_GUICONTENT);
EditorGUI.indentLevel--;
if (excludeBehavioursFoldoutValue)
{
excludeBehavioursList.DoLayoutList();
}
EditorGUILayout.EndVertical();
EditorGUILayout.LabelField(OPTIONAL_FOLDOUT_GUICONTENT, EditorStyles.boldLabel);
DrawProperty(stageTransformProperty, STAGE_TRANSFORM_GUICONTENT, STAGE_TRANSFORM_INFO_GUICONTENT, lightBGColor);
DrawProperty(mrCameraPrefabProperty, MR_CAMERA_PREFAB_GUICONTENT, MR_CAMERA_PREFAB_INFO_GUICONTENT, lightBGColor);
DrawProperty(FixPostEffectsAlphaProperty, FIX_POST_EFFECTS_ALPHA_GUICONTENT, FIX_POST_EFFECTS_ALPHA_INFO_GUICONTENT, lightBGColor);
serializedObject.ApplyModifiedProperties();
GUIContent helpContent = new GUIContent(EditorGUIUtility.IconContent("_Help"));
helpContent.text = "Help";
if (GUILayout.Button(helpContent))
{
Application.OpenURL(@"https://liv.tv/sdk-unity-docs");
}
EditorGUILayout.Space();
}
}
}
@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: f1c81e3022e00ae48afdcdd0a671deb3
timeCreated: 1594120597
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

@@ -1,76 +0,0 @@
fileFormatVersion: 2
guid: c093a09392bb4344486c0727eec7de81
timeCreated: 1594132790
licenseType: Free
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 4
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 0
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
filterMode: 1
aniso: -1
mipBias: -1
wrapMode: 1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 2
textureShape: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
- buildTarget: Standalone
maxTextureSize: 2048
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:
-522
View File
@@ -1,522 +0,0 @@
using UnityEngine;
using UnityEngine.Serialization;
using System.Collections;
using System;
#if UNITY_2017_2_OR_NEWER
using UnityEngine.XR;
#endif
namespace LIV.SDK.Unity
{
[System.Flags]
public enum INVALIDATION_FLAGS : uint
{
NONE = 0,
HMD_CAMERA = 1,
STAGE = 2,
MR_CAMERA_PREFAB = 4,
EXCLUDE_BEHAVIOURS = 8
}
/// <summary>
/// The LIV SDK provides a spectator view of your application.
/// </summary>
/// <remarks>
/// <para>It contextualizes what the user feels & experiences by capturing their body directly inside your world!</para>
/// <para>Thanks to our software, creators can film inside your app and have full control over the camera.</para>
/// <para>With the power of out-of-engine compositing, a creator can express themselves freely without limits;</para>
/// <para>as a real person or an avatar!</para>
/// </remarks>
/// <example>
/// <code>
/// public class StartFromScriptExample : MonoBehaviour
/// {
/// [SerializeField] Camera _hmdCamera;
/// [SerializeField] Transform _stage;
/// [SerializeField] Transform _stageTransform;
/// [SerializeField] Camera _mrCameraPrefab;
/// LIV.SDK.Unity.LIV _liv;
/// private void OnEnable()
/// {
/// _liv = gameObject.AddComponent<LIV.SDK.Unity.LIV>();
/// _liv.HMDCamera = _hmdCamera;
/// _liv.stage = _stage;
/// _liv.stageTransform = _stageTransform;
/// _liv.MRCameraPrefab = _mrCameraPrefab;
/// }
/// private void OnDisable()
/// {
/// if (_liv == null) return;
/// Destroy(_liv);
/// _liv = null;
/// }
/// }
/// </code>
/// </example>
[HelpURL("https://liv.tv/sdk-unity-docs")]
[AddComponentMenu("LIV/LIV")]
public class LIV : MonoBehaviour
{
/// <summary>
/// triggered when the LIV SDK is activated by the LIV App and enabled by the game.
/// </summary>
public System.Action onActivate = null;
/// <summary>
/// triggered before the Mixed Reality camera is about to render.
/// </summary>
public System.Action<SDKRender> onPreRender = null;
/// <summary>
/// triggered before the LIV SDK starts rendering background image.
/// </summary>
public System.Action<SDKRender> onPreRenderBackground = null;
/// <summary>
/// triggered after the LIV SDK starts rendering background image.
/// </summary>
public System.Action<SDKRender> onPostRenderBackground = null;
/// <summary>
/// triggered before the LIV SDK starts rendering the foreground image.
/// </summary>
public System.Action<SDKRender> onPreRenderForeground = null;
/// <summary>
/// triggered after the LIV SDK starts rendering the foreground image.
/// </summary>
public System.Action<SDKRender> onPostRenderForeground = null;
/// <summary>
/// triggered after the Mixed Reality camera has finished rendering.
/// </summary>
public System.Action<SDKRender> onPostRender = null;
/// <summary>
/// triggered when the LIV SDK is deactivated by the LIV App or disabled by the game.
/// </summary>
public System.Action onDeactivate = null;
[Tooltip("This is the topmost transform of your VR rig.")]
[FormerlySerializedAs("TrackedSpaceOrigin")]
[SerializeField] Transform _stage = null;
/// <summary>
/// This is the topmost transform of your VR rig.
/// </summary>
/// <remarks>
/// <para>When implementing VR locomotion(teleporting, joystick, etc),</para>
/// <para>this is the GameObject that you should move around your scene.</para>
/// <para>It represents the centre of the users playspace.</para>
/// </remarks>
public Transform stage {
get {
return _stage == null ? transform.parent : _stage;
}
set {
if (value == null)
{
Debug.LogWarning("LIV: Stage cannot be null!");
}
if (_stage != value)
{
_stageCandidate = value;
_invalidate = (INVALIDATION_FLAGS)SDKUtils.SetFlag((uint)_invalidate, (uint)INVALIDATION_FLAGS.STAGE, true);
}
}
}
[Obsolete("Use stage instead")]
public Transform trackedSpaceOrigin {
get {
return stage;
}
set {
stage = value;
}
}
public Matrix4x4 stageLocalToWorldMatrix {
get {
return (stage != null) ? stage.localToWorldMatrix : Matrix4x4.identity;
}
}
public Matrix4x4 stageWorldToLocalMatrix {
get {
return (stage != null) ? stage.worldToLocalMatrix : Matrix4x4.identity;
}
}
[Tooltip("This transform is an additional wrapper to the users playspace.")]
[FormerlySerializedAs("StageTransform")]
[SerializeField] Transform _stageTransform = null;
/// <summary>
/// This transform is an additional wrapper to the users playspace.
/// </summary>
/// <remarks>
/// <para>It allows for user-controlled transformations for special camera effects & transitions.</para>
/// <para>If a creator is using a static camera, this transformation can give the illusion of camera movement.</para>
/// </remarks>
public Transform stageTransform {
get {
return _stageTransform;
}
set {
_stageTransform = value;
}
}
[Tooltip("This is the camera responsible for rendering the users HMD.")]
[FormerlySerializedAs("HMDCamera")]
[SerializeField] Camera _HMDCamera = null;
/// <summary>
/// This is the camera responsible for rendering the users HMD.
/// </summary>
/// <remarks>
/// <para>The LIV SDK, by default clones this object to match your applications rendering setup.</para>
/// <para>You can use your own camera prefab should you want to!</para>
/// </remarks>
public Camera HMDCamera {
get {
return _HMDCamera;
}
set {
if (value == null)
{
Debug.LogWarning("LIV: HMD Camera cannot be null!");
}
if (_HMDCamera != value)
{
_HMDCameraCandidate = value;
_invalidate = (INVALIDATION_FLAGS)SDKUtils.SetFlag((uint)_invalidate, (uint)INVALIDATION_FLAGS.HMD_CAMERA, true);
}
}
}
[Tooltip("Camera prefab for customized rendering.")]
[FormerlySerializedAs("MRCameraPrefab")]
[SerializeField] Camera _MRCameraPrefab = null;
/// <summary>
/// Camera prefab for customized rendering.
/// </summary>
/// <remarks>
/// <para>By default, LIV uses the HMD camera as a reference for the Mixed Reality camera.</para>
/// <para>It is cloned and set up as a Mixed Reality camera.This approach works for most apps.</para>
/// <para>However, some games can experience issues because of custom MonoBehaviours attached to this camera.</para>
/// <para>You can use a custom camera prefab for those cases.</para>
/// </remarks>
public Camera MRCameraPrefab {
get {
return _MRCameraPrefab;
}
set {
if (_MRCameraPrefab != value)
{
_MRCameraPrefabCandidate = value;
_invalidate = (INVALIDATION_FLAGS)SDKUtils.SetFlag((uint)_invalidate, (uint)INVALIDATION_FLAGS.MR_CAMERA_PREFAB, true);
}
}
}
[Tooltip("This option disables all standard Unity assets for the Mixed Reality rendering.")]
[FormerlySerializedAs("DisableStandardAssets")]
[SerializeField] bool _disableStandardAssets = false;
/// <summary>
/// This option disables all standard Unity assets for the Mixed Reality rendering.
/// </summary>
/// <remarks>
/// <para>Unitys standard assets can interfere with the alpha channel that LIV needs to composite MR correctly.</para>
/// </remarks>
public bool disableStandardAssets {
get {
return _disableStandardAssets;
}
set {
_disableStandardAssets = value;
}
}
[Tooltip("The layer mask defines exactly which object layers should be rendered in MR.")]
[FormerlySerializedAs("SpectatorLayerMask")]
[SerializeField] LayerMask _spectatorLayerMask = ~0;
/// <summary>
/// The layer mask defines exactly which object layers should be rendered in MR.
/// </summary>
/// <remarks>
/// <para>You should use this to hide any in-game avatar that youre using.</para>
/// <para>LIV is meant to include the users body for you!</para>
/// <para>Certain HMD-based effects should be disabled here too.</para>
/// <para>Also, this can be used to render special effects or additional UI only to the MR camera.</para>
/// <para>Useful for showing the players health, or current score!</para>
/// </remarks>
public LayerMask spectatorLayerMask {
get {
return _spectatorLayerMask;
}
set {
_spectatorLayerMask = value;
}
}
[Tooltip("This is for removing unwanted scripts from the cloned MR camera.")]
[FormerlySerializedAs("ExcludeBehaviours")]
[SerializeField]
string[] _excludeBehaviours = new string[] {
"AudioListener",
"Collider",
"SteamVR_Camera",
"SteamVR_Fade",
"SteamVR_ExternalCamera"
};
/// <summary>
/// This is for removing unwanted scripts from the cloned MR camera.
/// </summary>
/// <remarks>
/// <para>By default, we remove the AudioListener, Colliders and SteamVR scripts, as these are not necessary for rendering MR!</para>
/// <para>The excluded string must match the name of the MonoBehaviour.</para>
/// </remarks>
public string[] excludeBehaviours {
get {
return _excludeBehaviours;
}
set {
if (_excludeBehaviours != value)
{
_excludeBehavioursCandidate = value;
_invalidate = (INVALIDATION_FLAGS)SDKUtils.SetFlag((uint)_invalidate, (uint)INVALIDATION_FLAGS.EXCLUDE_BEHAVIOURS, true);
}
}
}
/// <summary>
/// Recovers corrupted alpha channel when using post-effects.
/// </summary>
///
[Tooltip("Recovers corrupted alpha channel when using post-effects.")]
[FormerlySerializedAs("FixPostEffectsAlpha")]
[SerializeField]
private bool _fixPostEffectsAlpha = false;
public bool fixPostEffectsAlpha {
get {
return _fixPostEffectsAlpha;
}
set {
_fixPostEffectsAlpha = value;
}
}
/// <summary>
/// Is the curret LIV SDK setup valid.
/// </summary>
public bool isValid {
get {
if (_invalidate != INVALIDATION_FLAGS.NONE) return false;
if (_HMDCamera == null)
{
Debug.LogError("LIV: HMD Camera is a required parameter!");
return false;
}
if (_stage == null)
{
Debug.LogWarning("LIV: Tracked space origin should be assigned!");
}
if (_spectatorLayerMask == 0)
{
Debug.LogWarning("LIV: The spectator layer mask is set to not show anything. Is this correct?");
}
return true;
}
}
bool _isActive = false;
/// <summary>
/// Is the LIV SDK currently active.
/// </summary>
public bool isActive {
get {
return _isActive;
}
}
private bool _isReady {
get {
return isValid && _enabled && SDKBridge.IsActive;
}
}
private SDKRender _render = null;
/// <summary>
/// Script responsible for the MR rendering.
/// </summary>
public SDKRender render { get { return _render; } }
private bool _wasReady = false;
private INVALIDATION_FLAGS _invalidate = INVALIDATION_FLAGS.NONE;
private Transform _stageCandidate = null;
private Camera _HMDCameraCandidate = null;
private Camera _MRCameraPrefabCandidate = null;
private string[] _excludeBehavioursCandidate = null;
private bool _enabled = false;
private Coroutine _waitForEndOfFrameCoroutine;
void OnEnable()
{
_enabled = true;
UpdateSDKReady();
}
void Update()
{
UpdateSDKReady();
Invalidate();
}
void OnDisable()
{
_enabled = false;
UpdateSDKReady();
}
IEnumerator WaitForUnityEndOfFrame()
{
while (Application.isPlaying && enabled)
{
yield return new WaitForEndOfFrame();
if (isActive)
{
_render.Render();
}
}
}
void UpdateSDKReady()
{
bool ready = _isReady;
if (ready != _wasReady)
{
OnSDKReadyChanged(ready);
_wasReady = ready;
}
}
void OnSDKReadyChanged(bool value)
{
if (value)
{
OnSDKActivate();
}
else
{
OnSDKDeactivate();
}
}
void OnSDKActivate()
{
Debug.Log("LIV: Compositor connected, setting up Mixed Reality!");
SubmitSDKOutput();
CreateAssets();
StartRenderCoroutine();
_isActive = true;
if (onActivate != null) onActivate.Invoke();
}
void OnSDKDeactivate()
{
Debug.Log("LIV: Compositor disconnected, cleaning up Mixed Reality.");
if (onDeactivate != null) onDeactivate.Invoke();
StopRenderCoroutine();
DestroyAssets();
_isActive = false;
}
void CreateAssets()
{
DestroyAssets();
_render = new SDKRender(this);
}
void DestroyAssets()
{
if (_render != null)
{
_render.Dispose();
_render = null;
}
}
void StartRenderCoroutine()
{
StopRenderCoroutine();
_waitForEndOfFrameCoroutine = StartCoroutine(WaitForUnityEndOfFrame());
}
void StopRenderCoroutine()
{
if (_waitForEndOfFrameCoroutine != null)
{
StopCoroutine(_waitForEndOfFrameCoroutine);
_waitForEndOfFrameCoroutine = null;
}
}
void SubmitSDKOutput()
{
SDKApplicationOutput output = SDKApplicationOutput.empty;
output.supportedFeatures = FEATURES.BACKGROUND_RENDER |
FEATURES.FOREGROUND_RENDER |
FEATURES.OVERRIDE_POST_PROCESSING |
FEATURES.FIX_FOREGROUND_ALPHA;
output.sdkID = SDKConstants.SDK_ID;
output.sdkVersion = SDKConstants.SDK_VERSION;
output.engineName = SDKConstants.ENGINE_NAME;
output.engineVersion = Application.unityVersion;
output.applicationName = Application.productName;
output.applicationVersion = Application.version;
output.graphicsAPI = SystemInfo.graphicsDeviceType.ToString();
#if UNITY_2017_2_OR_NEWER
output.xrDeviceName = XRSettings.loadedDeviceName;
#endif
SDKBridge.SubmitApplicationOutput(output);
}
void Invalidate()
{
if (SDKUtils.ContainsFlag((uint)_invalidate, (uint)INVALIDATION_FLAGS.STAGE))
{
_stage = _stageCandidate;
_stageCandidate = null;
_invalidate = (INVALIDATION_FLAGS)SDKUtils.SetFlag((uint)_invalidate, (uint)INVALIDATION_FLAGS.STAGE, false);
}
if (SDKUtils.ContainsFlag((uint)_invalidate, (uint)INVALIDATION_FLAGS.HMD_CAMERA))
{
_HMDCamera = _HMDCameraCandidate;
_HMDCameraCandidate = null;
_invalidate = (INVALIDATION_FLAGS)SDKUtils.SetFlag((uint)_invalidate, (uint)INVALIDATION_FLAGS.HMD_CAMERA, false);
}
if (SDKUtils.ContainsFlag((uint)_invalidate, (uint)INVALIDATION_FLAGS.MR_CAMERA_PREFAB))
{
_MRCameraPrefab = _MRCameraPrefabCandidate;
_MRCameraPrefabCandidate = null;
_invalidate = (INVALIDATION_FLAGS)SDKUtils.SetFlag((uint)_invalidate, (uint)INVALIDATION_FLAGS.MR_CAMERA_PREFAB, false);
}
if (SDKUtils.ContainsFlag((uint)_invalidate, (uint)INVALIDATION_FLAGS.EXCLUDE_BEHAVIOURS))
{
_excludeBehaviours = _excludeBehavioursCandidate;
_excludeBehavioursCandidate = null;
_invalidate = (INVALIDATION_FLAGS)SDKUtils.SetFlag((uint)_invalidate, (uint)INVALIDATION_FLAGS.EXCLUDE_BEHAVIOURS, false);
}
}
}
}
-13
View File
@@ -1,13 +0,0 @@
fileFormatVersion: 2
guid: 419ad76f2ffc722478bc67f61f9c32e7
timeCreated: 1522333239
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
-366
View File
@@ -1,366 +0,0 @@
using UnityEngine;
using System;
using System.Runtime.InteropServices;
using System.Text;
namespace LIV.SDK.Unity
{
public static class SDKBridge
{
#if (UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN) && UNITY_64
#region Interop
[DllImport("LIV_Bridge")]
static extern IntPtr GetRenderEventFunc();
[DllImport("LIV_Bridge", EntryPoint = "LivCaptureIsActive")]
[return: MarshalAs(UnmanagedType.U1)]
static extern bool GetIsCaptureActive();
[DllImport("LIV_Bridge", EntryPoint = "LivCaptureWidth")]
static extern int GetTextureWidth();
[DllImport("LIV_Bridge", EntryPoint = "LivCaptureHeight")]
static extern int GetTextureHeight();
[DllImport("LIV_Bridge", EntryPoint = "LivCaptureSetTextureFromUnity")]
static extern void SetTexture(IntPtr texture);
//// Acquire a frame from the compositor, allowing atomic access to its properties - most current one by default
[DllImport("LIV_Bridge", EntryPoint = "AcquireCompositorFrame")]
public static extern int AcquireCompositorFrame(ulong timestamp);
[DllImport("LIV_Bridge", EntryPoint = "ReleaseCompositorFrame")]
public static extern int ReleaseCompositorFrame();
// Get timestamp of SDK2 object (C# timestamp) - must be an object in the bridge, not a copy.
[DllImport("LIV_Bridge", EntryPoint = "GetObjectTimeStamp")]
public static extern ulong GetObjectTimeStamp(IntPtr obj);
// Get current time in C# ticks
[DllImport("LIV_Bridge", EntryPoint = "GetCurrentTimeTicks")]
static extern ulong GetCurrentTimeTicks();
// Get object tag of SDK2 object - must be an object in the bridge, not a copy.
[DllImport("LIV_Bridge", EntryPoint = "GetObjectTag")]
public static extern ulong GetObjectTag(IntPtr obj);
// Get a frame object from the compositor
[DllImport("LIV_Bridge", EntryPoint = "GetCompositorFrameObject")]
public static extern IntPtr GetCompositorFrameObject(ulong tag);
// Get a frame object from the compositor
[DllImport("LIV_Bridge", EntryPoint = "GetViewportTexture")]
public static extern IntPtr GetViewportTexture();
// Get a channel object from the compositor
[DllImport("LIV_Bridge", EntryPoint = "GetCompositorChannelObject")]
public static extern IntPtr GetCompositorChannelObject(int slot, ulong tag, ulong timestamp);
// Get a channel object from our own source channel
[DllImport("LIV_Bridge", EntryPoint = "GetChannelObject")]
public static extern IntPtr GetChannelObject(int slot, ulong tag, ulong timestamp);
// Write an object to our channel
[DllImport("LIV_Bridge", EntryPoint = "AddObjectToChannel")]
public static extern int AddObjectToChannel(int slot, IntPtr obj, int objectsize, ulong tag);
// Write an object to the compostor's channel
[DllImport("LIV_Bridge", EntryPoint = "AddObjectToCompositorChannel")]
public static extern int AddObjectToCompositorChannel(int slot, IntPtr obj, int objectsize, ulong tag);
// Add a structure/object to the current frame / Considering if its simpler to combine with AddObjectToChannel with 0 being the frame
[DllImport("LIV_Bridge", EntryPoint = "AddObjectToFrame")]
public static extern int AddObjectToFrame(IntPtr obj, int objectsize, ulong tag);
// Helper to add strings
[DllImport("LIV_Bridge", EntryPoint = "AddObjectToFrame")]
public static extern int AddStringToFrame(IntPtr str, ulong tag);
[DllImport("LIV_Bridge", EntryPoint = "AddStringToChannel")]
public static extern int AddStringToChannel(int slot, IntPtr str, int length, ulong tag);
// Create a new frame for rendering / native code does this already - so probably don't use
[DllImport("LIV_Bridge", EntryPoint = "NewFrame")]
public static extern int NewFrame();
// Commit the frame early - not recommended - best to let the next NewFrame commit the frame to avoid pipeline stalls
[DllImport("LIV_Bridge", EntryPoint = "CommitFrame")]
public static extern IntPtr CommitFrame();
// Add a copy of a unity texture to the bridge
[DllImport("LIV_Bridge", EntryPoint = "addsharedtexture")]
public static extern int addsharedtexture(int width, int height, int format, IntPtr sourcetexture, ulong tag);
[DllImport("LIV_Bridge", EntryPoint = "addtexture")]
public static extern int addtexture(IntPtr sourcetexture, ulong tag);
[DllImport("LIV_Bridge", EntryPoint = "PublishTextures")]
public static extern void PublishTextures();
[DllImport("LIV_Bridge", EntryPoint = "updateinputframe")]
public static extern IntPtr updatinputframe(IntPtr InputFrame);
[DllImport("LIV_Bridge", EntryPoint = "setinputframe")]
public static extern IntPtr setinputframe(float x, float y, float z, float q0, float q1, float q2, float q3, float fov, int priority);
[DllImport("LIV_Bridge", EntryPoint = "setfeature")]
public static extern ulong setfeature(ulong feature);
[DllImport("LIV_Bridge", EntryPoint = "clearfeature")]
public static extern ulong clearfeature(ulong feature);
#endregion
#else
public static int AddStringToChannel(int slot, IntPtr str, int length, ulong tag) { return -2; }
public static int addtexture(IntPtr sourcetexture, ulong tag) { return -2; }
public static ulong GetObjectTimeStamp(IntPtr obj) { return 0; }
public static ulong GetCurrentTimeTicks() { return 0; }
static bool GetIsCaptureActive() { return false; }
public static IntPtr GetRenderEventFunc() { return IntPtr.Zero; }
public static IntPtr GetCompositorChannelObject(int slot, ulong tag, ulong timestamp) { return IntPtr.Zero; }
public static int AddObjectToCompositorChannel(int slot, IntPtr obj, int objectsize, ulong tag) { return -2; }
public static int AddObjectToFrame(IntPtr obj, int objectsize, ulong tag) { return -2; }
public static IntPtr updatinputframe(IntPtr InputFrame) { return IntPtr.Zero; }
public static IntPtr GetViewportTexture() { return IntPtr.Zero; }
public static IntPtr GetChannelObject(int slot, ulong tag, ulong timestamp) { return IntPtr.Zero; }
public static int AddObjectToChannel(int slot, IntPtr obj, int objectsize, ulong tag) { return -2; }
#endif
public struct SDKInjection<T>
{
public bool active;
public System.Action action;
public T data;
}
static SDKInjection<SDKInputFrame> _injection_SDKInputFrame = new SDKInjection<SDKInputFrame>()
{
active = false,
action = null,
data = SDKInputFrame.empty
};
static SDKInjection<SDKResolution> _injection_SDKResolution = new SDKInjection<SDKResolution>()
{
active = false,
action = null,
data = SDKResolution.zero
};
static SDKInjection<bool> _injection_IsActive = new SDKInjection<bool>()
{
active = false,
action = null,
data = false
};
static bool _injection_DisableSubmit = false;
static bool _injection_DisableSubmitApplicationOutput = false;
static bool _injection_DisableAddTexture = false;
static bool _injection_DisableCreateFrame = false;
// Get the tag code for a string - won't win any awards - pre-compute these and use constants.
public static ulong Tag(string str)
{
ulong tag = 0;
for (int i = 0; i < str.Length; i++)
{
if (i == 8) break;
char c = str[i];
tag |= (((ulong)(c & 255)) << (i * 8));
}
return tag;
}
public static void AddString(string tag, string value, int slot)
{
var utf8 = Encoding.UTF8;
byte[] utfBytes = utf8.GetBytes(value);
GCHandle gch = GCHandle.Alloc(utfBytes, GCHandleType.Pinned);
AddStringToChannel(slot, Marshal.UnsafeAddrOfPinnedArrayElement(utfBytes, 0), utfBytes.Length, Tag(tag));
gch.Free();
}
public static void AddTexture(SDKTexture texture, ulong tag)
{
GCHandle gch = GCHandle.Alloc(texture, GCHandleType.Pinned);
addtexture(gch.AddrOfPinnedObject(), tag);
gch.Free();
}
public static ulong GetObjectTime(IntPtr objectptr)
{
return GetObjectTimeStamp(objectptr) + 621355968000000000;
}
public static ulong GetCurrentTime()
{
return GetCurrentTimeTicks() + 621355968000000000;
}
public static bool IsActive {
get {
if (_injection_IsActive.active)
{
return _injection_IsActive.data;
}
return GetIsCaptureActive();
}
}
public static void IssuePluginEvent()
{
if (_injection_DisableSubmit) return;
GL.IssuePluginEvent(GetRenderEventFunc(), 2);
}
public static void SubmitApplicationOutput(SDKApplicationOutput applicationOutput)
{
if (_injection_DisableSubmitApplicationOutput) return;
AddString("APPNAME", applicationOutput.applicationName, 5);
AddString("APPVER", applicationOutput.applicationVersion, 5);
AddString("ENGNAME", applicationOutput.engineName, 5);
AddString("ENGVER", applicationOutput.engineVersion, 5);
AddString("GFXAPI", applicationOutput.graphicsAPI, 5);
AddString("SDKID", applicationOutput.sdkID, 5);
AddString("SDKVER", applicationOutput.sdkVersion, 5);
AddString("SUPPORT", applicationOutput.supportedFeatures.ToString(), 5);
AddString("XRNAME", applicationOutput.xrDeviceName, 5);
}
public static bool GetStructFromGlobalChannel <T> ( ref T mystruct, int channel, ulong tag)
{
IntPtr structPtr = GetCompositorChannelObject(channel, tag, UInt64.MaxValue);
if (structPtr == IntPtr.Zero) return false;
mystruct= (T)Marshal.PtrToStructure(structPtr, typeof(T));
return true;
}
public static int AddStructToGlobalChannel<T>(ref T mystruct, int channel, ulong tag)
{
GCHandle gch = GCHandle.Alloc(mystruct, GCHandleType.Pinned);
int output = AddObjectToCompositorChannel(channel, gch.AddrOfPinnedObject(), Marshal.SizeOf(mystruct), tag);
gch.Free();
return output;
}
public static bool GetStructFromLocalChannel<T>(ref T mystruct, int channel, ulong tag)
{
IntPtr structPtr = GetChannelObject(channel, tag, UInt64.MaxValue);
if (structPtr == IntPtr.Zero) return false;
mystruct = (T)Marshal.PtrToStructure(structPtr, typeof(T));
return true;
}
public static int AddStructToLocalChannel<T>(ref T mystruct, int channel, ulong tag)
{
GCHandle gch = GCHandle.Alloc(mystruct, GCHandleType.Pinned);
int output = AddObjectToChannel(channel, gch.AddrOfPinnedObject(), Marshal.SizeOf(mystruct), tag);
gch.Free();
return output;
}
// Add ANY structure to the current frame
public static void AddStructToFrame<T>(ref T mystruct, ulong tag)
{
GCHandle gch = GCHandle.Alloc(mystruct, GCHandleType.Pinned);
AddObjectToFrame(gch.AddrOfPinnedObject(), Marshal.SizeOf(mystruct), tag);
gch.Free();
}
/// <summary>
/// Update the master pose sent to ALL applications.
///
/// when called initialy, having the flags set to 0 will return the current pose (which includes resolution - which you might need)
/// If you wish to change the pose, change the parts of the structures you need to, and set the appropriate flag to update.
/// atm, the flags will be for Pose, Stage, Clipping Plane, and resolution.
///
/// </summary>
/// <param name="setframe"></param>
/// <returns>The current pose - could be yours, someone elses, or a combination</returns>
public static bool UpdateInputFrame(ref SDKInputFrame setframe)
{
if (_injection_SDKInputFrame.active && _injection_SDKInputFrame.action != null)
{
_injection_SDKInputFrame.action.Invoke();
setframe = _injection_SDKInputFrame.data;
}
else
{
// Pin the object briefly so we can send it to the API without it being accidentally garbage collected
GCHandle gch = GCHandle.Alloc(setframe, GCHandleType.Pinned);
IntPtr structPtr = updatinputframe(gch.AddrOfPinnedObject());
gch.Free();
if (structPtr == IntPtr.Zero)
{
setframe = SDKInputFrame.empty;
return false;
}
setframe = (SDKInputFrame)Marshal.PtrToStructure(structPtr, typeof(SDKInputFrame));
_injection_SDKInputFrame.data = setframe;
}
return true;
}
public static SDKTexture GetViewfinderTexture()
{
SDKTexture overlaytexture = SDKTexture.empty;
IntPtr structPtr = GetCompositorChannelObject(11, Tag("OUTTEX"), UInt64.MaxValue);
if (structPtr == IntPtr.Zero) return new SDKTexture();
overlaytexture = (SDKTexture)Marshal.PtrToStructure(structPtr, typeof(SDKTexture));
return overlaytexture;
}
public static void AddTexture(SDKTexture texture)
{
if (_injection_DisableAddTexture) return;
string tag = "";
switch (texture.id)
{
case TEXTURE_ID.BACKGROUND_COLOR_BUFFER_ID:
tag = "BGCTEX";
break;
case TEXTURE_ID.FOREGROUND_COLOR_BUFFER_ID:
tag = "FGCTEX";
break;
case TEXTURE_ID.OPTIMIZED_COLOR_BUFFER_ID:
tag = "OPTTEX";
break;
}
AddTexture(texture, Tag(tag));
}
public static void CreateFrame(SDKOutputFrame frame)
{
if (_injection_DisableCreateFrame) return;
GCHandle gch = GCHandle.Alloc(frame, GCHandleType.Pinned);
AddObjectToFrame(gch.AddrOfPinnedObject(), Marshal.SizeOf(frame), Tag("OUTFRAME"));
gch.Free();
}
public static void SetGroundPlane(SDKPlane groundPlane)
{
AddStructToGlobalChannel<SDKPlane>(ref groundPlane, 2, SDKBridge.Tag("SetGND"));
}
public static bool GetResolution(ref SDKResolution sdkResolution)
{
if(_injection_SDKResolution.active && _injection_SDKResolution.action != null)
{
_injection_SDKResolution.action.Invoke();
sdkResolution = _injection_SDKResolution.data;
return true;
}
bool output = GetStructFromLocalChannel<SDKResolution>(ref sdkResolution, 15, SDKBridge.Tag("SDKRes"));
_injection_SDKResolution.data = sdkResolution;
return output;
}
}
}
-12
View File
@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 29a5a59a66c726f4ea619531370e7ffd
timeCreated: 1508938582
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
-456
View File
@@ -1,456 +0,0 @@
#if !LIV_UNIVERSAL_RENDER
using UnityEngine;
using UnityEngine.Rendering;
namespace LIV.SDK.Unity
{
public partial class SDKRender : System.IDisposable
{
// Renders the clip plane in the foreground texture
private CommandBuffer _clipPlaneCommandBuffer = null;
// Renders the clipped opaque content in to the foreground texture alpha
private CommandBuffer _combineAlphaCommandBuffer = null;
// Captures texture before post-effects
private CommandBuffer _captureTextureCommandBuffer = null;
// Renders captured texture
private CommandBuffer _applyTextureCommandBuffer = null;
// Renders background and foreground in single render
private CommandBuffer _optimizedRenderingCommandBuffer = null;
private CameraEvent _clipPlaneCameraEvent = CameraEvent.AfterForwardOpaque;
private CameraEvent _clipPlaneCombineAlphaCameraEvent = CameraEvent.AfterEverything;
private CameraEvent _captureTextureEvent = CameraEvent.BeforeImageEffects;
private CameraEvent _applyTextureEvent = CameraEvent.AfterEverything;
private CameraEvent _optimizedRenderingCameraEvent = CameraEvent.AfterEverything;
// Tessellated quad
private Mesh _clipPlaneMesh = null;
// Clear material
private Material _clipPlaneSimpleMaterial = null;
// Transparent material for visual debugging
private Material _clipPlaneSimpleDebugMaterial = null;
// Tessellated height map clear material
private Material _clipPlaneComplexMaterial = null;
// Tessellated height map clear material for visual debugging
private Material _clipPlaneComplexDebugMaterial = null;
private Material _writeOpaqueToAlphaMaterial = null;
private Material _combineAlphaMaterial = null;
private Material _writeMaterial = null;
private Material _forceForwardRenderingMaterial = null;
private RenderTexture _backgroundRenderTexture = null;
private RenderTexture _foregroundRenderTexture = null;
private RenderTexture _optimizedRenderTexture = null;
private RenderTexture _complexClipPlaneRenderTexture = null;
Material GetClipPlaneMaterial(bool debugClipPlane, bool complexClipPlane, ColorWriteMask colorWriteMask)
{
Material output;
if (complexClipPlane)
{
output = debugClipPlane ? _clipPlaneComplexDebugMaterial : _clipPlaneComplexMaterial;
output.SetTexture(SDKShaders.LIV_CLIP_PLANE_HEIGHT_MAP_PROPERTY, _complexClipPlaneRenderTexture);
output.SetFloat(SDKShaders.LIV_TESSELLATION_PROPERTY, _inputFrame.clipPlane.tesselation);
}
else
{
output = debugClipPlane ? _clipPlaneSimpleDebugMaterial : _clipPlaneSimpleMaterial;
}
output.SetInt(SDKShaders.LIV_COLOR_MASK, (int)colorWriteMask);
return output;
}
Material GetGroundClipPlaneMaterial(bool debugClipPlane, ColorWriteMask colorWriteMask)
{
Material output;
output = debugClipPlane ? _clipPlaneSimpleDebugMaterial : _clipPlaneSimpleMaterial;
output.SetInt(SDKShaders.LIV_COLOR_MASK, (int)colorWriteMask);
return output;
}
bool useDeferredRendering {
get {
return _cameraInstance.actualRenderingPath == RenderingPath.DeferredLighting ||
_cameraInstance.actualRenderingPath == RenderingPath.DeferredShading;
}
}
bool interlacedRendering {
get {
return SDKUtils.FeatureEnabled(inputFrame.features, FEATURES.INTERLACED_RENDER);
}
}
bool canRenderBackground {
get {
if (interlacedRendering)
{
// Render only if frame is even
if (Time.frameCount % 2 != 0) return false;
}
return SDKUtils.FeatureEnabled(inputFrame.features, FEATURES.BACKGROUND_RENDER) && _backgroundRenderTexture != null;
}
}
bool canRenderForeground {
get {
if (interlacedRendering)
{
// Render only if frame is odd
if (Time.frameCount % 2 != 1) return false;
}
return SDKUtils.FeatureEnabled(inputFrame.features, FEATURES.FOREGROUND_RENDER) && _foregroundRenderTexture != null;
}
}
bool canRenderOptimized {
get {
return SDKUtils.FeatureEnabled(inputFrame.features, FEATURES.OPTIMIZED_RENDER) && _optimizedRenderTexture != null; ;
}
}
public SDKRender(LIV liv)
{
_liv = liv;
CreateAssets();
}
public void Render()
{
UpdateBridgeResolution();
UpdateBridgeInputFrame();
SDKUtils.ApplyUserSpaceTransform(this);
UpdateTextures();
InvokePreRender();
if (canRenderBackground) RenderBackground();
if (canRenderForeground) RenderForeground();
if (canRenderOptimized) RenderOptimized();
IvokePostRender();
SDKUtils.CreateBridgeOutputFrame(this);
SDKBridge.IssuePluginEvent();
}
// Default render without any special changes
private void RenderBackground()
{
SDKUtils.SetCamera(_cameraInstance, _cameraInstance.transform, _inputFrame, localToWorldMatrix, spectatorLayerMask);
_cameraInstance.targetTexture = _backgroundRenderTexture;
RenderTexture tempRenderTexture = null;
bool overridePostProcessing = SDKUtils.FeatureEnabled(inputFrame.features, FEATURES.OVERRIDE_POST_PROCESSING);
if (overridePostProcessing)
{
tempRenderTexture = RenderTexture.GetTemporary(_backgroundRenderTexture.width, _backgroundRenderTexture.height, 0, _backgroundRenderTexture.format);
#if UNITY_EDITOR
tempRenderTexture.name = "LIV.TemporaryRenderTexture";
#endif
_captureTextureCommandBuffer.Blit(BuiltinRenderTextureType.CurrentActive, tempRenderTexture);
_applyTextureCommandBuffer.Blit(tempRenderTexture, BuiltinRenderTextureType.CurrentActive);
_cameraInstance.AddCommandBuffer(_captureTextureEvent, _captureTextureCommandBuffer);
_cameraInstance.AddCommandBuffer(_applyTextureEvent, _applyTextureCommandBuffer);
}
SDKShaders.StartRendering();
SDKShaders.StartBackgroundRendering();
InvokePreRenderBackground();
SendTextureToBridge(_backgroundRenderTexture, TEXTURE_ID.BACKGROUND_COLOR_BUFFER_ID);
_cameraInstance.Render();
InvokePostRenderBackground();
_cameraInstance.targetTexture = null;
SDKShaders.StopBackgroundRendering();
SDKShaders.StopRendering();
if (overridePostProcessing)
{
_cameraInstance.RemoveCommandBuffer(_captureTextureEvent, _captureTextureCommandBuffer);
_cameraInstance.RemoveCommandBuffer(_applyTextureEvent, _applyTextureCommandBuffer);
_captureTextureCommandBuffer.Clear();
_applyTextureCommandBuffer.Clear();
RenderTexture.ReleaseTemporary(tempRenderTexture);
}
}
// Extract the image which is in front of our clip plane
// The compositing is heavily relying on the alpha channel, therefore we want to make sure it does
// not get corrupted by the postprocessing or any shader
private void RenderForeground()
{
bool debugClipPlane = SDKUtils.FeatureEnabled(inputFrame.features, FEATURES.DEBUG_CLIP_PLANE);
bool renderComplexClipPlane = SDKUtils.FeatureEnabled(inputFrame.features, FEATURES.COMPLEX_CLIP_PLANE);
bool renderGroundClipPlane = SDKUtils.FeatureEnabled(inputFrame.features, FEATURES.GROUND_CLIP_PLANE);
bool overridePostProcessing = SDKUtils.FeatureEnabled(inputFrame.features, FEATURES.OVERRIDE_POST_PROCESSING);
bool fixPostEffectsAlpha = SDKUtils.FeatureEnabled(inputFrame.features, FEATURES.FIX_FOREGROUND_ALPHA) | _liv.fixPostEffectsAlpha;
MonoBehaviour[] behaviours = null;
bool[] wasBehaviourEnabled = null;
if (disableStandardAssets) SDKUtils.DisableStandardAssets(_cameraInstance, ref behaviours, ref wasBehaviourEnabled);
// Capture camera defaults
CameraClearFlags capturedClearFlags = _cameraInstance.clearFlags;
Color capturedBgColor = _cameraInstance.backgroundColor;
Color capturedFogColor = RenderSettings.fogColor;
// Make sure that fog does not corrupt alpha channel
RenderSettings.fogColor = new Color(capturedFogColor.r, capturedFogColor.g, capturedFogColor.b, 0f);
SDKUtils.SetCamera(_cameraInstance, _cameraInstance.transform, _inputFrame, localToWorldMatrix, spectatorLayerMask);
_cameraInstance.clearFlags = CameraClearFlags.Color;
_cameraInstance.backgroundColor = Color.clear;
_cameraInstance.targetTexture = _foregroundRenderTexture;
RenderTexture capturedAlphaRenderTexture = RenderTexture.GetTemporary(_foregroundRenderTexture.width, _foregroundRenderTexture.height, 0, _foregroundRenderTexture.format);
#if UNITY_EDITOR
capturedAlphaRenderTexture.name = "LIV.CapturedAlphaRenderTexture";
#endif
// Render opaque pixels into alpha channel
_clipPlaneCommandBuffer.DrawMesh(_clipPlaneMesh, Matrix4x4.identity, _writeOpaqueToAlphaMaterial, 0, 0);
// Render clip plane
Matrix4x4 clipPlaneTransform = localToWorldMatrix * (Matrix4x4)_inputFrame.clipPlane.transform;
_clipPlaneCommandBuffer.DrawMesh(_clipPlaneMesh, clipPlaneTransform,
GetClipPlaneMaterial(debugClipPlane, renderComplexClipPlane, ColorWriteMask.All), 0, 0);
// Render ground clip plane
if (renderGroundClipPlane)
{
Matrix4x4 groundClipPlaneTransform = localToWorldMatrix * (Matrix4x4)_inputFrame.groundClipPlane.transform;
_clipPlaneCommandBuffer.DrawMesh(_clipPlaneMesh, groundClipPlaneTransform,
GetGroundClipPlaneMaterial(debugClipPlane, ColorWriteMask.All), 0, 0);
}
// Copy alpha in to texture
_clipPlaneCommandBuffer.Blit(BuiltinRenderTextureType.CurrentActive, capturedAlphaRenderTexture);
_cameraInstance.AddCommandBuffer(_clipPlaneCameraEvent, _clipPlaneCommandBuffer);
// Fix alpha corruption by post processing
RenderTexture tempRenderTexture = null;
if (overridePostProcessing || fixPostEffectsAlpha)
{
tempRenderTexture = RenderTexture.GetTemporary(_foregroundRenderTexture.width, _foregroundRenderTexture.height, 0, _foregroundRenderTexture.format);
#if UNITY_EDITOR
tempRenderTexture.name = "LIV.TemporaryRenderTexture";
#endif
_captureTextureCommandBuffer.Blit(BuiltinRenderTextureType.CurrentActive, tempRenderTexture);
_cameraInstance.AddCommandBuffer(_captureTextureEvent, _captureTextureCommandBuffer);
_writeMaterial.SetInt(SDKShaders.LIV_COLOR_MASK, overridePostProcessing ? (int)ColorWriteMask.All : (int)ColorWriteMask.Alpha);
_applyTextureCommandBuffer.Blit(tempRenderTexture, BuiltinRenderTextureType.CurrentActive, _writeMaterial);
_cameraInstance.AddCommandBuffer(_applyTextureEvent, _applyTextureCommandBuffer);
}
// Combine captured alpha with result alpha
_combineAlphaMaterial.SetInt(SDKShaders.LIV_COLOR_MASK, (int)ColorWriteMask.Alpha);
_combineAlphaCommandBuffer.Blit(capturedAlphaRenderTexture, BuiltinRenderTextureType.CurrentActive, _combineAlphaMaterial);
_cameraInstance.AddCommandBuffer(_clipPlaneCombineAlphaCameraEvent, _combineAlphaCommandBuffer);
if (useDeferredRendering) SDKUtils.ForceForwardRendering(cameraInstance, _clipPlaneMesh, _forceForwardRenderingMaterial);
SDKShaders.StartRendering();
SDKShaders.StartForegroundRendering();
InvokePreRenderForeground();
SendTextureToBridge(_foregroundRenderTexture, TEXTURE_ID.FOREGROUND_COLOR_BUFFER_ID);
_cameraInstance.Render();
InvokePostRenderForeground();
_cameraInstance.targetTexture = null;
SDKShaders.StopForegroundRendering();
SDKShaders.StopRendering();
if (overridePostProcessing || fixPostEffectsAlpha)
{
_cameraInstance.RemoveCommandBuffer(_captureTextureEvent, _captureTextureCommandBuffer);
_cameraInstance.RemoveCommandBuffer(_applyTextureEvent, _applyTextureCommandBuffer);
_captureTextureCommandBuffer.Clear();
_applyTextureCommandBuffer.Clear();
RenderTexture.ReleaseTemporary(tempRenderTexture);
}
_cameraInstance.RemoveCommandBuffer(_clipPlaneCameraEvent, _clipPlaneCommandBuffer);
_cameraInstance.RemoveCommandBuffer(_clipPlaneCombineAlphaCameraEvent, _combineAlphaCommandBuffer);
RenderTexture.ReleaseTemporary(capturedAlphaRenderTexture);
_clipPlaneCommandBuffer.Clear();
_combineAlphaCommandBuffer.Clear();
// Revert camera defaults
_cameraInstance.clearFlags = capturedClearFlags;
_cameraInstance.backgroundColor = capturedBgColor;
RenderSettings.fogColor = capturedFogColor;
SDKUtils.RestoreStandardAssets(ref behaviours, ref wasBehaviourEnabled);
}
// Renders a single camera in a single texture with occlusion only from opaque objects.
// This is the most performant option for mixed reality.
// It does not support any transparency in the foreground layer.
private void RenderOptimized()
{
bool debugClipPlane = SDKUtils.FeatureEnabled(inputFrame.features, FEATURES.DEBUG_CLIP_PLANE);
bool renderComplexClipPlane = SDKUtils.FeatureEnabled(inputFrame.features, FEATURES.COMPLEX_CLIP_PLANE);
bool renderGroundClipPlane = SDKUtils.FeatureEnabled(inputFrame.features, FEATURES.GROUND_CLIP_PLANE);
SDKUtils.SetCamera(_cameraInstance, _cameraInstance.transform, _inputFrame, localToWorldMatrix, spectatorLayerMask);
_cameraInstance.targetTexture = _optimizedRenderTexture;
// Clear alpha channel
_writeMaterial.SetInt(SDKShaders.LIV_COLOR_MASK, (int)ColorWriteMask.Alpha);
_optimizedRenderingCommandBuffer.Blit(BuiltinRenderTextureType.None, BuiltinRenderTextureType.CurrentActive, _writeMaterial);
// Render opaque pixels into alpha channel
_writeOpaqueToAlphaMaterial.SetInt(SDKShaders.LIV_COLOR_MASK, (int)ColorWriteMask.Alpha);
_optimizedRenderingCommandBuffer.DrawMesh(_clipPlaneMesh, Matrix4x4.identity, _writeOpaqueToAlphaMaterial, 0, 0);
// Render clip plane
Matrix4x4 clipPlaneTransform = localToWorldMatrix * (Matrix4x4)_inputFrame.clipPlane.transform;
_optimizedRenderingCommandBuffer.DrawMesh(_clipPlaneMesh, clipPlaneTransform,
GetClipPlaneMaterial(debugClipPlane, renderComplexClipPlane, ColorWriteMask.Alpha), 0, 0);
// Render ground clip plane
if (renderGroundClipPlane)
{
Matrix4x4 groundClipPlaneTransform = localToWorldMatrix * (Matrix4x4)_inputFrame.groundClipPlane.transform;
_optimizedRenderingCommandBuffer.DrawMesh(_clipPlaneMesh, groundClipPlaneTransform,
GetGroundClipPlaneMaterial(debugClipPlane, ColorWriteMask.Alpha), 0, 0);
}
_cameraInstance.AddCommandBuffer(CameraEvent.AfterEverything, _optimizedRenderingCommandBuffer);
// TODO: this is just proprietary
SDKShaders.StartRendering();
SDKShaders.StartBackgroundRendering();
InvokePreRenderBackground();
SendTextureToBridge(_optimizedRenderTexture, TEXTURE_ID.OPTIMIZED_COLOR_BUFFER_ID);
_cameraInstance.Render();
InvokePostRenderBackground();
_cameraInstance.targetTexture = null;
SDKShaders.StopBackgroundRendering();
SDKShaders.StopRendering();
_cameraInstance.RemoveCommandBuffer(CameraEvent.AfterEverything, _optimizedRenderingCommandBuffer);
_optimizedRenderingCommandBuffer.Clear();
}
private void CreateAssets()
{
bool cameraReferenceEnabled = cameraReference.enabled;
if (cameraReferenceEnabled)
{
cameraReference.enabled = false;
}
bool cameraReferenceActive = cameraReference.gameObject.activeSelf;
if (cameraReferenceActive)
{
cameraReference.gameObject.SetActive(false);
}
GameObject cloneGO = (GameObject)Object.Instantiate(cameraReference.gameObject, _liv.stage);
_cameraInstance = (Camera)cloneGO.GetComponent("Camera");
SDKUtils.CleanCameraBehaviours(_cameraInstance, _liv.excludeBehaviours);
if (cameraReferenceActive != cameraReference.gameObject.activeSelf)
{
cameraReference.gameObject.SetActive(cameraReferenceActive);
}
if (cameraReferenceEnabled != cameraReference.enabled)
{
cameraReference.enabled = cameraReferenceEnabled;
}
_cameraInstance.name = "LIV Camera";
if (_cameraInstance.tag == "MainCamera")
{
_cameraInstance.tag = "Untagged";
}
_cameraInstance.transform.localScale = Vector3.one;
_cameraInstance.rect = new Rect(0, 0, 1, 1);
_cameraInstance.depth = 0;
#if UNITY_5_4_OR_NEWER
_cameraInstance.stereoTargetEye = StereoTargetEyeMask.None;
#endif
#if UNITY_5_6_OR_NEWER
_cameraInstance.allowMSAA = false;
#endif
_cameraInstance.enabled = false;
_cameraInstance.gameObject.SetActive(true);
_clipPlaneMesh = new Mesh();
SDKUtils.CreateClipPlane(_clipPlaneMesh, 10, 10, true, 1000f);
_clipPlaneSimpleMaterial = new Material(Shader.Find(SDKShaders.LIV_CLIP_PLANE_SIMPLE_SHADER));
_clipPlaneSimpleDebugMaterial = new Material(Shader.Find(SDKShaders.LIV_CLIP_PLANE_SIMPLE_DEBUG_SHADER));
_clipPlaneComplexMaterial = new Material(Shader.Find(SDKShaders.LIV_CLIP_PLANE_COMPLEX_SHADER));
_clipPlaneComplexDebugMaterial = new Material(Shader.Find(SDKShaders.LIV_CLIP_PLANE_COMPLEX_DEBUG_SHADER));
_writeOpaqueToAlphaMaterial = new Material(Shader.Find(SDKShaders.LIV_WRITE_OPAQUE_TO_ALPHA_SHADER));
_combineAlphaMaterial = new Material(Shader.Find(SDKShaders.LIV_COMBINE_ALPHA_SHADER));
_writeMaterial = new Material(Shader.Find(SDKShaders.LIV_WRITE_SHADER));
_forceForwardRenderingMaterial = new Material(Shader.Find(SDKShaders.LIV_FORCE_FORWARD_RENDERING_SHADER));
_clipPlaneCommandBuffer = new CommandBuffer();
_combineAlphaCommandBuffer = new CommandBuffer();
_captureTextureCommandBuffer = new CommandBuffer();
_applyTextureCommandBuffer = new CommandBuffer();
_optimizedRenderingCommandBuffer = new CommandBuffer();
#if UNITY_EDITOR
_clipPlaneMesh.name = "LIV.clipPlane";
_clipPlaneSimpleMaterial.name = "LIV.clipPlaneSimple";
_clipPlaneSimpleDebugMaterial.name = "LIV.clipPlaneSimpleDebug";
_clipPlaneComplexMaterial.name = "LIV.clipPlaneComplex";
_clipPlaneComplexDebugMaterial.name = "LIV.clipPlaneComplexDebug";
_writeOpaqueToAlphaMaterial.name = "LIV.writeOpaqueToAlpha";
_combineAlphaMaterial.name = "LIV.combineAlpha";
_writeMaterial.name = "LIV.write";
_forceForwardRenderingMaterial.name = "LIV.forceForwardRendering";
_clipPlaneCommandBuffer.name = "LIV.renderClipPlanes";
_combineAlphaCommandBuffer.name = "LIV.foregroundCombineAlpha";
_captureTextureCommandBuffer.name = "LIV.captureTexture";
_applyTextureCommandBuffer.name = "LIV.applyTexture";
_optimizedRenderingCommandBuffer.name = "LIV.optimizedRendering";
#endif
}
private void DestroyAssets()
{
if (_cameraInstance != null)
{
Object.Destroy(_cameraInstance.gameObject);
_cameraInstance = null;
}
SDKUtils.DestroyObject<Mesh>(ref _clipPlaneMesh);
SDKUtils.DestroyObject<Material>(ref _clipPlaneSimpleMaterial);
SDKUtils.DestroyObject<Material>(ref _clipPlaneSimpleDebugMaterial);
SDKUtils.DestroyObject<Material>(ref _clipPlaneComplexMaterial);
SDKUtils.DestroyObject<Material>(ref _clipPlaneComplexDebugMaterial);
SDKUtils.DestroyObject<Material>(ref _writeOpaqueToAlphaMaterial);
SDKUtils.DestroyObject<Material>(ref _combineAlphaMaterial);
SDKUtils.DestroyObject<Material>(ref _writeMaterial);
SDKUtils.DestroyObject<Material>(ref _forceForwardRenderingMaterial);
SDKUtils.DisposeObject<CommandBuffer>(ref _clipPlaneCommandBuffer);
SDKUtils.DisposeObject<CommandBuffer>(ref _combineAlphaCommandBuffer);
SDKUtils.DisposeObject<CommandBuffer>(ref _captureTextureCommandBuffer);
SDKUtils.DisposeObject<CommandBuffer>(ref _applyTextureCommandBuffer);
SDKUtils.DisposeObject<CommandBuffer>(ref _optimizedRenderingCommandBuffer);
}
public void Dispose()
{
ReleaseBridgePoseControl();
DestroyAssets();
SDKUtils.DestroyTexture(ref _backgroundRenderTexture);
SDKUtils.DestroyTexture(ref _foregroundRenderTexture);
SDKUtils.DestroyTexture(ref _optimizedRenderTexture);
SDKUtils.DestroyTexture(ref _complexClipPlaneRenderTexture);
}
}
}
#endif
-12
View File
@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: d95a392402629db4ca4c405f095e331b
timeCreated: 1510036953
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
-455
View File
@@ -1,455 +0,0 @@
using UnityEngine;
using UnityEngine.Rendering;
using System.Collections;
namespace LIV.SDK.Unity
{
public partial class SDKRender : System.IDisposable
{
private LIV _liv = null;
public LIV liv {
get {
return _liv;
}
}
private SDKOutputFrame _outputFrame = SDKOutputFrame.empty;
public SDKOutputFrame outputFrame {
get {
return _outputFrame;
}
}
private SDKInputFrame _inputFrame = SDKInputFrame.empty;
public SDKInputFrame inputFrame {
get {
return _inputFrame;
}
}
private SDKResolution _resolution = SDKResolution.zero;
public SDKResolution resolution {
get {
return _resolution;
}
}
private Camera _cameraInstance = null;
public Camera cameraInstance {
get {
return _cameraInstance;
}
}
public Camera cameraReference {
get {
return _liv.MRCameraPrefab == null ? _liv.HMDCamera : _liv.MRCameraPrefab;
}
}
public Camera hmdCamera {
get {
return _liv.HMDCamera;
}
}
public Transform stage {
get {
return _liv.stage;
}
}
public Transform stageTransform {
get {
return _liv.stageTransform;
}
}
public Matrix4x4 stageLocalToWorldMatrix {
get {
return _liv.stage == null ? Matrix4x4.identity : _liv.stage.localToWorldMatrix;
}
}
public Matrix4x4 localToWorldMatrix {
get {
return _liv.stageTransform == null ? stageLocalToWorldMatrix : _liv.stageTransform.localToWorldMatrix;
}
}
public int spectatorLayerMask {
get {
return _liv.spectatorLayerMask;
}
}
public bool disableStandardAssets {
get {
return _liv.disableStandardAssets;
}
}
private SDKPose _requestedPose = SDKPose.empty;
private int _requestedPoseFrameIndex = 0;
/// <summary>
/// Detect if the game can actually change the pose during this frame.
/// </summary>
/// <remarks>
/// <para>Because other applications can take over the pose, the game has to know if it can take over the pose or not.</para>
/// </remarks>
/// <example>
/// <code>
/// public class CanControlCameraPose : MonoBehaviour
/// {
/// [SerializeField] LIV.SDK.Unity.LIV _liv;
///
/// private void Update()
/// {
/// if(_liv.isActive)
/// {
/// Debug.Log(_liv.render.canSetPose);
/// }
/// }
/// }
/// </code>
/// </example>
public bool canSetPose
{
get {
if (_inputFrame.frameid == 0) return false;
return _inputFrame.priority.pose <= (sbyte)PRIORITY.GAME;
}
}
/// <summary>
/// Control camera pose by calling this method each frame. The pose is released when you stop calling it.
/// </summary>
/// <remarks>
/// <para>By default the pose is set in worldspace, turn on local space for using the stage relative space instead.</para>
/// </remarks>
/// <example>
/// <code>
/// public class ControlCameraPose : MonoBehaviour
/// {
/// [SerializeField] LIV.SDK.Unity.LIV _liv;
/// [SerializeField] float _fov = 60f;
///
/// private void Update()
/// {
/// if(_liv.isActive)
/// {
/// _liv.render.SetPose(transform.position, transform.rotation, _fov);
/// }
/// }
/// }
/// </code>
/// </example>
public bool SetPose(Vector3 position, Quaternion rotation, float verticalFieldOfView = 60f, bool useLocalSpace = false)
{
if (_inputFrame.frameid == 0) return false;
SDKPose inputPose = _inputFrame.pose;
float aspect = 1f;
if (_resolution.height > 0)
{
aspect = (float)_resolution.width / (float)_resolution.height;
}
if (!useLocalSpace)
{
Matrix4x4 worldToLocal = Matrix4x4.identity;
Transform localTransform = stageTransform == null ? stage : stageTransform;
if(localTransform != null) worldToLocal = localTransform.worldToLocalMatrix;
position = worldToLocal.MultiplyPoint(position);
rotation = SDKUtils.RotateQuaternionByMatrix(worldToLocal, rotation);
}
_requestedPose = new SDKPose()
{
localPosition = position,
localRotation = rotation,
verticalFieldOfView = verticalFieldOfView,
projectionMatrix = Matrix4x4.Perspective(verticalFieldOfView, aspect, inputPose.nearClipPlane, inputPose.farClipPlane)
};
_requestedPoseFrameIndex = Time.frameCount;
return _inputFrame.priority.pose <= (sbyte)PRIORITY.GAME;
}
/// <summary>
/// Set the game ground plane.
/// </summary>
/// <remarks>
/// <para>If you wisth to use local space coordinates use local space instead.
/// The local space has to be relative to stage or stage transform if set.
/// </para>
/// </remarks>
public void SetGroundPlane(float distance, Vector3 normal, bool useLocalSpace = false)
{
float outputDistance = distance;
Vector3 outputNormal = normal;
if (!useLocalSpace)
{
Transform localTransform = stageTransform == null ? stage : stageTransform;
Matrix4x4 worldToLocal = localTransform.worldToLocalMatrix;
Vector3 localPosition = worldToLocal.MultiplyPoint(normal * distance);
outputNormal = worldToLocal.MultiplyVector(normal);
outputDistance = -Vector3.Dot(normal, localPosition);
}
SDKBridge.SetGroundPlane(new SDKPlane() { distance = outputDistance, normal = outputNormal });
}
/// <summary>
/// Set the game ground plane.
/// </summary>
/// <remarks>
/// <para>If you wisth to use local space coordinates use local space instead.
/// The local space has to be relative to stage or stage transform if set.
/// </para>
/// </remarks>
public void SetGroundPlane(Plane plane, bool useLocalSpace = false)
{
SetGroundPlane(plane.distance, plane.normal, useLocalSpace);
}
/// <summary>
/// Set the game ground plane.
/// </summary>
/// <remarks>
/// <para>The transform up vector defines the normal of the plane and the position defines the distance.
/// By default, the transform uses world space coordinates. If you wisth to use local space coordinates
/// use local space instead. The local space has to be relative to stage or stage transform if set.
/// </para>
/// </remarks>
/// <example>
/// <code>
/// public class SetGround : MonoBehaviour
/// {
/// [SerializeField] LIV.SDK.Unity.LIV _liv = null;
///
/// void Update ()
/// {
/// if(_liv.isActive)
/// {
/// _liv.render.SetGroundPlane(transform);
/// }
/// }
/// }
/// </code>
/// </example>
public void SetGroundPlane(Transform transform, bool useLocalSpace = false)
{
if (transform == null) return;
Quaternion rotation = useLocalSpace ? transform.localRotation : transform.rotation;
Vector3 position = useLocalSpace ? transform.localPosition : transform.position;
Vector3 normal = rotation * Vector3.up;
SetGroundPlane(-Vector3.Dot(normal, position), normal, useLocalSpace);
}
private void ReleaseBridgePoseControl()
{
_inputFrame.ReleaseControl();
SDKBridge.UpdateInputFrame(ref _inputFrame);
}
private void UpdateBridgeResolution()
{
SDKBridge.GetResolution(ref _resolution);
}
private void UpdateBridgeInputFrame()
{
if (_requestedPoseFrameIndex == Time.frameCount)
{
_inputFrame.ObtainControl();
_inputFrame.pose = _requestedPose;
_requestedPose = SDKPose.empty;
}
else
{
_inputFrame.ReleaseControl();
}
if (_cameraInstance != null)
{
// Near and far is always driven by game
_inputFrame.pose.nearClipPlane = _cameraInstance.nearClipPlane;
_inputFrame.pose.farClipPlane = _cameraInstance.farClipPlane;
}
SDKBridge.UpdateInputFrame(ref _inputFrame);
}
private void InvokePreRender()
{
if (_liv.onPreRender != null) _liv.onPreRender(this);
}
private void IvokePostRender()
{
if (_liv.onPostRender != null) _liv.onPostRender(this);
}
private void InvokePreRenderBackground()
{
if (_liv.onPreRenderBackground != null) _liv.onPreRenderBackground(this);
}
private void InvokePostRenderBackground()
{
if (_liv.onPostRenderBackground != null) _liv.onPostRenderBackground(this);
}
private void InvokePreRenderForeground()
{
if (_liv.onPreRenderForeground != null) _liv.onPreRenderForeground(this);
}
private void InvokePostRenderForeground()
{
if (_liv.onPostRenderForeground != null) _liv.onPostRenderForeground(this);
}
private void CreateBackgroundTexture()
{
if (SDKUtils.CreateTexture(ref _backgroundRenderTexture, _resolution.width, _resolution.height, 24, RenderTextureFormat.ARGB32))
{
#if UNITY_EDITOR
_backgroundRenderTexture.name = "LIV.BackgroundRenderTexture";
#endif
}
else
{
Debug.LogError("LIV: Unable to create background texture!");
}
}
private void CreateForegroundTexture()
{
if (SDKUtils.CreateTexture(ref _foregroundRenderTexture, _resolution.width, _resolution.height, 24, RenderTextureFormat.ARGB32))
{
#if UNITY_EDITOR
_foregroundRenderTexture.name = "LIV.ForegroundRenderTexture";
#endif
}
else
{
Debug.LogError("LIV: Unable to create foreground texture!");
}
}
private void CreateOptimizedTexture()
{
if (SDKUtils.CreateTexture(ref _optimizedRenderTexture, _resolution.width, _resolution.height, 24, RenderTextureFormat.ARGB32))
{
#if UNITY_EDITOR
_optimizedRenderTexture.name = "LIV.OptimizedRenderTexture";
#endif
}
else
{
Debug.LogError("LIV: Unable to create optimized texture!");
}
}
private void CreateComplexClipPlaneTexture()
{
if (SDKUtils.CreateTexture(ref _complexClipPlaneRenderTexture, _inputFrame.clipPlane.width, _inputFrame.clipPlane.height, 0, RenderTextureFormat.ARGB32))
{
#if UNITY_EDITOR
_complexClipPlaneRenderTexture.name = "LIV.ComplexClipPlaneRenderTexture";
#endif
}
else
{
Debug.LogError("LIV: Unable to create complex clip plane texture!");
}
}
private void UpdateTextures()
{
if (SDKUtils.FeatureEnabled(inputFrame.features, FEATURES.BACKGROUND_RENDER))
{
if (
_backgroundRenderTexture == null ||
_backgroundRenderTexture.width != _resolution.width ||
_backgroundRenderTexture.height != _resolution.height
)
{
CreateBackgroundTexture();
}
}
else
{
SDKUtils.DestroyTexture(ref _backgroundRenderTexture);
}
if (SDKUtils.FeatureEnabled(inputFrame.features, FEATURES.FOREGROUND_RENDER))
{
if (
_foregroundRenderTexture == null ||
_foregroundRenderTexture.width != _resolution.width ||
_foregroundRenderTexture.height != _resolution.height
)
{
CreateForegroundTexture();
}
}
else
{
SDKUtils.DestroyTexture(ref _foregroundRenderTexture);
}
if (SDKUtils.FeatureEnabled(inputFrame.features, FEATURES.OPTIMIZED_RENDER))
{
if (
_optimizedRenderTexture == null ||
_optimizedRenderTexture.width != _resolution.width ||
_optimizedRenderTexture.height != _resolution.height
)
{
CreateOptimizedTexture();
}
}
else
{
SDKUtils.DestroyTexture(ref _optimizedRenderTexture);
}
if (SDKUtils.FeatureEnabled(inputFrame.features, FEATURES.COMPLEX_CLIP_PLANE))
{
if (
_complexClipPlaneRenderTexture == null ||
_complexClipPlaneRenderTexture.width != _inputFrame.clipPlane.width ||
_complexClipPlaneRenderTexture.height != _inputFrame.clipPlane.height
)
{
CreateComplexClipPlaneTexture();
}
}
else
{
SDKUtils.DestroyTexture(ref _complexClipPlaneRenderTexture);
}
}
void SendTextureToBridge(RenderTexture texture, TEXTURE_ID id)
{
SDKBridge.AddTexture(new SDKTexture()
{
id = id,
texturePtr = texture.GetNativeTexturePtr(),
SharedHandle = System.IntPtr.Zero,
device = SDKUtils.GetDevice(),
dummy = 0,
type = TEXTURE_TYPE.COLOR_BUFFER,
format = TEXTURE_FORMAT.ARGB32,
colorSpace = SDKUtils.GetColorSpace(texture),
width = texture.width,
height = texture.height
});
}
}
}
@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: a94a68ad9d706bb4480459d82d94cd61
timeCreated: 1599996572
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
-56
View File
@@ -1,56 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace LIV.SDK.Unity
{
static class SDKShaders
{
public static readonly int LIV_COLOR_MASK = Shader.PropertyToID("_LivColorMask");
public static readonly int LIV_TESSELLATION_PROPERTY = Shader.PropertyToID("_LivTessellation");
public static readonly int LIV_CLIP_PLANE_HEIGHT_MAP_PROPERTY = Shader.PropertyToID("_LivClipPlaneHeightMap");
public const string LIV_MR_FOREGROUND_KEYWORD = "LIV_MR_FOREGROUND";
public const string LIV_MR_BACKGROUND_KEYWORD = "LIV_MR_BACKGROUND";
public const string LIV_MR_KEYWORD = "LIV_MR";
public const string LIV_CLIP_PLANE_SIMPLE_SHADER = "Hidden/LIV_ClipPlaneSimple";
public const string LIV_CLIP_PLANE_SIMPLE_DEBUG_SHADER = "Hidden/LIV_ClipPlaneSimpleDebug";
public const string LIV_CLIP_PLANE_COMPLEX_SHADER = "Hidden/LIV_ClipPlaneComplex";
public const string LIV_CLIP_PLANE_COMPLEX_DEBUG_SHADER = "Hidden/LIV_ClipPlaneComplexDebug";
public const string LIV_WRITE_OPAQUE_TO_ALPHA_SHADER = "Hidden/LIV_WriteOpaqueToAlpha";
public const string LIV_COMBINE_ALPHA_SHADER = "Hidden/LIV_CombineAlpha";
public const string LIV_WRITE_SHADER = "Hidden/LIV_Write";
public const string LIV_FORCE_FORWARD_RENDERING_SHADER = "Hidden/LIV_ForceForwardRendering";
public static void StartRendering()
{
Shader.EnableKeyword(LIV_MR_KEYWORD);
}
public static void StopRendering()
{
Shader.DisableKeyword(LIV_MR_KEYWORD);
}
public static void StartForegroundRendering()
{
Shader.EnableKeyword(LIV_MR_FOREGROUND_KEYWORD);
}
public static void StopForegroundRendering()
{
Shader.DisableKeyword(LIV_MR_FOREGROUND_KEYWORD);
}
public static void StartBackgroundRendering()
{
Shader.EnableKeyword(LIV_MR_BACKGROUND_KEYWORD);
}
public static void StopBackgroundRendering()
{
Shader.DisableKeyword(LIV_MR_BACKGROUND_KEYWORD);
}
}
}
-12
View File
@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 1ffc258898c8481478d5a2a57c4c6930
timeCreated: 1579099149
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
-941
View File
@@ -1,941 +0,0 @@
using UnityEngine;
using System.Runtime.InteropServices;
using System;
namespace LIV.SDK.Unity
{
public struct SDKConstants
{
public const string SDK_ID = "JRTV2MJRPD3LYLJRJ0VFI5MV36RRN9MD";
public const string SDK_VERSION = "1.5.4";
public const string ENGINE_NAME = "unity";
}
public enum PRIORITY : sbyte
{
NONE = 0,
GAME = 63
}
[System.Flags]
public enum FEATURES : ulong
{
NONE = 0L,
BACKGROUND_RENDER = 1L,
FOREGROUND_RENDER = 1L << 1,
COMPLEX_CLIP_PLANE = 1L << 2,
BACKGROUND_DEPTH_RENDER = 1L << 3,
OVERRIDE_POST_PROCESSING = 1L << 4,
FIX_FOREGROUND_ALPHA = 1L << 5,
GROUND_CLIP_PLANE = 1L << 6,
RELEASE_CONTROL = 1L << 15,
OPTIMIZED_RENDER = 1L << 28,
INTERLACED_RENDER = 1L << 29,
DEBUG_CLIP_PLANE = 1L << 48,
}
public enum TEXTURE_ID : uint
{
UNDEFINED = 0,
BACKGROUND_COLOR_BUFFER_ID = 10,
FOREGROUND_COLOR_BUFFER_ID = 20,
OPTIMIZED_COLOR_BUFFER_ID = 30
}
public enum TEXTURE_TYPE : uint
{
UNDEFINED = 0,
COLOR_BUFFER = 1
}
public enum TEXTURE_FORMAT : uint
{
UNDEFINED = 0,
ARGB32 = 10
}
public enum TEXTURE_DEVICE : uint
{
UNDEFINED = 0,
RAW = 1,
DIRECTX = 2,
OPENGL = 3,
VULKAN = 4,
METAL = 5
}
public enum TEXTURE_COLOR_SPACE : uint
{
UNDEFINED = 0,
LINEAR = 1,
SRGB = 2,
}
public enum RENDERING_PIPELINE : uint
{
UNDEFINED = 0,
FORWARD = 1,
DEFERRED = 2,
VERTEX_LIT = 3,
UNIVERSAL = 4,
HIGH_DEFINITION = 5
}
[StructLayout(LayoutKind.Sequential)]
public struct SDKResolution
{
public int width, height;
public static SDKResolution zero {
get {
return new SDKResolution() { width = 0, height = 0 };
}
}
public override string ToString()
{
return
$@"SDKResolution:
width: {width}
height: {height}";
}
}
[StructLayout(LayoutKind.Sequential)]
public struct SDKVector3
{
public float x, y, z;
public static SDKVector3 zero {
get {
return new SDKVector3() { x = 0, y = 0, z = 0 };
}
}
public static SDKVector3 one {
get {
return new SDKVector3() { x = 1, y = 1, z = 1 };
}
}
public static SDKVector3 forward {
get {
return new SDKVector3() { x = 0, y = 0, z = 1 };
}
}
public static SDKVector3 up {
get {
return new SDKVector3() { x = 0, y = 1, z = 0 };
}
}
public static SDKVector3 right {
get {
return new SDKVector3() { x = 1, y = 0, z = 0 };
}
}
public static implicit operator Vector3(SDKVector3 v)
{
return new Vector3(v.x, v.y, v.z);
}
public static implicit operator SDKVector3(Vector3 v)
{
return new SDKVector3() { x = v.x, y = v.y, z = v.z };
}
// Delete begin
public static SDKVector3 operator +(SDKVector3 lhs, SDKVector3 rhs)
{
SDKVector3 res;
res.x = lhs.x + rhs.x;
res.y = lhs.y + rhs.y;
res.z = lhs.z + rhs.z;
return res;
}
public static SDKVector3 operator -(SDKVector3 lhs, SDKVector3 rhs)
{
SDKVector3 res;
res.x = lhs.x - rhs.x;
res.y = lhs.y - rhs.y;
res.z = lhs.z - rhs.z;
return res;
}
public static SDKVector3 operator *(SDKVector3 lhs, SDKVector3 rhs)
{
SDKVector3 res;
res.x = lhs.x * rhs.x;
res.y = lhs.y * rhs.y;
res.z = lhs.z * rhs.z;
return res;
}
public static SDKVector3 operator *(SDKVector3 lhs, float rhs)
{
SDKVector3 res;
res.x = lhs.x * rhs;
res.y = lhs.y * rhs;
res.z = lhs.z * rhs;
return res;
}
// delete end
public override string ToString()
{
return
$@"SDKVector3:
x: {x}
y: {y}
z: {z}";
}
}
[StructLayout(LayoutKind.Sequential)]
public struct SDKQuaternion
{
public float x, y, z, w;
public static SDKQuaternion identity {
get {
return new SDKQuaternion() { x = 0, y = 0, z = 0, w = 1.0f };
}
}
public static implicit operator Quaternion(SDKQuaternion v)
{
return new Quaternion(v.x, v.y, v.z, v.w);
}
public static implicit operator SDKQuaternion(Quaternion v)
{
return new SDKQuaternion() { x = v.x, y = v.y, z = v.z, w = v.w };
}
// Delete begin
public static SDKQuaternion Euler(float pitch, float yaw, float roll)
{
float rollOver2 = roll * 0.5f;
float sinRollOver2 = Mathf.Sin(rollOver2);
float cosRollOver2 = Mathf.Cos(rollOver2);
float pitchOver2 = pitch * 0.5f;
float sinPitchOver2 = Mathf.Sin(pitchOver2);
float cosPitchOver2 = Mathf.Cos(pitchOver2);
float yawOver2 = yaw * 0.5f;
float sinYawOver2 = Mathf.Sin(yawOver2);
float cosYawOver2 = Mathf.Cos(yawOver2);
var w = cosYawOver2 * cosPitchOver2 * cosRollOver2 + sinYawOver2 * sinPitchOver2 * sinRollOver2;
var x = cosYawOver2 * sinPitchOver2 * cosRollOver2 + sinYawOver2 * cosPitchOver2 * sinRollOver2;
var y = sinYawOver2 * cosPitchOver2 * cosRollOver2 - cosYawOver2 * sinPitchOver2 * sinRollOver2;
var z = cosYawOver2 * cosPitchOver2 * sinRollOver2 - sinYawOver2 * sinPitchOver2 * cosRollOver2;
return new SDKQuaternion() { x = x, y = y, z = z, w = w };
}
public static SDKQuaternion operator *(SDKQuaternion lhs, SDKQuaternion rhs)
{
float tx = lhs.w * rhs.x + lhs.x * rhs.w + lhs.y * rhs.z - lhs.z * rhs.y;
float ty = lhs.w * rhs.y + lhs.y * rhs.w + lhs.z * rhs.x - lhs.x * rhs.z;
float tz = lhs.w * rhs.z + lhs.z * rhs.w + lhs.x * rhs.y - lhs.y * rhs.x;
float tw = lhs.w * rhs.w - lhs.x * rhs.x - lhs.y * rhs.y - lhs.z * rhs.z;
return new SDKQuaternion() { x = tx, y = ty, z = tz, w = tw };
}
public static SDKVector3 operator *(SDKQuaternion lhs, SDKVector3 rhs)
{
float tx = lhs.x * 2.0f;
float ty = lhs.y * 2.0f;
float tz = lhs.z * 2.0f;
float txx = lhs.x * tx;
float tyy = lhs.y * ty;
float tzz = lhs.z * tz;
float txy = lhs.x * ty;
float txz = lhs.x * tz;
float tyz = lhs.y * tz;
float twx = lhs.w * tx;
float twy = lhs.w * ty;
float twz = lhs.w * tz;
SDKVector3 res;
res.x = (1.0f - (tyy + tzz)) * rhs.x + (txy - twz) * rhs.y + (txz + twy) * rhs.z;
res.y = (txy + twz) * rhs.x + (1.0f - (txx + tzz)) * rhs.y + (tyz - twx) * rhs.z;
res.z = (txz - twy) * rhs.x + (tyz + twx) * rhs.y + (1.0f - (txx + tyy)) * rhs.z;
return res;
}
// Delete end
public override string ToString()
{
return
$@"SDKQuaternion:
x: {x}
y: {y}
z: {z}
w: {w}";
}
}
[StructLayout(LayoutKind.Sequential)]
public struct SDKMatrix4x4
{
public float m00, m01, m02, m03,
m10, m11, m12, m13,
m20, m21, m22, m23,
m30, m31, m32, m33;
public static SDKMatrix4x4 identity {
get {
return new SDKMatrix4x4()
{
m00 = 1,
m01 = 0,
m02 = 0,
m03 = 0,
m10 = 0,
m11 = 1,
m12 = 0,
m13 = 0,
m20 = 0,
m21 = 0,
m22 = 1,
m23 = 0,
m30 = 0,
m31 = 0,
m32 = 0,
m33 = 1
};
}
}
public static implicit operator Matrix4x4(SDKMatrix4x4 v)
{
return new Matrix4x4()
{
m00 = v.m00,
m01 = v.m01,
m02 = v.m02,
m03 = v.m03,
m10 = v.m10,
m11 = v.m11,
m12 = v.m12,
m13 = v.m13,
m20 = v.m20,
m21 = v.m21,
m22 = v.m22,
m23 = v.m23,
m30 = v.m30,
m31 = v.m31,
m32 = v.m32,
m33 = v.m33
};
}
public static implicit operator SDKMatrix4x4(Matrix4x4 v)
{
return new SDKMatrix4x4()
{
m00 = v.m00,
m01 = v.m01,
m02 = v.m02,
m03 = v.m03,
m10 = v.m10,
m11 = v.m11,
m12 = v.m12,
m13 = v.m13,
m20 = v.m20,
m21 = v.m21,
m22 = v.m22,
m23 = v.m23,
m30 = v.m30,
m31 = v.m31,
m32 = v.m32,
m33 = v.m33
};
}
public static SDKMatrix4x4 Perspective(float vFov, float aspect, float zNear, float zFar)
{
float vFovRad = vFov * Mathf.Deg2Rad;
float hFovRad = 2.0f * Mathf.Atan(Mathf.Tan(vFovRad * 0.5f) * aspect);
float w = 1.0f / Mathf.Tan(hFovRad * 0.5f);
float h = 1.0f / Mathf.Tan(vFovRad * 0.5f);
float q0 = (zFar + zNear) / (zNear - zFar);
float q1 = 2.0f * (zFar * zNear) / (zNear - zFar);
return new SDKMatrix4x4()
{
m00 = w,
m01 = 0,
m02 = 0,
m03 = 0,
m10 = 0,
m11 = h,
m12 = 0,
m13 = 0,
m20 = 0,
m21 = 0,
m22 = q0,
m23 = q1,
m30 = 0,
m31 = 0,
m32 = -1,
m33 = 0
};
}
// begin delete
public static SDKMatrix4x4 operator *(SDKMatrix4x4 lhs, SDKMatrix4x4 rhs)
{
SDKMatrix4x4 res = SDKMatrix4x4.identity;
res.m00 = lhs.m00 * rhs.m00 + lhs.m01 * rhs.m10 + lhs.m02 * rhs.m20 + lhs.m03 * rhs.m30;
res.m01 = lhs.m00 * rhs.m01 + lhs.m01 * rhs.m11 + lhs.m02 * rhs.m21 + lhs.m03 * rhs.m31;
res.m02 = lhs.m00 * rhs.m02 + lhs.m01 * rhs.m12 + lhs.m02 * rhs.m22 + lhs.m03 * rhs.m32;
res.m03 = lhs.m00 * rhs.m03 + lhs.m01 * rhs.m13 + lhs.m02 * rhs.m23 + lhs.m03 * rhs.m33;
res.m10 = lhs.m10 * rhs.m00 + lhs.m11 * rhs.m10 + lhs.m12 * rhs.m20 + lhs.m13 * rhs.m30;
res.m11 = lhs.m10 * rhs.m01 + lhs.m11 * rhs.m11 + lhs.m12 * rhs.m21 + lhs.m13 * rhs.m31;
res.m12 = lhs.m10 * rhs.m02 + lhs.m11 * rhs.m12 + lhs.m12 * rhs.m22 + lhs.m13 * rhs.m32;
res.m13 = lhs.m10 * rhs.m03 + lhs.m11 * rhs.m13 + lhs.m12 * rhs.m23 + lhs.m13 * rhs.m33;
res.m20 = lhs.m20 * rhs.m00 + lhs.m21 * rhs.m10 + lhs.m22 * rhs.m20 + lhs.m23 * rhs.m30;
res.m21 = lhs.m20 * rhs.m01 + lhs.m21 * rhs.m11 + lhs.m22 * rhs.m21 + lhs.m23 * rhs.m31;
res.m22 = lhs.m20 * rhs.m02 + lhs.m21 * rhs.m12 + lhs.m22 * rhs.m22 + lhs.m23 * rhs.m32;
res.m23 = lhs.m20 * rhs.m03 + lhs.m21 * rhs.m13 + lhs.m22 * rhs.m23 + lhs.m23 * rhs.m33;
res.m30 = lhs.m30 * rhs.m00 + lhs.m31 * rhs.m10 + lhs.m32 * rhs.m20 + lhs.m33 * rhs.m30;
res.m31 = lhs.m30 * rhs.m01 + lhs.m31 * rhs.m11 + lhs.m32 * rhs.m21 + lhs.m33 * rhs.m31;
res.m32 = lhs.m30 * rhs.m02 + lhs.m31 * rhs.m12 + lhs.m32 * rhs.m22 + lhs.m33 * rhs.m32;
res.m33 = lhs.m30 * rhs.m03 + lhs.m31 * rhs.m13 + lhs.m32 * rhs.m23 + lhs.m33 * rhs.m33;
return res;
}
public static SDKVector3 operator *(SDKMatrix4x4 lhs, SDKVector3 rhs)
{
SDKVector3 res;
res.x = lhs.m00 * rhs.x + lhs.m01 * rhs.y + lhs.m02 * rhs.z;
res.y = lhs.m10 * rhs.x + lhs.m11 * rhs.y + lhs.m12 * rhs.z;
res.z = lhs.m20 * rhs.x + lhs.m21 * rhs.y + lhs.m22 * rhs.z;
return res;
}
// Creates a translation matrix.
public static SDKMatrix4x4 Translate(SDKVector3 value)
{
return new SDKMatrix4x4
{
m00 = 1.0f,
m01 = 0.0f,
m02 = 0.0f,
m03 = value.x,
m10 = 0.0f,
m11 = 1.0f,
m12 = 0.0f,
m13 = value.y,
m20 = 0.0f,
m21 = 0.0f,
m22 = 1.0f,
m23 = value.z,
m30 = 0.0f,
m31 = 0.0f,
m32 = 0.0f,
m33 = 1.0f
};
}
// Creates a rotation matrix.
public static SDKMatrix4x4 Rotate(SDKQuaternion value)
{
float qx = value.x;
float qy = value.y;
float qz = value.z;
float qw = value.w;
return new SDKMatrix4x4
{
m00 = 1.0f - 2.0f * qy * qy - 2.0f * qz * qz,
m01 = 2.0f * qx * qy - 2.0f * qz * qw,
m02 = 2.0f * qx * qz + 2.0f * qy * qw,
m03 = 0.0f,
m10 = 2.0f * qx * qy + 2.0f * qz * qw,
m11 = 1.0f - 2.0f * qx * qx - 2.0f * qz * qz,
m12 = 2.0f * qy * qz - 2.0f * qx * qw,
m13 = 0.0f,
m20 = 2.0f * qx * qz - 2.0f * qy * qw,
m21 = 2.0f * qy * qz + 2.0f * qx * qw,
m22 = 1.0f - 2.0f * qx * qx - 2.0f * qy * qy,
m23 = 0.0f,
m30 = 0.0f,
m31 = 0.0f,
m32 = 0.0f,
m33 = 1.0f
};
}
// Creates a scaling matrix.
public static SDKMatrix4x4 Scale(SDKVector3 value)
{
return new SDKMatrix4x4
{
m00 = value.x,
m01 = 0.0f,
m02 = 0.0f,
m03 = 0.0f,
m10 = 0.0f,
m11 = value.y,
m12 = 0.0f,
m13 = 0.0f,
m20 = 0.0f,
m21 = 0.0f,
m22 = value.z,
m23 = 0.0f,
m30 = 0.0f,
m31 = 0.0f,
m32 = 0.0f,
m33 = 1.0f
};
}
public static SDKMatrix4x4 TRS(SDKVector3 translation, SDKQuaternion rotation, SDKVector3 scale)
{
return Translate(translation) * Rotate(rotation) * Scale(scale);
}
// end delete
public override string ToString()
{
return
$@"Matrix4x4:
{m00} {m01} {m02} {m03}
{m10} {m11} {m12} {m13}
{m20} {m21} {m22} {m23}
{m30} {m31} {m32} {m33}";
}
}
[StructLayout(LayoutKind.Sequential)]
public struct SDKPlane
{
public float distance;
public SDKVector3 normal;
public static implicit operator SDKPlane(Plane v)
{
return new SDKPlane()
{
distance = v.distance,
normal = v.normal
};
}
public static SDKPlane empty {
get {
return new SDKPlane() { distance = 0f, normal = SDKVector3.up };
}
}
public override string ToString()
{
return
$@"SDKPlane:
{distance} {normal}";
}
}
[StructLayout(LayoutKind.Sequential)]
public struct SDKPriority
{
public sbyte pose;
public sbyte clipPlane;
public sbyte stage;
public sbyte resolution;
public sbyte feature;
public sbyte nearFarAdjustment;
public sbyte groundPlane;
public sbyte reserved2;
public static SDKPriority empty {
get {
return new SDKPriority()
{
pose = -(sbyte)PRIORITY.GAME,
clipPlane = -(sbyte)PRIORITY.GAME,
stage = -(sbyte)PRIORITY.GAME,
resolution = -(sbyte)PRIORITY.GAME,
feature = -(sbyte)PRIORITY.GAME,
nearFarAdjustment = (sbyte)PRIORITY.GAME,
groundPlane = -(sbyte)PRIORITY.GAME,
reserved2 = -(sbyte)PRIORITY.GAME
};
}
}
public override string ToString()
{
return
$@"Priority:
pose: {pose}, clipPlane: {clipPlane}, stage: {stage}, resolution: {resolution}, feature: {feature}, nearFarAdjustment: {nearFarAdjustment}, groundPlane: {groundPlane}";
}
}
[StructLayout(LayoutKind.Sequential)]
public struct SDKApplicationOutput
{
public FEATURES supportedFeatures;
public string engineName;
public string engineVersion;
public string applicationName;
public string applicationVersion;
public string xrDeviceName;
public string graphicsAPI;
public string sdkID;
public string sdkVersion;
public static SDKApplicationOutput empty {
get {
return new SDKApplicationOutput()
{
supportedFeatures = FEATURES.NONE,
engineName = string.Empty,
engineVersion = string.Empty,
applicationName = string.Empty,
applicationVersion = string.Empty,
xrDeviceName = string.Empty,
graphicsAPI = string.Empty,
sdkID = SDKConstants.SDK_ID,
sdkVersion = string.Empty
};
}
}
public override string ToString()
{
return
$@"SDKApplicationOutput:
supportedFeatures: {supportedFeatures}
engineName: {engineName}
engineVersion: {engineVersion}
applicationName: {applicationName}
applicationVersion: {applicationVersion}
xrDeviceName: {xrDeviceName}
graphicsAPI: {graphicsAPI}
sdkID: {sdkID}
sdkVersion: {sdkVersion}";
}
}
[StructLayout(LayoutKind.Sequential)]
public struct SDKInputFrame
{
public SDKPose pose;
public SDKClipPlane clipPlane;
public SDKTransform stageTransform;
public FEATURES features;
public SDKClipPlane groundClipPlane;
public ulong frameid; // This is actually the time stamp of this frame - its populated by the bridge at creation time.
public ulong referenceframe; // Use the previous frames frameid to populate this field - it must be set to the correct frame id, or it will fail.
public SDKPriority priority; // this is a mixed field combining flags and priority - the contents of this flag are not yet set in stone
public static SDKInputFrame empty {
get {
return new SDKInputFrame()
{
pose = SDKPose.empty,
clipPlane = SDKClipPlane.empty,
stageTransform = SDKTransform.empty,
features = FEATURES.NONE,
groundClipPlane = SDKClipPlane.empty,
frameid = 0,
referenceframe = 0,
priority = SDKPriority.empty
};
}
}
public void ReleaseControl()
{
priority = SDKPriority.empty;
}
public void ObtainControl()
{
priority = SDKPriority.empty;
priority.pose = (sbyte)PRIORITY.GAME;
}
public override string ToString()
{
return
$@"SDKInputFrame:
pose: {pose}
clipPlane: {clipPlane}
stageTransform: {stageTransform}
features: {features}
groundClipPlane: {groundClipPlane}
frameid: {frameid}
referenceframe: {referenceframe}
priority: {priority:X4}";
}
}
[StructLayout(LayoutKind.Sequential)]
public struct SDKOutputFrame
{
public RENDERING_PIPELINE renderingPipeline;
public SDKTrackedSpace trackedSpace;
public static SDKOutputFrame empty {
get {
return new SDKOutputFrame()
{
renderingPipeline = RENDERING_PIPELINE.UNDEFINED,
trackedSpace = SDKTrackedSpace.empty
};
}
}
public override string ToString()
{
return
$@"SDKOutputFrame:
renderingPipeline: {renderingPipeline}
trackedSpace: {trackedSpace}";
}
}
[StructLayout(LayoutKind.Sequential)]
public struct SDKTrackedSpace
{
public SDKVector3 trackedSpaceWorldPosition;
public SDKQuaternion trackedSpaceWorldRotation;
public SDKVector3 trackedSpaceLocalScale;
public SDKMatrix4x4 trackedSpaceLocalToWorldMatrix;
public SDKMatrix4x4 trackedSpaceWorldToLocalMatrix;
public static SDKTrackedSpace empty {
get {
return new SDKTrackedSpace()
{
trackedSpaceWorldPosition = SDKVector3.zero,
trackedSpaceWorldRotation = SDKQuaternion.identity,
trackedSpaceLocalScale = SDKVector3.zero,
trackedSpaceLocalToWorldMatrix = SDKMatrix4x4.identity,
trackedSpaceWorldToLocalMatrix = SDKMatrix4x4.identity
};
}
}
public override string ToString()
{
return
$@"SDKTrackedSpace:
trackedSpaceWorldPosition: {trackedSpaceWorldPosition}
trackedSpaceWorldRotation: {trackedSpaceWorldRotation}
trackedSpaceLocalScale: {trackedSpaceLocalScale}
trackedSpaceLocalToWorldMatrix: {trackedSpaceLocalToWorldMatrix}
trackedSpaceWorldToLocalMatrix: {trackedSpaceWorldToLocalMatrix}";
}
}
[StructLayout(LayoutKind.Sequential)]
public struct SDKTexture
{
public TEXTURE_ID id;
public System.IntPtr texturePtr;
public System.IntPtr SharedHandle;
public TEXTURE_DEVICE device;
public int dummy;
public TEXTURE_TYPE type;
public TEXTURE_FORMAT format;
public TEXTURE_COLOR_SPACE colorSpace;
public int width;
public int height;
public static SDKTexture empty {
get {
return new SDKTexture()
{
id = TEXTURE_ID.UNDEFINED,
texturePtr = System.IntPtr.Zero,
SharedHandle = System.IntPtr.Zero,
device = TEXTURE_DEVICE.UNDEFINED,
dummy = 0,
type = TEXTURE_TYPE.UNDEFINED,
format = TEXTURE_FORMAT.UNDEFINED,
colorSpace = TEXTURE_COLOR_SPACE.UNDEFINED,
width = 0,
height = 0
};
}
}
public override string ToString()
{
return
$@"SDKTexture:
id: {id}
texturePtr: {texturePtr}
SharedHandle: {SharedHandle}
device: {device}
dummy: {dummy}
type: {type}
format: {format}
colorSpace: {colorSpace}
width: {width}
height: {height}";
}
}
[StructLayout(LayoutKind.Sequential)]
public struct SDKTransform
{
public SDKVector3 localPosition;
public SDKQuaternion localRotation;
public SDKVector3 localScale;
public static SDKTransform empty {
get {
return new SDKTransform()
{
localPosition = SDKVector3.zero,
localRotation = SDKQuaternion.identity,
localScale = SDKVector3.one
};
}
}
public override string ToString()
{
return
$@"SDKTransform:
localPosition: {localPosition}
localRotation: {localRotation}
localScale: {localScale}";
}
}
[StructLayout(LayoutKind.Sequential)]
public struct SDKClipPlane
{
public SDKMatrix4x4 transform;
public int width;
public int height;
public float tesselation;
public static SDKClipPlane empty {
get {
return new SDKClipPlane()
{
transform = SDKMatrix4x4.identity,
width = 0,
height = 0,
tesselation = 0
};
}
}
public override string ToString()
{
return
$@"SDKClipPlane:
transform: {transform}
width: {width}
height: {height}
tesselation: {tesselation}";
}
}
[StructLayout(LayoutKind.Sequential)]
public struct SDKControllerState
{
public SDKVector3 hmdposition;
public SDKQuaternion hmdrotation;
public SDKVector3 calibrationcameraposition;
public SDKQuaternion calibrationcamerarotation;
public SDKVector3 cameraposition;
public SDKQuaternion camerarotation;
public SDKVector3 leftposition;
public SDKQuaternion leftrotation;
public SDKVector3 rightposition;
public SDKQuaternion rightrotation;
public static SDKControllerState empty {
get {
return new SDKControllerState()
{
hmdposition = SDKVector3.zero,
hmdrotation = SDKQuaternion.identity,
calibrationcameraposition = SDKVector3.zero,
calibrationcamerarotation = SDKQuaternion.identity,
cameraposition = SDKVector3.zero,
camerarotation = SDKQuaternion.identity,
leftposition = SDKVector3.zero,
leftrotation = SDKQuaternion.identity,
rightposition = SDKVector3.zero,
rightrotation = SDKQuaternion.identity,
};
}
}
public override string ToString()
{
return
$@"SDKControllerState:
hmdposition: {hmdposition}
hmdrotation: {hmdrotation}
calibrationcameraposition: {calibrationcameraposition}
calibrationcamerarotation: {calibrationcamerarotation}
cameraposition: {cameraposition}
camerarotation: {camerarotation}
leftposition: {leftposition}
leftrotation: {leftrotation}
rightposition: {rightposition}
rightrotation: {rightrotation}";
}
}
[StructLayout(LayoutKind.Sequential)]
public struct SDKPose
{
public SDKMatrix4x4 projectionMatrix;
public SDKVector3 localPosition;
public SDKQuaternion localRotation;
public float verticalFieldOfView;
public float nearClipPlane;
public float farClipPlane;
public int unused0;
public int unused1;
public static SDKPose empty {
get {
return new SDKPose()
{
projectionMatrix = SDKMatrix4x4.Perspective(90f, 1f, 0.01f, 1000f),
localPosition = SDKVector3.zero,
localRotation = SDKQuaternion.identity,
verticalFieldOfView = 90f,
nearClipPlane = 0.01f,
farClipPlane = 1000f,
};
}
}
public override string ToString()
{
return
$@"SDKPose:
projectionMatrix: {projectionMatrix}
localPosition: {localPosition}
localRotation: {localRotation}
verticalFieldOfView: {verticalFieldOfView}
nearClipPlane: {nearClipPlane}
farClipPlane: {farClipPlane}";
}
}
}
-12
View File
@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: ddb23fb3248db5e458f1bd7a8b80a6a1
timeCreated: 1578922715
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
-476
View File
@@ -1,476 +0,0 @@
#if LIV_UNIVERSAL_RENDER
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
namespace LIV.SDK.Unity
{
public partial class SDKRender : System.IDisposable
{
// Renders the clip plane in the foreground texture
private SDKPass _clipPlanePass = null;
// Renders the clipped opaque content in to the foreground texture alpha
private SDKPass _combineAlphaPass = null;
// Captures texture before post-effects
private SDKPass _captureTexturePass = null;
// Renders captured texture
private SDKPass _applyTexturePass = null;
// Renders background and foreground in single render
private SDKPass _optimizedRenderingPass = null;
private RenderPassEvent _clipPlaneRenderPassEvent = RenderPassEvent.AfterRenderingOpaques;
private RenderPassEvent _addAlphaRenderPassEvent = RenderPassEvent.AfterRenderingPostProcessing;
private RenderPassEvent _captureTextureRenderPassEvent = RenderPassEvent.BeforeRenderingPostProcessing;
private RenderPassEvent _applyTextureRenderPassEvent = RenderPassEvent.AfterRenderingPostProcessing;
private RenderPassEvent _optimizedRenderingPassEvent = RenderPassEvent.AfterRendering;
// Tessellated quad
private Mesh _clipPlaneMesh = null;
// Clear material
private Material _clipPlaneSimpleMaterial = null;
// Transparent material for visual debugging
private Material _clipPlaneSimpleDebugMaterial = null;
// Tessellated height map clear material
private Material _clipPlaneComplexMaterial = null;
// Tessellated height map clear material for visual debugging
private Material _clipPlaneComplexDebugMaterial = null;
private Material _writeOpaqueToAlphaMaterial = null;
private Material _combineAlphaMaterial = null;
private Material _writeMaterial = null;
private Material _forceForwardRenderingMaterial = null;
private RenderTexture _backgroundRenderTexture = null;
private RenderTexture _foregroundRenderTexture = null;
private RenderTexture _optimizedRenderTexture = null;
private RenderTexture _complexClipPlaneRenderTexture = null;
private UniversalAdditionalCameraData _universalAdditionalCameraData = null;
private RenderTargetIdentifier _cameraColorTextureIdentifier = new RenderTargetIdentifier("_CameraColorTexture");
Material GetClipPlaneMaterial(bool debugClipPlane, bool complexClipPlane, ColorWriteMask colorWriteMask)
{
Material output;
if (complexClipPlane)
{
output = debugClipPlane ? _clipPlaneComplexDebugMaterial : _clipPlaneComplexMaterial;
output.SetTexture(SDKShaders.LIV_CLIP_PLANE_HEIGHT_MAP_PROPERTY, _complexClipPlaneRenderTexture);
output.SetFloat(SDKShaders.LIV_TESSELLATION_PROPERTY, _inputFrame.clipPlane.tesselation);
}
else
{
output = debugClipPlane ? _clipPlaneSimpleDebugMaterial : _clipPlaneSimpleMaterial;
}
output.SetInt(SDKShaders.LIV_COLOR_MASK, (int)colorWriteMask);
return output;
}
Material GetGroundClipPlaneMaterial(bool debugClipPlane, ColorWriteMask colorWriteMask)
{
Material output;
output = debugClipPlane ? _clipPlaneSimpleDebugMaterial : _clipPlaneSimpleMaterial;
output.SetInt(SDKShaders.LIV_COLOR_MASK, (int)colorWriteMask);
return output;
}
bool useDeferredRendering {
get {
return _cameraInstance.actualRenderingPath == RenderingPath.DeferredLighting ||
_cameraInstance.actualRenderingPath == RenderingPath.DeferredShading;
}
}
bool interlacedRendering {
get {
return SDKUtils.FeatureEnabled(inputFrame.features, FEATURES.INTERLACED_RENDER);
}
}
bool canRenderBackground {
get {
if (interlacedRendering)
{
// Render only if frame is even
if (Time.frameCount % 2 != 0) return false;
}
return SDKUtils.FeatureEnabled(inputFrame.features, FEATURES.BACKGROUND_RENDER) && _backgroundRenderTexture != null;
}
}
bool canRenderForeground {
get {
if (interlacedRendering)
{
// Render only if frame is odd
if (Time.frameCount % 2 != 1) return false;
}
return SDKUtils.FeatureEnabled(inputFrame.features, FEATURES.FOREGROUND_RENDER) && _foregroundRenderTexture != null;
}
}
bool canRenderOptimized {
get {
return SDKUtils.FeatureEnabled(inputFrame.features, FEATURES.OPTIMIZED_RENDER) && _optimizedRenderTexture != null; ;
}
}
public SDKRender(LIV liv)
{
_liv = liv;
CreateAssets();
}
public void Render()
{
UpdateBridgeResolution();
UpdateBridgeInputFrame();
SDKUtils.ApplyUserSpaceTransform(this);
UpdateTextures();
InvokePreRender();
if (canRenderBackground) RenderBackground();
if (canRenderForeground) RenderForeground();
if (canRenderOptimized) RenderOptimized();
IvokePostRender();
SDKUtils.CreateBridgeOutputFrame(this);
SDKBridge.IssuePluginEvent();
}
// Default render without any special changes
private void RenderBackground()
{
SDKUtils.SetCamera(_cameraInstance, _cameraInstance.transform, _inputFrame, localToWorldMatrix, spectatorLayerMask);
_cameraInstance.targetTexture = _backgroundRenderTexture;
RenderTexture tempRenderTexture = null;
bool overridePostProcessing = SDKUtils.FeatureEnabled(inputFrame.features, FEATURES.OVERRIDE_POST_PROCESSING);
if (overridePostProcessing)
{
tempRenderTexture = RenderTexture.GetTemporary(_backgroundRenderTexture.width, _backgroundRenderTexture.height, 0, _backgroundRenderTexture.format);
#if UNITY_EDITOR
tempRenderTexture.name = "LIV.TemporaryRenderTexture";
#endif
_captureTexturePass.commandBuffer.Blit(BuiltinRenderTextureType.CurrentActive, tempRenderTexture);
_applyTexturePass.commandBuffer.Blit(tempRenderTexture, BuiltinRenderTextureType.CurrentActive);
SDKUniversalRenderFeature.AddPass(_captureTexturePass);
SDKUniversalRenderFeature.AddPass(_applyTexturePass);
}
SDKShaders.StartRendering();
SDKShaders.StartBackgroundRendering();
InvokePreRenderBackground();
SendTextureToBridge(_backgroundRenderTexture, TEXTURE_ID.BACKGROUND_COLOR_BUFFER_ID);
_cameraInstance.Render();
InvokePostRenderBackground();
_cameraInstance.targetTexture = null;
SDKShaders.StopBackgroundRendering();
SDKShaders.StopRendering();
if (overridePostProcessing)
{
_captureTexturePass.commandBuffer.Clear();
_applyTexturePass.commandBuffer.Clear();
RenderTexture.ReleaseTemporary(tempRenderTexture);
}
SDKUniversalRenderFeature.ClearPasses();
}
// Extract the image which is in front of our clip plane
// The compositing is heavily relying on the alpha channel, therefore we want to make sure it does
// not get corrupted by the postprocessing or any shader
private void RenderForeground()
{
bool debugClipPlane = SDKUtils.FeatureEnabled(inputFrame.features, FEATURES.DEBUG_CLIP_PLANE);
bool renderComplexClipPlane = SDKUtils.FeatureEnabled(inputFrame.features, FEATURES.COMPLEX_CLIP_PLANE);
bool renderGroundClipPlane = SDKUtils.FeatureEnabled(inputFrame.features, FEATURES.GROUND_CLIP_PLANE);
bool overridePostProcessing = SDKUtils.FeatureEnabled(inputFrame.features, FEATURES.OVERRIDE_POST_PROCESSING);
bool fixPostEffectsAlpha = SDKUtils.FeatureEnabled(inputFrame.features, FEATURES.FIX_FOREGROUND_ALPHA) | _liv.fixPostEffectsAlpha;
MonoBehaviour[] behaviours = null;
bool[] wasBehaviourEnabled = null;
if (disableStandardAssets) SDKUtils.DisableStandardAssets(_cameraInstance, ref behaviours, ref wasBehaviourEnabled);
// Capture camera defaults
CameraClearFlags capturedClearFlags = _cameraInstance.clearFlags;
Color capturedBgColor = _cameraInstance.backgroundColor;
Color capturedFogColor = RenderSettings.fogColor;
// Make sure that fog does not corrupt alpha channel
RenderSettings.fogColor = new Color(capturedFogColor.r, capturedFogColor.g, capturedFogColor.b, 0f);
SDKUtils.SetCamera(_cameraInstance, _cameraInstance.transform, _inputFrame, localToWorldMatrix, spectatorLayerMask);
_cameraInstance.clearFlags = CameraClearFlags.Color;
_cameraInstance.backgroundColor = Color.clear;
_cameraInstance.targetTexture = _foregroundRenderTexture;
RenderTexture capturedAlphaRenderTexture = RenderTexture.GetTemporary(_foregroundRenderTexture.width, _foregroundRenderTexture.height, 0, _foregroundRenderTexture.format);
#if UNITY_EDITOR
capturedAlphaRenderTexture.name = "LIV.CapturedAlphaRenderTexture";
#endif
// Render opaque pixels into alpha channel
_clipPlanePass.commandBuffer.DrawMesh(_clipPlaneMesh, Matrix4x4.identity, _writeOpaqueToAlphaMaterial, 0, 0);
// Render clip plane
Matrix4x4 clipPlaneTransform = localToWorldMatrix * (Matrix4x4)_inputFrame.clipPlane.transform;
_clipPlanePass.commandBuffer.DrawMesh(_clipPlaneMesh, clipPlaneTransform,
GetClipPlaneMaterial(debugClipPlane, renderComplexClipPlane, ColorWriteMask.All), 0, 0);
// Render ground clip plane
if (renderGroundClipPlane)
{
Matrix4x4 groundClipPlaneTransform = localToWorldMatrix * (Matrix4x4)_inputFrame.groundClipPlane.transform;
_clipPlanePass.commandBuffer.DrawMesh(_clipPlaneMesh, groundClipPlaneTransform,
GetGroundClipPlaneMaterial(debugClipPlane, ColorWriteMask.All), 0, 0);
}
// Copy alpha in to texture
_clipPlanePass.commandBuffer.Blit(BuiltinRenderTextureType.CurrentActive, capturedAlphaRenderTexture);
_clipPlanePass.commandBuffer.SetRenderTarget(_cameraColorTextureIdentifier);
SDKUniversalRenderFeature.AddPass(_clipPlanePass);
// Fix alpha corruption by post processing
RenderTexture tempRenderTexture = null;
if (overridePostProcessing || fixPostEffectsAlpha)
{
tempRenderTexture = RenderTexture.GetTemporary(_foregroundRenderTexture.width, _foregroundRenderTexture.height, 0, _foregroundRenderTexture.format);
#if UNITY_EDITOR
tempRenderTexture.name = "LIV.TemporaryRenderTexture";
#endif
_captureTexturePass.commandBuffer.Blit(BuiltinRenderTextureType.CurrentActive, tempRenderTexture);
SDKUniversalRenderFeature.AddPass(_captureTexturePass);
_writeMaterial.SetInt(SDKShaders.LIV_COLOR_MASK, overridePostProcessing ? (int)ColorWriteMask.All : (int)ColorWriteMask.Alpha);
_applyTexturePass.commandBuffer.Blit(tempRenderTexture, BuiltinRenderTextureType.CurrentActive, _writeMaterial);
SDKUniversalRenderFeature.AddPass(_applyTexturePass);
}
// Combine captured alpha with result alpha
_combineAlphaMaterial.SetInt(SDKShaders.LIV_COLOR_MASK, (int)ColorWriteMask.Alpha);
_combineAlphaPass.commandBuffer.Blit(capturedAlphaRenderTexture, BuiltinRenderTextureType.CurrentActive, _combineAlphaMaterial);
SDKUniversalRenderFeature.AddPass(_combineAlphaPass);
if (useDeferredRendering) SDKUtils.ForceForwardRendering(cameraInstance, _clipPlaneMesh, _forceForwardRenderingMaterial);
SDKShaders.StartRendering();
SDKShaders.StartForegroundRendering();
InvokePreRenderForeground();
SendTextureToBridge(_foregroundRenderTexture, TEXTURE_ID.FOREGROUND_COLOR_BUFFER_ID);
_cameraInstance.Render();
InvokePostRenderForeground();
_cameraInstance.targetTexture = null;
SDKShaders.StopForegroundRendering();
SDKShaders.StopRendering();
if (overridePostProcessing || fixPostEffectsAlpha)
{
_captureTexturePass.commandBuffer.Clear();
_applyTexturePass.commandBuffer.Clear();
RenderTexture.ReleaseTemporary(tempRenderTexture);
}
RenderTexture.ReleaseTemporary(capturedAlphaRenderTexture);
_clipPlanePass.commandBuffer.Clear();
_combineAlphaPass.commandBuffer.Clear();
SDKUniversalRenderFeature.ClearPasses();
// Revert camera defaults
_cameraInstance.clearFlags = capturedClearFlags;
_cameraInstance.backgroundColor = capturedBgColor;
RenderSettings.fogColor = capturedFogColor;
SDKUtils.RestoreStandardAssets(ref behaviours, ref wasBehaviourEnabled);
}
// Renders a single camera in a single texture with occlusion only from opaque objects.
// This is the most performant option for mixed reality.
// It does not support any transparency in the foreground layer.
private void RenderOptimized()
{
bool debugClipPlane = SDKUtils.FeatureEnabled(inputFrame.features, FEATURES.DEBUG_CLIP_PLANE);
bool renderComplexClipPlane = SDKUtils.FeatureEnabled(inputFrame.features, FEATURES.COMPLEX_CLIP_PLANE);
bool renderGroundClipPlane = SDKUtils.FeatureEnabled(inputFrame.features, FEATURES.GROUND_CLIP_PLANE);
SDKUtils.SetCamera(_cameraInstance, _cameraInstance.transform, _inputFrame, localToWorldMatrix, spectatorLayerMask);
_cameraInstance.targetTexture = _optimizedRenderTexture;
// Clear alpha channel
_writeMaterial.SetInt(SDKShaders.LIV_COLOR_MASK, (int)ColorWriteMask.Alpha);
_optimizedRenderingPass.commandBuffer.Blit(BuiltinRenderTextureType.None, BuiltinRenderTextureType.CurrentActive, _writeMaterial);
// Render opaque pixels into alpha channel
_writeOpaqueToAlphaMaterial.SetInt(SDKShaders.LIV_COLOR_MASK, (int)ColorWriteMask.Alpha);
_optimizedRenderingPass.commandBuffer.DrawMesh(_clipPlaneMesh, Matrix4x4.identity, _writeOpaqueToAlphaMaterial, 0, 0);
// Render clip plane
Matrix4x4 clipPlaneTransform = localToWorldMatrix * (Matrix4x4)_inputFrame.clipPlane.transform;
_optimizedRenderingPass.commandBuffer.DrawMesh(_clipPlaneMesh, clipPlaneTransform,
GetClipPlaneMaterial(debugClipPlane, renderComplexClipPlane, ColorWriteMask.Alpha), 0, 0);
// Render ground clip plane
if (renderGroundClipPlane)
{
Matrix4x4 groundClipPlaneTransform = localToWorldMatrix * (Matrix4x4)_inputFrame.groundClipPlane.transform;
_optimizedRenderingPass.commandBuffer.DrawMesh(_clipPlaneMesh, groundClipPlaneTransform,
GetGroundClipPlaneMaterial(debugClipPlane, ColorWriteMask.Alpha), 0, 0);
}
SDKUniversalRenderFeature.AddPass(_optimizedRenderingPass);
// TODO: this is just proprietary
SDKShaders.StartRendering();
SDKShaders.StartBackgroundRendering();
InvokePreRenderBackground();
SendTextureToBridge(_optimizedRenderTexture, TEXTURE_ID.OPTIMIZED_COLOR_BUFFER_ID);
_cameraInstance.Render();
InvokePostRenderBackground();
_cameraInstance.targetTexture = null;
SDKShaders.StopBackgroundRendering();
SDKShaders.StopRendering();
_optimizedRenderingPass.commandBuffer.Clear();
SDKUniversalRenderFeature.ClearPasses();
}
private void CreateAssets()
{
bool cameraReferenceEnabled = cameraReference.enabled;
if (cameraReferenceEnabled)
{
cameraReference.enabled = false;
}
bool cameraReferenceActive = cameraReference.gameObject.activeSelf;
if (cameraReferenceActive)
{
cameraReference.gameObject.SetActive(false);
}
GameObject cloneGO = (GameObject)Object.Instantiate(cameraReference.gameObject, _liv.stage);
_cameraInstance = (Camera)cloneGO.GetComponent("Camera");
SDKUtils.CleanCameraBehaviours(_cameraInstance, _liv.excludeBehaviours);
if (cameraReferenceActive != cameraReference.gameObject.activeSelf)
{
cameraReference.gameObject.SetActive(cameraReferenceActive);
}
if (cameraReferenceEnabled != cameraReference.enabled)
{
cameraReference.enabled = cameraReferenceEnabled;
}
_cameraInstance.name = "LIV Camera";
if (_cameraInstance.tag == "MainCamera")
{
_cameraInstance.tag = "Untagged";
}
_cameraInstance.transform.localScale = Vector3.one;
_cameraInstance.rect = new Rect(0, 0, 1, 1);
_cameraInstance.depth = 0;
#if UNITY_5_4_OR_NEWER
_cameraInstance.stereoTargetEye = StereoTargetEyeMask.None;
#endif
#if UNITY_5_6_OR_NEWER
_cameraInstance.allowMSAA = false;
#endif
_cameraInstance.enabled = false;
_cameraInstance.gameObject.SetActive(true);
_universalAdditionalCameraData = _cameraInstance.GetComponent<UniversalAdditionalCameraData>();
_clipPlaneMesh = new Mesh();
SDKUtils.CreateClipPlane(_clipPlaneMesh, 10, 10, true, 1000f);
_clipPlaneSimpleMaterial = new Material(Shader.Find(SDKShaders.LIV_CLIP_PLANE_SIMPLE_SHADER));
_clipPlaneSimpleDebugMaterial = new Material(Shader.Find(SDKShaders.LIV_CLIP_PLANE_SIMPLE_DEBUG_SHADER));
_clipPlaneComplexMaterial = new Material(Shader.Find(SDKShaders.LIV_CLIP_PLANE_COMPLEX_SHADER));
_clipPlaneComplexDebugMaterial = new Material(Shader.Find(SDKShaders.LIV_CLIP_PLANE_COMPLEX_DEBUG_SHADER));
_writeOpaqueToAlphaMaterial = new Material(Shader.Find(SDKShaders.LIV_WRITE_OPAQUE_TO_ALPHA_SHADER));
_combineAlphaMaterial = new Material(Shader.Find(SDKShaders.LIV_COMBINE_ALPHA_SHADER));
_writeMaterial = new Material(Shader.Find(SDKShaders.LIV_WRITE_SHADER));
_forceForwardRenderingMaterial = new Material(Shader.Find(SDKShaders.LIV_FORCE_FORWARD_RENDERING_SHADER));
_clipPlanePass = new SDKPass();
_clipPlanePass.renderPassEvent = _clipPlaneRenderPassEvent;
_clipPlanePass.commandBuffer = new CommandBuffer();
_combineAlphaPass = new SDKPass();
_combineAlphaPass.renderPassEvent = _addAlphaRenderPassEvent;
_combineAlphaPass.commandBuffer = new CommandBuffer();
_captureTexturePass = new SDKPass();
_captureTexturePass.renderPassEvent = _captureTextureRenderPassEvent;
_captureTexturePass.commandBuffer = new CommandBuffer();
_applyTexturePass = new SDKPass();
_applyTexturePass.renderPassEvent = _applyTextureRenderPassEvent;
_applyTexturePass.commandBuffer = new CommandBuffer();
_optimizedRenderingPass = new SDKPass();
_optimizedRenderingPass.renderPassEvent = _optimizedRenderingPassEvent;
_optimizedRenderingPass.commandBuffer = new CommandBuffer();
_universalAdditionalCameraData.antialiasing = AntialiasingMode.None;
_universalAdditionalCameraData.antialiasingQuality = AntialiasingQuality.Low;
_universalAdditionalCameraData.dithering = false;
#if UNITY_EDITOR
_clipPlaneMesh.name = "LIV.clipPlane";
_clipPlaneSimpleMaterial.name = "LIV.clipPlaneSimple";
_clipPlaneSimpleDebugMaterial.name = "LIV.clipPlaneSimpleDebug";
_clipPlaneComplexMaterial.name = "LIV.clipPlaneComplex";
_clipPlaneComplexDebugMaterial.name = "LIV.clipPlaneComplexDebug";
_writeOpaqueToAlphaMaterial.name = "LIV.writeOpaqueToAlpha";
_combineAlphaMaterial.name = "LIV.combineAlpha";
_writeMaterial.name = "LIV.write";
_forceForwardRenderingMaterial.name = "LIV.forceForwardRendering";
_clipPlanePass.commandBuffer.name = "LIV.renderClipPlanes";
_combineAlphaPass.commandBuffer.name = "LIV.foregroundCombineAlpha";
_captureTexturePass.commandBuffer.name = "LIV.captureTexture";
_applyTexturePass.commandBuffer.name = "LIV.applyTexture";
_optimizedRenderingPass.commandBuffer.name = "LIV.optimizedRendering";
#endif
}
private void DestroyAssets()
{
if (_cameraInstance != null)
{
Object.Destroy(_cameraInstance.gameObject);
_cameraInstance = null;
}
SDKUtils.DestroyObject<Mesh>(ref _clipPlaneMesh);
SDKUtils.DestroyObject<Material>(ref _clipPlaneSimpleMaterial);
SDKUtils.DestroyObject<Material>(ref _clipPlaneSimpleDebugMaterial);
SDKUtils.DestroyObject<Material>(ref _clipPlaneComplexMaterial);
SDKUtils.DestroyObject<Material>(ref _clipPlaneComplexDebugMaterial);
SDKUtils.DestroyObject<Material>(ref _writeOpaqueToAlphaMaterial);
SDKUtils.DestroyObject<Material>(ref _combineAlphaMaterial);
SDKUtils.DestroyObject<Material>(ref _writeMaterial);
SDKUtils.DestroyObject<Material>(ref _forceForwardRenderingMaterial);
SDKUtils.DisposeObject<CommandBuffer>(ref _clipPlanePass.commandBuffer);
SDKUtils.DisposeObject<CommandBuffer>(ref _combineAlphaPass.commandBuffer);
SDKUtils.DisposeObject<CommandBuffer>(ref _captureTexturePass.commandBuffer);
SDKUtils.DisposeObject<CommandBuffer>(ref _applyTexturePass.commandBuffer);
SDKUtils.DisposeObject<CommandBuffer>(ref _optimizedRenderingPass.commandBuffer);
}
public void Dispose()
{
ReleaseBridgePoseControl();
DestroyAssets();
SDKUtils.DestroyTexture(ref _backgroundRenderTexture);
SDKUtils.DestroyTexture(ref _foregroundRenderTexture);
SDKUtils.DestroyTexture(ref _optimizedRenderTexture);
SDKUtils.DestroyTexture(ref _complexClipPlaneRenderTexture);
}
}
}
#endif
@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 48c849f01a195c64b80eb295625f6b4c
timeCreated: 1599996572
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -1,49 +0,0 @@
#if LIV_UNIVERSAL_RENDER
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using System.Collections;
using System.Collections.Generic;
namespace LIV.SDK.Unity
{
public class SDKPass : ScriptableRenderPass
{
public CommandBuffer commandBuffer;
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
context.ExecuteCommandBuffer(commandBuffer);
}
}
public class SDKUniversalRenderFeature : ScriptableRendererFeature
{
static List<SDKPass> passes = new List<SDKPass>();
public static void AddPass(SDKPass pass)
{
passes.Add(pass);
}
public static void ClearPasses()
{
passes.Clear();
}
public override void Create()
{
}
public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
{
while (passes.Count > 0)
{
renderer.EnqueuePass(passes[0]);
passes.RemoveAt(0);
}
}
}
}
#endif
@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 8e67cb7969c50a9428e7b47bea58abff
timeCreated: 1599996572
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
-343
View File
@@ -1,343 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace LIV.SDK.Unity
{
public static class SDKUtils
{
public static void CreateClipPlane(Mesh mesh, int resX, int resY, bool useQuads, float skirtLength)
{
int vertexCount = (resX + 1) * (resY + 1);
int triangleCount = useQuads ? (resX * resY * 4) : (resX * resY * 2 * 3);
Vector3[] v = new Vector3[vertexCount];
Vector2[] uv = new Vector2[vertexCount];
int[] t = new int[triangleCount];
float hWidth = 0.5f;
float hHeight = 0.5f;
int resX1 = resX + 1;
int resY1 = resY + 1;
for (int y = 0; y < resY1; y++)
{
for (int x = 0; x < resX1; x++)
{
int vi = y * resX1 + x;
float uvx = (float)x / (float)resX;
float uvy = (float)y / (float)resY;
float skirtX = (x == 0 || x == resX) ? skirtLength : 1f;
float skirtY = (y == 0 || y == resY) ? skirtLength : 1f;
v[vi] = new Vector2((-hWidth + uvx) * skirtX, (-hHeight + uvy) * skirtY);
uv[vi] = new Vector2(Mathf.InverseLerp(1, resX - 1, x), Mathf.InverseLerp(1, resY - 1, y));
}
}
mesh.Clear();
mesh.vertices = v;
mesh.uv = uv;
mesh.bounds = new Bounds(Vector3.zero, Vector3.one * float.MaxValue);
{
int faces = resX * resY;
int vi = 0;
int ti = 0;
if (useQuads)
{
for (int i = 0; i < faces; i++)
{
vi = (i / resX) * resX1 + (i % resX);
t[ti++] = vi + 1;
t[ti++] = vi;
t[ti++] = vi + 1 + resX;
t[ti++] = vi + 2 + resX;
}
mesh.SetIndices(t, MeshTopology.Quads, 0);
}
else
{
for (int i = 0; i < faces; i++)
{
vi = (i / resX) * resX1 + (i % resX);
t[ti++] = vi + 2 + resX;
t[ti++] = vi + 1;
t[ti++] = vi;
t[ti++] = vi + 1 + resX;
t[ti++] = vi + 2 + resX;
t[ti++] = vi;
}
mesh.SetIndices(t, MeshTopology.Triangles, 0);
}
}
}
public static RenderTextureReadWrite GetReadWriteFromColorSpace(TEXTURE_COLOR_SPACE colorSpace)
{
switch (colorSpace)
{
case TEXTURE_COLOR_SPACE.LINEAR:
return RenderTextureReadWrite.Linear;
case TEXTURE_COLOR_SPACE.SRGB:
return RenderTextureReadWrite.sRGB;
default:
return RenderTextureReadWrite.Default;
}
}
public static TEXTURE_COLOR_SPACE GetDefaultColorSpace {
get {
switch (QualitySettings.activeColorSpace)
{
case UnityEngine.ColorSpace.Gamma:
return TEXTURE_COLOR_SPACE.SRGB;
case UnityEngine.ColorSpace.Linear:
return TEXTURE_COLOR_SPACE.LINEAR;
}
return TEXTURE_COLOR_SPACE.UNDEFINED;
}
}
public static TEXTURE_COLOR_SPACE GetColorSpace(RenderTexture renderTexture)
{
if (renderTexture == null) return TEXTURE_COLOR_SPACE.UNDEFINED;
if (renderTexture.sRGB) return TEXTURE_COLOR_SPACE.SRGB;
return TEXTURE_COLOR_SPACE.LINEAR;
}
public static RENDERING_PIPELINE GetRenderingPipeline(RenderingPath renderingPath)
{
switch (renderingPath)
{
case RenderingPath.DeferredLighting:
return RENDERING_PIPELINE.DEFERRED;
case RenderingPath.DeferredShading:
return RENDERING_PIPELINE.DEFERRED;
case RenderingPath.Forward:
return RENDERING_PIPELINE.FORWARD;
case RenderingPath.VertexLit:
return RENDERING_PIPELINE.VERTEX_LIT;
default:
return RENDERING_PIPELINE.UNDEFINED;
}
}
public static TEXTURE_DEVICE GetDevice()
{
switch (SystemInfo.graphicsDeviceType)
{
case UnityEngine.Rendering.GraphicsDeviceType.Direct3D11:
case UnityEngine.Rendering.GraphicsDeviceType.Direct3D12:
return TEXTURE_DEVICE.DIRECTX;
case UnityEngine.Rendering.GraphicsDeviceType.Vulkan:
return TEXTURE_DEVICE.VULKAN;
case UnityEngine.Rendering.GraphicsDeviceType.Metal:
return TEXTURE_DEVICE.METAL;
case UnityEngine.Rendering.GraphicsDeviceType.OpenGLCore:
return TEXTURE_DEVICE.OPENGL;
default:
return TEXTURE_DEVICE.UNDEFINED;
}
}
public static bool ContainsFlag(ulong flags, ulong flag)
{
return (flags & flag) != 0;
}
public static ulong SetFlag(ulong flags, ulong flag, bool enabled)
{
if (enabled)
{
return flags | flag;
}
else
{
return flags & (~flag);
}
}
public static void GetCameraPositionAndRotation(SDKPose pose, Matrix4x4 originLocalToWorldMatrix, out Vector3 position, out Quaternion rotation)
{
position = originLocalToWorldMatrix.MultiplyPoint(pose.localPosition);
rotation = RotateQuaternionByMatrix(originLocalToWorldMatrix, pose.localRotation);
}
public static void CleanCameraBehaviours(Camera camera, string[] excludeBehaviours)
{
// Remove all children from camera clone.
foreach (Transform child in camera.transform)
{
Object.Destroy(child.gameObject);
}
if (excludeBehaviours == null) return;
for (int i = 0; i < excludeBehaviours.Length; i++)
{
Object.Destroy(camera.GetComponent(excludeBehaviours[i]));
}
}
public static void SetCamera(Camera camera, Transform cameraTransform, SDKInputFrame inputFrame, Matrix4x4 originLocalToWorldMatrix, int layerMask)
{
Vector3 worldPosition = Vector3.zero;
Quaternion worldRotation = Quaternion.identity;
float verticalFieldOfView = inputFrame.pose.verticalFieldOfView;
float nearClipPlane = inputFrame.pose.nearClipPlane;
float farClipPlane = inputFrame.pose.farClipPlane;
Matrix4x4 projectionMatrix = inputFrame.pose.projectionMatrix;
GetCameraPositionAndRotation(inputFrame.pose, originLocalToWorldMatrix, out worldPosition, out worldRotation);
cameraTransform.position = worldPosition;
cameraTransform.rotation = worldRotation;
camera.fieldOfView = verticalFieldOfView;
camera.nearClipPlane = nearClipPlane;
camera.farClipPlane = farClipPlane;
camera.projectionMatrix = projectionMatrix;
camera.cullingMask = layerMask;
}
public static Quaternion RotateQuaternionByMatrix(Matrix4x4 matrix, Quaternion rotation)
{
return Quaternion.LookRotation(
matrix.MultiplyVector(Vector3.forward),
matrix.MultiplyVector(Vector3.up)
) * rotation;
}
public static SDKTrackedSpace GetTrackedSpace(Transform transform)
{
if (transform == null) return SDKTrackedSpace.empty;
return new SDKTrackedSpace
{
trackedSpaceWorldPosition = transform.position,
trackedSpaceWorldRotation = transform.rotation,
trackedSpaceLocalScale = transform.localScale,
trackedSpaceLocalToWorldMatrix = transform.localToWorldMatrix,
trackedSpaceWorldToLocalMatrix = transform.worldToLocalMatrix,
};
}
public static bool DestroyObject<T>(ref T reference) where T : UnityEngine.Object
{
if (reference == null) return false;
Object.Destroy(reference);
reference = default(T);
return true;
}
public static bool DisposeObject<T>(ref T reference) where T : System.IDisposable
{
if (reference == null) return false;
reference.Dispose();
reference = default(T);
return true;
}
public static bool CreateTexture(ref RenderTexture renderTexture, int width, int height, int depth, RenderTextureFormat format)
{
DestroyTexture(ref renderTexture);
if (width <= 0 || height <= 0)
{
Debug.LogError("LIV: Unable to create render texture. Texture dimension must be higher than zero.");
return false;
}
renderTexture = new RenderTexture(width, height, depth, format)
{
antiAliasing = 1,
wrapMode = TextureWrapMode.Clamp,
useMipMap = false,
anisoLevel = 0
};
if (!renderTexture.Create())
{
Debug.LogError("LIV: Unable to create render texture.");
return false;
}
return true;
}
public static void DestroyTexture(ref RenderTexture _renderTexture)
{
if (_renderTexture == null) return;
if (_renderTexture.IsCreated())
{
_renderTexture.Release();
}
_renderTexture = null;
}
public static void ApplyUserSpaceTransform(SDKRender render)
{
if (render.stageTransform == null) return;
render.stageTransform.localPosition = render.inputFrame.stageTransform.localPosition;
render.stageTransform.localRotation = render.inputFrame.stageTransform.localRotation;
render.stageTransform.localScale = render.inputFrame.stageTransform.localScale;
}
public static void CreateBridgeOutputFrame(SDKRender render)
{
RENDERING_PIPELINE renderingPipeline = RENDERING_PIPELINE.UNDEFINED;
#if LIV_UNIVERSAL_RENDER
renderingPipeline = RENDERING_PIPELINE.UNIVERSAL;
#else
if(render.cameraInstance != null)
{
renderingPipeline = SDKUtils.GetRenderingPipeline(render.cameraInstance.actualRenderingPath);
}
#endif
SDKBridge.CreateFrame(new SDKOutputFrame()
{
renderingPipeline = renderingPipeline,
trackedSpace = SDKUtils.GetTrackedSpace(render.stageTransform == null ? render.stage : render.stageTransform)
});
}
public static bool FeatureEnabled(FEATURES features, FEATURES feature)
{
return SDKUtils.ContainsFlag((ulong)features, (ulong)feature);
}
// Disable standard assets if required.
public static void DisableStandardAssets(Camera cameraInstance, ref MonoBehaviour[] behaviours, ref bool[] wasBehaviourEnabled)
{
behaviours = null;
wasBehaviourEnabled = null;
behaviours = cameraInstance.gameObject.GetComponents<MonoBehaviour>();
wasBehaviourEnabled = new bool[behaviours.Length];
for (var i = 0; i < behaviours.Length; i++)
{
var behaviour = behaviours[i];
// generates garbage
if (behaviour.enabled && behaviour.GetType().ToString().StartsWith("UnityStandardAssets."))
{
behaviour.enabled = false;
wasBehaviourEnabled[i] = true;
}
}
}
// Restore disabled behaviours.
public static void RestoreStandardAssets(ref MonoBehaviour[] behaviours, ref bool[] wasBehaviourEnabled)
{
if (behaviours != null)
for (var i = 0; i < behaviours.Length; i++)
if (wasBehaviourEnabled[i])
behaviours[i].enabled = true;
}
public static void ForceForwardRendering(Camera cameraInstance, Mesh clipPlaneMesh, Material forceForwardRenderingMaterial)
{
Matrix4x4 forceForwardRenderingMatrix = cameraInstance.transform.localToWorldMatrix * Matrix4x4.TRS(Vector3.forward * (cameraInstance.nearClipPlane + 0.1f), Quaternion.identity, Vector3.one);
Graphics.DrawMesh(clipPlaneMesh, forceForwardRenderingMatrix, forceForwardRenderingMaterial, 0, cameraInstance, 0, new MaterialPropertyBlock(), false, false, false);
}
}
}
-12
View File
@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 265bd0837467547429af97301e3dc911
timeCreated: 1579009038
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+1 -15
View File
@@ -16,8 +16,7 @@ MonoBehaviour:
debugReplacementPS: {fileID: 4800000, guid: cf852408f2e174538bcd9b7fda1c5ae7, type: 3}
m_RendererFeatures:
- {fileID: 6268505285573851889}
- {fileID: 7884254645102370362}
m_RendererFeatureMap: f1ba49635834fe563ade0cc0d37f6a6d
m_RendererFeatureMap: f1ba49635834fe56
m_UseNativeRenderPass: 0
postProcessData: {fileID: 11400000, guid: 41439944d30ece34e96484bdb6645b55, type: 2}
xrSystemData: {fileID: 11400000, guid: 60e1133243b97e347b653163a8c01b64, type: 2}
@@ -78,16 +77,3 @@ MonoBehaviour:
DirectLightingStrength: 0.25
Radius: 0.03
SampleCount: 4
--- !u!114 &7884254645102370362
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8e67cb7969c50a9428e7b47bea58abff, type: 3}
m_Name: SDKUniversalRenderFeature
m_EditorClassIdentifier:
m_Active: 1
+58 -64
View File
@@ -537,6 +537,11 @@ Camera:
m_CorrespondingSourceObject: {fileID: 9134142658244189910, guid: 04d52eb88b320e143850786efdd3061b, type: 3}
m_PrefabInstance: {fileID: 1877231928}
m_PrefabAsset: {fileID: 0}
--- !u!4 &1421334284 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 9134142658244189909, guid: 04d52eb88b320e143850786efdd3061b, type: 3}
m_PrefabInstance: {fileID: 1877231928}
m_PrefabAsset: {fileID: 0}
--- !u!114 &1421334285
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -582,6 +587,59 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 948f4100a11a5c24981795d21301da5c, type: 3}
m_Name:
m_EditorClassIdentifier:
volumeTrigger: {fileID: 1421334284}
volumeLayer:
m_Bits: 0
stopNaNPropagation: 1
finalBlitToCameraTarget: 0
antialiasingMode: 0
temporalAntialiasing:
jitterSpread: 0.75
sharpness: 0.25
stationaryBlending: 0.95
motionBlending: 0.85
<jitter>k__BackingField: {x: 0, y: 0}
m_ResetHistory: 1
<sampleIndex>k__BackingField: 0
subpixelMorphologicalAntialiasing:
quality: 2
fastApproximateAntialiasing:
fastMode: 0
keepAlpha: 0
fog:
enabled: 1
excludeSkybox: 1
dithering:
m_NoiseTextureIndex: 0
debugLayer:
lightMeter: {<output>k__BackingField: {fileID: 0}, requested: 0, width: 512, height: 256, showCurves: 1}
histogram: {<output>k__BackingField: {fileID: 0}, requested: 0, width: 512, height: 256, channel: 3}
waveform: {<output>k__BackingField: {fileID: 0}, requested: 0, exposure: 0.12, height: 256}
vectorscope: {<output>k__BackingField: {fileID: 0}, requested: 0, size: 256, exposure: 0.12}
frameWidth: 0
frameHeight: 0
<debugOverlayTarget>k__BackingField: {fileID: 0}
<debugOverlayActive>k__BackingField: 0
<debugOverlay>k__BackingField: 0
overlaySettings:
linearDepth: 0
motionColorIntensity: 4
motionGridSize: 64
colorBlindnessType: 0
colorBlindnessStrength: 1
m_Resources: {fileID: 11400000, guid: d82512f9c8e5d4a4d938b575d47f88d4, type: 2}
m_ShowToolkit: 1
m_ShowCustomSorter: 1
breakBeforeColorGrading: 0
m_BeforeTransparentBundles: []
m_BeforeStackBundles: []
m_AfterStackBundles: []
<cameraDepthFlags>k__BackingField: 0
<haveBundlesBeenInited>k__BackingField: 0
m_Camera: {fileID: 0}
m_SettingsUpdateNeeded: 1
m_IsRenderingInSceneView: 0
m_NaNKilled: 0
--- !u!114 &1804532912
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -594,65 +652,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: b3354e8208862c341940152f5340d41a, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1872625422
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1872625424}
- component: {fileID: 1872625423}
m_Layer: 0
m_Name: Liv
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1872625423
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1872625422}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 419ad76f2ffc722478bc67f61f9c32e7, type: 3}
m_Name:
m_EditorClassIdentifier:
_stage: {fileID: 1907551038}
_stageTransform: {fileID: 0}
_HMDCamera: {fileID: 1421334281}
_MRCameraPrefab: {fileID: 0}
_disableStandardAssets: 0
_spectatorLayerMask:
serializedVersion: 2
m_Bits: 4294967295
_excludeBehaviours:
- AudioListener
- Collider
- SteamVR_Camera
- SteamVR_Fade
- SteamVR_ExternalCamera
_fixPostEffectsAlpha: 1
--- !u!4 &1872625424
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1872625422}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &1877231928
PrefabInstance:
m_ObjectHideFlags: 0
@@ -1430,11 +1429,6 @@ PrefabInstance:
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 04d52eb88b320e143850786efdd3061b, type: 3}
--- !u!4 &1907551038 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 9134142656768682068, guid: 04d52eb88b320e143850786efdd3061b, type: 3}
m_PrefabInstance: {fileID: 1877231928}
m_PrefabAsset: {fileID: 0}
--- !u!1 &2066820608
GameObject:
m_ObjectHideFlags: 0
@@ -14,9 +14,9 @@ namespace VRSample.Interactions
internal void OnEnable()
{
// var interactable = GetComponent<IXRHoverInteractable>();
// interactable.hoverEntered.AddListener(Select);
// interactable.hoverExited.AddListener(Deselect);
var interactable = GetComponent<IXRHoverInteractable>();
interactable.hoverEntered.AddListener(Select);
interactable.hoverExited.AddListener(Deselect);
}
internal void OnDisable()
File diff suppressed because one or more lines are too long
+201
View File
@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2023 AEC Systems
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
+1 -1
View File
@@ -840,7 +840,7 @@ PlayerSettings:
PS4: UNITY_POST_PROCESSING_STACK_V2
PS5: UNITY_POST_PROCESSING_STACK_V2
Stadia: UNITY_POST_PROCESSING_STACK_V2
Standalone: UNITY_POST_PROCESSING_STACK_V2;LIV_UNIVERSAL_RENDER
Standalone: UNITY_POST_PROCESSING_STACK_V2
WebGL: UNITY_POST_PROCESSING_STACK_V2
Windows Store Apps: UNITY_POST_PROCESSING_STACK_V2
XboxOne: UNITY_POST_PROCESSING_STACK_V2
+24 -5
View File
@@ -1,12 +1,31 @@
# speckle-unity-vr
A work in progress example project of Speckle in VR!
A VR Sample project for a Speckle Unity VR app.
Currently working with OpenXR on Windows, with the Quest 2.
https://www.youtube.com/watch?v=Y-RGPZJIHf4
https://drive.google.com/file/d/1ls5zovY15Bxhis9e0SgxjKp9k_rLsxzE/preview
This project demonstrates a minimal VR app to visualise and modify 3D models in VR.
3D data can be sent through any [Speckle](https://speckle.systems) connector, and received in the VR application.
- Receiving a selected Speckle commit (from a selection of accounts -> stream -> branch -> commit)
The sample project is built to showcase the Speckle Unity connector, and how developers can easily build custom tools and applications that integrate with Speckle.
---
### Features
- UI for Receiving a selected Speckle commit (from a selection of accounts -> stream -> branch -> commit)
- Move objects around in 3D space using XR Grab Interactables
- Sending (all) to a selected branch
Note: Currently wip, and only working on PCVR (See [discussion](https://speckle.community/t/virtual-augmented-reality/4467))
### Pre-requisites
Currently working with OpenXR on Windows, Likely won't work out of the box for android standalone (See [discussion](https://speckle.community/t/virtual-augmented-reality/4467))
You must have [Speckle Manager](https://speckle.systems/download/) installed with an [Speckle account](https://speckle.xyz/) setup.
You should send some 3D data to Speckle from one of the other [supported connectors](https://speckle.systems/features/connectors/)
See [Releases](https://github.com/specklesystems/speckle-unity-vr/releases) for project download or clone this repo, and open in Unity 2021 or 2022.
Feel free to ask any questions on [our Forum](https://speckle.community/)