forked from przemyslawzaworski/Unity3D-CG-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParticleCollision.cs
More file actions
35 lines (31 loc) · 866 Bytes
/
ParticleCollision.cs
File metadata and controls
35 lines (31 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using UnityEngine;
public class ParticleCollision : MonoBehaviour
{
public ComputeShader shader;
public Material material;
public int resolution = 1024;
public int amount = 200;
private ComputeBuffer buffer;
private int counter = 0;
void Start ()
{
buffer = new ComputeBuffer(resolution*resolution, sizeof(float)*4, ComputeBufferType.Default);
shader.SetBuffer(0, "buffer", buffer);
material.SetBuffer("buffer", buffer);
material.SetInt("amount",amount);
shader.SetInt("amount",amount);
}
void Update ()
{
material.SetInt("resolution",resolution);
shader.SetInt("iFrame",counter);
shader.SetFloat("iTimeDelta",Time.deltaTime);
shader.SetInt("resolution",resolution);
shader.Dispatch(0, resolution / 16, resolution / 16, 1);
counter++;
}
void OnDestroy()
{
buffer.Release();
}
}