Color by object distance

I have a ring of prt’ed particles that need to have four different colors at distinct zones along the circle.

I am using four boxes to indicate the four color "zones" and trying to use the "hot surface" method with some basic boxes and testing if the particles are inside their respective zone. This method works great for one box but as soon as I start adding more boxes with the switch operator I get harsh divisions between the zones in the circle and I need a nice bleeding of colors between the different zones. 

If anyone has any suggestions on how I solve this problem that would be great. thanks!

There are KCM presets that might help you…

viewtopic.php?f=56&t=5042 this is simple position to color operator with some settings based from the tutorials, maybe a good start

viewtopic.php?f=56&t=4448 - density to camera distance, if you change object camera to an object in the scene, and density output to color output, it will give you color based on object distance i would assum

Let’s assume that the 4 zones are exact quadrants on the circle - from 0 to 90 to 180 to 270 degrees.
Here is a procedural way to generate masks for the 4 quadrants based on either fixed vectors in object space or on a reference object.

*I created a Torus and turned into a PRT Volume to represent a circle of particles.
*I added a KCM to the stack and connected the following flow:

This takes the Normalized position of the particle (which is a vector from the origin in object space, the center of the torus) to the particle, and calculates the Dot Product with the +X, +Y and -Y local axes of a Point Helper. (alternatively, you could simply enter Vectors [1,0,0], [0,1,0] and [0,-1,0] instead of using Script Operators to read the transforms of the Point Helper).

These Dot Products go into the R, G and B channels, thus producing a Gradient which has Red between -90 and +90 degrees (dot product with the X axis changes from 0 to 1 to 0), Green color from 0 to 180 with max. at 90, and Blue going from 0 through 1 to 0 from 180 to 360 with max. at 270 degrees.
KRA_CircleMappingQuadrants_ViewportRGB_01.png
If you would rotate the Point Helper, these gradients would slide around the Torus particles, following the X and Y axes orientations:
KRA_CircleMappingQuadrants_ViewportRGB_02.png
Note that the Position of the Point Helper plays no role, it does NOT have to be in the center of the Torus. Only its axes in world space define the color gradient in object space of the Torus.

Now you can take a set of Blend Materials and use the R,G and B channels of the Vertex Color Map to combine them based on the generated data:
KRA_CircleMappingQuadrants_BlendMatByRed_1.png
The first sub-material has a Cellular Map and shows up where there Red <=0. The second has a Checker map and shows up where Red > 0.0.
KRA_CircleMappingQuadrants_BlendMatByRed_Viewport.png

Then I added another set of Blend Materials as sub-material of the first Blend Material. Here I controlled the blending with the Green channel of the Vertex Color Map, producing the Orange Noise Map see in the screenshot where the Green is > 0:
KRA_CircleMappingQuadrants_BlendMatByRG_Viewport.png

I could then add yet another level of Blend Material where the Blue is > 0 and blend in a 4th material… See the attached Max 2010 scene!

Of course, we could calculate the actual angle of the particle’s position vector and define gradients in ranges less than 180 degrees, but the above approach is quite useful when only 4 are needed…

Hope this helps.
KRA_CircleQuadrantColorMapping_v002.zip (21.1 KB)

Using the Box selecting method would also work using this Color Channel approach - each Box selection could set a Color Channel (Red, Green, Blue) to assign a different Material via Blend Materials and Vertex Color Maps controlling them.
Instead of Box selection, a Volume Select modifier could be used for the same purpose…

Attached is a Max 2010 scene that shows 3 Volume Select modifiers with 3 KCMs setting the Red, Green and Blue channels via the Selection channel, including Soft Selection.


The Channels could then be used in Blend Materials with Vertex Color Maps…
KRA_CircleQuadrantColorByVolumeSelect_Viewport.png
KRA_CircleQuadrantColorByVolumeSelect_v001.zip (22 KB)

Thanks Bobo! It worked out great!

One thing I noticed, is that as you pointed out, the color masks of the RGB channels change if the orientation of the dummy/point helper is moved. If I needed the rgb masks to stay on the circle the whole time, no matter its orientation; would I then use the volume select method?

-Christian

No, you could just use a constant vector value like [1,0,0], [0,1,0] and [0,-1,0], or hide the Helper and not rotate it at all. If you rotate the PRT object, since the calculation is in object space, the colors would stick to the particles as they rotate.
If you would convert the Position to World Space first, the colors would stick to the world space axes and the particles would rotate within the color space.

I am not sure why you changed the orientation of the dummy though, the idea was to have it as a custom control, but if you don’t want it changing, just don’t change it. It does not have to be parented to anything or move with the PRT object.

Yeah, I just discovered that myself. I was moving it with the dummy the whole time. Mybad. Anyway, thanks again! :slight_smile:

One more thing I should add:

What happens when you run out of RGB channels to blend by?
Well, Max comes with support for 100 Mapping Channels, this gives you up to 300 R, G and B channels to blend by!
So you can use Mapping2, Mapping3 etc. to store influences of Volume Selects or KCM calculated values and set the Vertex Color Maps in the Blend Materials to Mapping Channel 2 or 3, Red, Green or Blue to get the mix you want…

Just thought to mention that…

Thanks Bobo!

I was wondering if you could give me an example of this. How do I assign or use different UVW channels on the prt and is there a way to visualize this in the viewport so that I can see how much I am blending between channels and so forth. Thanks again.

-Christian

I am in Utrecht for the End User Event, and generally on vacation, so I cannot really produce an example right now.
But you just set the Output node in your KCM to Mapping2, Mapping3 etc., and the Vertex Color Map in your Blend Material’s 3rd slot to Map Channel N (where N is 2, 3 etc.) instead of using “TextureCoord” (which is Mapping Channel 1) or “Color” which is Vertex Color channel. Isn’t it obvious? :wink: