diff --git a/Assets/Scenes/Bloody Mary.unity b/Assets/Scenes/Bloody Mary.unity index 86a1649..5b9001d 100644 --- a/Assets/Scenes/Bloody Mary.unity +++ b/Assets/Scenes/Bloody Mary.unity @@ -696,6 +696,7 @@ GameObject: m_Component: - component: {fileID: 1068354138} - component: {fileID: 1068354137} + - component: {fileID: 1068354139} m_Layer: 0 m_Name: Blood m_TagString: Untagged @@ -722,7 +723,11 @@ MonoBehaviour: size: 0.22 activeParticles: 0 score: 0 - CleanRadius: 2 + squeakVolume: 0 + squeakPlayer: {fileID: 1199570139} + splatterVolume: 0 + splatterPlayer: {fileID: 1068354139} + CleanRadius: 0 bufferLookPointer: 0 --- !u!4 &1068354138 Transform: @@ -739,6 +744,102 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!82 &1068354139 +AudioSource: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1068354136} + m_Enabled: 1 + serializedVersion: 4 + OutputAudioMixerGroup: {fileID: 0} + m_audioClip: {fileID: 8300000, guid: b27a091fa88210edeb0c964e7072d56e, type: 3} + m_PlayOnAwake: 1 + m_Volume: 1 + m_Pitch: 1 + Loop: 1 + Mute: 0 + Spatialize: 0 + SpatializePostEffects: 0 + Priority: 128 + DopplerLevel: 1 + MinDistance: 1 + MaxDistance: 500 + Pan2D: 0 + rolloffMode: 0 + BypassEffects: 0 + BypassListenerEffects: 0 + BypassReverbZones: 0 + rolloffCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 1 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + panLevelCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + spreadCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + reverbZoneMixCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 --- !u!1 &1199570134 GameObject: m_ObjectHideFlags: 0 @@ -751,6 +852,7 @@ GameObject: - component: {fileID: 1199570136} - component: {fileID: 1199570135} - component: {fileID: 1199570138} + - component: {fileID: 1199570139} m_Layer: 0 m_Name: Main Camera m_TagString: MainCamera @@ -876,6 +978,102 @@ MonoBehaviour: mipBias: 0 varianceClampScale: 0.9 contrastAdaptiveSharpening: 0 +--- !u!82 &1199570139 +AudioSource: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1199570134} + m_Enabled: 1 + serializedVersion: 4 + OutputAudioMixerGroup: {fileID: 0} + m_audioClip: {fileID: 8300000, guid: 06f8108a8e1a3b9aeb66dff63dd1e112, type: 3} + m_PlayOnAwake: 1 + m_Volume: 1 + m_Pitch: 1 + Loop: 1 + Mute: 0 + Spatialize: 0 + SpatializePostEffects: 0 + Priority: 128 + DopplerLevel: 1 + MinDistance: 1 + MaxDistance: 500 + Pan2D: 0 + rolloffMode: 0 + BypassEffects: 0 + BypassListenerEffects: 0 + BypassReverbZones: 0 + rolloffCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + - serializedVersion: 3 + time: 1 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + panLevelCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + spreadCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 0 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + reverbZoneMixCustomCurve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: 0 + value: 1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0.33333334 + outWeight: 0.33333334 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 --- !u!1 &1311093279 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/BloodComputeShader.cs b/Assets/Scripts/BloodComputeShader.cs index 8b7881d..752c1f4 100644 --- a/Assets/Scripts/BloodComputeShader.cs +++ b/Assets/Scripts/BloodComputeShader.cs @@ -9,6 +9,7 @@ public struct Droplet public Vector3 position; public Vector3 velocity; public uint enabled; + public uint airborne; } public class BloodComputeShader : MonoBehaviour @@ -23,6 +24,12 @@ public class BloodComputeShader : MonoBehaviour public int activeParticles = 0; public int score = 0; + public float squeakVolume = 0.0f; + public AudioSource squeakPlayer; + + public float splatterVolume = 0.0f; + public AudioSource splatterPlayer; + ComputeBuffer particleBuffer; ComputeBuffer positionBuffer; ComputeBuffer numParticlesConsumedBuffer; @@ -59,7 +66,7 @@ public class BloodComputeShader : MonoBehaviour for (int i = 0; i < numParticles; i++) { - particles[i] = new Droplet() { position = Vector3.zero, velocity = Vector3.zero, enabled = 0 }; + particles[i] = new Droplet() { position = Vector3.zero, velocity = Vector3.zero, enabled = 0, airborne = 0 }; } @@ -83,8 +90,8 @@ public class BloodComputeShader : MonoBehaviour argsBuffer = new ComputeBuffer(1, 5 * sizeof(uint), ComputeBufferType.IndirectArguments); argsBuffer.SetData(args); - ComputeHelper.CreateStructuredBuffer(ref numParticlesConsumedBuffer, 1); - numParticlesConsumedBuffer.SetData(new uint[] { 0 }); + ComputeHelper.CreateStructuredBuffer(ref numParticlesConsumedBuffer, 2); + numParticlesConsumedBuffer.SetData(new uint[] { 0, 0 }); bloodCompute.SetBuffer(UpdateDustKernel, "numParticlesConsumed", numParticlesConsumedBuffer); // Initialize with empty data @@ -123,30 +130,65 @@ public class BloodComputeShader : MonoBehaviour return; } + bool putBuffer = false; + uint[] bufferData = new uint[] {0,0}; + if (readbackRequest.done) { - uint data = readbackRequest.GetData()[0]; + bufferData[0] = readbackRequest.GetData()[0]; + bufferData[1] = readbackRequest.GetData()[1]; - if (data > 0) + // Blood cleaned + if (bufferData[0] > 0) { + // Debug.Log("Cleaned " + bufferData[0]); - Debug.Log("Cleaned " + data); + activeParticles -= (int)bufferData[0]; - activeParticles -= (int)data; + score += (int)bufferData[0]; - score += (int)data; + squeakVolume += 0.1f; // Reset counter - numParticlesConsumedBuffer.SetData(new uint[] { 0 }); - bloodCompute.SetBuffer(UpdateDustKernel, "numParticlesConsumed", numParticlesConsumedBuffer); + putBuffer = true; + bufferData[0] = 0; } + + // Blood hitting the floor + if (bufferData[1] > 0) { + splatterVolume += bufferData[1]/25.0f; + + // Debug.Log("splat x" + bufferData[1]); + + putBuffer = true; + bufferData[1] = 0; + } + RequestAsyncReadback(); } + if (putBuffer) { + numParticlesConsumedBuffer.SetData(bufferData); + bloodCompute.SetBuffer(UpdateDustKernel, "numParticlesConsumed", numParticlesConsumedBuffer); + + } + ComputeHelper.Dispatch(bloodCompute, numParticles, 1, 1, UpdateDustKernel); Graphics.DrawMeshInstancedIndirect(mesh, 0, instancedMaterial, new Bounds(Vector3.zero, Vector3.one * 1000), argsBuffer); + + splatterVolume *= 0.9f; + splatterPlayer.volume = splatterVolume; + + squeakPlayer.volume = squeakVolume; + squeakVolume *= 0.8f; + + if (splatterVolume < 0.001) + splatterVolume = 0; + + if (squeakVolume < 0.001) + squeakVolume = 0; } void FixedUpdate() @@ -175,6 +217,7 @@ public class BloodComputeShader : MonoBehaviour Droplet[] particles = new Droplet[numParticles]; var as_Particles = freeBloodReadRequest.GetData().ToArray(); + int length = as_Particles.Length; // particleBuffer.GetData(particles); uint[] particleIndeces = new uint[amount]; @@ -182,7 +225,7 @@ public class BloodComputeShader : MonoBehaviour // oof while (i < numParticles) { - if (as_Particles[i % numParticles].enabled == 0) + if (as_Particles[i % (length - 1)].enabled == 0) { // Found unused particle particleIndeces[found] = i; found++; diff --git a/Assets/Scripts/ComputeShaders/BloodCompute.compute b/Assets/Scripts/ComputeShaders/BloodCompute.compute index 12590bb..b6222f5 100644 --- a/Assets/Scripts/ComputeShaders/BloodCompute.compute +++ b/Assets/Scripts/ComputeShaders/BloodCompute.compute @@ -5,6 +5,7 @@ struct Particle { float3 position; float3 velocity; uint enabled; + uint airborne; }; RWStructuredBuffer positions; @@ -86,7 +87,9 @@ void InitDust (uint3 id : SV_DispatchThreadID) particles[i].velocity = nvel; particles[i].position = particleInitPos; + particles[i].position.z = 1; particles[i].enabled = 1; + particles[i].airborne = 1; positions[i] = float4(particles[i].position, 1 * size); // particles[i].position = positions[i].xyz; @@ -109,6 +112,12 @@ void UpdateDust (uint3 id : SV_DispatchThreadID) } else { particles[i].velocity -= particles[i].velocity * deltaTime * 15; + if (particles[i].airborne == 1) { + particles[i].airborne = 0; + + // Increase splattered particles + InterlockedAdd(numParticlesConsumed[1],1); + } float3 offset1 = mop1Pos - pos; offset1.z = 0; @@ -122,6 +131,7 @@ void UpdateDust (uint3 id : SV_DispatchThreadID) if (dist < CleanRadius) { particles[i].enabled = 0; + // Increase cleaned particles InterlockedAdd(numParticlesConsumed[0],1); } } diff --git a/Assets/Sounds/temp_blod_smol.wav b/Assets/Sounds/temp_blod_smol.wav new file mode 100644 index 0000000..c74dfdc Binary files /dev/null and b/Assets/Sounds/temp_blod_smol.wav differ diff --git a/Assets/Sounds/temp_blod_smol.wav.meta b/Assets/Sounds/temp_blod_smol.wav.meta new file mode 100644 index 0000000..65ae831 --- /dev/null +++ b/Assets/Sounds/temp_blod_smol.wav.meta @@ -0,0 +1,23 @@ +fileFormatVersion: 2 +guid: b27a091fa88210edeb0c964e7072d56e +AudioImporter: + externalObjects: {} + serializedVersion: 7 + defaultSettings: + serializedVersion: 2 + loadType: 0 + sampleRateSetting: 0 + sampleRateOverride: 44100 + compressionFormat: 1 + quality: 1 + conversionMode: 0 + preloadAudioData: 0 + platformSettingOverrides: {} + forceToMono: 0 + normalize: 1 + loadInBackground: 0 + ambisonic: 0 + 3D: 1 + userData: + assetBundleName: + assetBundleVariant: