--- /dev/null
+#pragma MSP stage(compute)
+layout(local_size_x=8, local_size_y=8) in;
+
+uniform sampler2D surface_in;
+layout(rg8) uniform image2D normals_out;
+
+void main()
+{
+ ivec2 coord = ivec2(gl_GlobalInvocationID.xy)+1;
+ float dzdx = (texelFetch(surface_in, coord+ivec2(1, 0), 0).x-texelFetch(surface_in, coord-ivec2(1, 0), 0).x);
+ float dzdy = (texelFetch(surface_in, coord+ivec2(0, 1), 0).x-texelFetch(surface_in, coord-ivec2(0, 1), 0).x);
+ vec3 normal = normalize(vec3(-dzdx, -dzdy, 2.0));
+ imageStore(normals_out, coord, vec4(normal.xy*0.5+0.5, 0.0, 0.0));
+}