1
$\begingroup$

I'm trying to recreate this effect Is it possible to change an object's color depending on its distance? In my project, I have 2*2 KM plane which need to be painted gradually in different colors based on distance from camera. I've tried this: Is it possible to calculate the distance between the vertices of two objects in Geometry Nodes? but it didn't help me. Thank you for response.

$\endgroup$
2
  • $\begingroup$ In which way it didn't help you? What Geometry Nodes setup do you have so far? $\endgroup$ Aug 22, 2022 at 16:19
  • $\begingroup$ Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. $\endgroup$
    – Community Bot
    Aug 22, 2022 at 16:52

2 Answers 2

2
$\begingroup$

enter image description here

A camera has no geometry, so you would have to convert the instance of the camera into a point with Instances to Points.

You can then use this point as a reference with Geometry Proximity and thus assign values to the points of your mesh.

The values resulting from the distance to the camera you would have to adjust to your needs with Map Range.

You store these values with Store Named Attribute in the geometry, which you can read again in the shader with Attribute and convert into a color.

enter image description here


(Blender 3.2+)


Update

Of course you can solve this even easier (thanks to @Gordon Brinkmann for the attentive reading):

Instead of solving the distance via Geometry Proximity, you can directly do the distance to the camera with Vector Math:

enter image description here

$\endgroup$
7
  • $\begingroup$ No need for the Store Named Attribute, just plug the Result from the Map Range node into the empty socket of the Group Output and give it the name in the modifier. $\endgroup$ Aug 22, 2022 at 17:59
  • $\begingroup$ Oh, and you could calculate the distance between the camera's location and the position of the plane's vertices by using a Vector Math node. No need for geometry proximity and hence no converting of the camera into a point. And you can leave the camera's Object Info node at default values, no switching to Relative or enabling As Instance. $\endgroup$ Aug 22, 2022 at 18:04
  • $\begingroup$ @GordonBrinkmann Thank you, that is completely correct! I have once again thought a little more complicated than necessary :D ...but with the example can still do a lot. $\endgroup$
    – quellenform
    Aug 22, 2022 at 18:15
  • $\begingroup$ I actually thought the OP was asking for what the link directly showed me at first, cubes that get an overall uniform color depending on the distance instead of a gradient. In this case your Store Named Attribute (or Capture Attribute linked to the Group Output) with domain set to Instance would be the better solution, since you can capture the location of the instances. Coloring the cubes differently only works if you realize the instances, but then you'll get the gradient with my simpler solution. The Store Named/Capture Attribute gets the location before they are realized. $\endgroup$ Aug 22, 2022 at 18:28
  • $\begingroup$ @GordonBrinkmann: Looks like you are the only one here who reads ALL the answers :D (and understands them) :D :D $\endgroup$
    – Chris
    Aug 23, 2022 at 5:12
1
$\begingroup$

If you want the color-change at render-time and/or at render, (rather than the geometry's,) resolution, it might be better to do this with a shader?

enter image description here

You always have the option of baking the color to an image-texture..

enter image description here

$\endgroup$

You must log in to answer this question.

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