diff --git a/Assets/Resources/depthShader.shader b/Assets/Resources/depthShader.shader new file mode 100644 index 0000000..4f69f9c --- /dev/null +++ b/Assets/Resources/depthShader.shader @@ -0,0 +1,75 @@ + +Shader "InterDigital/depthShader" { + Properties + { + + } + SubShader + { + Tags { "RenderType"="Opaque" } + + Pass + { + + CGPROGRAM + // to use the built-in helper functions + #include "UnityCG.cginc" + // use "vert" function as the vertex shader + #pragma vertex vert + // use "frag" function as the pixel (fragment) shader + #pragma fragment frag + + #pragma target 3.0 + + // vertex shader inputs + struct vertIn + { + float4 vertex : POSITION; // vertex position + }; + + // vertex shader outputs + struct vertOut + { + float depth : TEXCOORD0; // linear depth + float4 projPos : SV_POSITION; // clip space position + }; + + // fragment shader outputs + struct fragOut + { + float4 color : SV_Target; + }; + + + // vertex shader + vertOut vert(vertIn v) + { + vertOut o; + + // computes the linear depth + o.depth = COMPUTE_DEPTH_01; + + // calculates the clip space position + o.projPos = UnityObjectToClipPos(v.vertex.xyz); + + return o; + + } + + + // fragment shader + fragOut frag(vertOut i) + { + fragOut o; + + // outputs the linear depth + o.color = float4(i.depth, 0.0, 0.0, 0.0); + + return o; + + } + ENDCG + } + } + Fallback off +} diff --git a/Assets/Resources/depthShader.shader.meta b/Assets/Resources/depthShader.shader.meta new file mode 100644 index 0000000..7110578 --- /dev/null +++ b/Assets/Resources/depthShader.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 2c400243d89176b418bd2b7e89e970d4 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/visibilityComputationShader.shader b/Assets/Resources/visibilityComputationShader.shader new file mode 100644 index 0000000..f0abd76 --- /dev/null +++ b/Assets/Resources/visibilityComputationShader.shader @@ -0,0 +1,114 @@ + +Shader "InterDigital/visibilityComputationShader" +{ + Properties + { + + } + + SubShader + { + Tags { "RenderType" = "Opaque" } + + // visibility computation + Pass + { + CGPROGRAM + // to use the built-in helper functions + #include "UnityCG.cginc" + // use "vert" function as the vertex shader + #pragma vertex vert + // use "frag" function as the pixel (fragment) shader + #pragma fragment frag + + #pragma target 4.5 + + // vertex shader inputs + struct vertIn + { + float4 vertex : POSITION; // vertex position + }; + + // vertex shader outputs + struct vertOut + { + float3 worldPos : TEXCOORD0; // world position + float4 projPos : SV_POSITION; // clip space position + }; + + // fragment shader outputs + struct fragOut + { + float4 color : SV_Target; + }; + + + // vertex shader + vertOut vert(vertIn v) + { + vertOut o; + + o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz; + + // calculates the clip space position + o.projPos = UnityObjectToClipPos(v.vertex.xyz); + + return o; + + } + + sampler2D sceneDepthTexture; + RWStructuredBuffer visiblePixelsBuffer : register(u1); // size = 2: (maxVisible, visible) pixels + float4x4 worldToViewMatrix; + float4x4 worldToScreenMatrix; + float visibilityBias; + float cameraZFar; + + // fragment shader + fragOut frag(vertOut i) + { + fragOut o; + + // add a visible pixel to the maxVisiblePixels counter + InterlockedAdd(visiblePixelsBuffer[0], 1); + + // + // check if the pixel is occluded + // + + // retrieve the pixel world coordinates + float4 worldPosition = float4(i.worldPos, 1.0f); + + // calculates the input world position in the camera screen space + float4 screenPosition = mul(worldToScreenMatrix, worldPosition); + screenPosition /= screenPosition.w; + + // retrieves the normalized linear eye depth information stored in the camera depth map + float4 cameraDepthwMapTextureCoords = float4((screenPosition.xy + 1.0) / 2.0, 0.0f, 0.0f); + float eyeCameraDepth = tex2D(sceneDepthTexture, cameraDepthwMapTextureCoords).x; + eyeCameraDepth *= cameraZFar; + + // calculates the input world position in the camera eye space + float4 cameraEyePosition = mul(worldToViewMatrix, worldPosition); + cameraEyePosition.xyz /= cameraEyePosition.w; + + // checks if the pixel world position is not occluded. The cameraEyePosition.z < 0 + if (cameraEyePosition.z > (-eyeCameraDepth - visibilityBias)) + { + // is visible + InterlockedAdd(visiblePixelsBuffer[1], 1); + } + + + // outputs a red color + o.color = float4(1.0, 0.0, 0.0, 1.0); + + return o; + + } + ENDCG + } + + } + Fallback off +} diff --git a/Assets/Resources/visibilityComputationShader.shader.meta b/Assets/Resources/visibilityComputationShader.shader.meta new file mode 100644 index 0000000..0c7b026 --- /dev/null +++ b/Assets/Resources/visibilityComputationShader.shader.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 05c4fa145c5a6e94ea802c3eab860d5b +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + preprocessorOverride: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Runtime/MediaPlayer.cs b/Assets/Scripts/Runtime/MediaPlayer.cs index 7326e37..bff3f22 100644 --- a/Assets/Scripts/Runtime/MediaPlayer.cs +++ b/Assets/Scripts/Runtime/MediaPlayer.cs @@ -277,7 +277,7 @@ public static MediaPlayer Create(Media media, MediaPipelineConfig cfg, GameObjec Debug.LogException(e); return null; } - mp.autoPlay = media.autoPlay; + mp.autoPlay = media.autoplay; return mp; } @@ -392,6 +392,8 @@ public void AddAudioSource(SpatialAudioSource aSrc) public void Play(TimeInfo t = null, ViewInfo v = null) { + autoPlay = false; + if (timeInfo == null) { timeInfo = new TimeInfo(); diff --git a/Assets/Scripts/Runtime/SceneViewer.cs b/Assets/Scripts/Runtime/SceneViewer.cs index b052bc6..b1d0d47 100644 --- a/Assets/Scripts/Runtime/SceneViewer.cs +++ b/Assets/Scripts/Runtime/SceneViewer.cs @@ -11,6 +11,7 @@ */ using System; +using System.Collections; using System.Collections.Generic; using UnityEngine; @@ -41,19 +42,27 @@ public class SceneViewer : MonoBehaviour int minFps = int.MaxValue; int maxFps = int.MinValue; - bool autoplay = true; + public bool autoplayAnimation = true; + bool showLog = false; int sceneIndex = 0; SceneImport? gltf; List? mediaPlayers = null; Bounds bounds; + uint maxLogMessages = 15; + Queue logQueue = new Queue(); public string GetSourceUriFromCommandLineArgs() { string[] args = Environment.GetCommandLineArgs(); for (int i = 0; i < args.Length; i++) { + if (args[i] == "--log") + { + showLog = true; + continue; + } int j = i + 1; if (args[i] == "--gltf") { @@ -94,7 +103,7 @@ public void ConfigureInitialCamera() } bounds = Utils.ComputeSceneBounds(); - Utils.LookAt(main, bounds, transform.forward); + Utils.LookAt(main, bounds, transform.forward); } public Camera GetMainCamera() @@ -187,9 +196,16 @@ async void Start() } var instantiator = new GameObjectInstantiator(gltf, transform); + await gltf.InstantiateSceneAsync(instantiator, sceneIndex); + if (autoplayAnimation) + { + var legacyAnimation = instantiator.sceneInstance.legacyAnimation; + if (legacyAnimation != null) + { + legacyAnimation.Play(); + } + } - await gltf.InstantiateSceneAsync(instantiator, sceneIndex); - mediaPlayers = CreateMediaPlayers(gltf, baseUri); CreateVideoTextures(gltf, mediaPlayers); CreateAudioSources(gltf, instantiator, mediaPlayers); @@ -230,8 +246,23 @@ private void disposeMemoryRecorder() memoryUsageRecording = false; } + void HandleLog(string logString, string stackTrace, LogType type) + { + logQueue.Enqueue("[" + type + "] : " + logString); + if (type == LogType.Exception) + logQueue.Enqueue(stackTrace); + while (logQueue.Count > maxLogMessages) + logQueue.Dequeue(); + } + + void OnEnable() + { + Application.logMessageReceived += HandleLog; + } + private void OnDisable() { + Application.logMessageReceived -= HandleLog; disposeMemoryRecorder(); } @@ -266,13 +297,15 @@ void Update() disposeMemoryRecorder(); } - if (autoplay && (mediaPlayers != null)) + if (mediaPlayers != null) { foreach (var mp in mediaPlayers) { - mp.Play(); + if (mp.autoPlay) + { + mp.Play(); + } } - autoplay = false; } if (Input.GetKeyDown(KeyCode.Tab)) @@ -280,6 +313,15 @@ void Update() ConfigureInitialCamera(); } + if (Input.GetKeyDown(KeyCode.L)) + { + if(showLog){ + showLog = false; + } else { + showLog = true; + } + } + } private void OnDrawGizmos() @@ -306,6 +348,13 @@ void OnGUI() { if (memoryUsageRecorder) GUI.TextArea(new Rect(10, 30, 250, 50), statsText); + + if (showLog) + { + GUILayout.BeginArea(new Rect(0, 0, Screen.width, Screen.height)); + GUILayout.Label("\n" + string.Join("\n", logQueue.ToArray())); + GUILayout.EndArea(); + } } } diff --git a/Packages/com.atteneder.gltfast b/Packages/com.atteneder.gltfast index 6f71e32..1ebd310 160000 --- a/Packages/com.atteneder.gltfast +++ b/Packages/com.atteneder.gltfast @@ -1 +1 @@ -Subproject commit 6f71e32dacbb653f523b9442a80271b3c7b79c7c +Subproject commit 1ebd310096b37c4026ad74920582f53de3b071be diff --git a/Packages/manifest.json b/Packages/manifest.json index b3350a2..ea63dea 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -1,19 +1,20 @@ { "dependencies": { - "com.unity.collab-proxy": "1.17.2", + "com.unity.ai.navigation": "1.1.5", + "com.unity.collab-proxy": "2.2.0", "com.unity.feature.development": "1.0.1", - "com.unity.ide.rider": "3.0.15", - "com.unity.ide.visualstudio": "2.0.16", + "com.unity.ide.rider": "3.0.26", + "com.unity.ide.visualstudio": "2.0.22", "com.unity.ide.vscode": "1.2.5", - "com.unity.memoryprofiler": "0.7.1-preview.1", - "com.unity.test-framework": "1.1.31", + "com.unity.memoryprofiler": "1.1.0", + "com.unity.test-framework": "1.1.33", "com.unity.textmeshpro": "3.0.6", - "com.unity.timeline": "1.6.4", + "com.unity.timeline": "1.7.6", "com.unity.toolchain.win-x86_64-linux-x86_64": "2.0.5", "com.unity.ugui": "1.0.0", - "com.unity.visualscripting": "1.7.8", + "com.unity.visualscripting": "1.9.1", "com.unity.xr.management": "4.4.0", - "com.unity.xr.openxr": "1.4.2", + "com.unity.xr.openxr": "1.9.1", "com.unity.modules.ai": "1.0.0", "com.unity.modules.androidjni": "1.0.0", "com.unity.modules.animation": "1.0.0", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index 95d4e5f..a3d15b9 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -8,11 +8,21 @@ "com.unity.modules.jsonserialize": "1.0.0", "com.unity.modules.unitywebrequest": "1.0.0", "com.unity.mathematics": "1.2.6", + "com.unity.inputsystem": "1.7.0", "com.unity.burst": "1.6.6" } }, + "com.unity.ai.navigation": { + "version": "1.1.5", + "depth": 0, + "source": "registry", + "dependencies": { + "com.unity.modules.ai": "1.0.0" + }, + "url": "https://packages.unity.com" + }, "com.unity.burst": { - "version": "1.6.6", + "version": "1.8.9", "depth": 1, "source": "registry", "dependencies": { @@ -21,12 +31,10 @@ "url": "https://packages.unity.com" }, "com.unity.collab-proxy": { - "version": "1.17.2", + "version": "2.2.0", "depth": 0, "source": "registry", - "dependencies": { - "com.unity.services.core": "1.0.1" - }, + "dependencies": {}, "url": "https://packages.unity.com" }, "com.unity.editorcoroutines": { @@ -48,17 +56,17 @@ "depth": 0, "source": "builtin", "dependencies": { - "com.unity.ide.visualstudio": "2.0.16", - "com.unity.ide.rider": "3.0.15", + "com.unity.ide.visualstudio": "2.0.22", + "com.unity.ide.rider": "3.0.26", "com.unity.ide.vscode": "1.2.5", "com.unity.editorcoroutines": "1.0.0", - "com.unity.performance.profile-analyzer": "1.1.1", - "com.unity.test-framework": "1.1.31", - "com.unity.testtools.codecoverage": "1.0.1" + "com.unity.performance.profile-analyzer": "1.2.2", + "com.unity.test-framework": "1.1.33", + "com.unity.testtools.codecoverage": "1.2.4" } }, "com.unity.ide.rider": { - "version": "3.0.15", + "version": "3.0.26", "depth": 0, "source": "registry", "dependencies": { @@ -67,7 +75,7 @@ "url": "https://packages.unity.com" }, "com.unity.ide.visualstudio": { - "version": "2.0.16", + "version": "2.0.22", "depth": 0, "source": "registry", "dependencies": { @@ -83,7 +91,7 @@ "url": "https://packages.unity.com" }, "com.unity.inputsystem": { - "version": "1.4.2", + "version": "1.7.0", "depth": 1, "source": "registry", "dependencies": { @@ -99,7 +107,7 @@ "url": "https://packages.unity.com" }, "com.unity.memoryprofiler": { - "version": "0.7.1-preview.1", + "version": "1.1.0", "depth": 0, "source": "registry", "dependencies": { @@ -107,33 +115,15 @@ }, "url": "https://packages.unity.com" }, - "com.unity.nuget.newtonsoft-json": { - "version": "3.0.2", - "depth": 2, - "source": "registry", - "dependencies": {}, - "url": "https://packages.unity.com" - }, "com.unity.performance.profile-analyzer": { - "version": "1.1.1", + "version": "1.2.2", "depth": 1, "source": "registry", "dependencies": {}, "url": "https://packages.unity.com" }, - "com.unity.services.core": { - "version": "1.4.2", - "depth": 1, - "source": "registry", - "dependencies": { - "com.unity.modules.unitywebrequest": "1.0.0", - "com.unity.nuget.newtonsoft-json": "3.0.2", - "com.unity.modules.androidjni": "1.0.0" - }, - "url": "https://packages.unity.com" - }, "com.unity.settings-manager": { - "version": "1.0.3", + "version": "2.0.1", "depth": 2, "source": "registry", "dependencies": {}, @@ -156,7 +146,7 @@ "url": "https://packages.unity.com" }, "com.unity.test-framework": { - "version": "1.1.31", + "version": "1.1.33", "depth": 0, "source": "registry", "dependencies": { @@ -167,7 +157,7 @@ "url": "https://packages.unity.com" }, "com.unity.testtools.codecoverage": { - "version": "1.0.1", + "version": "1.2.4", "depth": 1, "source": "registry", "dependencies": { @@ -186,7 +176,7 @@ "url": "https://packages.unity.com" }, "com.unity.timeline": { - "version": "1.6.4", + "version": "1.7.6", "depth": 0, "source": "registry", "dependencies": { @@ -217,7 +207,7 @@ } }, "com.unity.visualscripting": { - "version": "1.7.8", + "version": "1.9.1", "depth": 0, "source": "registry", "dependencies": { @@ -226,6 +216,15 @@ }, "url": "https://packages.unity.com" }, + "com.unity.xr.core-utils": { + "version": "2.2.3", + "depth": 1, + "source": "registry", + "dependencies": { + "com.unity.modules.xr": "1.0.0" + }, + "url": "https://packages.unity.com" + }, "com.unity.xr.legacyinputhelpers": { "version": "2.1.10", "depth": 1, @@ -249,13 +248,14 @@ "url": "https://packages.unity.com" }, "com.unity.xr.openxr": { - "version": "1.4.2", + "version": "1.9.1", "depth": 0, "source": "registry", "dependencies": { - "com.unity.xr.management": "4.0.1", + "com.unity.xr.management": "4.4.0", "com.unity.xr.legacyinputhelpers": "2.1.2", - "com.unity.inputsystem": "1.3.0" + "com.unity.inputsystem": "1.6.3", + "com.unity.xr.core-utils": "2.1.1" }, "url": "https://packages.unity.com" }, @@ -397,17 +397,6 @@ "version": "1.0.0", "depth": 0, "source": "builtin", - "dependencies": { - "com.unity.modules.ui": "1.0.0", - "com.unity.modules.imgui": "1.0.0", - "com.unity.modules.jsonserialize": "1.0.0", - "com.unity.modules.uielementsnative": "1.0.0" - } - }, - "com.unity.modules.uielementsnative": { - "version": "1.0.0", - "depth": 1, - "source": "builtin", "dependencies": { "com.unity.modules.ui": "1.0.0", "com.unity.modules.imgui": "1.0.0", diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt index 8ea1b85..91206fd 100644 --- a/ProjectSettings/ProjectVersion.txt +++ b/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 2021.3.11f1 -m_EditorVersionWithRevision: 2021.3.11f1 (0a5ca18544bf) +m_EditorVersion: 2022.3.13f1 +m_EditorVersionWithRevision: 2022.3.13f1 (5f90a5ebde0f) diff --git a/ProjectSettings/boot.config b/ProjectSettings/boot.config deleted file mode 100644 index e69de29..0000000 diff --git a/README.md b/README.md index 51bc3a0..adb7a2f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,18 @@ # sample gltf scene viewer implementing mpeg extensions +## Supported platforms + +The project supports the latest [Unity3D LTS editor release](https://unity.com/releases/editor/qa/lts-releases). + +XR is implemented through the [OpenXR plugin](https://docs.unity3d.com/Packages/com.unity.xr.openxr@latest) for Unity's [XR plugin management package](https://docs.unity3d.com/Packages/com.unity.xr.management@latest). + +The OpenXR plugin provides a [list of supported platforms](https://docs.unity3d.com/Packages/com.unity.xr.openxr@1.10/manual/index.html#runtimes). + +It is currently developed and tested on Windows 11 using the [Meta Quest Link](https://www.meta.com/help/quest/articles/headsets-and-accessories/oculus-link/set-up-link/). + +Please open an issue to request support for new platforms. + + ## Build **1. clone the project and its submodules** @@ -30,7 +43,6 @@ This is a dependency of the sample media pipeline based on libav. For details, i **5. use the editor's play mode, or build the project and run the executable** (eg. `File > Build settings > Build > Clean Build`) -The project is currently developped and tested on windows only (precompiled maf library). ## Usage