- Home /
What's the difference between clamp and repeat textures?
By logic, setting a texture to "repeat" should repeat the texture. So why do I get no difference between clamp and repeat settings when I apply a texture to a cube and scale the cube? This feels like a very big oversight for a game engine if it can only "tile" textures on terrain, which is the only place I've actually seen textures tile correctly.
To illustrate my point, here is what the texture looks like when I scale a cube.
Here is what I want it to look like when I scale the cube.
Regardless of whether I have my texture set to repeat or clamp, I get the exact same result. So what is the difference, and how can I get my texture to work like example 2, and not like example 1?
Hey, Guys! A new answer to this question: http://answers.unity3d.com/questions/361573/how-to-make-a-texture-tile-and-not-stretch.html from DevLurkin has a working answer and script. Give him all the kudos!
Answer by MrSoad · Dec 08, 2014 at 01:30 PM
Scaling an object does not change how the Texture is applied to that object.
To increase or decrease the tiling you have to change the texture tiling property in the Material. Clamp will stop tiling and just stretch the last pixel row if the texture tiling property is set to more than 1 in the x or y dimensions. Repeat makes it tile but only in accordance with the tiling property setting, not scale.
...and this is the way standard 3D modelling works. Unity just copied the way everyone else does it (which is good.) "Everyone knows" that stretching a wall stretches the texture.
Then, to emphasize, Repeat and Clamp say that if you have tiling, how should the extra textures look. So if you don't tile, they do nothing.
Here is a good example of repeat and clamp wrapmodes. Note that those wrapmodes are actually how the hardware handles texture lookup in shaders. So it's nothing Unity has specifically copied but it's simply how our graphics hardware works.
The wrapmode applies for texture coordinates which are outside of the texture area (smaller than 0 or greater than 1).
Actually the hardware would support setting the wrapmode for the u and v axis seperately but most (high level) engines only set them as pair since in most cases you either need clamp or repeat on both axes.
So in order to get the results I want, I would have to add a script to every object that manually changes the wrapmode on the individual uv's?
Just look up $$anonymous$$aterials and tiling. That will do what you want, not Clamp and Repeat modes.
$$anonymous$$aterial tiling does not give me the result I want, not by a long shot.
Answer by Owen-Reynolds · Dec 11, 2014 at 07:22 PM
Ah...looked at that second "what I want" picture again. It can't be done, not by using the Unity cube and changing settings. Asking about Repeat/Clamp was just confusing the issue.
The rule for 3D models is, when an object stretches, the texture stretches. You're wanting the system to change that to "when an object stretches, the texture tiles more." That makes sense. It's called planar-mapping. But it takes a special set-up this cube doesn't have. And it won't track the model (if you did get a different cube to look this way, then changed size, the texture would still just stretch/shrink.)
In 3D modelling, objects are unwrapped a certain way, using a certain number of materials. The Unity cube has one material, and is unwrapped so the entire texture is pasted 1x1 on each face. Since it uses one material, you can only set the tiling on them all the same way. In other words, you can make the right side tile 1x2, the way you have it, but then every face will tile 1x2.
One way would be to make/find a new cube, using three materials (for each pair of aligned faces.) Three materials means you can supply three tilings. Or, could just use 3 small cubes (if the match is correct, they will be seamless.)
So how does tiling work on a Terrain object? Feels like a major oversight to not have such functionality, especially with the recent push towards 2D games and sprites. Or is there a script/plugin out there for it that I just haven't found yet? I keep looking, only to come up with answers that are incomplete at best.
That's like saying not curing the common cold is an oversite. We tried, and it's way, way harder than we thought.
3D modellers have been trying for over a decade to make things easier, and this is the best we can do. Terrains are easy -- they're just bumpy planes, using blend shaders. Look at the sides of a game mountain to see how the "magic" really works.
Um... you might want to re-read that. I know it's very possible in a basic 3D modeling program so long as you know how to control uv's. Tiling is also cheaper on memory in many 2D games and dev platforms that I've seen. If it works on a flat terrain, why not a flat box, or even just the plane object? $$anonymous$$aybe if I add the terrain shader to it...
Your answer
Follow this Question
Related Questions
Vertical or Horizontal texture wrapmode 1 Answer
How do I clamp a texture only on the y axis, but repeat on the x axis? 0 Answers
2D - How to make sprites repeat tiles? 4 Answers
How to render html text in new UI system (unity 4.6) 0 Answers
How to clean on RenderTexture to transparent with brush 0 Answers