doyubkim / fluid-engine-dev

Fluid simulation engine for computer graphics applications
https://fluidenginedevelopment.org/
MIT License
1.9k stars 265 forks source link

Add Particle Colors #277

Open kentbarber opened 4 years ago

kentbarber commented 4 years ago

I would like to add color information to the particles. This would also involve adding an initial color to the emitters.

@doyubkim Are you in favour of this, or should I look for an alternative way of implementing it so that it is external to the Jet Framework? I don't want to break away from the main branch so any changes I make to the Jet Framework I would like to be integrated, if approved, otherwise I will look for an external approach.

doyubkim commented 4 years ago

Original thinking behind the particle system data class is to have arbitrary channels like colors, vorticities, texture coordinates, etc, so that the particle system can be as compact as possible if all these channels are not needed (i.e. have positions and velocities only). However, I can see the value of color channel being there by default (or at least toggle-able).

Let's first add color channel to the system just like positions. Once we have something working that meets the need, we can then iterate on the design.

kentbarber commented 4 years ago

Yes I also thought that having a system to attach arbitrary data to particles would be better. I am glad you brought this up. Since it felt wrong to add color as its own channel since it is not required data for the fluid simulation.

I have it almost implemented but have no objections removing it in favour of a generalised system, since I would also like to add additional information to particles as well.

Do you have part of this new system in place already in one of your other branches?

utilForever commented 4 years ago

@doyubkim I consider std::optional or rework code to support additional data such as color, vorticities and temperature. Do you have any preference?

doyubkim commented 4 years ago

ParticleSystemData class already has full ability to add arbitrary/optional channel (see addScalarData/addVectorData). I would rather focus more how to make it interact with other modules such as the emitters and mesher

For example, a particle emitter will generate pairs of position and velocity and append it to a particle system. If that particle system has other channels, new particles will have zero values for such an non-position/velocity channels. So what should be added to the code is an API to specify default values of an arbitrary channels from emitters (and then particle system data which emitter should communicate with).

Mesher is actually more complicated and I don’t have good API design in my head yet. Ideally a mesher should take a particle system data with arbitrary channels, generate a mesh as well as interpolated channel values per vertices. That could be done by also making triangle mesh somewhat similar to a particle system data then we can not only handle colors, but also can handle any other channels that we couldn’t think of right now.

Lastly, the actual algorithm that interpolates color (or any values) from particles to mesh needs to be implemented which I think is quite straightforward if SPH style interpolation is used.

utilForever commented 4 years ago

@doyubkim Are you consider this way? These variables is declared in ParticleSystemData. If this method is used, it will have to add a variable called _colorIdx.

_positionIdx = addVectorData();
_velocityIdx = addVectorData();
_forceIdx = addVectorData();
doyubkim commented 4 years ago

@utilForever Yes, something like that. We can also make the color channel optional by taking a boolean parameter from the ctor. While having a dedicate color channel is useful for many cases, it also impacts memory cost if it's turned on by default. I won't recommend using std::optional, though. I still would like to stick with C++11 for v1.x.