From ea368c67adbafaf35785e3cc36e202a602f29f0e Mon Sep 17 00:00:00 2001 From: uc deploy Date: Thu, 19 Apr 2018 17:33:40 +0800 Subject: [PATCH] add multi kinect2motion support --- Unity_2018_Frozen/Assets/Frozen/Frozen.unity | 312 +++++++++++++++++- .../Assets/Frozen/Script/SpaceHomography.cs | 3 + .../Kinect2MotionTexture1.renderTexture | 33 ++ .../Kinect2MotionTexture1.renderTexture.meta | 9 + .../KinectOpticalFlow/KinectOpticalFlow.cs | 20 +- .../KinectUpdateShader.compute | 73 ++-- 6 files changed, 402 insertions(+), 48 deletions(-) create mode 100644 Unity_2018_Frozen/Assets/KinectOpticalFlow/Kinect2MotionTexture1.renderTexture create mode 100644 Unity_2018_Frozen/Assets/KinectOpticalFlow/Kinect2MotionTexture1.renderTexture.meta diff --git a/Unity_2018_Frozen/Assets/Frozen/Frozen.unity b/Unity_2018_Frozen/Assets/Frozen/Frozen.unity index 64a1adf..30c40df 100644 --- a/Unity_2018_Frozen/Assets/Frozen/Frozen.unity +++ b/Unity_2018_Frozen/Assets/Frozen/Frozen.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 1071731254} - m_IndirectSpecularColor: {r: 0.021216419, g: 0.053037524, b: 0.08577964, a: 1} + m_IndirectSpecularColor: {r: 0.021216419, g: 0.053037528, b: 0.08577964, a: 1} --- !u!157 &3 LightmapSettings: m_ObjectHideFlags: 0 @@ -579,7 +579,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: - {fileID: 694714222} - - {fileID: 806122350} + - {fileID: 1553193321} m_Father: {fileID: 0} m_RootOrder: 6 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -822,7 +822,7 @@ Transform: m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 520040865} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 1.2665577, y: 6.04, z: 0.06573248} + m_LocalPosition: {x: 0, y: 40, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} @@ -1111,6 +1111,62 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 11 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &671544960 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 5 + m_Component: + - component: {fileID: 671544961} + - component: {fileID: 671544962} + m_Layer: 5 + m_Name: Canvas + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &671544961 +RectTransform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 671544960} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 0, y: 0, z: 0} + m_Children: + - {fileID: 1028300135} + - {fileID: 718864549} + m_Father: {fileID: 1553193321} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0, y: 0} +--- !u!223 &671544962 +Canvas: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 671544960} + m_Enabled: 1 + serializedVersion: 3 + m_RenderMode: 1 + m_Camera: {fileID: 1553193322} + m_PlaneDistance: 1 + m_PixelPerfect: 0 + m_ReceivesEvents: 1 + m_OverrideSorting: 0 + m_OverridePixelPerfect: 0 + m_SortingBucketNormalizedSize: 0 + m_AdditionalShaderChannelsFlag: 0 + m_SortingLayerID: 0 + m_SortingOrder: 0 + m_TargetDisplay: 0 --- !u!1 &694714221 GameObject: m_ObjectHideFlags: 0 @@ -1121,7 +1177,7 @@ GameObject: - component: {fileID: 694714222} - component: {fileID: 694714223} m_Layer: 5 - m_Name: Camera + m_Name: Kinect Camera m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -1136,7 +1192,8 @@ Transform: m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: -2.28, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] + m_Children: + - {fileID: 806122350} m_Father: {fileID: 401185751} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -1176,6 +1233,86 @@ Camera: m_OcclusionCulling: 1 m_StereoConvergence: 10 m_StereoSeparation: 0.022 +--- !u!1 &718864548 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 5 + m_Component: + - component: {fileID: 718864549} + - component: {fileID: 718864552} + - component: {fileID: 718864551} + - component: {fileID: 718864550} + m_Layer: 5 + m_Name: Velocity + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &718864549 +RectTransform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 718864548} + 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_Children: [] + m_Father: {fileID: 671544961} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 1} + m_AnchorMax: {x: 0, y: 1} + m_AnchoredPosition: {x: 512, y: 0} + m_SizeDelta: {x: 512, y: 424} + m_Pivot: {x: 0, y: 1} +--- !u!114 &718864550 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 718864548} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 846b026f9a6af4049ae8cbc3b560f976, type: 3} + m_Name: + m_EditorClassIdentifier: + _sharingName: 020945164847-Velocity +--- !u!114 &718864551 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 718864548} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: -98529514, guid: f70555f144d8491a825f0804e09c671c, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI, + Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + m_Texture: {fileID: 0} + m_UVRect: + serializedVersion: 2 + x: 0 + y: 0 + width: 1 + height: 1 +--- !u!222 &718864552 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 718864548} --- !u!1 &732632614 GameObject: m_ObjectHideFlags: 0 @@ -1626,8 +1763,8 @@ RectTransform: m_Children: - {fileID: 1974547831} - {fileID: 1842692481} - m_Father: {fileID: 401185751} - m_RootOrder: 1 + m_Father: {fileID: 694714222} + m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 0, y: 0} @@ -1894,6 +2031,86 @@ CanvasRenderer: m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 1000268178} +--- !u!1 &1028300134 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 5 + m_Component: + - component: {fileID: 1028300135} + - component: {fileID: 1028300138} + - component: {fileID: 1028300137} + - component: {fileID: 1028300136} + m_Layer: 5 + m_Name: Position + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1028300135 +RectTransform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1028300134} + 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_Children: [] + m_Father: {fileID: 671544961} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 1} + m_AnchorMax: {x: 0, y: 1} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 512, y: 424} + m_Pivot: {x: 0, y: 1} +--- !u!114 &1028300136 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1028300134} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 846b026f9a6af4049ae8cbc3b560f976, type: 3} + m_Name: + m_EditorClassIdentifier: + _sharingName: 020945164847-Position +--- !u!114 &1028300137 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1028300134} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: -98529514, guid: f70555f144d8491a825f0804e09c671c, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI, + Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + m_Texture: {fileID: 0} + m_UVRect: + serializedVersion: 2 + x: 0 + y: 0 + width: 1 + height: 1 +--- !u!222 &1028300138 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1028300134} --- !u!1 &1035960133 GameObject: m_ObjectHideFlags: 0 @@ -2256,6 +2473,72 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 12 m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0} +--- !u!1 &1553193320 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 5 + m_Component: + - component: {fileID: 1553193321} + - component: {fileID: 1553193322} + m_Layer: 5 + m_Name: Kinect Camera (1) + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1553193321 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1553193320} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: -2.28, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 671544961} + m_Father: {fileID: 401185751} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!20 &1553193322 +Camera: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1553193320} + m_Enabled: 1 + serializedVersion: 2 + m_ClearFlags: 1 + m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} + m_NormalizedViewPortRect: + serializedVersion: 2 + x: 0 + y: 0 + width: 1 + height: 1 + near clip plane: 0.3 + far clip plane: 1000 + field of view: 60 + orthographic: 0 + orthographic size: 5 + m_Depth: 0 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_RenderingPath: 1 + m_TargetTexture: {fileID: 8400000, guid: 1276428e64b9c6444aaa6e9b476ebb1c, type: 2} + m_TargetDisplay: 1 + m_TargetEye: 3 + m_HDR: 1 + m_AllowMSAA: 0 + m_AllowDynamicResolution: 0 + m_ForceIntoRT: 0 + m_OcclusionCulling: 1 + m_StereoConvergence: 10 + m_StereoSeparation: 0.022 --- !u!1 &1765914293 GameObject: m_ObjectHideFlags: 0 @@ -2320,9 +2603,9 @@ Canvas: m_GameObject: {fileID: 1765914293} m_Enabled: 1 serializedVersion: 3 - m_RenderMode: 0 - m_Camera: {fileID: 151858423} - m_PlaneDistance: 1 + m_RenderMode: 1 + m_Camera: {fileID: 520040868} + m_PlaneDistance: 10 m_PixelPerfect: 0 m_ReceivesEvents: 1 m_OverrideSorting: 0 @@ -2658,7 +2941,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 846b026f9a6af4049ae8cbc3b560f976, type: 3} m_Name: m_EditorClassIdentifier: - _sharingName: Velocity + _sharingName: 020929664847-Velocity --- !u!114 &1842692483 MonoBehaviour: m_ObjectHideFlags: 0 @@ -2713,7 +2996,7 @@ Transform: m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 1848145249} - m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalRotation: {x: 0, y: -1, z: 0, w: 0} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_Children: @@ -2721,7 +3004,7 @@ Transform: - {fileID: 563719737} m_Father: {fileID: 386695297} m_RootOrder: 2 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_LocalEulerAnglesHint: {x: 0, y: -180, z: 0} --- !u!114 &1848145251 MonoBehaviour: m_ObjectHideFlags: 0 @@ -2745,6 +3028,7 @@ MonoBehaviour: kinectAmount: 4 renderTextures: - {fileID: 8400000, guid: f9c2cef894c9cc54f807a92207bf6eda, type: 2} + - {fileID: 8400000, guid: 1276428e64b9c6444aaa6e9b476ebb1c, type: 2} debug: 0 colorize: 1 debugMaterial: {fileID: 2100000, guid: 95b4d9b25b7a7e3449627228b10d9009, type: 2} @@ -2796,7 +3080,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 846b026f9a6af4049ae8cbc3b560f976, type: 3} m_Name: m_EditorClassIdentifier: - _sharingName: Position + _sharingName: 020929664847-Position --- !u!114 &1974547833 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Unity_2018_Frozen/Assets/Frozen/Script/SpaceHomography.cs b/Unity_2018_Frozen/Assets/Frozen/Script/SpaceHomography.cs index 71875f8..e7867c6 100644 --- a/Unity_2018_Frozen/Assets/Frozen/Script/SpaceHomography.cs +++ b/Unity_2018_Frozen/Assets/Frozen/Script/SpaceHomography.cs @@ -102,6 +102,9 @@ public class SpaceHomography : MonoBehaviour material.SetMatrixArray("homography", homos); material.SetVector("homo_space", space); material.SetVector("texture_size", texture_size); + + //print(space); + //print(texture_size); } #endif } diff --git a/Unity_2018_Frozen/Assets/KinectOpticalFlow/Kinect2MotionTexture1.renderTexture b/Unity_2018_Frozen/Assets/KinectOpticalFlow/Kinect2MotionTexture1.renderTexture new file mode 100644 index 0000000..27b42d4 --- /dev/null +++ b/Unity_2018_Frozen/Assets/KinectOpticalFlow/Kinect2MotionTexture1.renderTexture @@ -0,0 +1,33 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!84 &8400000 +RenderTexture: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_Name: Kinect2MotionTexture1 + m_ImageContentsHash: + serializedVersion: 2 + Hash: 00000000000000000000000000000000 + m_ForcedFallbackFormat: 4 + m_DownscaleFallback: 0 + m_Width: 1024 + m_Height: 424 + m_AntiAliasing: 1 + m_DepthFormat: 0 + m_ColorFormat: 11 + m_MipMap: 0 + m_GenerateMips: 1 + m_SRGB: 0 + m_UseDynamicScale: 0 + m_BindMS: 0 + m_TextureSettings: + serializedVersion: 2 + m_FilterMode: 1 + m_Aniso: 0 + m_MipBias: 0 + m_WrapU: 1 + m_WrapV: 1 + m_WrapW: 1 + m_Dimension: 2 + m_VolumeDepth: 1 diff --git a/Unity_2018_Frozen/Assets/KinectOpticalFlow/Kinect2MotionTexture1.renderTexture.meta b/Unity_2018_Frozen/Assets/KinectOpticalFlow/Kinect2MotionTexture1.renderTexture.meta new file mode 100644 index 0000000..7d76262 --- /dev/null +++ b/Unity_2018_Frozen/Assets/KinectOpticalFlow/Kinect2MotionTexture1.renderTexture.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 1276428e64b9c6444aaa6e9b476ebb1c +timeCreated: 1508289246 +licenseType: Free +NativeFormatImporter: + mainObjectFileID: 8400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Unity_2018_Frozen/Assets/KinectOpticalFlow/KinectOpticalFlow.cs b/Unity_2018_Frozen/Assets/KinectOpticalFlow/KinectOpticalFlow.cs index dd377bf..e835c39 100644 --- a/Unity_2018_Frozen/Assets/KinectOpticalFlow/KinectOpticalFlow.cs +++ b/Unity_2018_Frozen/Assets/KinectOpticalFlow/KinectOpticalFlow.cs @@ -36,6 +36,7 @@ namespace UltraCombos [Range(0, 5)] public float kinectAmount = 0; public List renderTextures; + Texture2DArray kinectTextureArray; [SerializeField, Header("Debug")] bool debug = false; @@ -70,10 +71,14 @@ namespace UltraCombos } { - home_position_buffer = new ComputeBuffer(512 * 424, sizeof(float) * 4, ComputeBufferType.Append); - home_velocity_buffer = new ComputeBuffer(512 * 424, sizeof(float) * 4, ComputeBufferType.Append); + home_position_buffer = new ComputeBuffer(512 * 424 * renderTextures.Count, sizeof(float) * 4, ComputeBufferType.Append); + home_velocity_buffer = new ComputeBuffer(512 * 424 * renderTextures.Count, sizeof(float) * 4, ComputeBufferType.Append); home_count_buffer = new ComputeBuffer(1, sizeof(int), ComputeBufferType.Raw); } + + { + kinectTextureArray = new Texture2DArray(512 * 2, 424, 8, TextureFormat.RGBAFloat, false); + } } private void FixedUpdate() @@ -83,6 +88,15 @@ namespace UltraCombos args_buffer = updateShader.CreateIndirectComputeArgsBuffer(width * height, 1, 1); } + { + for (int i = 0; i < renderTextures.Count; i++) + { + if (renderTextures[i].IsCreated()) + Graphics.CopyTexture(renderTextures[i], 0, kinectTextureArray, i); + } + } + + // update { var m = transform.localToWorldMatrix; @@ -99,9 +113,11 @@ namespace UltraCombos updateShader.SetVector("FluidRoot", fluidSimulation.GridRoot); updateShader.SetVector("FluidDim", fluidSimulation.GridDim); updateShader.SetInt("flipX", flipX ? 1 : 0); + updateShader.SetInt("NumKinects", renderTextures.Count); //updateShader.SetTexture(0, "PositionTexture", renderTextures[POSITION]); //updateShader.SetTexture(0, "VelocityTexture", renderTextures[VELOCITY]); + updateShader.SetTexture(0, "MotionTextureArray", kinectTextureArray); updateShader.SetTexture(0, "MotionTexture", renderTextures[0]); foreach (var buf in kinectBuffers) updateShader.SetBuffer(0, buf.bufferName, buf.obj); diff --git a/Unity_2018_Frozen/Assets/KinectOpticalFlow/KinectUpdateShader.compute b/Unity_2018_Frozen/Assets/KinectOpticalFlow/KinectUpdateShader.compute index 3f44ad2..49027cf 100644 --- a/Unity_2018_Frozen/Assets/KinectOpticalFlow/KinectUpdateShader.compute +++ b/Unity_2018_Frozen/Assets/KinectOpticalFlow/KinectUpdateShader.compute @@ -3,6 +3,8 @@ #pragma kernel CSMain +#include "UnityCG.cginc" + RWStructuredBuffer KinectPositionBuffer; RWStructuredBuffer KinectVelocityBuffer; RWStructuredBuffer KinectGridBuffer; @@ -13,6 +15,7 @@ AppendStructuredBuffer HomeVelocityBuffer; //Texture2D PositionTexture; //Texture2D VelocityTexture; Texture2D MotionTexture; +Texture2DArray MotionTextureArray; float4 ClipMin; float4 ClipMax; @@ -21,52 +24,58 @@ float4 FluidSize; float4 FluidRoot; float4 FluidDim; int flipX; +int NumKinects; [numthreads(512,1,1)] void CSMain (uint3 id : SV_DispatchThreadID) { uint2 tex_coord = uint2(id.x % HEIGHT, id.x / HEIGHT); - float4 pos = float4(MotionTexture[tex_coord].xyz, 1); - //pos.y *= -1; - pos.z *= -1; - pos.x = lerp(pos.x, -pos.x, flipX); + for (int i = 0; i < NumKinects; i++) + { + float4 pos = float4(MotionTexture[tex_coord].xyz, 1); + pos = float4(MotionTextureArray[uint3(tex_coord, i)].xyz, 1); + //pos.y *= -1; + pos.z *= -1; + pos.x = lerp(pos.x, -pos.x, flipX); - float pos_mag = length(pos.xyz); + float pos_mag = length(pos.xyz); - { - pos = mul(pos, ModelMatrix); - - float4 vel = MotionTexture[tex_coord + uint2(WIDTH, 0)]; - //vel.y *= -1; - vel.z *= -1; - vel.x = lerp(vel.x, -vel.x, flipX); - - float3 grid_pos = (pos.xyz - FluidRoot.xyz) / FluidSize.xyz; - int grid_index = -1; - if (grid_pos.x > 0 && grid_pos.x < 1 && - grid_pos.y > 0 && grid_pos.y < 1 && - grid_pos.z > 0 && grid_pos.z < 1 && - pos_mag > 0.0f)// && length(pos) > 10.0f) { - grid_pos *= FluidDim.xyz; - grid_index = (int)grid_pos.x + (int)grid_pos.y * FluidDim.x + (int)grid_pos.z * FluidDim.x * FluidDim.y; - KinectGridBuffer[grid_index] += float4(vel.xyz, 1); + pos = mul(pos, ModelMatrix); + + float4 vel = MotionTexture[tex_coord + uint2(WIDTH, 0)]; + vel = MotionTextureArray[uint3(tex_coord, i) + uint3(WIDTH, 0, 0)]; + //vel.y *= -1; + vel.z *= -1; + vel.x = lerp(vel.x, -vel.x, flipX); - if (pos_mag > 0.1f)// && pos.y < 0.5f) + float3 grid_pos = (pos.xyz - FluidRoot.xyz) / FluidSize.xyz; + int grid_index = -1; + if (grid_pos.x > 0 && grid_pos.x < 1 && + grid_pos.y > 0 && grid_pos.y < 1 && + grid_pos.z > 0 && grid_pos.z < 1 && + pos_mag > 0.0f)// && length(pos) > 10.0f) { - pos.y = 0.0f; - vel.xyz = float3(0, 0, 0); + grid_pos *= FluidDim.xyz; + grid_index = (int)grid_pos.x + (int)grid_pos.y * FluidDim.x + (int)grid_pos.z * FluidDim.x * FluidDim.y; + KinectGridBuffer[grid_index] += float4(vel.xyz, 1); - HomePositionBuffer.Append(float4(pos.xyz, 0)); - HomeVelocityBuffer.Append(float4(vel.xyz, 0)); + if (pos_mag > 0.1f)// && pos.y < 0.5f) + { + //pos.y = 0.0f; + //vel.xyz = float3(0, 0, 0); + + HomePositionBuffer.Append(float4(pos.xyz, 0)); + HomeVelocityBuffer.Append(float4(vel.xyz, 0)); + } + } - - } - KinectPositionBuffer[id.x] = float4(pos.xyz, grid_index); - KinectVelocityBuffer[id.x] = float4((pos_mag == 0.0f) ? float3(0, 0, 0) : vel.xyz, 0); + KinectPositionBuffer[id.x] = float4(pos.xyz, grid_index); + KinectVelocityBuffer[id.x] = float4((pos_mag == 0.0f) ? float3(0, 0, 0) : vel.xyz, 0); + } } - + }