On this page
Introduction
A texture is a picture the shader can ask questions to. You point at a spot with two numbers, and it answers with a color. That single act, sampling a texture, is the foundation of everything in this category, from a simple base color all the way to fake rooms and screen space tricks.
// The whole relationship, in three words:
float2 uv = IN.uv; // where to look
half4 tex = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv); // the answer
half3 color = _BaseColor.rgb * tex.rgb; // what you do with it
A texture is a 2D lookup table¶
A texture is a grid of pixels, called texels. Each texel stores a small set of numbers, usually one or more color channels. When your fragment shader runs, it can ask for the value at any point in that grid, and the GPU returns it. The question is a two-dimensional coordinate, the UV, and the answer is a color. Every effect you will ever make with textures, scrolling, blending, dissolving, faking depth, is a variation on the same idea: decide which coordinate to ask with, and then decide what to do with the answer.
That framing is the entire mental model of this category. Most texture work is not about the sampling itself, which is one line of code. It is about where the UV comes from and how it changes. UVs come from the mesh, from object space, from the screen, from the view direction, or from pure math. And they change with tiling, rotation, time, noise, or a radial push. Once you see that the coordinate is the ingredient, the category organizes itself.
How the category is organized¶
Basics is where the texture itself lives. What color data means, what a UV actually is, how sampling and tinting work, how the GPU filters the result, and the special texture types you will meet, arrays, cubemaps, normal maps, shadow maps. If you are new to textures, start there and read in order.
Projections is about inventing UVs. Instead of trusting the UVs the artist painted, you generate coordinates from other data you already have: object position, world position, the screen, the sprite, or the view direction. This is where techniques like tri-planar mapping, polar coordinates, billboarding, and parallax live, and it is where a lot of the visual magic happens.
Time is about animation. Textures are usually still, so moving the UV over time is the main way to bring them to life: scrolling, blending between two maps, dissolving. Time also brings one trap, precision loss in long sessions, which gets its own chapter.
Where textures fit in the pipeline¶
The mesh hands you a UV per vertex, the rasterizer interpolates it across the triangle, and your fragment stage uses it to sample. If you have not yet seen how mesh attributes travel to the fragment stage, read Mesh Data. If you want to know where the fragment stage sits inside a frame, read The Render Pipeline.
🔗 Related Chapters¶
Mesh Data • The Render Pipeline • Coordinate Spaces
Related functions: Lerp • Frac
❤️ 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.