4
$\begingroup$

How could be used instance position generated by geometry nodes in material node tree as Texture Coordinate > Object?

I tried to use position vector, but with no luck ...

enter image description here

What I'm trying here is to take attribute of this two instances position (stored under name attribute) and I expect this vector position will be used like an origin of regular Object in shader so I can control up/down position of mask.

Probably could be done simpler by Domain Size node, but I don' know how either :) Also using Value node directly to Output socket as value to be used in shader via Attribute node > Fac > Math as Ad with Texture Coordinate node as Object.

Anyway ... I'm looking for this result - two planes position control min-max of mask.

enter image description here

In this sample node-tree I used real objects for Texture Coordinates.
For Geometry Nodes version I used Attribute node, but result is zero info.

enter image description here

There is a plenty of threads how to bring texture coordinates into geometry nodes, but not an opposite way.

Q2: In GeoNodes I use node group with Add and Subtract node to math negative value, that seems to me complicated. What is the proper way?

$\endgroup$
8
  • 1
    $\begingroup$ As a shading-point on the shaded object, you can read where you are in another object's space.. but I don't know of a way to read attributes from another object.. (if that's what you're after) .. could be wrong, as always.. Vector Math > Scale > -1 for the negative? $\endgroup$
    – Robin Betts
    Commented Jan 11, 2023 at 15:45
  • $\begingroup$ Be careful that you're capturing the attributes in the Instance domain, but they're not yet instances at that stage. You should either switch them to Point (and the Attribute to Geometry in the Shader), or do the storing after Instance on Points: i.imgur.com/Eeiw1HK.png I know very little about shaders though so I don't know what to do after that :D If it's possible it would also answer this q from yesterday where I similarly fell short: blender.stackexchange.com/questions/283444/… And yes, Vec Math > Scale -1 $\endgroup$
    – Kuboå
    Commented Jan 11, 2023 at 16:24
  • $\begingroup$ Oh, just remembered that in my screenshot you actually need to keep the mode as Instancer in the shader. You capture on Point domain, but those values are propogated to the instances when you create them so you end up reading them from the Instance domain at the end (unless you Realize Instances). $\endgroup$
    – Kuboå
    Commented Jan 11, 2023 at 16:51
  • $\begingroup$ @RobinBetts ... Scale -1 Great, thanks a lot :) As always I'm not sure I understood (GN primitiv here :)) ... In given file there are animated two Torus objects their location (XYZ) controls texture coordinates. So I thought if I can store location (XYZ) of a point generated by GN in an attribute I can use this XYZ vector in shader. It means this attribute will act in the same way as Torus object as texture coordinator, but it didnt. $\endgroup$
    – vklidu
    Commented Jan 11, 2023 at 17:41
  • 1
    $\begingroup$ @RobinBetts No ... Cylinder use mentioned shader. Planes are another object with geo-nodes. $\endgroup$
    – vklidu
    Commented Jan 11, 2023 at 20:30

1 Answer 1

6
$\begingroup$

In your setup, you are trying to capture the Position vectors (via Store Named Attribute) in the Instance domain, but at that step there aren't any instances created yet so the capture fails. Simply switch to the Point domain and the information will be captured correctly:

However, even now that we're managing to bring that information into our shader, there's one big problem: to the best of my knowledge, those values are written on the very geometry the Geometry Nodes modifier is manipulating—they don't magically become available to any and all objects. When you ask a shader to use values captured by a GN modifier, shader tries to read those values from the geometry it is currently assigned to. We captured two Position vectors on our points, but those points aren't in the Cylinder's mesh, they're in the two Grids we instanced in the GN object, so the shader fails to find anything to read (see the bottom of the post for a visual demonstration).

This insight makes it obvious as to how we can affect the colors of the Cylinder with our GN setup: we need to bring the Cylinder into our GN tree so its geometry becomes available to capture values on:

enter image description hereGN SETUP. We sample the position vectors from the points, but capture them as attributes on the Cylinder's geometry. I also took the liberty of swapping out the two Grids with the two Toruses available in the file.

Now to use that captured information in the shader. Simply comparing the two vectors (or rather their separated Z components) to each other like in your setup doesn't yield the desired result, because what we wanna compare them to is the shader's coordinate system itself. We get that from the Position socket of the Geometry node. If the Position—Z of the geometry the shader is assigned to is lesser than the captured Bottom value OR greater than the captured Top value, use the Green shader, otherwise use the Pink:

enter image description hereSHADER SETUP. The OR logic gate node is from this answer

enter image description hereWHOLE SETUP

BONUS: Here's a demonstration of the shader failing to read values captured by the GN setup if it's not assigned to the same object. Below, you can see the Cylinder as re-created in the GN setup on the left, and on the right the original Cylinder with no GN setup, both using the same shader. The one with the GN modifier can correctly compare the captured position with its own coordinates, but the one on the right cannot read those values which means it gets a blanket value of $0$, so everything greater than $0$ gets colored green, and everything smaller gets colored pink:

enter image description here

$\endgroup$
7
  • $\begingroup$ This time.. with Metropolis Wah-Wah rings. Exemplary. :) $\endgroup$
    – Robin Betts
    Commented Jan 11, 2023 at 20:53
  • $\begingroup$ @RobinBetts It's from a 2000s cartoon, apparently! blender.stackexchange.com/questions/283296/… It must've been.. what, 20 years since I've seen Metropolis, I don't even remember the rings. You made me feel old :) $\endgroup$
    – Kuboå
    Commented Jan 11, 2023 at 21:00
  • 1
    $\begingroup$ Ahh I see! It was a homage to Meister vklidu! (Say it in a whisper... that work is a tad derivative) :) $\endgroup$
    – Robin Betts
    Commented Jan 11, 2023 at 21:04
  • 1
    $\begingroup$ @vklidu It kinda makes sense. There are so many scenarios where it would create awkward choices. If the captured values were "global", what happens when two objects with the same GN tree tries to produce the same-named attribute? Obj A has its "Top" point at Z:1, Obj B has it at Z:2, for ex? You could say "they prioritize their own setup first". But what about Obj C which doesn't have the GN setup on it but uses the shader. Which value should that choose? And that's with this simple, one-value setup, what about dynamic field values? You see? I wonder how other programs handle this though. $\endgroup$
    – Kuboå
    Commented Jan 11, 2023 at 22:07
  • 1
    $\begingroup$ @RobinBetts Metropolis ... wow what a great tip to watch :) Thanks ... About "derivative" - I wanted to help and extend my answer there, but fell into this black hole of attribute transfer. $\endgroup$
    – vklidu
    Commented Jan 11, 2023 at 22:10

You must log in to answer this question.

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