2
$\begingroup$

I am using Geometry Nodes to populate a bookshelf with random books. I've got the sizes, rotations, and positions properly randomizing, but for some reason any time I try to alter the UV coordinates they just become distorted.

My bookshelf and texture sheet: enter image description here

What ends up happening when I try to use Random Value: enter image description here

My nodes setup: enter image description here

I can shift the coordinates manually if I unplug the random value node, but nothing I try seems to keep it from distorting the texture. I think it has to do with Index or ID but I cannot for the life of me figure out why this isn't working. I also notice that the textures are distorted in the exact same way on each book, which tells me ID isn't doing what I think it should be.

And because I am exporting this to a game engine, no tricks involving materials will work here. The UV coordinates need to actually shift per book. None of the other answers on the site seem to apply to my case.

Any help would be greatly appreciated.

$\endgroup$
0

1 Answer 1

2
$\begingroup$

I solved my own issue!

enter image description here

I had to capture the Index of the instance BEFORE realizing the instances, and then I had to move the UVMap node to be AFTER the realize instances node. I'm still not totally certain how all this works, but I managed to get it working.

enter image description here

$\endgroup$
4
  • 3
    $\begingroup$ For how this works: I guess without close inspection you are shifting UVs by indices of elements. The problem is, the index number is always automatically assigned from $0$ for the first element to $n-1$ for the $n^{th}$ element. Instances count as single elements regardless of how many vertices they might have. Let's say you have 4 instances of a basic cube (8 vertices, 12 edges, 6 faces), then the index goes from 0 to 3. If you now realize the instances you have 32 vertices (index 0-31), 48 edges (index 0-47) and 24 faces (index 0-23). If your UV shift relies on index 0-3 you get an issue. $\endgroup$ Commented Aug 8, 2023 at 7:35
  • 1
    $\begingroup$ If you now capture the index of the instance and pass it on to the realized instances, the vertices get the attributes based on the index of instances they belonged to before realizing. In your nodetree you are directly using the captured attribute for the calculations, but you could also change the ID of the vertices to their instances' indices by using a Set ID node. This is the main difference between the values you can retrieve by an Index node and an ID node. The index is automatically assigned to each element. The ID is by default the same as the index unless assigned differently. $\endgroup$ Commented Aug 8, 2023 at 7:51
  • 2
    $\begingroup$ Next trick... pack the books on the shelves :) The trick after that.. have the occasional leaning book in a bigger gap... $\endgroup$
    – Robin Betts
    Commented Aug 8, 2023 at 10:06
  • $\begingroup$ @RobinBetts Haha, that was similar to my next move. My plan was to simply create multiple types of book "blocks" and pick them randomly, but for my purposes (just setdressing for a game level) this is as detailed as I really need it to be. Next time we'll see. $\endgroup$
    – Ec Little
    Commented Aug 14, 2023 at 19:52

You must log in to answer this question.

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