On this page
Tiling & Offset
Tiling and offset is the most repeated line in all of shader code: scale the UV, shift the UV, sample. Two properties, one multiply, one add. And yet it is the main way a single texture becomes a dozen materials, because it changes how much of the texture each surface shows.
float2 uv = IN.uv * _Tiling + _Offset;
half4 tex = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv);
Scale and shift, in that order¶
The expression has a fixed order, and the order matters. Tiling multiplies the UV, stretching or compressing the texture across the surface. A tiling of 1.0 shows the whole texture once. A tiling of 2.0 shows it twice, because the UV now runs from 0 to 2 across the same surface, and with a Repeat wrap mode the second half of that range wraps back to the beginning. Offset adds, sliding the texture without changing its size. Offset is where you reach for it when an artist says “the seam is in the wrong place.”
// Tiling 3.0, offset (0.25, 0): three copies, shifted a quarter
float2 uv = IN.uv * 3.0 + half2(0.25, 0.0);
Because UVs are fractions of a texture, tiling above 1.0 is the only way to show a texture “more than once”, and it only works when the texture’s wrap mode is Repeat. With Clamp, the UVs past the edge just pin to the border and you get a stretched smear instead of a repeat. If a tiled texture ever looks smeared, check the wrap mode before you touch the math.
Where to apply it: vertex or fragment¶
You can do the scale and shift in the vertex stage and hand the finished UV to the fragment stage, or you can pass the raw UV and do it per pixel. For a flat transform like tiling and offset, both produce the same picture, because the transform is linear and the rasterizer interpolates linearly: scaling before or after interpolation gives the same result.
The reason to prefer the fragment stage is flexibility. Any UV transform that is not linear, rotation around a point that moves, a radial bulge, a parallax offset that depends on the view, needs the full per pixel precision that only the fragment stage has, and once you are there there is no reason to split the transform in half. The rule of thumb: linear transforms may live in the vertex stage, everything else lives in the fragment stage.
Seams¶
A texture that tiles cleanly is an art decision. If the right edge of the image does not match its left edge, tiling above 1.0 turns that mismatch into a visible line across the surface, one seam per repeat. Artists fix this at the source by painting the texture to wrap, and the shader’s job is mostly not to make it worse: keep the tiling value a power friendly number, and remember that non uniform tiling, different X and Y, stretches the pattern, which is a look, not a bug, but an intentional one.
What the shader does¶
The shader tiles and offsets a single texture through four properties: tiling X and Y, offset X and Y. The pattern repeats and glides with those values, and the wrap behavior at the edges shows where seams appear.
Illustrative schematic: Tiling and offset shift the pattern.
The standard tiling and offset material. One texture, one color, four sliders, and the wrap mode on the texture import does the repeating.
Shader "DecompiledArt/Textures/Basics/TilingOffset/TilingOffset"
{
Properties
{
_MainTex("Texture (set to Repeat)", 2D) = "white" {}
[MainColor] _BaseColor("Base Color", Color) = (1, 1, 1, 1)
_Tiling("Tiling", Vector) = (1, 1, 0, 0)
_Offset("Offset", Vector) = (0, 0, 0, 0)
}
SubShader
{
Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" "Queue" = "Geometry" }
Pass
{
Name "ForwardOnly"
Tags { "LightMode" = "UniversalForward" }
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment Frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
TEXTURE2D(_MainTex); SAMPLER(sampler_MainTex);
struct Attributes
{
float4 positionOS : POSITION;
float2 uv : TEXCOORD0;
};
struct Varyings
{
float4 positionCS : SV_POSITION;
float2 uv : TEXCOORD0;
};
CBUFFER_START(UnityPerMaterial)
half4 _BaseColor;
half2 _Tiling;
half2 _Offset;
CBUFFER_END
Varyings Vert(Attributes IN)
{
Varyings OUT;
OUT.positionCS = TransformObjectToHClip(IN.positionOS.xyz);
OUT.uv = IN.uv;
return OUT;
}
half4 Frag(Varyings IN) : SV_Target
{
// Scale first, then shift. Order matters.
float2 uv = IN.uv * _Tiling + _Offset;
half4 tex = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv);
return half4(_BaseColor.rgb * tex.rgb, _BaseColor.a);
}
ENDHLSL
}
}
FallBack Off
}
🔗 Related Chapters¶
Basic UVs • Filtering & Mipmaps • UVs & Time
Related functions: Lerp • Remap
❤️ Support Shader Story¶
If this article helped you, consider supporting the project on Patreon: you’ll get access to the related source files and reference cheat-sheets.
Your support helps keep this library open and free for everyone.