I’m trying to make a simple level editor for a game. To make the walls and grounds i use simple cube that I rescale. I want the material to tile with the scale of the cube so it doesn’t look stretched.
I have no idea how to do it.
I know I can modify the tiling of the material but I have 2 problem with that, first is that i need to create a material for each potential size, and the second is that this tiling is only on 2 axis, so there are two face well tiled and the third one completely strectched.
Ex :
Okay so afer a bit of research I think that i found what I need, it’s called an Object Space Triplanar shader, but i can’t find how to do one. I’ve found how to do a world space triplanar shader like so
Your object-space shader works perfectly, but scaling (like in a transform) happens outside of object space. There is no way to get a purely object-space mapping to work how you want.
I suppose you could write a script to pass the scale to the shader as a parameter and you could multiply by that or whatever. I’m not sure what sort of math you need but you need to take either the scale or the world-space into account.
Scaling is kind-of a fudge, though. You’d be better off creating meshes procedurally if you can manage it.
I’ve also found this script that appears to do exactly what I want, but as I’ve not seen anyone mention this way of doing, I was wondering if it was a good way for aproaching the problem. As I understand, it modifies the UV of the cune to match its scale
That should work fine too. If you use this on a mesh that you’ve imported in to your project, you’ll need to check the checkbox that makes the mesh read/writable in the import settings.