Repeating and Tiling UVs
by GameDev.net · GLSL ES 3.00 (WebGL2) · 25 Aug 2026
Run the shader to adjust these controls.
What it demonstrates
This shader repeats one circular motif across a configurable grid. It separates global UVs into a cell identifier and a local coordinate inside each cell. Integer Rows and Columns controls show how repetition density can change while the motif code remains constant.
Shader inputs
void mainImage(out vec4 fragColor, in vec2 fragCoord)
Called once per pixel. Write the colour to fragColor.
-
iResolutionvec3 - Viewport size in pixels (z is the pixel aspect ratio).
-
iTimefloat - Seconds since the shader started.
-
iTimeDeltafloat - Seconds since the previous frame.
-
iFrameRatefloat - Frames per second, smoothed.
-
iFrameint - Frames rendered since the start.
-
iMousevec4 - Mouse position: xy while held, zw of the last click.
-
iDatevec4 - Year, month, day, and seconds within the day.
-
iChannel0sampler2D - Texture bound to channel 0.
-
iChannel1sampler2D - Texture bound to channel 1.
-
iChannel2sampler2D - Texture bound to channel 2.
-
iChannel3sampler2D - Texture bound to channel 3.
-
iChannelResolutionvec3[4] - Pixel size of each bound channel texture.
-
iChannelTimefloat[4] - Playback time of each channel, in seconds.
-
iSampleRatefloat - Audio sample rate, always 44100.
Main Image6
uniform int uColumns; // @param 1..12 = 7 "Columns"
uniform int uRows; // @param 1..12 = 5 "Rows"
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = fragCoord / iResolution.xy;
vec2 gridSize = vec2(float(uColumns), float(uRows));
vec2 tiled = uv * gridSize;
vec2 cellId = floor(tiled);
vec2 cellUv = fract(tiled) - 0.5;
float dotShape = 1.0 - smoothstep(0.25, 0.32, length(cellUv));
float checker = mod(cellId.x + cellId.y, 2.0);
vec3 tileColor = mix(vec3(0.12, 0.38, 0.70), vec3(0.82, 0.28, 0.32), checker);
vec3 color = mix(vec3(0.025, 0.035, 0.06), tileColor, dotShape);
fragColor = vec4(color, 1.0);
}
Learn from this shader
How it works
Multiplying normalized UV coordinates by the grid dimensions expands their range to cover several cells. floor extracts the integer part, which identifies the current cell. fract extracts the repeating fractional part, resetting from zero to one in every cell; subtracting one half centers that local space. A radial distance and smoothstep draw the same soft circle in each local coordinate system. Repetition does not erase global structure: the stored cell identifier is summed and reduced modulo two to alternate colors like a checkerboard.
Try changing
Use unequal Rows and Columns and notice that each dot follows its cell proportions because the lesson stays in UV space. In a fork, correct each cell to a circle in screen pixels, replace fract(tiled) - 0.5 with fract(tiled + 0.5) - 0.5 to shift boundaries, or hash cellId to vary size and color. Draw cell borders from the absolute local coordinates.
Using it in a game
Tiled coordinates support procedural floors, grids, halftones, repeated decals, and atlas-like material logic. Mesh UV scale and texture wrapping may already perform part of this job, but retaining cell identity enables controlled per-tile variation without an external asset. Watch filtering and derivatives at discontinuous fract boundaries in detailed production materials.
Explore the techniques
Continue with curated explanations and progressively related examples.
Discussion