subdivision-edge.compute 1.08 KB
Newer Older
1
#version 430 core
Philipp Adolf committed
2

3
layout  (local_size_x  =  1)  in;
4

5 6 7 8
struct Vertex {
    vec3 pos;
    vec3 norm;
    vec2 uv;
9 10
};

11 12 13 14 15 16 17 18 19
layout(std430, binding=0) readonly buffer Vertices {
    Vertex vertices[];
};

layout(std430, binding=1) readonly buffer EdgeIndices {
    unsigned int indices[][4];
};

layout(std430, binding=2) writeonly buffer Output {
20
    Vertex edges[];
21 22 23
};

void main(){
24 25
    edges[gl_GlobalInvocationID.x].uv = vec2(0.0, 0.0);

26 27 28 29 30 31 32 33 34
    Vertex a = vertices[indices[gl_GlobalInvocationID.x][0]];
    Vertex b = vertices[indices[gl_GlobalInvocationID.x][1]];
    Vertex c = vertices[indices[gl_GlobalInvocationID.x][2]];
    Vertex d = vertices[indices[gl_GlobalInvocationID.x][3]];

    vec3 pos;

    edges[gl_GlobalInvocationID.x].pos = 3.0f/8.0f * a.pos + 3.0f/8.0f * b.pos + 1.0f/8.0f * c.pos + 1.0f/8.0f * d.pos;
    edges[gl_GlobalInvocationID.x].norm = normalize(3.0/8.0 * (vertices[indices[gl_GlobalInvocationID.x][0]].norm + vertices[indices[gl_GlobalInvocationID.x][1]].norm) + 1.0/8.0 * (vertices[indices[gl_GlobalInvocationID.x][2]].norm + vertices[indices[gl_GlobalInvocationID.y][3]].norm));
Philipp Adolf committed
35
}