flat assembler
Message board for the users of flat assembler.
  
|  Index
      > Projects and Ideas > Physically Based Fluid Effect | 
| Author | 
 | 
| donn 29 Mar 2022, 05:29 Experimenting with the Navier Stokes Equations to visualize fluids. Just uploaded a video of some early results:
 "Physically Based Fluid Effect" https://youtu.be/HGWMK2RYWoM Fluid is slightly viscous and features vorticity confinement. The orchestration of the compute shaders is done 100% with fasmg making calls to Vulkan. The calculations are mostly done in Vulkan's Compute Shaders unfortunately, but I have a plan to switch to something better, more fasm-like (SPIR-V). There are 6 shaders: Advection, Divergence, Jacobi Integration, Projection, Torques, and visualization. The fluid test is currently very tightly tied to a bigger project, would not be useful to share in its entirety as is. Can speak to how any specific sections work though and probably share snippets if desired. Also did the music in the video as an improv, more to come. Next steps are numerous, but include working with gravity, differentiating between specific kinds of fluids, improving lighting and detail, including buoyancy etc. References ______________________________ J. Stam. Stable Fluids. August 1999 M. Harris. Fast Fluid Dynamis Simulation on the GPU. 2004 K. Crane, et al. Real-Time Simulation and Rendering of 3D Fluids. 2007 R. Fedkiw, et al. Visual Simulation of Smoke. 2001 A. Selle, et al. A Vortex Particle Method for Smoke, Water and Explosions. 2005 J. Steinhof. Modification of the Euler equations for "vorticity confinement": Application to the computation of interacting vortex rings. 1994 
 | ||||||||||
|  29 Mar 2022, 05:29 | 
 | |||||||||
| donn 12 Oct 2022, 04:46 Just finished this project. Now have a liquid that is influenced by gravity and interacts with obstacles
 Scene of a TOXIC FLUID: https://youtu.be/THH_ymq69ok A ton of other improvements too, including: - Better visualization 1920x1080 screen (HD) - Up to 125 samples per path (Path Tracing), though visualization is still a bit unstable and crude, crashed during many renders - Maccormack advection - Interpolation of level sets, visualization, etc with Monotonic Cubic Hermites - Vorticity Confinement (swirls, more realism) - Multiple direct lights, diffuse and specular Method: - 100% orchestration of Vulkan (OpenGL successor) from fasmg, dispatching compute shaders, copying memory buffers, etc. - Compute kernels in GLSL, still haven't built with SPIR-V yet from fasmg though I did some tests. Also have some great samples to work with in decompiled shaders. - Trickiest part on fasmg side was in binding the resources used in each shader as I needed more and more. Defined the layouts in data sections and used a builder pattern to traverse and build them. Each buffer definition was a sequence of dqs but Vulkan is very tricky and you have to be careful that Resource Descriptors, binding slots, etc each line up. Did the music myself and first time writing and playing guitar instruments so go easy on me! Any feedback welcome, however. 
 | ||||||||||
|  12 Oct 2022, 04:46 | 
 | |||||||||
| NETSTALKER 12 Jan 2023, 13:42 Hello. This is a very interesting project. Can you show the source code? | |||
|  12 Jan 2023, 13:42 | 
 | 
| NETSTALKER 14 Jan 2024, 19:14 How are things going with the project? | |||
|  14 Jan 2024, 19:14 | 
 | 
| Roman 15 Jan 2024, 15:43 Sample 6 compute shader.
 Its explained why so small asm code for Vulkan API | |||
|  15 Jan 2024, 15:43 | 
 | 
| donn 15 Jan 2024, 16:58 Samples 6-8 are parts of compute shaders. Each compute shader is ~3000 lines of GLSL.
 Quote: 3. Fluid shaders:..........glsl (for now, which is MATLAB-like, building with SPIR-V in future) You can do this in fasm, but it would be faster to dispatch as a shader, not on the CPU. I'm also in the middle of building binary versions of the compute shaders from fasm. So this would be binary, not asm. SPIR-V asm of Sample 7 looks like this: Code: 57(jacobian(struct-Fluid-vf3-f1-f1-f1-vf3[8]-vf3[6]-f1-vf3-f1-vf3-vf3-i11;struct-PSample-vf3-vf3-vf3[6]-f1-i1-f1[6]-i1[6]1;struct-PSample-vf3-vf3-vf3[6]-f1-i1-f1[6]-i1[6]1;f1;i1;): 10(fvec3) Function None 51 52(fluid): 17(ptr) FunctionParameter 53(pSample): 36(ptr) FunctionParameter 54(velSample): 36(ptr) FunctionParameter 55(divergenceAmt): 37(ptr) FunctionParameter 56(jacobianDiffusion): 25(ptr) FunctionParameter 58: Label 392(timeStep): 37(ptr) Variable Function 400(fieldL): 211(ptr) Variable Function 403(fieldR): 211(ptr) Variable Function 406(fieldD): 211(ptr) Variable Function 409(fieldT): 211(ptr) Variable Function 412(fieldF): 211(ptr) Variable Function 415(fieldB): 211(ptr) Variable Function 418(alphVal): 37(ptr) Variable Function 423(jacobianAmt): 211(ptr) Variable Function 446(betaVal): 37(ptr) Variable Function 447(fieldL): 37(ptr) Variable Function 450(fieldR): 37(ptr) Variable Function 453(fieldD): 37(ptr) Variable Function 456(fieldT): 37(ptr) Variable Function 459(fieldF): 37(ptr) Variable Function 462(fieldB): 37(ptr) Variable Function 394: 37(ptr) AccessChain 52(fluid) 393 395: 9(float) Load 394 Store 392(timeStep) 395 396: 6(int) Load 56(jacobianDiffusion) 397: 63(bool) IEqual 396 87 SelectionMerge 399 None BranchConditional 397 398 445 398: Label 401: 211(ptr) AccessChain 54(velSample) 112 67 402: 10(fvec3) Load 401 Store 400(fieldL) 402 404: 211(ptr) AccessChain 54(velSample) 112 87 405: 10(fvec3) Load 404 Store 403(fieldR) 405 407: 211(ptr) AccessChain 54(velSample) 112 112 408: 10(fvec3) Load 407 Store 406(fieldD) 408 410: 211(ptr) AccessChain 54(velSample) 112 100 411: 10(fvec3) Load 410 Store 409(fieldT) 411 413: 211(ptr) AccessChain 54(velSample) 112 324 414: 10(fvec3) Load 413 Store 412(fieldF) 414 416: 211(ptr) AccessChain 54(velSample) 112 339 417: 10(fvec3) Load 416 Store 415(fieldB) 417 Store 418(alphVal) 272 420: 9(float) Load 392(timeStep) 421: 9(float) FMul 419 420 422: 9(float) FDiv 191 421 Store 418(alphVal) 422 424: 10(fvec3) Load 400(fieldL) 425: 10(fvec3) Load 403(fieldR) 426: 10(fvec3) FAdd 424 425 427: 10(fvec3) Load 406(fieldD) 428: 10(fvec3) FAdd 426 427 429: 10(fvec3) Load 409(fieldT) 430: 10(fvec3) FAdd 428 429 431: 10(fvec3) Load 412(fieldF) 432: 10(fvec3) FAdd 430 431 433: 10(fvec3) Load 415(fieldB) 434: 10(fvec3) FAdd 432 433 435: 9(float) Load 418(alphVal) 436: 211(ptr) AccessChain 54(velSample) 87 437: 10(fvec3) Load 436 438: 10(fvec3) VectorTimesScalar 437 435 439: 10(fvec3) FAdd 434 438 441: 9(float) Load 418(alphVal) 442: 9(float) FAdd 440 441 443: 10(fvec3) CompositeConstruct 442 442 442 444: 10(fvec3) FDiv 439 443 Store 423(jacobianAmt) 444 Branch 399 445: Label Store 446(betaVal) 440 448: 37(ptr) AccessChain 53(pSample) 339 67 449: 9(float) Load 448 Store 447(fieldL) 449 451: 37(ptr) AccessChain 53(pSample) 339 87 452: 9(float) Load 451 Store 450(fieldR) 452 454: 37(ptr) AccessChain 53(pSample) 339 112 455: 9(float) Load 454 Store 453(fieldD) 455 457: 37(ptr) AccessChain 53(pSample) 339 100 458: 9(float) Load 457 Store 456(fieldT) 458 460: 37(ptr) AccessChain 53(pSample) 339 324 461: 9(float) Load 460 Store 459(fieldF) 461 463: 37(ptr) AccessChain 53(pSample) 339 339 464: 9(float) Load 463 Store 462(fieldB) 464 465: 9(float) Load 447(fieldL) 466: 9(float) Load 450(fieldR) 467: 9(float) FAdd 465 466 468: 9(float) Load 453(fieldD) 469: 9(float) FAdd 467 468 470: 9(float) Load 456(fieldT) 471: 9(float) FAdd 469 470 472: 9(float) Load 459(fieldF) 473: 9(float) FAdd 471 472 474: 9(float) Load 462(fieldB) 475: 9(float) FAdd 473 474 476: 9(float) Load 55(divergenceAmt) 477: 9(float) FSub 475 476 478: 9(float) Load 446(betaVal) 479: 9(float) FDiv 477 478 480: 37(ptr) AccessChain 423(jacobianAmt) 64 Store 480 479 Branch 399 399: Label 481: 10(fvec3) Load 423(jacobianAmt) ReturnValue 481 FunctionEnd And the Vulkan dispatching asm from fasm is not small, it's quite massive. The above are just samples. | |||
|  15 Jan 2024, 16:58 | 
 | 
| Roman 16 Jan 2024, 08:53 2016 year. My Vulkan API & fasm game.
 https://www.youtube.com/watch?v=-G_kjgklYEs | |||
|  16 Jan 2024, 08:53 | 
 | 
| NETSTALKER 21 Jan 2024, 17:14 What sources did you use to study SPIR-V? How do you compile it? How do I use your code from the last message? | |||
|  21 Jan 2024, 17:14 | 
 | 
| donn 14 Apr 2024, 20:45 Roman wrote: 2016 year. My Vulkan API & fasm game. Cool game! Was it difficult? How did you organize it | |||
|  14 Apr 2024, 20:45 | 
 | 
| donn 14 Apr 2024, 20:54 NETSTALKER wrote: What sources did you use to study SPIR-V? How do you compile it? How do I use your code from the last message? SPIR-V is here, with a few other docs on the Khronos site: https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html SPIR-V tools is the other project to build it. Vulkan is also by Khronos and their docs specify how to dispatch it, etc. John Kessenich is the architect of SPIR-V, he gives some interesting overviews: https://youtu.be/qKbtrVEhaw8?si=4P-vEkX_rI4Soyad&t=1947 I would learn how to just assemble the simple example or anything that is 'legal' SPIR-V if you want to use it. You might also be able to use it as a high level library. Then, if you want to do some damage, you'll be most efficient using GLSL or HLSL or something and converting to SPIR-V. You can see the SPIR-V in the conversions and this might help you plan out how to use SPIR-V directly. That's the approach I took. | |||
|  14 Apr 2024, 20:54 | 
 | 
| donn 14 Apr 2024, 20:58 Sorry last thing: If you want usable examples, this was useful to me: https://github.com/SaschaWillems/Vulkan
 You'll see you need to use bindings, setup buffers, etc, using my snippets above will not work. | |||
|  14 Apr 2024, 20:58 | 
 | 
| NETSTALKER 03 May 2025, 15:27 How are things going with your project? I would love to take a look at the source code. | |||
|  03 May 2025, 15:27 | 
 | 
| < Last Thread | Next Thread > | 
| Forum Rules: 
 | 
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.