Skip to content

Commit 6c6a06a

Browse files
committed
Begin to impl GPU version.
1 parent 82b3b1c commit 6c6a06a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1498
-30
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[Bb]uild/
55
[Pp]rojectSettings/
66
Papers/
7+
.vs/
78

89
# Autogenerated VS/MD solution and project files
910
*.csproj

Diff for: Assets/Packages/Verlet/Demo.meta

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Assets/Packages/Verlet/Demo/CPU.meta

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Assets/Packages/Verlet/DemoBase.cs renamed to Assets/Packages/Verlet/Demo/CPU/CPUDemoBase.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace Verlet.Demo
88
{
99

10-
public class DemoBase : MonoBehaviour {
10+
public class CPUDemoBase : MonoBehaviour {
1111

1212
const string SHADER_PATH = "Hidden/Internal-Colored";
1313

@@ -21,12 +21,12 @@ protected virtual void OnRenderObject()
2121
lineMaterial.SetInt("_ZTest", (int)CompareFunction.Always);
2222
}
2323

24-
protected void RenderConnection(List<VParticle> particles, Color color)
24+
protected void RenderConnection(List<Node> particles, Color color)
2525
{
2626
particles.ForEach(p => RenderConnection(p, color));
2727
}
2828

29-
protected void RenderConnection(VParticle p, Color color)
29+
protected void RenderConnection(Node p, Color color)
3030
{
3131
p.Connection.ForEach(e => {
3232
var other = e.Other(p);

Diff for: Assets/Packages/Verlet/ChainDemo.cs renamed to Assets/Packages/Verlet/Demo/CPU/ChainDemo.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace Verlet.Demo
77
{
88

9-
public class ChainDemo : DemoBase {
9+
public class ChainDemo : CPUDemoBase {
1010

1111
[SerializeField] int count = 20;
1212
[SerializeField] int iterations = 12;
@@ -18,14 +18,14 @@ public class ChainDemo : DemoBase {
1818
List<GameObject> debuggers;
1919

2020
VerletSimulator simulator;
21-
List<VParticle> particles;
21+
List<Node> particles;
2222

2323
void Start () {
2424
debuggers = new List<GameObject>();
25-
particles = new List<VParticle>();
25+
particles = new List<Node>();
2626
for(int i = 0; i < count; i++)
2727
{
28-
var p = new VParticle(Vector3.right * i);
28+
var p = new Node(Vector3.right * i);
2929
particles.Add(p);
3030

3131
var sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
@@ -39,7 +39,7 @@ void Start () {
3939
{
4040
var a = particles[i];
4141
var b = particles[i + 1];
42-
var e = new VEdge(a, b);
42+
var e = new Edge(a, b);
4343
a.Connect(e);
4444
b.Connect(e);
4545
}

Diff for: Assets/Packages/Verlet/ClothDemo.cs renamed to Assets/Packages/Verlet/Demo/CPU/ClothDemo.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace Verlet.Demo
77
{
88

9-
public class ClothDemo : DemoBase {
9+
public class ClothDemo : CPUDemoBase {
1010

1111
[SerializeField] int count = 20;
1212
[SerializeField] int iterations = 12;
@@ -18,19 +18,19 @@ public class ClothDemo : DemoBase {
1818
List<GameObject> debuggers;
1919

2020
VerletSimulator simulator;
21-
List<VParticle> particles;
21+
List<Node> particles;
2222

2323
void Start () {
2424
debuggers = new List<GameObject>();
25-
particles = new List<VParticle>();
25+
particles = new List<Node>();
2626

2727
var offset = -count * 0.5f;
2828

2929
for(int y = 0; y < count; y++)
3030
{
3131
for(int x = 0; x < count; x++)
3232
{
33-
var p = new VParticle(y * Vector3.forward + (Vector3.right * (x - offset)));
33+
var p = new Node(y * Vector3.forward + (Vector3.right * (x - offset)));
3434
particles.Add(p);
3535

3636
var sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
@@ -50,11 +50,11 @@ void Start () {
5050
if(x != count - 1)
5151
{
5252
var right = particles[index + 1];
53-
var re = new VEdge(c, right);
53+
var re = new Edge(c, right);
5454
c.Connect(re); right.Connect(re);
5555
}
5656
var down = particles[index + count];
57-
var de = new VEdge(c, down);
57+
var de = new Edge(c, down);
5858
c.Connect(de); down.Connect(de);
5959
}
6060
} else
@@ -64,7 +64,7 @@ void Start () {
6464
var index = y * count + x;
6565
var c = particles[index];
6666
var right = particles[index + 1];
67-
var re = new VEdge(c, right);
67+
var re = new Edge(c, right);
6868
c.Connect(re); right.Connect(re);
6969
}
7070
}

Diff for: Assets/Packages/Verlet/Demo/GPU.meta

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Assets/Packages/Verlet/Demo/GPU/GPUDemo.cs

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
namespace Verlet.Demo
6+
{
7+
8+
public class GPUDemo : MonoBehaviour {
9+
10+
[SerializeField] protected ComputeShader compute;
11+
12+
protected ComputeBuffer nodes, edges;
13+
14+
void Start () {
15+
}
16+
17+
void Update () {
18+
}
19+
20+
protected void OnDestroy()
21+
{
22+
ReleaseBuffer(ref nodes);
23+
ReleaseBuffer(ref edges);
24+
}
25+
26+
protected void ReleaseBuffer(ref ComputeBuffer buf)
27+
{
28+
if(buf != null)
29+
{
30+
buf.Release();
31+
}
32+
buf = null;
33+
}
34+
35+
}
36+
37+
}
38+
39+

Diff for: Assets/Packages/Verlet/Demo/GPU/GPUDemo.cs.meta

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)