| 1229 | } |
| 1230 | |
| 1231 | function step (dt) { |
| 1232 | gl.disable(gl.BLEND); |
| 1233 | |
| 1234 | curlProgram.bind(); |
| 1235 | gl.uniform2f(curlProgram.uniforms.texelSize, velocity.texelSizeX, velocity.texelSizeY); |
| 1236 | gl.uniform1i(curlProgram.uniforms.uVelocity, velocity.read.attach(0)); |
| 1237 | blit(curl); |
| 1238 | |
| 1239 | vorticityProgram.bind(); |
| 1240 | gl.uniform2f(vorticityProgram.uniforms.texelSize, velocity.texelSizeX, velocity.texelSizeY); |
| 1241 | gl.uniform1i(vorticityProgram.uniforms.uVelocity, velocity.read.attach(0)); |
| 1242 | gl.uniform1i(vorticityProgram.uniforms.uCurl, curl.attach(1)); |
| 1243 | gl.uniform1f(vorticityProgram.uniforms.curl, config.CURL); |
| 1244 | gl.uniform1f(vorticityProgram.uniforms.dt, dt); |
| 1245 | blit(velocity.write); |
| 1246 | velocity.swap(); |
| 1247 | |
| 1248 | divergenceProgram.bind(); |
| 1249 | gl.uniform2f(divergenceProgram.uniforms.texelSize, velocity.texelSizeX, velocity.texelSizeY); |
| 1250 | gl.uniform1i(divergenceProgram.uniforms.uVelocity, velocity.read.attach(0)); |
| 1251 | blit(divergence); |
| 1252 | |
| 1253 | clearProgram.bind(); |
| 1254 | gl.uniform1i(clearProgram.uniforms.uTexture, pressure.read.attach(0)); |
| 1255 | gl.uniform1f(clearProgram.uniforms.value, config.PRESSURE); |
| 1256 | blit(pressure.write); |
| 1257 | pressure.swap(); |
| 1258 | |
| 1259 | pressureProgram.bind(); |
| 1260 | gl.uniform2f(pressureProgram.uniforms.texelSize, velocity.texelSizeX, velocity.texelSizeY); |
| 1261 | gl.uniform1i(pressureProgram.uniforms.uDivergence, divergence.attach(0)); |
| 1262 | for (let i = 0; i < config.PRESSURE_ITERATIONS; i++) { |
| 1263 | gl.uniform1i(pressureProgram.uniforms.uPressure, pressure.read.attach(1)); |
| 1264 | blit(pressure.write); |
| 1265 | pressure.swap(); |
| 1266 | } |
| 1267 | |
| 1268 | gradienSubtractProgram.bind(); |
| 1269 | gl.uniform2f(gradienSubtractProgram.uniforms.texelSize, velocity.texelSizeX, velocity.texelSizeY); |
| 1270 | gl.uniform1i(gradienSubtractProgram.uniforms.uPressure, pressure.read.attach(0)); |
| 1271 | gl.uniform1i(gradienSubtractProgram.uniforms.uVelocity, velocity.read.attach(1)); |
| 1272 | blit(velocity.write); |
| 1273 | velocity.swap(); |
| 1274 | |
| 1275 | advectionProgram.bind(); |
| 1276 | gl.uniform2f(advectionProgram.uniforms.texelSize, velocity.texelSizeX, velocity.texelSizeY); |
| 1277 | if (!ext.supportLinearFiltering) |
| 1278 | gl.uniform2f(advectionProgram.uniforms.dyeTexelSize, velocity.texelSizeX, velocity.texelSizeY); |
| 1279 | let velocityId = velocity.read.attach(0); |
| 1280 | gl.uniform1i(advectionProgram.uniforms.uVelocity, velocityId); |
| 1281 | gl.uniform1i(advectionProgram.uniforms.uSource, velocityId); |
| 1282 | gl.uniform1f(advectionProgram.uniforms.dt, dt); |
| 1283 | gl.uniform1f(advectionProgram.uniforms.dissipation, config.VELOCITY_DISSIPATION); |
| 1284 | blit(velocity.write); |
| 1285 | velocity.swap(); |
| 1286 | |
| 1287 | if (!ext.supportLinearFiltering) |
| 1288 | gl.uniform2f(advectionProgram.uniforms.dyeTexelSize, dye.texelSizeX, dye.texelSizeY); |