You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
1.9 KiB

4 months ago
#version 450
layout (local_size_x = 32) in;
4 months ago
struct Vertex {
4 months ago
vec3 position;
vec3 color;
vec3 normal;
vec3 velocity;
vec3 prevPosition;
float w;
4 months ago
};
struct Edge {
4 months ago
uint a;
uint b;
float restLength;
};
4 months ago
4 months ago
layout (std430, set = 0, binding = 0) buffer VertexBuffer {
4 months ago
Vertex vertices[];
4 months ago
};
layout (std430, set = 0, binding = 2) buffer EdgeBuffer {
4 months ago
Edge edges[];
};
layout (std140, set = 0, binding = 5) uniform Sizes {
4 months ago
uint vertexCount;
uint faceCount;
};
layout (std140, set = 1, binding = 0) uniform Properties {
vec3 gravity;
float dt;
uint k;
};
4 months ago
struct Partition {
uint offset;
uint size;
4 months ago
};
4 months ago
layout (push_constant, std430) uniform PushConstants {
uint state;
Partition edgePartition;
Partition tetrahedronPartition;
4 months ago
};
void preSolve(uint vID){
4 months ago
vertices[vID].prevPosition = vertices[vID].position;
// vertices[vID].velocity += dt * gravity;
vertices[vID].position += dt * vertices[vID].velocity;
}
void solveEdge(uint eID){
Edge e = edges[eID];
Vertex v1 = vertices[e.a];
Vertex v2 = vertices[e.b];
vec3 diff = v1.position - v2.position;
float currentLength = length(diff);
float alpha = 0.0001 / (dt * dt);
float s = (currentLength - e.restLength) / (1 + 1 + alpha);
vec3 g1 = normalize(diff);
vec3 g2 = -g1;
vec3 delta1 = -s * 1 * g1;
vec3 delta2 = -s * 1 * g2;
vertices[e.a].position += delta1;
vertices[e.b].position += delta2;
}
void solveTetrahedron(uint tetID){
}
4 months ago
void postSolve(uint vID){
4 months ago
vertices[vID].velocity = (vertices[vID].position - vertices[vID].prevPosition) / dt;
}
void main() {
4 months ago
uint id = gl_GlobalInvocationID.x;
switch (state){
case 0:
if (id < vertexCount){
preSolve(id);
}
break;
case 1:
if (id < edgePartition.size){
solveEdge(id + edgePartition.offset);
}
if (id < tetrahedronPartition.size){
solveTetrahedron(id + tetrahedronPartition.offset);
}
break;
case 2:
if (id < vertexCount){
postSolve(id);
}
break;
}
4 months ago
}