diff --git a/Unity_2018_Frozen/Assets/FluidSim3D/Shaders/ApplyImpulse.compute b/Unity_2018_Frozen/Assets/FluidSim3D/Shaders/ApplyImpulse.compute index e32da82..3b57a9a 100644 --- a/Unity_2018_Frozen/Assets/FluidSim3D/Shaders/ApplyImpulse.compute +++ b/Unity_2018_Frozen/Assets/FluidSim3D/Shaders/ApplyImpulse.compute @@ -14,7 +14,6 @@ void GaussImpulse(uint3 id : SV_DispatchThreadID) { float3 pos = id/(_Size.xyz-1.0f) - _Pos.xyz; - pos.y /= 2.0f; float mag = pos.x*pos.x + pos.y*pos.y + pos.z*pos.z; float rad2 = _Radius*_Radius; diff --git a/Unity_2018_Frozen/Assets/Frozen/Frozen.unity b/Unity_2018_Frozen/Assets/Frozen/Frozen.unity index 56c9997..5660d61 100644 --- a/Unity_2018_Frozen/Assets/Frozen/Frozen.unity +++ b/Unity_2018_Frozen/Assets/Frozen/Frozen.unity @@ -548,7 +548,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: reset: 0 - maxParticles: 500000 + maxParticles: 100000 particleBuffer: {fileID: 438615022} homeBuffer: {fileID: 1375512057} homeVelocityBuffer: {fileID: 1924148042} @@ -687,31 +687,13 @@ GameObject: serializedVersion: 5 m_Component: - component: {fileID: 386695297} - - component: {fileID: 386695296} m_Layer: 11 m_Name: Simulation and Kinect m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 0 ---- !u!95 &386695296 -Animator: - serializedVersion: 3 - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 386695295} - m_Enabled: 1 - m_Avatar: {fileID: 0} - m_Controller: {fileID: 0} - m_CullingMode: 0 - m_UpdateMode: 0 - m_ApplyRootMotion: 0 - m_LinearVelocityBlending: 0 - m_WarningMessage: - m_HasTransformHierarchy: 1 - m_AllowConstantClipSamplingOptimization: 1 + m_IsActive: 1 --- !u!4 &386695297 Transform: m_ObjectHideFlags: 0 @@ -742,7 +724,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 0 + m_IsActive: 1 --- !u!4 &401185751 Transform: m_ObjectHideFlags: 0 @@ -940,6 +922,47 @@ MeshFilter: m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 528715328} m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0} +--- !u!1 &563719736 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 5 + m_Component: + - component: {fileID: 563719737} + - component: {fileID: 563719738} + m_Layer: 11 + m_Name: KinectVelocityBuffer + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &563719737 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 563719736} + 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: 1848145250} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &563719738 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 563719736} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: afa75a2a1fe8aff4ab1d6418df9d62dd, type: 3} + m_Name: + m_EditorClassIdentifier: + bufferName: KinectVelocityBuffer --- !u!1 &569878373 GameObject: m_ObjectHideFlags: 0 @@ -1349,6 +1372,47 @@ MonoBehaviour: material: {fileID: 2100000, guid: 0858735f439783448b9cc855a56a9e94, type: 2} shader: {fileID: 7200000, guid: 226ca53b2a6b1f34cb8e462337683d07, type: 3} references: [] +--- !u!1 &810572921 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 5 + m_Component: + - component: {fileID: 810572922} + - component: {fileID: 810572923} + m_Layer: 11 + m_Name: KinectPositionBuffer + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &810572922 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 810572921} + 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: 1848145250} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &810572923 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 810572921} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: afa75a2a1fe8aff4ab1d6418df9d62dd, type: 3} + m_Name: + m_EditorClassIdentifier: + bufferName: KinectPositionBuffer --- !u!1 &850228140 GameObject: m_ObjectHideFlags: 0 @@ -1879,7 +1943,9 @@ Transform: 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_Children: + - {fileID: 810572922} + - {fileID: 563719737} m_Father: {fileID: 386695297} m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -1894,6 +1960,9 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 639d7a6f2452c7d4cab5ffcb304b1d8c, type: 3} m_Name: m_EditorClassIdentifier: + kinectBuffers: + - {fileID: 810572923} + - {fileID: 563719738} updateShader: {fileID: 7200000, guid: 514ebfeae1aec6342b486c73b1fbfa32, type: 3} clearShader: {fileID: 7200000, guid: 5a8d2c045ee23f743a54f85301ca1c0b, type: 3} flipX: 1 @@ -1901,13 +1970,13 @@ MonoBehaviour: clipMax: {x: 0.71, y: 0.45, z: 1.63} fluidSimulation: {fileID: 774429923} kinectAmount: 4 + renderTextures: + - {fileID: 8400000, guid: da32e5550d217674aa980199f6a84db3, type: 2} + - {fileID: 8400000, guid: 3d63e39cdb1f2e5419672e7560e22145, type: 2} debug: 1 colorize: 1 debugMaterial: {fileID: 2100000, guid: 95b4d9b25b7a7e3449627228b10d9009, type: 2} debugInfo: - renderTextures: - - {fileID: 8400000, guid: da32e5550d217674aa980199f6a84db3, type: 2} - - {fileID: 8400000, guid: 3d63e39cdb1f2e5419672e7560e22145, type: 2} --- !u!1 &1924148040 GameObject: m_ObjectHideFlags: 0 diff --git a/Unity_2018_Frozen/Assets/KinectOpticalFlow/KinectOpticalFlow.cs b/Unity_2018_Frozen/Assets/KinectOpticalFlow/KinectOpticalFlow.cs index 82c8afb..b4076a0 100644 --- a/Unity_2018_Frozen/Assets/KinectOpticalFlow/KinectOpticalFlow.cs +++ b/Unity_2018_Frozen/Assets/KinectOpticalFlow/KinectOpticalFlow.cs @@ -11,9 +11,10 @@ namespace UltraCombos const int POSITION = 0; const int VELOCITY = 1; - List kinectBuffers = new List(); - public ComputeBuffer PositionBuffer { get { return kinectBuffers[POSITION]; } } - public ComputeBuffer VelocityBuffer { get { return kinectBuffers[VELOCITY]; } } + [SerializeField] + List kinectBuffers = new List(); + public ComputeBuffer PositionBuffer { get { return kinectBuffers[POSITION].obj; } } + public ComputeBuffer VelocityBuffer { get { return kinectBuffers[VELOCITY].obj; } } [SerializeField] ComputeShader updateShader; @@ -34,6 +35,7 @@ namespace UltraCombos int grid_width, grid_height, grid_depth; [Range(0, 5)] public float kinectAmount = 0; + public List renderTextures; [SerializeField, Header("Debug")] bool debug = false; @@ -44,17 +46,14 @@ namespace UltraCombos [SerializeField] string debugInfo; - public List renderTextures; + ComputeBuffer home_buffer; + int home_count; + private void Start() { - List spout_names = new List() { "Position", "Velocity" }; - - foreach (var name in spout_names) - { - var buf = new ComputeBuffer(width * height, sizeof(float) * 4); - kinectBuffers.Add(buf); - } + foreach (var buf in kinectBuffers) + buf.Allocate(width * height, sizeof(float) * 4); { grid_width = fluidSimulation.m_width; @@ -63,32 +62,14 @@ namespace UltraCombos int grid_count = grid_width * grid_height * grid_depth; kinect_grid_buffer = new ComputeBuffer(grid_count, sizeof(float) * 4); } - } - bool is_initialized = false; - - private void FixedUpdate() - { - if (is_initialized == false) { - is_initialized = true; - - List spout_names = new List() { "Position", "Velocity" }; - int count = 0; - foreach (var name in spout_names) - { - updateShader.SetBuffer(0, string.Format("{0}Buffer", name), kinectBuffers[count]); - debugMaterial.SetBuffer(string.Format("{0}Buffer", name), kinectBuffers[count]); - - count++; - } - - { - updateShader.SetBuffer(0, "KinectGridBuffer", kinect_grid_buffer); - clearShader.SetBuffer(0, "KinectGridBuffer", kinect_grid_buffer); - } + home_buffer = new ComputeBuffer(512 * 424, sizeof(float) * 4, ComputeBufferType.Append); } - + } + + private void FixedUpdate() + { if (args_buffer == null) { #if false @@ -102,14 +83,6 @@ namespace UltraCombos #endif } - // reset kinect buffer counter - { - foreach (var buf in kinectBuffers) - { - buf.SetCounterValue(0); - } - } - // update { var m = transform.localToWorldMatrix; @@ -129,6 +102,9 @@ namespace UltraCombos updateShader.SetTexture(0, "PositionTexture", renderTextures[POSITION]); updateShader.SetTexture(0, "VelocityTexture", renderTextures[VELOCITY]); + foreach (var buf in kinectBuffers) + updateShader.SetBuffer(0, buf.bufferName, buf.obj); + updateShader.SetBuffer(0, "KinectGridBuffer", kinect_grid_buffer); updateShader.DispatchIndirect(0, args_buffer); } @@ -156,6 +132,7 @@ namespace UltraCombos clearShader.SetFloat("temperatureAmount", fluidSimulation.m_temperatureAmount); clearShader.SetFloat("densityAmount", fluidSimulation.m_densityAmount); clearShader.SetFloat("kinectAmount", kinectAmount); + clearShader.SetBuffer(0, "KinectGridBuffer", kinect_grid_buffer); clearShader.DispatchIndirect(0, clear_grid_buffer_args_buffer); } } @@ -180,13 +157,13 @@ namespace UltraCombos debugMaterial.SetPass(0); debugMaterial.SetInt("colorize", colorize ? 1 : 0); + foreach (var buf in kinectBuffers) + debugMaterial.SetBuffer(buf.bufferName, buf.obj); Graphics.DrawProcedural(MeshTopology.Points, PositionBuffer.count); } private void OnDestroy() { - foreach (var buf in kinectBuffers) - buf.Release(); clear_grid_buffer_args_buffer.Release(); args_buffer.Release(); KinectGridBuffer.Release(); diff --git a/Unity_2018_Frozen/Assets/KinectOpticalFlow/KinectOpticalFlowDebugShader.shader b/Unity_2018_Frozen/Assets/KinectOpticalFlow/KinectOpticalFlowDebugShader.shader index 61deb0e..26d031b 100644 --- a/Unity_2018_Frozen/Assets/KinectOpticalFlow/KinectOpticalFlowDebugShader.shader +++ b/Unity_2018_Frozen/Assets/KinectOpticalFlow/KinectOpticalFlowDebugShader.shader @@ -20,8 +20,8 @@ #include "UnityCG.cginc" #ifdef SHADER_API_D3D11 - StructuredBuffer PositionBuffer; - StructuredBuffer VelocityBuffer; + StructuredBuffer KinectPositionBuffer; + StructuredBuffer KinectVelocityBuffer; #endif struct appdata @@ -58,8 +58,8 @@ void geom(point v2g input[1], inout LineStream OutputStream) { #ifdef SHADER_API_D3D11 - float4 position = PositionBuffer[input[0].id]; - float4 velocity = VelocityBuffer[input[0].id]; + float4 position = KinectPositionBuffer[input[0].id]; + float4 velocity = KinectVelocityBuffer[input[0].id]; #else float4 position = float4(0, 0, 0, 1); float4 velocity = float4(0, 0, 0, 0); diff --git a/Unity_2018_Frozen/Assets/KinectOpticalFlow/KinectUpdateShader.compute b/Unity_2018_Frozen/Assets/KinectOpticalFlow/KinectUpdateShader.compute index af25cd0..6349ecc 100644 --- a/Unity_2018_Frozen/Assets/KinectOpticalFlow/KinectUpdateShader.compute +++ b/Unity_2018_Frozen/Assets/KinectOpticalFlow/KinectUpdateShader.compute @@ -1,11 +1,9 @@ // Each #kernel tells which function to compile; you can have many kernels #pragma kernel CSMain -RWStructuredBuffer PositionBuffer; -RWStructuredBuffer VelocityBuffer; +RWStructuredBuffer KinectPositionBuffer; +RWStructuredBuffer KinectVelocityBuffer; RWStructuredBuffer KinectGridBuffer; -//RWStructuredBuffer FullPositionBuffer; -//RWStructuredBuffer FullVelocityBuffer; Texture2D PositionTexture; Texture2D VelocityTexture; @@ -60,8 +58,8 @@ void CSMain (uint3 id : SV_DispatchThreadID) ///VelocityBuffer.Append(float4(vel.xyz, 0)); } - PositionBuffer[id.x] = float4(pos.xyz, grid_index); - VelocityBuffer[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); //FullPositionBuffer[id.x] = float4(pos.xyz, grid_index); //FullVelocityBuffer[id.x] = float4((pos_mag == 0.0f) ? float3(0, 0, 0) : vel.xyz, 0);