taichi-dev / taichi

Productive, portable, and performant GPU programming in Python.
https://taichi-lang.org
Apache License 2.0
25.58k stars 2.29k forks source link

Integrate into blender #299

Closed PavelBlend closed 4 years ago

PavelBlend commented 4 years ago

Integrate this simulator in blender.

yuanming-hu commented 4 years ago

I think it's a great idea! I'm recently traveling and will do a fluid simulator that is suitable for Blender integration (with particle IO using numpy) once I'm back in the US next week.

Taichi is cross-platform and supports GPU on Linux (and Windows soon). We will end up with a continuum simulation plugin (fluid, snow, sand, jelly) simulation addon for Blender that is very efficient and easy-to-use.

PS: I'm amazed by all the wonderful Blender addons you have created!

PavelBlend commented 4 years ago

Hello.

I have a question: Is it possible to create similar effects with taichi? https://youtu.be/TJxbiCEoo1Y https://youtu.be/XSPwM8Yv6YE https://youtu.be/r3-PSEijh_I

All these effects were created in blender using the Molecular Script addon: https://github.com/Pyroevil/Blender-Molecular-Script

Addon Molecular Script should be replaced with something newer and more technological. Since the addon is not completely stable and the method used, it processes a large number of particles rather slowly.

If I had enough knowledge about taichi, then I could try to integrate it into blender.

And is there a complete list of key features for taichi?

yuanming-hu commented 4 years ago

Hi,

@PavelBlend , thanks for the inquiry. Molecular is really cool. Recently I've been working on some Taichi compiler infrastructure stuff, but very soon (in one week or two) I can start building a CPU/GPU Material Point Method (MPM) solver using Taichi.

MPM is quite versatile, and please check out papers we have published to learn what it can do: https://github.com/yuanming-hu/taichi_mpm

https://www.youtube.com/watch?v=X-TJGBrfeBE (with the snowman simulation)

https://youtu.be/eGtB0VXJsuI (cloth, hair)

In fact, one of the reasons why MPM gets gradually more popular is that people can use MPM to simulate quite a lot of different materials, within a unified framework.

Clearly I won't be able to share with you a solver that immediately with all these features since everything needs to be re-built using Taichi, to make it portable on different platforms and runnable on GPUs. Fortunately, Taichi has greatly reduced the development cost of MPM solvers, and I can share with you a version with basic fluid, snow, and sand simulation features within 10 days, and then gradually add more features. If you would like to, I believe the initial solver will be fun enough to integrate into Blender. During this process, I can learn to design the API of the solver to match the Blender interface.

Thanks, Yuanming

PavelBlend commented 4 years ago

Blender really lacks physical simulators. Currently, developers are introducing a liquid and gas simulator Mantaflow. But it seems to me that Mantaflow has many limitations. If you add an MPM simulator to the blender, this would make it closer to Houdini when possible. In the meantime, the blender has never had a simulator of snow and granular substances. And in the blender it was never possible to create Multiphysics simulations (snow and water with sand within the same simulation).

yuanming-hu commented 4 years ago

Yeah, Mantaflow is a good choice too. I'm more than happy to explore having Taichi multiphysics in Blender.

PavelBlend commented 4 years ago

if you are going to create a taichi addon for a blender, how will you do it? In what style?

It’s just that I just got an idea:

make taichi addon based on nodes. Or are nodes inappropriate for taichi? It's just that all advanced physical simulators (houdini, realflow, maya/max fluids (naiad in the past)) are based on nodes. And I believe that the standard method (which is not based on nodes) is deprecated. In the future, almost all blender 2.8x functionality will be rewritten to nodes. nodes

yuanming-hu commented 4 years ago

Hi @PavelBlend ,

This is really a good suggestion. I think the node systems are much more flexible than the traditional flat interfaces. I'm finalizing performance tuning for Taichi and will do an experimental 3D MPM simulator for liquid/elastic objects/snow tomorrow or the day after.

I would discuss more what should the node look like, specifically for simulation. The figure you posted is more designed for rendering (BxDFs). Maybe we should look at the simulation node system for Houdini/realflow/Bifrost.

Without node systems, users are often exposed with a set of global parameters (time step, gravity, num of frames, etc) and a list of collision objects/source objects. It'll be great to explore how the node system should be designed for more customizability.

I believe designing the node system is not only a UI problem but also an important factor to consider when modularizing the simulator.

Best, Yuanming

PavelBlend commented 4 years ago

I have no experience in such simulators that are built on nodes. But there is experience in rendering engines.

But I can offer some examples of fluid simulations that can be created on nodes. I do not know if there are such opportunities in taichi as viscosity, variable viscosity, fluid temperature. But here are examples:

Fluid particles have a viscosity and this viscosity can be set using 3D textures (Noise for example): nodes

Also in this example, the ambient temperature increases by 4 degrees per second (and starts at 10 degrees).

It would be convenient to be able to specify values for particles using 3D textures that are built into the blender. For example, to control viscosity, temperature, initial speed, color...

Also with the help of nodes it would be possible to indicate which objects from different simulations can interact with each other, and which I can not.

Examples of using 3D textures to indicate viscosity and color: https://vimeo.com/102554547 https://youtu.be/OEfpkvxx5kg

I look at this task as a user, not as a programmer. And I can’t imagine if this can be realized in a reasonable amount of time or not. If this is still difficult to implement, then the standard approach will be more appropriate.

yuanming-hu commented 4 years ago

This looks quite reasonable to me! I'll design the simulator following this paradigm. We can, of course, implement variable viscosity/stiffness/temperature in MPM, as well as specify the object coupling.

I think your "user's view" is quite helpful, and as a "programmer" I'm sure these can be implemented without too much difficulty. However, the implementation would be gradual: I would implement the simulator feature by feature so that I can get some feedback from you and users.

I guess we can directly borrow the "Value", "Time", "Multiply", "Add" nodes from Blender, right?

PavelBlend commented 4 years ago

I guess we can directly borrow the "Value", "Time", "Multiply", "Add" nodes from Blender, right?

I'm not very good at writing code for the new node system. Therefore, I can’t say for sure. But if I'm not mistaken, then I have to create my own class of given nodes. Since the developers of the blender made separate nodes for materials and made the same nodes for textures and compositor: https://docs.blender.org/api/current/bpy.types.ShaderNodeMath.html https://docs.blender.org/api/current/bpy.types.CompositorNodeMath.html https://docs.blender.org/api/current/bpy.types.TextureNodeMath.html

for each type of processed data its own nodes were created

Probably in the taichi MPM node system it will be necessary to create similar nodes. Do not get to borrow them from the standard part of the blender. And I have not seen any ready-made add-ons that would have standard Math and Value nodes. Also, there are no time nodes even in standard blender node systems.

I'm not 100% sure how everything really works.

yuanming-hu commented 4 years ago

It's interesting that the MathNode APIs for the shader, the compositor and texture are identical. I guess the underlying implementations are similar in some sense, or they actually refer to the same piece of code. We will gradually figure these things out :-)

yuanming-hu commented 4 years ago

The solver will be hosted in https://github.com/taichi-dev/elements and you should already have write permissions to it.

The current version is just 2D, but I'll make it 3D tomorrow.

Taichi is super suitable for implementing simulators and as you can see the solver is implemented in just < 200 lines of code, and can run on a GPU.

A high-res 2D demo: https://www.youtube.com/watch?v=cej640B2_Bo 3D coming tomorrow!

PavelBlend commented 4 years ago

I wrote a draft version of a node system. This system includes the most basic nodes. But these nodes do nothing. This is a layout or interface: draft_nodes At the moment, I do not know how to make the node system perform any actions. Here is the code: https://github.com/PavelBlend/blender-taichi-elements-concept

I have a list of all the nodes (in the form of a text file) that I considered necessary for creating simulations. But I have not yet decided how exactly the node system should look. I can post this list to discuss what can be added and what cannot be added.

yuanming-hu commented 4 years ago

OMG, this looks so cool! Feel free to post the list and we can have a discussion.

I would also suggest that we first make a few core nodes work, e.g. "solver" and "emitter", "simulation hub" in the figure above, and see how everything works. This will give us more knowledge about how the node system should be further designed, and how the simulator should be built.

PavelBlend commented 4 years ago

Maybe move the conversation here?: https://github.com/taichi-dev/elements/issues So that all discussions are in the same place where the development is underway. You are planning to add a blender addon to this repository?: https://github.com/taichi-dev/elements Or will a separate repository be created for the blender addon? I looked at my list of nodes and realized that there are a lot of them and at this stage of development it is too early to discuss all the nodes. I will try later to reduce the number of nodes in the list to an acceptable number and publish this list. And I had questions: why was the repository named elements? Do you plan to rename it in the future?

yuanming-hu commented 4 years ago

Sure let's move the conversation to the new repo: https://github.com/taichi-dev/elements/issues/1