10
$\begingroup$

I am trying to do rocks and I want them to have a random base color from within the colors that look "rocky". The only method I know of is to duplicate the base objects over and over and give each a different color in the node editor, then group them all and use them as the group input for the particles. This is slow, inefficient to change, duplicates a lot of data, and comes out with a uniform distribution of the colors. Is there a way to have give particles a random color from a set or range?

$\endgroup$
  • $\begingroup$ The first 2 answers together make up a pretty complete solution for this (read both; part of one answer is fixed in the other). There isn't a way to make both as the answer, though. $\endgroup$ – Elliot Jan 8 '17 at 3:05
  • $\begingroup$ wouldn't the second answer be the correct one since it's building on top of the first one? $\endgroup$ – Dalibor Karlović Aug 17 at 13:30
14
$\begingroup$

I'm going to keep this short and simple. Do everything Duane Dibbley did but use an Object Info node instead of a Particle Info node. Connect the random output directly to the color ramp, no math node needed.

enter image description here

Pro Tip: Make sure that if you are using a color ramp set to constant that you don't put any colors at position 1 (all the way to the right). They won't end up being used.

$\endgroup$
  • $\begingroup$ Apart from being marginally simpler than my setup, it doesn't make much difference. The randomness still isn't random enough. +1 for noting that position 1 won't get used (though with my math node, exactly one particle will get the colour at position 1). $\endgroup$ – Duane Dibbley Jan 4 '17 at 4:19
11
$\begingroup$

In Cycles, you can achieve this with a Particle Info node and a color ramp. It has an Index output socket, which gives you a integer from zero to one less than the total number of particles emitted, so you'll need to divide the index by one less than the total number of particles, to get a value between 0.0 and 1.0 which will drive the color ramp. This material goes on the dupli object, not on the emitter. If you set the particle emission to Random, each new particle emitted will appear in a random location, meaning the indices will not be ordered. This in turn makes the differently colored particles appear randomly accross the emitter.

enter image description here

The color ramp can be defined in several different ways: Ease, Cardinal, Linear, B-Spline and Constant. With the first four, the colors will smoothly transition between the control points, and they differ only in what formula is used to calculate the transition, and with Constant the color changes abruptly at each control point and remains unchanged between the control point (any point which is not a control point will have the color defined by the control point to its left). I will show Linear and Constant here.

This is with Linear

enter image description here

Here's a rendered preview of a very bland scene with only a plane emitting 250 duplicates of the same object, using a linear color ramp.

enter image description here

This is with Constant

enter image description here

Here's a rendered preview of a very bland scene with only a plane emitting 250 duplicates of the same object, using a constant color ramp.

enter image description here

$\endgroup$
  • 1
    $\begingroup$ This isn't quite it. It creates a RANGE of colors, which covers a lot of situations. But it doesn't create a SET of colors. Fine for the rocks. But let's say you want to make sprinkles for a donut. Sprinkles need to be in specific colors, not just a range, or it looks wrong. You need to pick a set of colors (ie 5 specific shades) and have them randomly distributed. $\endgroup$ – Elliot Jan 1 '17 at 17:13
  • $\begingroup$ @Elliot Set the color ramp to Constant instead of Linear, and define more distinct colors. You can have up to 32 if I'm not mistaken. $\endgroup$ – Duane Dibbley Jan 1 '17 at 17:15
  • $\begingroup$ Thanks, that all works except that even though I set it to random it's still just grouping spatially (seems to be making the particles in order across the surface). Since I previously had all this generated and I'm just changing settings now (and I cut the group back to just one of each shape), do I need to do something to force it to reseed the particles? Of course since I'm doing fixed objects I am in hair mode, not emitter; does that matter? $\endgroup$ – Elliot Jan 1 '17 at 17:26
  • $\begingroup$ @Elliot If it wasn't set to random before, and the particles had been baked, you need to free the bake and bake it again. If they weren't baked, try going to frame 0 on the timeline, and then scrub the timeline (i.e. play it). If that doesn't help, try playing with the jittering amount and/or try disabling/enabling Even Distribution. $\endgroup$ – Duane Dibbley Jan 1 '17 at 17:33
  • $\begingroup$ I've tried this. Nothing I can figure out to do will make them come out random. The spatial distribution holds in every case except Emit From: Verts, which gives random distribution but otherwise fails to look like anything reasonable. $\endgroup$ – Elliot Jan 1 '17 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.