3 #pragma MSP stage(compute)
6 ivec2 size = imageSize(surface_out);
7 ivec2 coord = ivec2(gl_GlobalInvocationID.xy)+1;
8 if(coord.x>=size.x-1 || coord.y>=size.y-1)
11 float surface = texelFetch(surface_in, coord, 0).x;
12 float bottom = texelFetch(bottom_in, coord, 0).x;
13 float depth = surface-bottom;
14 vec2 velocity = texelFetch(velocity_in, coord, 0).xy;
15 float clamping = texelFetch(clamping_in, coord, 0).x;
16 float left_depth = get_depth(coord-ivec2(1, 0));
17 float left_clamping = texelFetch(clamping_in, coord-ivec2(1, 0), 0).x;
18 float left_vx = texelFetch(velocity_in, coord-ivec2(1, 0), 0).x;
19 float right_depth = get_depth(coord+ivec2(1, 0));
20 float right_clamping = texelFetch(clamping_in, coord+ivec2(1, 0), 0).x;
21 float down_depth = get_depth(coord-ivec2(0, 1));
22 float down_clamping = texelFetch(clamping_in, coord-ivec2(0, 1), 0).x;
23 float down_vy = texelFetch(velocity_in, coord-ivec2(0, 1), 0).y;
24 float up_depth = get_depth(coord+ivec2(0, 1));
25 float up_clamping = texelFetch(clamping_in, coord+ivec2(0, 1), 0).x;
27 // Integration step: change surface level based on velocities
28 float total_flow = left_vx*mix(left_depth*left_clamping, depth*clamping, left_vx<0)-
29 velocity.x*mix(depth*clamping, right_depth*right_clamping, velocity.x<0)+
30 down_vy*mix(down_depth*down_clamping, depth*clamping, down_vy<0)-
31 velocity.y*mix(depth*clamping, up_depth*up_clamping, velocity.y<0);
32 float new_surface = surface+total_flow*delta_time;
34 imageStore(surface_out, coord, vec4(new_surface, 0.0, 0.0, 0.0));