0
$\begingroup$

It is a very simple caveman geometry node setup.

I want to change the color of these bars as they rise [from black at lowest to orange at full scale]

enter image description here

and please explain in detail, how to control material from geometry nodes.

$\endgroup$
0

1 Answer 1

4
$\begingroup$

To color geometry procedurally created inside a Geometry Nodes setup, you need to capture a certain attribute of that geometry and pass that information over to the shader nodes. Capturing part is usually done with a Store Named Attribute node. You then retrieve and manipulate the captured data inside the Shader Editor via an Attribute node. Do note that you also need to assign the relevant material to the geometry inside Geometry Nodes using a Set Material node--assigning a material the usual way, through the material window in the Properties panel is not sufficient.

In this first example, I'm capturing the Instance Scale information as a named attribute called 'i_s', then accessing it in the shader nodes and converting it to color through a ColorRamp. Since scale is a singular value, I'm capturing it as float. Additionally, since I'm capturing this information in the Instance domain, I need to use the Instancer mode of the Attribute node:

enter image description here

This second setup is very similar. I'm still capturing float values in the Instance domain, but instead of their scales, I'm using the Index numbers of our instances. ColorRamp node only uses values within the $0-1$ range, so if my captured values contain smaller or larger values than that, mapping them to the $0-1$ range beforehand is a good idea. In your setup you have $2500$ instances, which means our index numbers go from $0$ to $2499$. I use a Map Range to fit that between $0-1$. I also use the Constant mode of the ColorRamp node so there's no interpolation between colors, just to demonstrate that it is an option:

enter image description here

Since we've been employing the Instance domain, our cylinders are colored one by one, as singular instances, regardless of their shape or number of faces--the whole cylinder is always just one color. You're not limited to that. If you Realize Instances, you get access to their internal, raw geometry: vertices, edges, faces. In this third example, after realizing the instances, I'm capturing the Z location of eeach point of our geometry, and using that information to color it. Notice that in the Attribute node we've switched to Geometry mode, and since the captured attribute is evaluated and converted to color between each and all points, cylinders can have multiple colors at the same time. Using the B-Spline mode of the ColorRamp also makes the interpolation between points more gradual.

enter image description here

A last example from an older answer below, where I'm coloring the sphere instances according to their distance to the outer capsule mesh they're located in:

enter image description here

$\endgroup$

Not the answer you're looking for? Browse other questions tagged .