# Grid material that extends with mesh?

For clarification, I am trying to create a Supergrid:

• Put a 2m x 2m grid texture on a mesh.
• When I move or scale the mesh, the grid will increase as the mesh does
(the 2m x 2m does not stretch or distort, but instead increases the number of lines which represent the 2m grid)
• The grid is shown equally on XYZ faces of a mesh.

A bonus would be changing colors, as boxing out a whole level in one color could be confusing.

Details:
I was trying to set up a grid material(s) for blocking out game levels. A short effort to make a simple material seems to have drained my day without a solution, if anyone could help I would greatly appreciate it.

I was trying to use a grid node created by Anton Nevesolv. https://m.youtube.com/watch?v=gsZoJBeAWGc Though, this might not be ideal for creating the desired results?

If we take the above grid and use it in a cube material node,

• then attach the Object socket of a Texture Coordinate node to the vector of the Grid node,
• then use the eye dropper on the Texture Coordinate to assign a plane as the mesh that will represent the ground of a level,

This seems to work similarly to what is happening in Supergrid for UE4. However, the sides of the cube becomes lines instead of a grid.

The same things happens if you use an image of the grid. However, if you change the texture coordinate from Object to UV, we get a nice grid on all sides of the mesh, but now it wont slide in relation to the ground plane, and it also distorts when scaling the mesh.

Any help would be greatly appreciated. I have been trying for hours and I don't see a solution in sight.

This will work for mesh with planar surfaces aligned to the world axis.

That can be this kind of settings, based on world coordinates as input:

It adds the object location to object coordinates so that the result is sensible to the mesh location. Then, it takes a cross product with the normal, in order to avoid limit values to appear when calculating the grid (you'll can test the difference, using it or not).

The grid itself is just a comparison to some value, of the fraction part of the scaled coordinates. More precisely, if the value is around 0.5 (again to avoid limit cases we may encounter if comparing to 0 or 1).

Edit

If you want the grid to be stable from the object position, change the input like that (the object location is substrated from the surface location in world coordinates):

Is you want the grid to be aligned to the object (if its origin is in a corner), change the node group shifting it 0.5/scale (see below on left).

And to avoid limit cases, keep only one positive test (below on right).

Updated blend file:

• Thank you so much! This looks exactly what I am looking for. However, when I try to recreate or Open the blender file you generously provided, the cube is white. Any Idea of what might be happening? Oct 25 '20 at 17:06
• Should not be white. Or does it appear in solid mode? (or your blender version is not 2.9?) Oct 25 '20 at 17:20
• 2.9 fixed it! Thank you so much! I posted this question in a few different places. If you don't mind, I would like to credit you in those places by posting a link to this solution. I wonder if there is a way to replicate this effect (having the grid expand when a mesh is scaled or size changed) by using the local object. That way when a mesh is moved around the map, the grid will always represent the scale of the mesh. (Example, a 2m x 2m cube. No matter where you move it, there will be a 2x2 grid on it. If scaled by 2.0, the grid will now show 4x4.) I can't thank you enough! Oct 25 '20 at 19:12
• @vklidu, done. Edited the last part according to Shinyu comments. Though, I should add more explaination about some points. Will try to do it when possible. Oct 26 '20 at 8:17
• @vklidu, by the way, I think this tricky one may interest you blender.stackexchange.com/questions/199977/… Oct 26 '20 at 19:05

For now based on image texture. Cube is scaling in all axis from corner, for that texture coordinates are assigned to Empty object.

Empty object uses Location Costraint of Cube to keep coordinates in corener when Cube is moved. (Ussually I parent empty to object , but in this case scaling would destroy texture proportions.)

The grid itself - I didnt check OP reference, but I will. I wanted to make it easier for me, but at the end the crucial part was to mix image on sides of Cube without UVmap. It is not a problem let texture project from three sides and mix with Multiply, but issue raised when cube started to scale - it changed the color of shorted face = result of mixed textures. So I created node mask (stored in Node Group) for sides in XYZ and thouse I used for mixing.

• This is also amazing! Any idea why I am getting strange white glare? ibb.co/TP4Q0Wx Oct 25 '20 at 19:51
• Looks like a nice solution! I think a sketched explanation of how it works, even if it seems obvious to you, would really improve the answer? Oct 25 '20 at 20:32
• @vklidu, do you also have this kind of issues with your blend on your computer? i.stack.imgur.com/amywM.jpg . Most of the "complicated" things in mine were about get rid of this. Oct 26 '20 at 8:22
• @vklidu, here both Eevee and Cycles causes the problem. This is some kind of z fighting in the face normal axis. That's why I've used a cross product (which eliminates the vector componant that is along this normal). Will try to explain that in my answer when possible (will ping you when done). Oct 26 '20 at 15:27
• @lemon Ha ... also Shinyu was referring to that (I missed his screen), yes seems like a z-fight. Can you check updated blend? Should be fixed. Just from couriousity. Since I could see that only in Cycles I'm not sure what others see. Thanks Oct 26 '20 at 18:07