Skip to content

Commit

Permalink
Unity sample compatiable with newer Unity version (XRSDK support), up…
Browse files Browse the repository at this point in the history
…date point cloud shader to support single pass instanced.
  • Loading branch information
petergu684 committed Nov 15, 2021
1 parent 08cd757 commit b45a881
Show file tree
Hide file tree
Showing 14 changed files with 230 additions and 507 deletions.
42 changes: 29 additions & 13 deletions UnitySample/Assets/Materials/GS Billboard.shader
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//This is a modified version of a shader published by smb02dunnal on the Unity forums:
// Upgrade NOTE: replaced 'UNITY_INSTANCE_ID' with 'UNITY_VERTEX_INPUT_INSTANCE_ID'

//This is a modified version of a shader published by smb02dunnal on the Unity forums:
//https://forum.unity3d.com/threads/billboard-geometry-shader.169415/

Shader "Custom/GS Billboard"
Expand All @@ -16,11 +18,12 @@ Shader "Custom/GS Billboard"
LOD 200

CGPROGRAM
#pragma target 5.0
#pragma vertex VS_Main
#pragma fragment FS_Main
#pragma geometry GS_Main
#include "UnityCG.cginc"
#pragma target 5.0
#pragma vertex VS_Main
#pragma fragment FS_Main
#pragma geometry GS_Main
#pragma multi_compile_instancing
#include "UnityCG.cginc"

// **************************************************************
// Data structures *
Expand All @@ -29,20 +32,24 @@ Shader "Custom/GS Billboard"
{
float4 pos : POSITION;
float4 col : COLOR;
UNITY_VERTEX_INPUT_INSTANCE_ID
};

struct FS_INPUT
{
float4 pos : POSITION;
float4 pos : SV_POSITION;
float4 col : COLOR;
UNITY_VERTEX_OUTPUT_STEREO
};


// **************************************************************
// Vars *
// **************************************************************

float _PointSize;
UNITY_INSTANCING_BUFFER_START(Props)
UNITY_DEFINE_INSTANCED_PROP(float, _PointSize)
UNITY_INSTANCING_BUFFER_END(Props)
//float _PointSize;

// **************************************************************
// Shader Programs *
Expand All @@ -53,6 +60,9 @@ Shader "Custom/GS Billboard"
{
GS_INPUT output = (GS_INPUT)0;

UNITY_SETUP_INSTANCE_ID(v);
UNITY_TRANSFER_INSTANCE_ID(v, output);

output.pos = mul(unity_ObjectToWorld, v.vertex);
output.col = v.color;

Expand All @@ -63,21 +73,26 @@ Shader "Custom/GS Billboard"
[maxvertexcount(4)]
void GS_Main(point GS_INPUT p[1], inout TriangleStream<FS_INPUT> triStream)
{
FS_INPUT pIn;

UNITY_SETUP_INSTANCE_ID(p[0]);
//UNITY_TRANSFER_INSTANCE_ID(p[0], pIn);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(pIn);

float3 up = float3(0, 1, 0);
float3 look = _WorldSpaceCameraPos - p[0].pos;
look.y = 0;
look = normalize(look);
float3 right = cross(up, look);

float halfS = 0.5f * _PointSize;
float halfS = 0.5f * UNITY_ACCESS_INSTANCED_PROP(Props, _PointSize);

float4 v[4];
v[0] = float4(p[0].pos + halfS * right - halfS * up, 1.0f);
v[1] = float4(p[0].pos + halfS * right + halfS * up, 1.0f);
v[2] = float4(p[0].pos - halfS * right - halfS * up, 1.0f);
v[3] = float4(p[0].pos - halfS * right + halfS * up, 1.0f);
v[2] = float4(p[0].pos - halfS * right + halfS * up, 1.0f);
v[3] = float4(p[0].pos - halfS * right - halfS * up, 1.0f);

FS_INPUT pIn;
pIn.pos = UnityObjectToClipPos(v[0]);
pIn.col = p[0].col;
triStream.Append(pIn);
Expand All @@ -98,6 +113,7 @@ Shader "Custom/GS Billboard"
// Fragment Shader -----------------------------------------------
float4 FS_Main(FS_INPUT input) : COLOR
{
//UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
return input.col;
}

Expand Down
2 changes: 1 addition & 1 deletion UnitySample/Assets/Materials/PointCloudMaterial.mat
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Material:
m_Shader: {fileID: 4800000, guid: 326251e82500d6b47839b3d5fcdba082, type: 3}
m_ShaderKeywords: _EMISSION
m_LightmapFlags: 1
m_EnableInstancingVariants: 0
m_EnableInstancingVariants: 1
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
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: 7612acbc1a4a4ed0afa5f4ccbe42bee4, type: 3}
m_Name: New XRSDKConfigurationProfile
m_EditorClassIdentifier:
isCustomProfile: 1
targetExperienceScale: 3
enableCameraSystem: 1
cameraProfile: {fileID: 11400000, guid: 6a6ea8e8cca71344ba773e4317537580, type: 2}
cameraSystemType:
reference: Microsoft.MixedReality.Toolkit.CameraSystem.MixedRealityCameraSystem,
Microsoft.MixedReality.Toolkit.Services.CameraSystem
enableInputSystem: 1
inputSystemProfile: {fileID: 11400000, guid: a99ae78a82ae4d14ba741d7e75a64c48, type: 2}
inputSystemType:
reference: Microsoft.MixedReality.Toolkit.Input.MixedRealityInputSystem, Microsoft.MixedReality.Toolkit.Services.InputSystem
enableBoundarySystem: 0
boundarySystemType:
reference: Microsoft.MixedReality.Toolkit.XRSDK.XRSDKBoundarySystem, Microsoft.MixedReality.Toolkit.Providers.XRSDK
boundaryVisualizationProfile: {fileID: 11400000, guid: 6d28cce596b44bd3897ca86f8b24e076,
type: 2}
enableTeleportSystem: 0
teleportSystemType:
reference: Microsoft.MixedReality.Toolkit.Teleport.MixedRealityTeleportSystem,
Microsoft.MixedReality.Toolkit.Services.TeleportSystem
enableSpatialAwarenessSystem: 0
spatialAwarenessSystemType:
reference: Microsoft.MixedReality.Toolkit.SpatialAwareness.MixedRealitySpatialAwarenessSystem,
Microsoft.MixedReality.Toolkit.Services.SpatialAwarenessSystem
spatialAwarenessSystemProfile: {fileID: 11400000, guid: 2f8932c6c78438e4d9bff23af5c710be,
type: 2}
diagnosticsSystemProfile: {fileID: 11400000, guid: 478436bd1083882479a52d067e98e537,
type: 2}
enableDiagnosticsSystem: 0
diagnosticsSystemType:
reference: Microsoft.MixedReality.Toolkit.Diagnostics.MixedRealityDiagnosticsSystem,
Microsoft.MixedReality.Toolkit.Services.DiagnosticsSystem
sceneSystemProfile: {fileID: 11400000, guid: 069efa41032a317409790a6a08435311, type: 2}
enableSceneSystem: 0
sceneSystemType:
reference: Microsoft.MixedReality.Toolkit.SceneSystem.MixedRealitySceneSystem,
Microsoft.MixedReality.Toolkit.Services.SceneSystem
registeredServiceProvidersProfile: {fileID: 11400000, guid: efbaf6ea540c69f4fb75415a5d145a53,
type: 2}
useServiceInspectors: 0
renderDepthBuffer: 0
enableVerboseLogging: 0

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
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: 8275efdbe76bdff49a97a8e82fba118d, type: 3}
m_Name: New XRSDKHandTrackingProfile
m_EditorClassIdentifier:
isCustomProfile: 1
jointPrefab: {fileID: 1955475817299902, guid: 6a3f88d2571cd234a86d95ee5856b9ec,
type: 3}
palmPrefab: {fileID: 6797406804172968804, guid: 750bdc3344567a447960aae3eda2b462,
type: 3}
fingertipPrefab: {fileID: 7094064642998883381, guid: b37dde41a983d664c8a09a91313733e7,
type: 3}
handMeshPrefab: {fileID: 1887883006053652, guid: a86f479797fea8f4189f924b3b6ad979,
type: 3}
handMeshVisualizationModes: 1
handJointVisualizationModes: 1

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
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: b71cb900fa9dec5488df2deb180db58f, type: 3}
m_Name: New XRSDKInputSystemProfile
m_EditorClassIdentifier:
isCustomProfile: 1
dataProviderConfigurations:
- componentType:
reference: Microsoft.MixedReality.Toolkit.XRSDK.WindowsMixedReality.WindowsMixedRealityDeviceManager,
Microsoft.MixedReality.Toolkit.Providers.XRSDK.WindowsMixedReality
componentName: XRSDK Windows Mixed Reality Device Manager
priority: 0
runtimePlatform: 9
deviceManagerProfile: {fileID: 0}
- componentType:
reference: Microsoft.MixedReality.Toolkit.XRSDK.Oculus.Input.OculusXRSDKDeviceManager,
Microsoft.MixedReality.Toolkit.Providers.XRSDK.Oculus
componentName: XRSDK Oculus Device Manager
priority: 0
runtimePlatform: 33
deviceManagerProfile: {fileID: 11400000, guid: 8f48cb9c26fb518499c65c9f9e8bb4ed,
type: 2}
- componentType:
reference: Microsoft.MixedReality.Toolkit.Input.InputSimulationService, Microsoft.MixedReality.Toolkit.Services.InputSimulation
componentName: Input Simulation Service
priority: 0
runtimePlatform: 208
deviceManagerProfile: {fileID: 11400000, guid: 41478039094d47641bf4e09c20e61a5a,
type: 2}
- componentType:
reference: Microsoft.MixedReality.Toolkit.Input.HandJointService, Microsoft.MixedReality.Toolkit
componentName: Hand Joint Service
priority: 0
runtimePlatform: -1
deviceManagerProfile: {fileID: 0}
focusProviderType:
reference: Microsoft.MixedReality.Toolkit.Input.FocusProvider, Microsoft.MixedReality.Toolkit.Services.InputSystem
raycastProviderType:
reference: Microsoft.MixedReality.Toolkit.Input.DefaultRaycastProvider, Microsoft.MixedReality.Toolkit.Services.InputSystem
focusQueryBufferSize: 128
focusIndividualCompoundCollider: 0
inputActionsProfile: {fileID: 11400000, guid: 723eb97b02944311b92861f473eee53e,
type: 2}
inputActionRulesProfile: {fileID: 11400000, guid: 03945385d89102f41855bc8f5116b199,
type: 2}
pointerProfile: {fileID: 11400000, guid: 48aa63a9725047b28d4137fd0834bc31, type: 2}
gesturesProfile: {fileID: 11400000, guid: bd7829a9b29409045a745b5a18299291, type: 2}
speechCommandsProfile: {fileID: 11400000, guid: e8d0393e66374dae9646851a57dc6bc1,
type: 2}
enableControllerMapping: 1
controllerMappingProfile: {fileID: 11400000, guid: 39ded1fd0711a0c448413d0e1ec4f7f3,
type: 2}
controllerVisualizationProfile: {fileID: 11400000, guid: d9ee3d709133f504a8d76410d0135d17,
type: 2}
handTrackingProfile: {fileID: 11400000, guid: 8aab3750554745a4bada0754ae123059,
type: 2}

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

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ MonoBehaviour:
- _MixedRealityToolkit_Editor_IgnoreSettingsPrompts
- _MixedRealityToolkit_Editor_LockProfiles
- MixedRealityToolkit_Editor_RunOptimalConfig
values: 010101
- _MixedRealityToolkit_Editor_AutoEnableUWPCapabilities
values: 01010101
intPreferences:
keys:
- MixedRealityToolkit_Editor_AudioSpatializerCount
Expand Down
4 changes: 2 additions & 2 deletions UnitySample/Assets/Scenes/PointCloudSample.unity
Original file line number Diff line number Diff line change
Expand Up @@ -1626,7 +1626,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 83d9acc7968244a8886f3af591305bcb, type: 3}
m_Name:
m_EditorClassIdentifier:
activeProfile: {fileID: 11400000, guid: d2a1b54c6ea39bc49a725c4d4fba0102, type: 2}
activeProfile: {fileID: 11400000, guid: dccee802765a6c04bb87130af583c8ce, type: 2}
--- !u!4 &752144244
Transform:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -3375,8 +3375,8 @@ GameObject:
- component: {fileID: 1517424693}
- component: {fileID: 1517424692}
- component: {fileID: 1517424695}
- component: {fileID: 1517424696}
- component: {fileID: 1517424697}
- component: {fileID: 1517424696}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
Expand Down
19 changes: 14 additions & 5 deletions UnitySample/Assets/Scipts/ResearchModeVideoStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,25 @@ public class ResearchModeVideoStream : MonoBehaviour
public GameObject pointCloudRendererGo;
public Color pointColor = Color.white;
private PointCloudRenderer pointCloudRenderer;
void Start()
#if ENABLE_WINMD_SUPPORT
Windows.Perception.Spatial.SpatialCoordinateSystem unityWorldOrigin;
#endif

private void Awake()
{
#if WINDOWS_UWP
#if UNITY_2020_OR_NEWER
var unityWorldOrigin = Windows.Perception.Spatial.SpatialLocator.GetDefault().CreateStationaryFrameOfReferenceAtCurrentLocation().CoordinateSystem;
#if ENABLE_WINMD_SUPPORT
#if UNITY_2020_1_OR_NEWER
IntPtr WorldOriginPtr = UnityEngine.XR.WindowsMR.WindowsMREnvironment.OriginSpatialCoordinateSystem;
unityWorldOrigin = Marshal.GetObjectForIUnknown(WorldOriginPtr) as Windows.Perception.Spatial.SpatialCoordinateSystem;
//unityWorldOrigin = Windows.Perception.Spatial.SpatialLocator.GetDefault().CreateStationaryFrameOfReferenceAtCurrentLocation().CoordinateSystem;
#else
IntPtr WorldOriginPtr = UnityEngine.XR.WSA.WorldManager.GetNativeISpatialCoordinateSystemPtr();
var unityWorldOrigin = Marshal.GetObjectForIUnknown(WorldOriginPtr) as Windows.Perception.Spatial.SpatialCoordinateSystem;
unityWorldOrigin = Marshal.GetObjectForIUnknown(WorldOriginPtr) as Windows.Perception.Spatial.SpatialCoordinateSystem;
#endif
#endif
}
void Start()
{
if (depthPreviewPlane != null)
{
depthMediaMaterial = depthPreviewPlane.GetComponent<MeshRenderer>().material;
Expand Down
Loading

0 comments on commit b45a881

Please sign in to comment.