Page 1 of 1

How to repeat the texture instead of stretching?

PostPosted: Sun Jan 14, 2018 6:28 pm
by RuhanBello
Hi guys,

I am new to shader things and I have a noob question:

How can I make a shader that repeats the texture when the object gets bigger?

I mean, when you put some texture on a cube, for example, and you stretch it only on the X axis, the texture gets stretched. But currently I need the texture to repeat instead of stretching. Can someone please help me with this?

Re: How to repeat the texture instead of stretching?

PostPosted: Mon Jan 15, 2018 10:09 am
by Amplify_Borba
Hello RuhanBello, thank you for getting in touch and for your support!

First you need to set the texture's Wrap Mode to Repeat, by selecting it in Unity and using the Inspector, hitting Apply after doing so.
Then, within the shader, you may use an Object Scale node passing the scale for the current game object from its X and Y coordinates to the tiling value of a Texture Coordinates node to the UV of the Texture Sample node.

Here's an image of the suggested node setup for your convenience:

Repeat.jpg
Repeat.jpg (177.85 KiB) Viewed 4632 times


Please let us know if this helps, or if you have any further questions, thanks!

Re: How to repeat the texture instead of stretching?

PostPosted: Mon Feb 18, 2019 3:27 am
by JayExbl
Hi,
I've been experimenting with Object Scale but I'm having an issue - I'm guessing this only works if the object is uniformly scaled on all axes, right? If I have an object with scale 1, 1, 0.1 the tiling will be incorrect on the Z axis.

Not sure if it's possible to work around this without using a triplanar mapped shader, is that right?

Re: How to repeat the texture instead of stretching?

PostPosted: Tue Feb 19, 2019 3:37 pm
by Amplify_Borba
Hello, can you share a sample of what you've created so that I might best help you out?