Geometry nodes: apply color gradient to instances?

Hi folks,

Please take a look at the picture below.

I’m trying to apply a rainbow texture to an instance. Later i want to scatter these instances across some points, and each instance should retain the same shading. So i somehow need to tell the color ramp how to apply it to the instance.

In my example, i’ve used the position to place the gradient, but if i move my instance, the gradient doesn’t move with it!

Any ideas?

I’m fully open to the possibility that i’m doing something very silly or wrong!

Here’s the blend as well:
rainbow.blend (968.0 KB)

Hi looking at your setup there are a few things that complicate this, which is probably why nobody has answered yet. :rofl:

First I would map the texture to the instances in the shader editor not the GN editor this will give you more mapping options.

You are using a text object for the instances.

You can not use UV cords for a text object……well you can but text gives you random uv values for each triangle and you can not unwrap it, so you would find it imposible to map your rainbow horizontaly across the text.

This limits your usefull mapping options to object or generated. To map as you are doing the easiest would be to use generated like this: (the mapping will sttay consistent even if you edit the text and make it longer or shorter)

Note: I did not realize the instances.

The next problem is that you are realizing the instances. If you realize the instances using object or generated cords it will mess up the mapping because the instances no longer exist and they all form part of one new object. Object or generated cords will refere to this new “compound object” and map across it as a whole.

So the big question is:

Do you really need to realize the instances for some specific reason?

If the answer is “no” do not do it. The easiest thing to do is to use generated cords like my example.

If the answer is “yes” the other way to do it would be to covert your text to mesh and UV unwrap it (before using the GN modifer).

So the next question is: Do you need the text instance object to stay editable as text?

If not covert the text object to mesh (without the GN modifier) and unwrap it (project from view bounds).

Then you can make a new GN setup like this and enter the UV map as an atribute in the shader editor and realise the instances.

Then in the shader setup you can input the UVMap with the “Atribute” node or the “UVMap” node. It will not work with the texture coordinate node’s UV output.

I hope that all makes sense, as far as I know there is no way to do it without either “not realizing” instances or converting the text to mesh.

Here are the files, in the first one the text is still text but I did not realize the instances, in the second one I coverted the text to mesh and did realise the instances.

Burger.blend (88.6 KB)
Burger2.blend (250.9 KB)

:slightly_smiling_face:

3 Likes

Many thanks for taking the time to reply in detail!

Your suggestions fix it to a point, but i’ve still been struggling to actually do what i want (i don’t think i explained it properly in my OP).

I’m not sure, but i think i might have cracked it, but it still feels a bit hacky.

Please check the blend here:
another try.blend (859.6 KB)

In this example, what i’m trying to do is scale the checker texture on each instance depending on it’s distance from an empty.

I had to include a math snap value in the shader, otherwise the difference in distance from the edge compared to the middle was causing weirdness. Just to test if that was the actual case, i made this blend and here’s also a video of the problem (snap) in action below:
warp.blend (883.0 KB)

I guess my biggest remaining question is: am i on the right track with this, or is there some other, better way?

Ok, I had a feeling there was more to it!

To do this you need to get the position of each instance. With generated cords it was “staggering” so I used UV cords to map the texture. It seems to do what you are asking. I did displace the UV’S of the “Mesh Square” so it scales from the centre.
Also I gave the Geo Line the material simply so it would show up in the screenshot, it is not necessary as the instances have the material.

another try2.blend (103.9 KB)

  • a tip.
    To save a little web space for the forum it is nice to compress the blend files you upload, when you save the file in the save dialog hit N (N panel) and tick the “compress” checkbox. :grinning:
1 Like

Thanks man, this is super useful, many thanks! :pray: