import fluidsim; #pragma MSP stage(compute) void main() { ivec2 size = imageSize(velocity_out); ivec2 coord = ivec2(gl_GlobalInvocationID.xy)+ivec2(1, 1); if(coord.x>=size.x-1 || coord.y>=size.y-1) return; vec4 data = get_data(coord); vec2 sd_right = get_depth(coord+ivec2(1, 0)); vec2 sd_up = get_depth(coord+ivec2(0, 1)); // Advection step: move velocity vectors vec2 uv_coord = (vec2(coord)+vec2(0.5))/size; vec2 offset = vec2(0.5, -0.5)/size; vec2 multi = delta_time/size; vec2 v_right = vec2(data.x, textureLod(velocity_in, uv_coord+offset, 0).y); vec2 v_up = vec2(textureLod(velocity_in, uv_coord-offset, 0).x, data.y); vec2 new_velocity = vec2(textureLod(velocity_in, uv_coord-v_right*multi, 0).x, textureLod(velocity_in, uv_coord-v_up*multi, 0).y)*velocity_damping; // Update step: change velocities based on surface level differences vec2 source_depth = mix(vec2(sd_right.y, sd_up.y), vec2(data.w), greaterThan(vec2(data.z), vec2(sd_right.x, sd_up.x))); new_velocity += (vec2(data.z)-vec2(sd_right.x, sd_up.x))*0.1*gravity*delta_time*min(source_depth/residual_depth, 1.0); if(time>=drop_time && time<=drop_time+0.01 && data.w>1.0) { ivec2 d = coord-drop_pos; if(d.x*d.x+d.y*d.y<4) { float v = cos(fract(time-drop_time)*628.3)*100.0; new_velocity.x += normalize(vec2(d.x+0.5, d.y)).x*v; new_velocity.y += normalize(vec2(d.x, d.y+0.5)).y*v; } } imageStore(velocity_out, coord, vec4(new_velocity, 0.0, 0.0)); }