Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/interactivity #17

Merged
merged 8 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions Assets/Resources/depthShader.shader
Original file line number Diff line number Diff line change
@@ -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
}
9 changes: 9 additions & 0 deletions Assets/Resources/depthShader.shader.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

114 changes: 114 additions & 0 deletions Assets/Resources/visibilityComputationShader.shader
Original file line number Diff line number Diff line change
@@ -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<int> 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
}
10 changes: 10 additions & 0 deletions Assets/Resources/visibilityComputationShader.shader.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Assets/Scripts/Runtime/MediaPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();
Expand Down
63 changes: 56 additions & 7 deletions Assets/Scripts/Runtime/SceneViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/

using System;
using System.Collections;
using System.Collections.Generic;

using UnityEngine;
Expand Down Expand Up @@ -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<MediaPlayer>? 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")
{
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -266,20 +297,31 @@ 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))
{
ConfigureInitialCamera();
}

if (Input.GetKeyDown(KeyCode.L))
{
if(showLog){
showLog = false;
} else {
showLog = true;
}
}

}

private void OnDrawGizmos()
Expand All @@ -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();
}
}

}
Expand Down
2 changes: 1 addition & 1 deletion Packages/com.atteneder.gltfast
Submodule com.atteneder.gltfast updated 72 files
+63 −0 Runtime/Scripts/ActionActivate.cs
+11 −0 Runtime/Scripts/ActionActivate.cs.meta
+80 −0 Runtime/Scripts/ActionAnimation.cs
+11 −0 Runtime/Scripts/ActionAnimation.cs.meta
+91 −0 Runtime/Scripts/ActionBlock.cs
+11 −0 Runtime/Scripts/ActionBlock.cs.meta
+209 −0 Runtime/Scripts/ActionManipulate.cs
+11 −0 Runtime/Scripts/ActionManipulate.cs.meta
+55 −0 Runtime/Scripts/ActionMedia.cs
+11 −0 Runtime/Scripts/ActionMedia.cs.meta
+43 −0 Runtime/Scripts/ActionSetAvatar.cs
+11 −0 Runtime/Scripts/ActionSetAvatar.cs.meta
+43 −0 Runtime/Scripts/ActionSetHaptic.cs
+11 −0 Runtime/Scripts/ActionSetHaptic.cs.meta
+62 −0 Runtime/Scripts/ActionSetMaterial.cs
+11 −0 Runtime/Scripts/ActionSetMaterial.cs.meta
+75 −0 Runtime/Scripts/ActionTransform.cs
+11 −0 Runtime/Scripts/ActionTransform.cs.meta
+220 −0 Runtime/Scripts/Behavior.cs
+11 −0 Runtime/Scripts/Behavior.cs.meta
+45 −0 Runtime/Scripts/BehaviorController.cs
+11 −0 Runtime/Scripts/BehaviorController.cs.meta
+151 −0 Runtime/Scripts/CollisionNodeTrigger.cs
+11 −0 Runtime/Scripts/CollisionNodeTrigger.cs.meta
+192 −0 Runtime/Scripts/CollisionSceneTrigger.cs
+11 −0 Runtime/Scripts/CollisionSceneTrigger.cs.meta
+25 −1 Runtime/Scripts/Extensions.cs
+144 −7 Runtime/Scripts/GameObjectInstantiator.cs
+72 −3 Runtime/Scripts/GltfImport.cs
+15 −0 Runtime/Scripts/IInstantiator.cs
+36 −0 Runtime/Scripts/IMpegInteractivityAction.cs
+11 −0 Runtime/Scripts/IMpegInteractivityAction.cs.meta
+51 −0 Runtime/Scripts/IMpegInteractivityBehavior.cs
+11 −0 Runtime/Scripts/IMpegInteractivityBehavior.cs.meta
+34 −0 Runtime/Scripts/IMpegInteractivityTrigger.cs
+11 −0 Runtime/Scripts/IMpegInteractivityTrigger.cs.meta
+7 −0 Runtime/Scripts/JsonParser.cs
+440 −0 Runtime/Scripts/PrimitivesHelper.cs
+11 −0 Runtime/Scripts/PrimitivesHelper.cs.meta
+71 −0 Runtime/Scripts/ProximityNodeTrigger.cs
+11 −0 Runtime/Scripts/ProximityNodeTrigger.cs.meta
+207 −0 Runtime/Scripts/ProximitySceneTrigger.cs
+11 −0 Runtime/Scripts/ProximitySceneTrigger.cs.meta
+1 −0 Runtime/Scripts/Schema/MpegBufferCircular.cs
+2 −2 Runtime/Scripts/Schema/MpegMedia.cs
+204 −0 Runtime/Scripts/Schema/MpegNodeInteractivity.cs
+11 −0 Runtime/Scripts/Schema/MpegNodeInteractivity.cs.meta
+677 −0 Runtime/Scripts/Schema/MpegSceneInteractivity.cs
+11 −0 Runtime/Scripts/Schema/MpegSceneInteractivity.cs.meta
+7 −1 Runtime/Scripts/Schema/Node.cs
+49 −41 Runtime/Scripts/Schema/RootExtension.cs
+30 −1 Runtime/Scripts/Schema/Scene.cs
+47 −0 Runtime/Scripts/TimeUtils.cs
+11 −0 Runtime/Scripts/TimeUtils.cs.meta
+61 −0 Runtime/Scripts/UserInputNodeTrigger.cs
+11 −0 Runtime/Scripts/UserInputNodeTrigger.cs.meta
+135 −0 Runtime/Scripts/UserInputSceneTrigger.cs
+11 −0 Runtime/Scripts/UserInputSceneTrigger.cs.meta
+279 −0 Runtime/Scripts/VirtualSceneGraph.cs
+11 −0 Runtime/Scripts/VirtualSceneGraph.cs.meta
+337 −0 Runtime/Scripts/VisibilityNodeTrigger.cs
+13 −0 Runtime/Scripts/VisibilityNodeTrigger.cs.meta
+66 −0 Runtime/Scripts/VisibilitySceneTrigger.cs
+11 −0 Runtime/Scripts/VisibilitySceneTrigger.cs.meta
+3 −1 Runtime/Scripts/glTFast.asmdef
+8 −0 Runtime/Shader/Extensions.meta
+8 −0 Runtime/Shader/Extensions/MPEG_Interactivity.meta
+75 −0 Runtime/Shader/Extensions/MPEG_Interactivity/depthShader.shader
+9 −0 Runtime/Shader/Extensions/MPEG_Interactivity/depthShader.shader.meta
+114 −0 Runtime/Shader/Extensions/MPEG_Interactivity/visibilityComputationShader.shader
+9 −0 Runtime/Shader/Extensions/MPEG_Interactivity/visibilityComputationShader.shader.meta
+1 −0 package.json
17 changes: 9 additions & 8 deletions Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Loading