Bloodmanager now has seperate values for blood mopped for both players
This commit is contained in:
parent
54b6c3115c
commit
a70473e7e8
|
@ -28,6 +28,9 @@ public class BloodComputeShader : MonoBehaviour
|
||||||
public int activeParticles = 0;
|
public int activeParticles = 0;
|
||||||
public long score = 0;
|
public long score = 0;
|
||||||
|
|
||||||
|
public int mop1Clean = 0;
|
||||||
|
public int mop2Clean = 0;
|
||||||
|
|
||||||
public float squeakVolume = 0.0f;
|
public float squeakVolume = 0.0f;
|
||||||
public AudioSource squeakPlayer;
|
public AudioSource squeakPlayer;
|
||||||
|
|
||||||
|
@ -104,8 +107,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, 2);
|
ComputeHelper.CreateStructuredBuffer<uint>(ref numParticlesConsumedBuffer, 3);
|
||||||
numParticlesConsumedBuffer.SetData(new uint[] { 0, 0 });
|
numParticlesConsumedBuffer.SetData(new uint[] { 0, 0, 0 });
|
||||||
bloodCompute.SetBuffer(UpdateDustKernel, "numParticlesConsumed", numParticlesConsumedBuffer);
|
bloodCompute.SetBuffer(UpdateDustKernel, "numParticlesConsumed", numParticlesConsumedBuffer);
|
||||||
|
|
||||||
// Initialize with empty data
|
// Initialize with empty data
|
||||||
|
@ -145,47 +148,55 @@ public class BloodComputeShader : MonoBehaviour
|
||||||
}
|
}
|
||||||
|
|
||||||
bool putBuffer = false;
|
bool putBuffer = false;
|
||||||
uint[] bufferData = new uint[] {0,0};
|
uint[] bufferData = {0,0,0};
|
||||||
|
|
||||||
if (readbackRequest.done)
|
if (readbackRequest.done)
|
||||||
{
|
{
|
||||||
bufferData[0] = readbackRequest.GetData<uint>()[0];
|
bufferData = readbackRequest.GetData<uint>().ToArray();
|
||||||
bufferData[1] = readbackRequest.GetData<uint>()[1];
|
|
||||||
|
|
||||||
// Blood cleaned
|
// Blood cleaned
|
||||||
if (bufferData[0] > 0)
|
if (bufferData[0] > 0 || bufferData[1] > 0)
|
||||||
{
|
{
|
||||||
// Debug.Log("Cleaned " + bufferData[0]);
|
// Debug.Log("Cleaned " + bufferData[0]);
|
||||||
|
|
||||||
activeParticles -= (int)bufferData[0];
|
uint totalBloodCleaned = bufferData[0] + bufferData[1];
|
||||||
|
|
||||||
|
activeParticles -= (int)totalBloodCleaned;
|
||||||
|
|
||||||
score += bufferData[0];
|
score += bufferData[0];
|
||||||
|
|
||||||
float mappedRumble = Convert.ToSingle(bufferData[0]).Remap(0, RumbleAmount, 0, 0.1f);
|
// this doesnt exist but ok
|
||||||
|
// float mappedRumble = Convert.ToSingle(bufferData[0]).Remap(0, RumbleAmount, 0, 0.1f);
|
||||||
//RumbleManager.StartRumble(-1, 0, mappedRumble, 0.1f);
|
//RumbleManager.StartRumble(-1, 0, mappedRumble, 0.1f);
|
||||||
|
|
||||||
squeakVolume += 0.1f;
|
squeakVolume += 0.1f;
|
||||||
|
|
||||||
|
mop1Clean += (int)bufferData[0];
|
||||||
|
mop2Clean += (int)bufferData[1];
|
||||||
|
|
||||||
// Reset counter
|
// Reset counter
|
||||||
putBuffer = true;
|
putBuffer = true;
|
||||||
bufferData[0] = 0;
|
bufferData[0] = 0;
|
||||||
|
bufferData[1] = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Blood hitting the floor
|
// Blood hitting the floor
|
||||||
if (bufferData[1] > 0) {
|
if (bufferData[1] > 0)
|
||||||
|
{
|
||||||
splatterVolume += bufferData[1] / 25.0f;
|
splatterVolume += bufferData[1] / 25.0f;
|
||||||
|
|
||||||
// Debug.Log("splat x" + bufferData[1]);
|
// Debug.Log("splat x" + bufferData[1]);
|
||||||
|
|
||||||
putBuffer = true;
|
putBuffer = true;
|
||||||
bufferData[1] = 0;
|
bufferData[2] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
RequestAsyncReadback();
|
RequestAsyncReadback();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (putBuffer) {
|
if (putBuffer)
|
||||||
|
{
|
||||||
numParticlesConsumedBuffer.SetData(bufferData);
|
numParticlesConsumedBuffer.SetData(bufferData);
|
||||||
bloodCompute.SetBuffer(UpdateDustKernel, "numParticlesConsumed", numParticlesConsumedBuffer);
|
bloodCompute.SetBuffer(UpdateDustKernel, "numParticlesConsumed", numParticlesConsumedBuffer);
|
||||||
|
|
||||||
|
@ -206,6 +217,9 @@ public class BloodComputeShader : MonoBehaviour
|
||||||
|
|
||||||
if (squeakVolume < 0.001)
|
if (squeakVolume < 0.001)
|
||||||
squeakVolume = 0;
|
squeakVolume = 0;
|
||||||
|
|
||||||
|
mop1Clean = (int)(mop1Clean * 0.8f);
|
||||||
|
mop2Clean = (int)(mop2Clean * 0.8f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FixedUpdate()
|
void FixedUpdate()
|
||||||
|
|
|
@ -28,8 +28,7 @@ float gravity;
|
||||||
float particleVel;
|
float particleVel;
|
||||||
|
|
||||||
// Hash function www.cs.ubc.ca/~rbridson/docs/schechter-sca08-turbulence.pdf
|
// Hash function www.cs.ubc.ca/~rbridson/docs/schechter-sca08-turbulence.pdf
|
||||||
uint hash(uint state)
|
uint hash(uint state) {
|
||||||
{
|
|
||||||
state ^= 2747636419u;
|
state ^= 2747636419u;
|
||||||
state *= 2654435769u;
|
state *= 2654435769u;
|
||||||
state ^= state >> 16;
|
state ^= state >> 16;
|
||||||
|
@ -39,22 +38,18 @@ uint hash(uint state)
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
float scaleToRange01(uint state)
|
float scaleToRange01(uint state) { return state / 4294967295.0; }
|
||||||
{
|
|
||||||
return state / 4294967295.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
[numthreads(64, 1, 1)] void InitDust(uint3 id
|
||||||
[numthreads(64,1,1)]
|
: SV_DispatchThreadID) {
|
||||||
void InitDust (uint3 id : SV_DispatchThreadID)
|
|
||||||
{
|
|
||||||
if (id.x > particlesToInitialize) {
|
if (id.x > particlesToInitialize) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint i = freeParticles[id.x];
|
uint i = freeParticles[id.x];
|
||||||
|
|
||||||
// if (particles[id.x].enabled != 0 || numParticlesInitialized[0] >= numParticles ) {
|
// if (particles[id.x].enabled != 0 || numParticlesInitialized[0] >=
|
||||||
|
// numParticles ) {
|
||||||
while (i <= numParticles) {
|
while (i <= numParticles) {
|
||||||
if (i == numParticles) {
|
if (i == numParticles) {
|
||||||
return;
|
return;
|
||||||
|
@ -96,9 +91,8 @@ void InitDust (uint3 id : SV_DispatchThreadID)
|
||||||
// InterlockedAdd(numParticlesInitialized[0],1);
|
// InterlockedAdd(numParticlesInitialized[0],1);
|
||||||
}
|
}
|
||||||
|
|
||||||
[numthreads(64,1,1)]
|
[numthreads(64, 1, 1)] void UpdateDust(uint3 id
|
||||||
void UpdateDust (uint3 id : SV_DispatchThreadID)
|
: SV_DispatchThreadID) {
|
||||||
{
|
|
||||||
uint i = id.x;
|
uint i = id.x;
|
||||||
|
|
||||||
if (particles[i].enabled == 0) {
|
if (particles[i].enabled == 0) {
|
||||||
|
@ -116,7 +110,7 @@ void UpdateDust (uint3 id : SV_DispatchThreadID)
|
||||||
particles[i].airborne = 0;
|
particles[i].airborne = 0;
|
||||||
|
|
||||||
// Increase splattered particles
|
// Increase splattered particles
|
||||||
InterlockedAdd(numParticlesConsumed[1],1);
|
InterlockedAdd(numParticlesConsumed[2], 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
float3 offset1 = mop1Pos - pos;
|
float3 offset1 = mop1Pos - pos;
|
||||||
|
@ -132,11 +126,14 @@ void UpdateDust (uint3 id : SV_DispatchThreadID)
|
||||||
if (dist < CleanRadius) {
|
if (dist < CleanRadius) {
|
||||||
particles[i].enabled = 0;
|
particles[i].enabled = 0;
|
||||||
// Increase cleaned particles
|
// Increase cleaned particles
|
||||||
|
if (dist1 < dist2) { // Mop1 is the one that cleaned
|
||||||
InterlockedAdd(numParticlesConsumed[0], 1);
|
InterlockedAdd(numParticlesConsumed[0], 1);
|
||||||
|
} else {
|
||||||
|
InterlockedAdd(numParticlesConsumed[1], 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
particles[i].position += particles[i].velocity * deltaTime;
|
particles[i].position += particles[i].velocity * deltaTime;
|
||||||
positions[i] = float4(particles[i].position, particles[i].enabled * size);
|
positions[i] = float4(particles[i].position, particles[i].enabled * size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue