# How to select highest point in grid? (geometry node)

so I have a system that instances blocks in a grid pattern based on a mesh

and this without the geo node being on

What im trying to achieve is to make the highest block in an x y coordinate a red block. so for each xy coordinate I want to select the box that is on top of all the other boxes.

here's another example

• could you please add a sketch or image of the result you wanna achieve? Because if you make the highest block for each row and column red, you would have e.g. on a "typical" v roof of a house everything red, because all x height values are equal -> so all are "highest" -> red. Jan 28, 2023 at 9:07
• ive edited the post but basically im trying to get the cubes that are on top of the other cubes to change the material. well a better example would be like how in minecraft the dirt block that is the highest becomes a grass block. Jan 28, 2023 at 9:56

To do it, I propose to generate the grid a bit differently, using the bounding box of the shape.

From that,

• ray cast the grid points along Z with the original shape as target
• if the ray is inside the target (the dot product of the ray with the hit normal is positive)
• then if the distance to the hit point is less than the grid space, the point is on top
• if this distance is greater than that, the point is not on top

• wow thanks, ive been tinkering around with raycast node aswell but never got it to work like that. Jan 28, 2023 at 10:22
• After playing around with this, I found that you actually dont need a bounding box and removing the bounding box gives massive performance boost since you dont need too calculate all of the points in the bounding box. Jan 29, 2023 at 2:35
• ok Aqil, I was not able to obtain a good result starting with the initial volume. How did you did it? Jan 29, 2023 at 7:13
• you can replace the bounding box node with an extra extrude node (if the spacing in the distribute points on volume nodes are smaller tho, like 1.000 x 1.000 x 1.000 you dont even need to add an extra extrude node) and play around with the value in the "less than" compare node that is connected to the hit distance value from the raycast node. Jan 29, 2023 at 17:03
• basically you just play around with the values manually until it looks right Jan 29, 2023 at 17:13