Added sound to blood and cleaning
This commit is contained in:
parent
ca3de70787
commit
825761ea81
|
@ -696,6 +696,7 @@ GameObject:
|
||||||
m_Component:
|
m_Component:
|
||||||
- component: {fileID: 1068354138}
|
- component: {fileID: 1068354138}
|
||||||
- component: {fileID: 1068354137}
|
- component: {fileID: 1068354137}
|
||||||
|
- component: {fileID: 1068354139}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: Blood
|
m_Name: Blood
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
|
@ -722,7 +723,11 @@ MonoBehaviour:
|
||||||
size: 0.22
|
size: 0.22
|
||||||
activeParticles: 0
|
activeParticles: 0
|
||||||
score: 0
|
score: 0
|
||||||
CleanRadius: 2
|
squeakVolume: 0
|
||||||
|
squeakPlayer: {fileID: 1199570139}
|
||||||
|
splatterVolume: 0
|
||||||
|
splatterPlayer: {fileID: 1068354139}
|
||||||
|
CleanRadius: 0
|
||||||
bufferLookPointer: 0
|
bufferLookPointer: 0
|
||||||
--- !u!4 &1068354138
|
--- !u!4 &1068354138
|
||||||
Transform:
|
Transform:
|
||||||
|
@ -739,6 +744,102 @@ Transform:
|
||||||
m_Children: []
|
m_Children: []
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 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
|
--- !u!1 &1199570134
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -751,6 +852,7 @@ GameObject:
|
||||||
- component: {fileID: 1199570136}
|
- component: {fileID: 1199570136}
|
||||||
- component: {fileID: 1199570135}
|
- component: {fileID: 1199570135}
|
||||||
- component: {fileID: 1199570138}
|
- component: {fileID: 1199570138}
|
||||||
|
- component: {fileID: 1199570139}
|
||||||
m_Layer: 0
|
m_Layer: 0
|
||||||
m_Name: Main Camera
|
m_Name: Main Camera
|
||||||
m_TagString: MainCamera
|
m_TagString: MainCamera
|
||||||
|
@ -876,6 +978,102 @@ MonoBehaviour:
|
||||||
mipBias: 0
|
mipBias: 0
|
||||||
varianceClampScale: 0.9
|
varianceClampScale: 0.9
|
||||||
contrastAdaptiveSharpening: 0
|
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
|
--- !u!1 &1311093279
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|
|
@ -9,6 +9,7 @@ public struct Droplet
|
||||||
public Vector3 position;
|
public Vector3 position;
|
||||||
public Vector3 velocity;
|
public Vector3 velocity;
|
||||||
public uint enabled;
|
public uint enabled;
|
||||||
|
public uint airborne;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BloodComputeShader : MonoBehaviour
|
public class BloodComputeShader : MonoBehaviour
|
||||||
|
@ -23,6 +24,12 @@ public class BloodComputeShader : MonoBehaviour
|
||||||
public int activeParticles = 0;
|
public int activeParticles = 0;
|
||||||
public int score = 0;
|
public int score = 0;
|
||||||
|
|
||||||
|
public float squeakVolume = 0.0f;
|
||||||
|
public AudioSource squeakPlayer;
|
||||||
|
|
||||||
|
public float splatterVolume = 0.0f;
|
||||||
|
public AudioSource splatterPlayer;
|
||||||
|
|
||||||
ComputeBuffer particleBuffer;
|
ComputeBuffer particleBuffer;
|
||||||
ComputeBuffer positionBuffer;
|
ComputeBuffer positionBuffer;
|
||||||
ComputeBuffer numParticlesConsumedBuffer;
|
ComputeBuffer numParticlesConsumedBuffer;
|
||||||
|
@ -59,7 +66,7 @@ public class BloodComputeShader : MonoBehaviour
|
||||||
for (int i = 0; i < numParticles; i++)
|
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 = new ComputeBuffer(1, 5 * sizeof(uint), ComputeBufferType.IndirectArguments);
|
||||||
argsBuffer.SetData(args);
|
argsBuffer.SetData(args);
|
||||||
|
|
||||||
ComputeHelper.CreateStructuredBuffer<uint>(ref numParticlesConsumedBuffer, 1);
|
ComputeHelper.CreateStructuredBuffer<uint>(ref numParticlesConsumedBuffer, 2);
|
||||||
numParticlesConsumedBuffer.SetData(new uint[] { 0 });
|
numParticlesConsumedBuffer.SetData(new uint[] { 0, 0 });
|
||||||
bloodCompute.SetBuffer(UpdateDustKernel, "numParticlesConsumed", numParticlesConsumedBuffer);
|
bloodCompute.SetBuffer(UpdateDustKernel, "numParticlesConsumed", numParticlesConsumedBuffer);
|
||||||
|
|
||||||
// Initialize with empty data
|
// Initialize with empty data
|
||||||
|
@ -123,30 +130,65 @@ public class BloodComputeShader : MonoBehaviour
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool putBuffer = false;
|
||||||
|
uint[] bufferData = new uint[] {0,0};
|
||||||
|
|
||||||
if (readbackRequest.done)
|
if (readbackRequest.done)
|
||||||
{
|
{
|
||||||
uint data = readbackRequest.GetData<uint>()[0];
|
bufferData[0] = readbackRequest.GetData<uint>()[0];
|
||||||
|
bufferData[1] = readbackRequest.GetData<uint>()[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
|
// Reset counter
|
||||||
numParticlesConsumedBuffer.SetData(new uint[] { 0 });
|
putBuffer = true;
|
||||||
bloodCompute.SetBuffer(UpdateDustKernel, "numParticlesConsumed", numParticlesConsumedBuffer);
|
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();
|
RequestAsyncReadback();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (putBuffer) {
|
||||||
|
numParticlesConsumedBuffer.SetData(bufferData);
|
||||||
|
bloodCompute.SetBuffer(UpdateDustKernel, "numParticlesConsumed", numParticlesConsumedBuffer);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
ComputeHelper.Dispatch(bloodCompute, numParticles, 1, 1, UpdateDustKernel);
|
ComputeHelper.Dispatch(bloodCompute, numParticles, 1, 1, UpdateDustKernel);
|
||||||
|
|
||||||
Graphics.DrawMeshInstancedIndirect(mesh, 0, instancedMaterial, new Bounds(Vector3.zero, Vector3.one * 1000), argsBuffer);
|
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()
|
void FixedUpdate()
|
||||||
|
@ -175,6 +217,7 @@ public class BloodComputeShader : MonoBehaviour
|
||||||
|
|
||||||
Droplet[] particles = new Droplet[numParticles];
|
Droplet[] particles = new Droplet[numParticles];
|
||||||
var as_Particles = freeBloodReadRequest.GetData<Droplet>().ToArray();
|
var as_Particles = freeBloodReadRequest.GetData<Droplet>().ToArray();
|
||||||
|
int length = as_Particles.Length;
|
||||||
// particleBuffer.GetData(particles);
|
// particleBuffer.GetData(particles);
|
||||||
|
|
||||||
uint[] particleIndeces = new uint[amount];
|
uint[] particleIndeces = new uint[amount];
|
||||||
|
@ -182,7 +225,7 @@ public class BloodComputeShader : MonoBehaviour
|
||||||
// oof
|
// oof
|
||||||
while (i < numParticles)
|
while (i < numParticles)
|
||||||
{
|
{
|
||||||
if (as_Particles[i % numParticles].enabled == 0)
|
if (as_Particles[i % (length - 1)].enabled == 0)
|
||||||
{ // Found unused particle
|
{ // Found unused particle
|
||||||
particleIndeces[found] = i;
|
particleIndeces[found] = i;
|
||||||
found++;
|
found++;
|
||||||
|
|
|
@ -5,6 +5,7 @@ struct Particle {
|
||||||
float3 position;
|
float3 position;
|
||||||
float3 velocity;
|
float3 velocity;
|
||||||
uint enabled;
|
uint enabled;
|
||||||
|
uint airborne;
|
||||||
};
|
};
|
||||||
|
|
||||||
RWStructuredBuffer<float4> positions;
|
RWStructuredBuffer<float4> positions;
|
||||||
|
@ -86,7 +87,9 @@ void InitDust (uint3 id : SV_DispatchThreadID)
|
||||||
particles[i].velocity = nvel;
|
particles[i].velocity = nvel;
|
||||||
|
|
||||||
particles[i].position = particleInitPos;
|
particles[i].position = particleInitPos;
|
||||||
|
particles[i].position.z = 1;
|
||||||
particles[i].enabled = 1;
|
particles[i].enabled = 1;
|
||||||
|
particles[i].airborne = 1;
|
||||||
positions[i] = float4(particles[i].position, 1 * size);
|
positions[i] = float4(particles[i].position, 1 * size);
|
||||||
// particles[i].position = positions[i].xyz;
|
// particles[i].position = positions[i].xyz;
|
||||||
|
|
||||||
|
@ -109,6 +112,12 @@ void UpdateDust (uint3 id : SV_DispatchThreadID)
|
||||||
} else {
|
} else {
|
||||||
particles[i].velocity -= particles[i].velocity * deltaTime * 15;
|
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;
|
float3 offset1 = mop1Pos - pos;
|
||||||
offset1.z = 0;
|
offset1.z = 0;
|
||||||
|
@ -122,6 +131,7 @@ void UpdateDust (uint3 id : SV_DispatchThreadID)
|
||||||
|
|
||||||
if (dist < CleanRadius) {
|
if (dist < CleanRadius) {
|
||||||
particles[i].enabled = 0;
|
particles[i].enabled = 0;
|
||||||
|
// Increase cleaned particles
|
||||||
InterlockedAdd(numParticlesConsumed[0],1);
|
InterlockedAdd(numParticlesConsumed[0],1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
|
@ -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:
|
Loading…
Reference in New Issue