🍩 Donut A: UV Image Textures

Drag to rotate, wheel to zoom

← Home → Demo B: Procedural

Controls

Raise the tiling and switch the filter to Nearest: the dough shimmers and aliases when texels are smaller than a pixel. Mipmap removes it.

UV Unwrap

Flat texture space. Right = u (around the ring), down = v (around the tube). The grid shows 8x4 UV cells; the icing sits near the top band (v around 0.25).

Theory: UV Mapping

P(u,v) = ( (R + r·cosφ)·cosθ, r·sinφ, (R + r·cosφ)·sinθ ) θ = 2πu φ = 2πv R = 0.7 r = 0.3 Each vertex stores (u,v). The rasterizer interpolates it per pixel, and the fragment shader looks up the color: vec4 c = texture(uIcing, vUV);

Theory: Filtering & Mipmaps

ρ = texels covered by one screen pixel level λ = log2(ρ) NEAREST : closest texel, blocky, aliases when minified LINEAR : blend 4 texels (bilinear) MIPMAP : blend 2 levels of a pre-shrunk chain (trilinear) A mip chain costs 1/3 extra memory: 1 + 1/4 + 1/16 + ... = 4/3

Theory: Layering with Alpha

albedo = mix(dough, icing.rgb, icing.a) albedo = mix(albedo, chocolate.rgb, chocolate.a) mix(a,b,t) = a·(1-t) + b·t The alpha channel of the icing texture is the drip mask.

Theory: Normal Mapping

n = texture(uNormalMap, uv).xyz · 2 - 1 (decode 0..1 to -1..1) T = dP/du (tangent, stored per vertex) B = cross(T, N) N' = normalize( mat3(T,B,N) · n ) The map stores bumps in tangent space, so it follows the curved surface. Lighting then uses N' instead of N.

Theory: Lighting

color = (0.3 + max(N·L, 0))·albedo + k·(N·H)^s Icing and chocolate use a higher s (64) than dough (8).