| 728 | } |
| 729 | |
| 730 | function step(dt) { |
| 731 | gl.disable(gl.BLEND); |
| 732 | curlProgram.bind(); |
| 733 | gl.uniform2f(curlProgram.uniforms.texelSize, velocity.texelSizeX, velocity.texelSizeY); |
| 734 | gl.uniform1i(curlProgram.uniforms.uVelocity, velocity.read.attach(0)); |
| 735 | blit(curl); |
| 736 | |
| 737 | vorticityProgram.bind(); |
| 738 | gl.uniform2f(vorticityProgram.uniforms.texelSize, velocity.texelSizeX, velocity.texelSizeY); |
| 739 | gl.uniform1i(vorticityProgram.uniforms.uVelocity, velocity.read.attach(0)); |
| 740 | gl.uniform1i(vorticityProgram.uniforms.uCurl, curl.attach(1)); |
| 741 | gl.uniform1f(vorticityProgram.uniforms.curl, config.CURL); |
| 742 | gl.uniform1f(vorticityProgram.uniforms.dt, dt); |
| 743 | blit(velocity.write); |
| 744 | velocity.swap(); |
| 745 | |
| 746 | divergenceProgram.bind(); |
| 747 | gl.uniform2f(divergenceProgram.uniforms.texelSize, velocity.texelSizeX, velocity.texelSizeY); |
| 748 | gl.uniform1i(divergenceProgram.uniforms.uVelocity, velocity.read.attach(0)); |
| 749 | blit(divergence); |
| 750 | |
| 751 | clearProgram.bind(); |
| 752 | gl.uniform1i(clearProgram.uniforms.uTexture, pressure.read.attach(0)); |
| 753 | gl.uniform1f(clearProgram.uniforms.value, config.PRESSURE); |
| 754 | blit(pressure.write); |
| 755 | pressure.swap(); |
| 756 | |
| 757 | pressureProgram.bind(); |
| 758 | gl.uniform2f(pressureProgram.uniforms.texelSize, velocity.texelSizeX, velocity.texelSizeY); |
| 759 | gl.uniform1i(pressureProgram.uniforms.uDivergence, divergence.attach(0)); |
| 760 | for (let i = 0; i < config.PRESSURE_ITERATIONS; i++) { |
| 761 | gl.uniform1i(pressureProgram.uniforms.uPressure, pressure.read.attach(1)); |
| 762 | blit(pressure.write); |
| 763 | pressure.swap(); |
| 764 | } |
| 765 | |
| 766 | gradienSubtractProgram.bind(); |
| 767 | gl.uniform2f(gradienSubtractProgram.uniforms.texelSize, velocity.texelSizeX, velocity.texelSizeY); |
| 768 | gl.uniform1i(gradienSubtractProgram.uniforms.uPressure, pressure.read.attach(0)); |
| 769 | gl.uniform1i(gradienSubtractProgram.uniforms.uVelocity, velocity.read.attach(1)); |
| 770 | blit(velocity.write); |
| 771 | velocity.swap(); |
| 772 | |
| 773 | advectionProgram.bind(); |
| 774 | gl.uniform2f(advectionProgram.uniforms.texelSize, velocity.texelSizeX, velocity.texelSizeY); |
| 775 | if (!ext.supportLinearFiltering) |
| 776 | gl.uniform2f(advectionProgram.uniforms.dyeTexelSize, velocity.texelSizeX, velocity.texelSizeY); |
| 777 | let velocityId = velocity.read.attach(0); |
| 778 | gl.uniform1i(advectionProgram.uniforms.uVelocity, velocityId); |
| 779 | gl.uniform1i(advectionProgram.uniforms.uSource, velocityId); |
| 780 | gl.uniform1f(advectionProgram.uniforms.dt, dt); |
| 781 | gl.uniform1f(advectionProgram.uniforms.dissipation, config.VELOCITY_DISSIPATION); |
| 782 | blit(velocity.write); |
| 783 | velocity.swap(); |
| 784 | |
| 785 | if (!ext.supportLinearFiltering) |
| 786 | gl.uniform2f(advectionProgram.uniforms.dyeTexelSize, dye.texelSizeX, dye.texelSizeY); |
| 787 | gl.uniform1i(advectionProgram.uniforms.uVelocity, velocity.read.attach(0)); |