12
$\begingroup$

Basically I have a field of spheres that are a bunch of different sizes that use the same material and I want them to be a different color based on their size.

I'm using a volumetric shader, so each of those little clusters is one sphere.

I accomplished something similar to what I want by using the Object Info input node's position attribute. It looks like this. Unfortunately the Object Info node doesn't have a scale option. Is there a way to add that? Or perhaps some method using drivers? I'm still not very good with drivers so maybe I'm just missing something.

atomicbezierslinger has suggested a way to change the color of a particle based on its size, which is an interesting solution, and it worked well.

I'm not very experienced with particle systems, so I basically manually went through to each sphere and gave it it's own particle system that emits 1 particle from its volume and with no physics. I manually changed the size of each particle then shrunk the emitter sphere down to .01 so it would be in about the right spot. I'm feeling a bit like a monkey on a typewriter but it got the job done.

My problem is solved thanks toatomicbezierslinger, but I would still be interested in whether or not it's possible to not have to use particles to do this. I can't be the only person to have this problem and the method I used wasn't exactly fast.

Perhaps there's a way to use Object Index on the Object Info node by assigning an index to each sphere based on its size using a script of some sort? I don't know the first thing about python, so I wouldn't know.

I'm using blender v2.76b, by the way.

$\endgroup$
  • $\begingroup$ Can you show a image of your field so that we can see the quantity and how easily particles might enter the picture? $\endgroup$ – atomicbezierslinger Dec 28 '15 at 4:18
  • $\begingroup$ You placed a link in my proposed answer below. I suggest you add it to your question where all can see it more easily. $\endgroup$ – atomicbezierslinger Dec 29 '15 at 5:14
  • $\begingroup$ Haha my bad, I didn't get what you meant. I've added it now. $\endgroup$ – stapleshotz Dec 29 '15 at 20:22
  • $\begingroup$ I wrote a simple data driven script below for use with particles. Are these values changing dynamically over time? YN? Do the values come from a text string or file? Is this a single image or an sequence of images animation? Should the script position the object as well or not? $\endgroup$ – atomicbezierslinger Dec 31 '15 at 6:14
9
$\begingroup$

Size ratio from Texture coordinate (Object) comparison

Concept:

The idea is to compare the Object's texture coordinates type of each object with the ones of a "fixed" size object (e.g. an empty).

By dividing the corrisponding values of each field, you'll get the same value for each surfaces's point, which is also the size's ratio between the considerd object and the "fixed" one.

enter image description here

Node setup:

The shader is composed by two Texture coordinate nodes followed by a Color Mix node (set to Divide). Note that the node on top has the empty object as target.

The output of the math node is already the size ratio factor. It can be, for example, plugged into a Ramp node and then in the wanted shader type.

enter image description here

To achieve a usable shader, we should also get rid of the dipendency from the object's position by taking advance of the Object info node.

The node tree used in the image sequence above result the following:

enter image description here

Note: similar implementation should follows to get rid of rotation's dipendency.

$\endgroup$
  • 1
    $\begingroup$ I think this should be the accepted answer, since it works for objects not in a particle system, which is more applicable to the question (and easier, in this case, than creating a particle system for every object - yikes!) $\endgroup$ – Stuntddude Jan 3 '16 at 8:50
  • $\begingroup$ Yep. That looks like a pretty good solution. atomicbezierslinger's is what actually god my project done, but this looks like the best answer to the question. This community is awesome. $\endgroup$ – stapleshotz Jan 9 '16 at 20:53
11
$\begingroup$

Cycles Sample 01

enter image description here

Cycles Sample 02

enter image description here

Consider a particle system and material shader nodes.

Use the particle info node size [relative scale] value.

Note the object particles with [size] set to 1 and [random size] set to 1 in the image below. enter image description here

We assume that your placement of spheres can use a particle system. Particles are emitted in 2 frames. Of course with a more complex mesh particles can be placed anywhere. There was no artistry in placement of the example I provided. You can do better.

Below same Material with different Particles Settings. A more controlled placement with particles spaced evenly.

enter image description here

$\endgroup$
  • $\begingroup$ Here's the image of my field: link It's kinda hard to tell since they're all soft, but theres like 50 something data points, each with its own specific size. A particle system seems like a good choice, but is it possible to control exactly where each particle appears and what size it is? $\endgroup$ – stapleshotz Dec 28 '15 at 16:46
4
$\begingroup$

Script/User Action Answer

enter image description here

Position and Particle Settings Scale determined from Python Script.

Rotation from Particles Settings via Script. Color is maintained across rotation.

enter image description here

We have seen above you have attached a particle system to a plane. I will show my settings later. You may also show yours.

User preferences allows you to duplicate object with fresh/unshared particle system. So copying object will copy new particle system. Script does not need to create particle system. Script changes position of emitter object and scale of particle system. Use at your own risk. Standard Disclaimer.

enter image description here

User Steps

  • Make single particle system. Place in group for selection convenience.
  • Copy N times. Logarithmic steps if new selection is copied.

  • Place script below in editor. Select all objects created in step above. Run Script.

Notes

  • Use material in previous answer or your capable material.

  • Python can probably easily import/parse the original textual data into python list format. The original data format has not been posted by the OP.

  • Below we assume 3 coordinates [X,Y,Z] for your position. Single scale value in the range [0.0, 1,0] for relative scale.

  • In the Python below you may need to normalize size by division by largest in list or largest possible size.

  • This is a simple script. Many assumptions such as only using zeroth particle system. Modify to your particular needs.

Script

import bpy 
import datetime
import math

def place_scale():
    print("Place Scale")
    print(datetime.datetime.today())
    print(datetime.datetime.now())
    #your data is different, from processed file or other
    lc1 = [[[1,0,1], 0.50], [[2,0,2], 0.75], [[3,0,3], 0.10]]
    lc2 = [[[1,0,1], 1.00], [[1,0,2], 1.00], [[1,0,3], 1.00]]    
    pos_scale = lc1
    so = bpy.context.selected_objects
    limit = min(len(pos_scale), len (so))
    for x in range(0,limit):  
        so[x].location = pos_scale[x][0]
        so[x].particle_systems[0].settings.particle_size = pos_scale[x][1]
place_scale()
$\endgroup$

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.