1 #pragma MSP stage(compute)
2 layout(local_size_x=8, local_size_y=8) in;
4 uniform sampler2D surface_in;
5 layout(rg8) uniform image2D normals_out;
9 ivec2 coord = ivec2(gl_GlobalInvocationID.xy)+1;
10 float dzdx = (texelFetch(surface_in, coord+ivec2(1, 0), 0).x-texelFetch(surface_in, coord-ivec2(1, 0), 0).x);
11 float dzdy = (texelFetch(surface_in, coord+ivec2(0, 1), 0).x-texelFetch(surface_in, coord-ivec2(0, 1), 0).x);
12 vec3 normal = normalize(vec3(-dzdx, -dzdy, 2.0));
13 imageStore(normals_out, coord, vec4(normal.xy*0.5+0.5, 0.0, 0.0));