AWS Thinkbox Discussion Forums

Density by Red, Green or Blue values?

Hi, I am trying to figure out a problem and I seem to be stuck. Please see the attached render and screen grabs as a reference. What I would like to do is control the density of this prt loader object with it’s red, green and blue color values with the goal being the ability to save out separate prts of just the red, green and blue values (with some sort of falloff where the colors blend). I would like to be able to have 100% density for particles with pure red color while having 0% density for pure green and blue colored particles (hopefully with a smooth gradient falloff for the areas of color transition). Then I would like to repeat the same effect with 100% Density for the green particles and 0% density for the pure red and blue particles, etc.

I tried several approaches to this including the attached Magma flow examples but I can’t seem to find a method that works correctly. Any ideas would be greatly appreciated!



I might be missing the obvious, but why don’t you just extract the X (red component) of the color channel and Multiply the existing Density by it? Or set the Density straight to the X component without multiplying by the existing Density, this would give you 1.0 for pure red, and 0.0 for no red at all, regardless of what the other channels are.

However, if you intend to SAVE only the particles with a specific color, while DELETING the rest, you should not be setting the Density, but the Selection channel to the inverse of the color channel (1-color.x). Then add a Krakatoa Delete set to using the Soft Selection, and it will keep pure red particles, delete non-red particles, while keeping some of the non-so-pure-red ones around with a probability based on the Selection value (0.5 means 50/50 change of being deleted).

Can you send me the data file to bobo AT thinkboxsoftware DOT com so I can take a look?

Thanks Bobo! I tried the methods you described but I still didn’t have any luck. I thought multiplying the density by the red from the color channel (X from the breakout node) would work but it seems to have no effect on the overall color or density. The soft selection with the delete modifier works to some degree but the results are very choppy. I sent you an email with the prt files if you want to take a look. I’ll try a few more things on my end to see if I can get this to work.

Thanks again!!

Hi Bobo, I attached a screen grab of an approach that is beginning to work but still leaves much to be desired. I highlighted my Magma flow and render settings in red. I am simply subtracting out the green and blue to leave only the red and while it works it still creates a sharp cutoff rather than a smooth fade off in density.

The render on the left is the red, the middle is the green and the render on the right is the blue. FYI - these brain fiber tracts were saved in a format that colors them based on their direction in space. Any fibers pointing straight up and down will be pure blue, straight front to back are green and left to right are red. Any part of a fiber that is at an angle will blend between these colors depending on their direction in space. Our aim to to isolate these by RGB with some kind of smooth fade off.

Thanks again for your help!

Oh, you should have started with that :slight_smile:
Basically the color is the tangent, and all you need is a Vector Dot Product with the corresponding vector - Dot product with 0,0,1 (blue, up), to the power of some float and output as density will isolate particles whose tangent is nearly parallel to the up direction!

Do the same with Green and Red and use the Absolute value of the Dot Product just in case, and you have your filtering!

I used a PRT Hair with Tangent channel from the Max Hair&Fur output as color, and passed through an Absolute operator to remove the negative sign when pointing in the opposite direction.

Then the Magma used a Mux to pass the red, green, or blue vector as the one operand of the Dot product, and the Color(Tangent) as the second operand. The result to the power of 10.0 or 100.0 filters more or less of the points:

EDIT:
From geometry point of view, Vector Dot product represents the projection of the one vector onto the other, and is equivalent to the cosine of the angle between the two vectors. When the two vectors are perpendicular, the projection of the one vector onto the other is exactly 0.0. When the two are parallel and pointing in the same direction, the dot product is obviously one (the whole vector coincides with the other), which is cos(0.0)=1.0. If the two are parallel. but pointing in the opposite directions, the angle is 180 degrees and the Dot Product value is -1.0 (so we take the Absolute to remove the sign in that case to still produce 1.0).

This works in 3D space, so if you use the up vector (blue), any particle whose “color” tangent value is also pointing straight up will produce 1.0. A vector at 45 degrees to the reference direction will produce cos(45) = 0.707107. This is a significant Density to assign to a particle, but with a Power operator set to 10.0, you get 0.707107^10 = 0.0312501, much closer to 0.0. To the power of 100, it is practically 0.0!

Btw, the download from Dropbox failed with “Network Error” eventually, but I think my hair-based test is close enough to what you need…

Thanks Bobo, you rule!! This setup works great in my scene and I’m going to keep playing with the settings. I’m still trying to get familiar with some of the math and operations happening in Magma flow so your explanations were very helpful for me to understand what’s happening. Thanks again!!!

Just wanted to mention that it is a good idea to insert Vector > Normalize operators behind the Color input, and possibly after the Mux operator in case the vectors are not of length 1.0. In your case they probably are already unit vectors, but just to be on the safer side… Dot Product expects unit vectors with length of 1.0…

Hey thanks for the suggestion Bobo! In my case I didn’t notice any difference after introducing the normalize nodes into my flow but it’s good to know for next time

Privacy | Site terms | Cookie preferences