How to i add a gradient to particles, normal to the emitters surface? This is a very special question i'd imagine ;)

I have a base shape, that uses a particle system with pyramids on it.



Im triyng to add a gradient to the pyramid-spikes.

This efffect by itself can be easily done in a material for the particle.




BUT: The fade on the pyramids will only be a part of a more complex material for the whole shape.



Currently i convert the particles into a mesh and then join them into one object to achieve this.

I currently have no way to achieve the gradient on each pyramid, but also have control over the material of the whole shape.

So im emulating it with this node setup, someone shared with me.


But this only works partially, since i dont have a sperical shape.

Any ideas on how to solve this problem are well appreciated.

Thanks in advance :)
Gradient texture upon Generate coordinates

To assign a gradient texture to the single particle object you can use the built-in node available for cycles. You can control the gradient with a color ramp node as well.

The tricky part in your setup is that you would like to access the data of a different mesh that doesn't belong to the particle. One possible way is to take advantage of the Object option in the Texture Coordinate node.

You didn't share your setup for the colored shader (the one you show with particles baked and joined), so I'll assume by guessing that you are using the Generate texture coordinate of the object. We can't access that data, but we can try to transform the Object's texture coordinate from an empty object.

In the following example I'm using the Mapping node to translate the empty's (which was created in the same location of the object's origin) coordinates.



An altenative would be to simply move the empty in one of the corner of the object's bounding box and scale it appropriately:



The following image sequence is showing the node in action. The shape on the right is the mesh with particles baked with a shader showing the Generated coordinates to use as reference.





Note: accessing data from other objects may not be possible for all the attributes. Object's texture from another object can only provide location, rotation and scale of the object.