View Full Version : emit color from particles into a fluid

05 May 2010, 01:26 PM

if i get the 2011 manuals correctly, it should be possible to use particles/nParticles to emit color into a fluid.
but how?

neither having a general color on the particles nor using rgbPP values gives me any success.
i turned on dynamic grid for color and in the emitter i used "emit fluid color" as well.

but the resulting color always is the one from the color chooser in the emitter. the particle color is ignored.
turning emit fluid color off results in black color in the fluid.



05 May 2010, 08:24 PM
You would need to use multiple emitters.. one for each desired color, setting the color on the fluid emitter. You can then set up ratePP for the different emitters and the individual particles could chose the rate PP for each of the emitters. All colors should be possible by using just 3 fluid emitters... one for Red, Green and Blue. (I've not tried it, but it should work)

Keep in mind also that the base fluid color grid is initialized to grey (you could initialize it to some other color if desired). In general it also helps to emit color over a larger radius than density to avoid fringing effects.

Note that there is currently a ratePP bug on the fluid emitter. The fix is to connect the particle position to the fluid emitter instead of the cached position. (there is a recent thread on this issue). You may not hit the problem if the particle count stays constant for your simulation.


05 May 2010, 10:49 PM
sounds a lot easier to use the MEL commands to set the color :) ts ts bad manuals

thx duncan



05 May 2010, 11:38 PM
I tried setting up the three r,g,b emitters and it sort of works(see attached scene file), but you can't emit black (if r,g,and b are all zero there is no emission). One could set up yet a forth black emitter, but it starts to get complex. The mel command method may be better if you need to exactly set the color.

Hopefully in future we will get around to implementing more per particle emission attributes(currently one can only set rate and radius per particle).

07 July 2010, 02:09 PM
sounds a lot easier to use the MEL commands to set the color :) ts ts bad manuals

thx duncan



is there a MEL command to do this?

Thanks for that scene, Duncan. Looks like fun!

I'm tying to emit particles from a textured surface, with the 'inherit color'.
I would then like those colored particles to emit fluids with that same color.

So I tried changing your scene (replacing the random rgb thing to rgbPP):

nParticleShape1.fluidEmitter1RatePP = nParticleShape1.rgbPP * 100;
nParticleShape1.fluidEmitter2RatePP = nParticleShape1.rgbPP * 100;
nParticleShape1.fluidEmitter3RatePP = nParticleShape1.rgbPP * 100;

but that was probably a little too simple to be true? Not realy the best MEL scripter, sorry.

The reason I'm not emitting fluids from that textured surface, but instead using because i'd like to animate those particles (flying to the surface as a goal object, and then flying away...).

Kinda like the "goalMayaSmokeLong4" example in the "fun stuff in Maya 2011", but then with the goal being a colored texture (on a poly plane).

thanks in advance!

07 July 2010, 09:01 PM
You would need to set the red, green and blue from the rgbPP...
float $col[3] = rgbPP;
fluidEmitter1RatePP = $col[0] *100;
fluidEmitter2RatePP = $col[1] *100;
fluidEmitter3RatePP = $col[2] *100;

It will still not match the color from a texture that well... there will be no fluid where it is black. One could add emittion into a 4th black emitter to improve things:

blackFluidEmitterRatePP = (1.0-($col[0] + $col[1]+$col[2])/3.0) * 100;


07 July 2010, 12:36 AM
thanks for your reply, duncan!
I sort of got it to work, but I'm not getting any colors in between the R, G or B. (like yellow,...) as you can see in the attachment. Weird, cause they were in your first example-scene...

Am I doing something wrong?

And maybe it needs another 'white' emitter aswell?


07 July 2010, 01:19 AM
you can also try SOuP.

07 July 2010, 09:15 AM
well, you read my mind. That was actually the next thing I was planning on doing! Looks very very promising!

I just hope it doesn't take too much time to learn, since I'm (like everyone else, I guess) on a rather tight deadline. But it does look like it's worth the risk :).


07 July 2010, 09:08 PM
Perhaps you need to create an emitter that just emits density, not color, instead of having a black emitter. Use the paint fluids tool to flood the fluid with black then set initial state( black but no density instead of the default grey) Then lower the emission rate on your emitters... the color is emitted based on the relative change in density... if the emitters are too strong the color will simply be determined by the last emission into the fluid( which from the looks of it is your green emitter) instead of being a blend of rgb.

OR...One can manually create a simple expression to set fluid color values based on particle color and position, although it can look pixelated( the standard particle emission emits as antialiased moving spheres). However with lots of small particles it can work fine:

float $densityEmit = 1; // rate of density emission

//get particle position and color
vector $p = nParticleShape1.position;
vector $c = nParticleShape1.rgbPP;

//get which voxel (with -cv the return value is an empty array if the point is outside the fluid)
int $v[] = `fluidVoxelInfo -cb -voxel ($p.x) ($p.y) ($p.z) fluidShape1`;

//add density and set color
if( size($v) > 1 ){
setFluidAttr -at "density" -ad -fv $densityEmit -xi ($v[0]) -yi ($v[1]) -zi ($v[2]) fluidShape1;
setFluidAttr -at "color" -vv ($c.x) ($c.y) ($c.z) -xi ($v[0]) -yi ($v[1]) -zi ($v[2]) fluidShape1;


07 July 2010, 07:21 AM
Wow thanks Duncan!

I won't have enough time left to dig into SOuP so I was planning on creating a seperate particle-system for each color...and then manually set each color to the correct color of the image (logo). Since they are solid colors, no gradients, this would work good enough...

But with your new advice, I can't wait to check it out!

Thanks, update coming soon :D


08 August 2010, 10:37 AM
alright, been busy improving my setup with the particles...I found that the density emitter wasn't even realy necessary for the setup to work properly with colors. What I did find out was that I had to use the 'Add' density emission method. With 'Replace' I was more likely to get some interpolated colors, (only when using motion streaks, though).

I'm using solid colors, The colored images I emit from are logos, so matching colors is not realy a big problem (can always shift it a little in post).
This is also why I stepped back to using 3 nParticle systems, for each color one. This way I can easily control each color-fluid without having to use expressions to separate the color particles.
I think it's a good setup to continue with, too bad it 'll just work on a max. of 3 colors (but for the project I'm working on that's enough).

What I'm trying to figure out how I can color my transparency with the same color as the (dynamically colored) fluid. Here's why I want to use this:
in this example-scene, Duncan uses a blue-ish transparency color, which gives the fluid a much more ink-look.

I tried to achieve this effect in post, rendering my fluids with a gray (nearly black) transp. color...but couldn't get near that same look.

When I render my fluid on black background and I merge that image (with alpha) on a white background, I can't achieve the same look as when rendering the fluid on white. Which seems strange, I thought?

Now I tried rendering the fluid on a white background (but with an alpha channel = black > white lambert (incandescence) with full transparency)...which gave better results.

But the only thing I cannot seem to find is how to achieve a same look as with colored transparency. I tried it in post but couldn't seem to find anything close to it.

Here are some renders to help explain:
- The 'Blue_TransparencyColor' shows a blue-ish look, which clearly only works nice for the blue.
- The 'No_TransparencyColor' is with a transparency value of HSV= 0 / 0 / 0.1 (so no color, just gray). Doesn't look as good as previous render to me.
- 'Post_TransparencyColor' is a quick attempt to get that colored transparency-look...which obviously looks completely different. I could get away with it like this, but I'd love to have more of that other look.

Am I missing something on that transparency, alpha,...?

Thanks in advance!


CGTalk Moderation
08 August 2010, 10:37 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.