#pragma MSP stage(compute) layout(local_size_x=8, local_size_y=8) in; uniform sampler2D surface_in; uniform sampler2D bottom_in; uniform sampler2D normals_in; layout(r16f) uniform image2D variance_out; void main() { ivec2 coord = ivec2(gl_GlobalInvocationID.xy)+ivec2(4, 1); float variance = 0.0; for(int i=-3; i<=3; ++i) { ivec2 c = coord+ivec2(i, 0); float depth = texelFetch(surface_in, c, 0).x-texelFetch(bottom_in, c, 0).x; vec2 normal_xy = texelFetch(normals_in, c, 0).xy*2.0-1.0; float xy_sq = dot(normal_xy, normal_xy); float slope_sq = xy_sq/max(1-xy_sq, 0.001); variance += slope_sq*clamp(depth, 0.0, 1.0); } imageStore(variance_out, coord, vec4(variance/7.0, 0.0, 0.0, 0.0)); }