Part 3: using custom attributes in your shaders¶
In this third and last part of our series we will use our custom attributes in a shader to give the particle shower some color and shine.
We start by going to the Shading workspace and we go to the Material Properties tab in the Properties Editor on the right. We click on the +
-sign to add a material slot. We link the material slot to the Object (instead of the Object Data) using the menu encircled in red in Fig. 2. XXX why?
Now we click the New
button to make a new material. We will keep the shader simple and in the Shader Editor we delete the Principled BSDF
and instead we add an Emission
shader (see Fig. 2).
Now we create an Attribute Node and link the Color
socket to the Color
socket of the Emission shader. We only need to fill in the name of the Attribute we want to use into the Name
field in the node. For some reason Blender does not give a selection menu for this and you need to copy and paste the name of the attribute. One way to find the attribute name is by going to the Object Data Properties tab in the Properties Editor and go to the tab Attributes. Here is a list of custom attributes and we see the myAttributeFloat
attribute we made in the first part.
Now you have the shader shown in Fig. 2 and you see already some grey scaled coloring of the particle shower. Now we want to bring some color to the data. For this we add a Map Range Node to scale the attribute data to a range of one to zero (see Fig. 3). By inspecting the data I know the data in the myAttributeFloat
attribute varies roughly between 0 and 13. So we use those values for the From Min
and the From Max
settings.
Lastly, we will add some color by adding a ColorRamp Node. We select red and blue and we see that the cubes in the shower with low energy values color blue and those with higher energy, color red:
This is the basics when using custom attributes in your shaders. I used multiple of the showers from different data sources to make Fig. 1 and the animation in Fig. 4 below.
Pretty nice! I hope this helps.
Cheers, Ben