import fluidsim; #pragma MSP stage(compute) void main() { ivec2 size = imageSize(surface_out); ivec2 coord = ivec2(gl_GlobalInvocationID.xy)+1; if(coord.x>=size.x-1 || coord.y>=size.y-1) return; float surface = texelFetch(surface_in, coord, 0).x; float bottom = texelFetch(bottom_in, coord, 0).x; float depth = surface-bottom; vec2 velocity = texelFetch(velocity_in, coord, 0).xy; float clamping = texelFetch(clamping_in, coord, 0).x; float left_depth = get_depth(coord-ivec2(1, 0)); float left_clamping = texelFetch(clamping_in, coord-ivec2(1, 0), 0).x; float left_vx = texelFetch(velocity_in, coord-ivec2(1, 0), 0).x; float right_depth = get_depth(coord+ivec2(1, 0)); float right_clamping = texelFetch(clamping_in, coord+ivec2(1, 0), 0).x; float down_depth = get_depth(coord-ivec2(0, 1)); float down_clamping = texelFetch(clamping_in, coord-ivec2(0, 1), 0).x; float down_vy = texelFetch(velocity_in, coord-ivec2(0, 1), 0).y; float up_depth = get_depth(coord+ivec2(0, 1)); float up_clamping = texelFetch(clamping_in, coord+ivec2(0, 1), 0).x; // Integration step: change surface level based on velocities float total_flow = left_vx*mix(left_depth*left_clamping, depth*clamping, left_vx<0)- velocity.x*mix(depth*clamping, right_depth*right_clamping, velocity.x<0)+ down_vy*mix(down_depth*down_clamping, depth*clamping, down_vy<0)- velocity.y*mix(depth*clamping, up_depth*up_clamping, velocity.y<0); float new_surface = surface+total_flow*delta_time; imageStore(surface_out, coord, vec4(new_surface, 0.0, 0.0, 0.0)); }