blob: df60dfdc8b7a4eb1f878987942e4e7685f6214bd (
plain)
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
36
37
38
39
|
#version 430 compatibility
#extension GL_ARB_compute_shader : enable
#extension GL_ARB_shader_storage_buffer_object : enable
#define HORZ_NODES 6
#define VERT_NODES 22
#define INDEX gl_GlobalInvocationID.x
#define TARGET_DIST 0.05f
layout(local_size_x = HORZ_NODES, local_size_y = 1, local_size_z = 1) in;
struct Node {
vec3 position;
float numInfluences;
vec2 influences[8];
};
layout(std430, binding=0) buffer nodes_buffer {
Node nodes[HORZ_NODES*VERT_NODES];
};
void resolve(vec2 influence, float strength) {
vec3 dist = nodes[INDEX+int(influence.x)].position - nodes[INDEX].position;
float l = length(dist);
float factor = strength*(l - influence.y)/(2f*l);
if(INDEX >= HORZ_NODES) nodes[INDEX].position = nodes[INDEX].position + dist * factor;
}
void main() {
float kPrime = 1.0 - pow(1-0.9f, 1.0/30f); //K = 0.9f
kPrime = 0.5f;
int influences = int(nodes[INDEX].numInfluences);
for(int i=0; i<influences; i++) resolve(nodes[INDEX].influences[i], kPrime);
}
|