3 #pragma MSP stage(compute)
6 ivec2 size = imageSize(clamping_out);
7 ivec2 coord = ivec2(gl_GlobalInvocationID.xy)+ivec2(1, 1);
8 if(coord.x>=size.x-1 || coord.y>=size.y-1)
11 float depth = get_depth(coord);
12 vec2 velocity = texelFetch(velocity_in, coord, 0).xy;
13 float left_vx = texelFetch(velocity_in, coord-ivec2(1, 0), 0).x;
14 float down_vy = texelFetch(velocity_in, coord-ivec2(0, 1), 0).y;
16 // Clamping step: prevent fluid depth from going negative
17 float total_out = max(velocity.x, 0.0)+max(velocity.y, 0.0)-min(left_vx, 0.0)-min(down_vy, 0.0);
18 float scale = min(max_flow_fraction/(total_out*delta_time), depth/residual_depth);
20 imageStore(clamping_out, coord, vec4(clamp(scale, 0.0, 1.0), 0.0, 0.0, 0.0));