Video Game Dev University of insubria
Textures
Marco Tarini
Texture mapping
3D geometry (set of quadrilaterals )
+
RGB texture 2D (here: a color-map)
=
Example (color-map)
+ =
Texture maps!
One of the most common and important asset of a game
One of the most GPU RAM consumer
Texture maps: data structures
Substantially, a raster image
Texture sheet
«Texel»
Texutres (in games)
Texture sheet =
def. of a singale onto the surface (the mesh)
Similar purpose to the per-vertex attributes!
but…
# texels >> # vertices
More complex signals!
A
texel= a sample of that signal
Between samples: (bilinear) interpolation
Signal sampling:
On a regular 2D grid (raster image)
At a given resolution (NOT adaptive!)
Texture: regular sampling, and dense (easy to get detail!) Attributes: irregular samplling (adaptive), and sparse
Signals typically stored in textures (in games)
Each texel a base-color (components: R-G-B)
Texture is a “diffuse-map” / “color-map” / “RGB-map”
Each texel a transparency factor (components: α)
Texture is an “alpha-map” o “cutout-texture”
Each texel a normal (components: X-Y-Z)
Texture is a “normal-map” or “bump-map” (more later)
Each texel contains a value di specularity
Texture is a “specular-map”
Each texel contains a glossiness value
Texture is a “glossiness-map”
Each texel contains lighting baked value...
Texture is a (baked) “light-map”
Each texel contains a dist. From surface value
Texture is a “displacemnt map” o “height texture”
MIP map levels
Pre-filtering of textures
“LOD pyramid, for images”!
Hardware chooses the right level (for pixel)
Avoid subsampling artifacts
1024x1024
512x512
256x256
1x1
Texture maps as assets
Carachteristics:
Size:
resolution
channels (eg: alpha?)
MIP-map
(available of not?)
Compression?
e.g. quantized “color-map”, or specific compression schemes
Recurrent constraints:
Power of 2 for side
(requested by always fewer engines)
Both in U and V
(e.g.: 256x256 o 1024x512)
res < max
(e.g.: max = 4096 o 2048)
The majority of visual richness perceived in the typical videogame is due to textures!
Textures resolution have more impact (quality wise) than Meshes resolution!
GPU rendering of a Mesh in a nutshell
(reminder)
Load…
store all data on GPU RAM
Geometry + Attributes
Connectivity
Textures
Shaders
Parameters / Settings
…and Fire!
send the command: “do it” !
THE MESH
THE “MATERIAL”
Texture Sheet on GPU
LOAD
Life of a Texture in a Game Engine
DISK CENTRAL RAM GPU RAM
Image Object
IMPORT
Image File
(as, basically, any 3D assets)
Texture Sheets (in GPU RAM)
Rastered images, but with peculiarity …
mipmap levels
channels per texels: 1,2,3, or (usually) 4
bits per channels:
usually 8, fixed point («true-color») – or compression
resolution: powers of 2 (usually)
Texture Sheets (in GPU RAM)
During rendering:
GPU
(hardwired!)
access mechanisms to the texture :
1. Selection of the appropriate level of MIPmap (opt)
2. Decompression
3. Management of off-the-edge accesses (e.g. repeat)
4. Translation from UV coord [0,1]2
to texel coord [0..RESU -1]×[0..RESV -1]
5. Bilinear interpolation (if required)
Texture Sheets (in GPU RAM)
Special compression schemes:
quantization
(e.g. 16 bits per texel: 5 red 5 green 5 blue 1 alpha)
color-table (or “palette”)
(e.g. 256 color table, an 8 bit index per texel)
Special scheme for texture
(because they need to allow random accessibility of texture!)
Very lossy,
Low efficiency of the compression rate, and fixed rate!
Most diffuse scheme S3TC, witch variants
DXT1
DXT2
DXT3
DXT4
DXT5
(different trade-off between quality, cost, channels…)
“no / 1-bit alpha”
“rough alpha”
“smooth alpha ”
Texture Sheets:
files format
For generic images:
.JPG /.JPEG
lossy,
Good compression rate
“photographic” images: best
only 3 channels (no choice)
8 bit per channel (no choice)
.PNG
lossless
< compression ratio
drawings: best
alpha channel also possible
16bits also possible
.TIFF e.RAW (rare)
Specialized for textures:
(most used option)
.DDS
(«direct draw surface») same format used in GPU.
Thus:
includes MIPmap levels (if wanted)
compression: very lossy And bad compression rate (and fixed)
GPU ready!
Texture maps as assets:
file formats
For generic images
(decompress the entire image to access the pixels)
compression: excellent
loading: heavy:
Decompress from RAM, (maybe) recompress in GPU-RAM
MIP-map lvls:
Controlled by the engine
Specialized for textures
(random accessibility to texels, without decompressing the entire image)
compression: bad
loading: light
direct copy Disc => RAM =>
GPU RAM
MIP-map lvls:
Controlled by the artist
Texture maps assets and Mesh assets
Several texture «sheets» associated to a mesh
or also: more meshes on the same sheet (bene)
Typical structure :
each meshassociated to a material
each material:
1 sheet di diffuse-map
1 sheet bumpmap (if needed)
1 sheet di alphamap (if needed)
1 vertex shaders + fragment shader
Several parameters
(e.g., shininess, …)
If different parts of mesh associated to different textures: decompose the object in sub-mesh
Texture maps assets and Mesh assets
Not necessarly 1:1
1:N -- several textures «sheets» associated to a mesh
N:1 – more meshes on the same sheet (goof)
If different part of mesh associated to different textures: decompose the object into sub-mesh
MATERIAL MESH A
B MESH
A
TEXTURE 1 BUMPMAP
TEXTURE 2 COLORMAP
How is the texture
mapped into the surface
of a mesh?
3D Models i.e. tri-meshes with:
per vertex attrib
normals, color, AO, …
LODs
uv-mapping
keyframes
cyclic animations
face-morphs, …
“skinning”
Materials
lighting model stats / flags
textures
RGB maps
normal maps
alpha maps …
shaders
vertex, fragments, …
The 3D part of game assets
Animations
blend shapes
skeletal animations
kinematic animations
geometry caches
skeletons (rigs)
Geometric proxies
hit-boxes
bounding objects
AI-meshes
Particle systems
Environments
3d scenes
skydomes
env. maps
scene props
UV-Mapping of a mesh
A mapping : mesh surface 2D texture space is needed
«parametrization» of the surface
Idea: store this mapping as attribute: (s,t) per vertex
The «u-v mapping» of the mesh (u,v) == (s,t)
[0..1]
2Modeling task:
“u-v mapping” construction
Texture “atlas”
(composed of several “charts”)
u
v
UV mapping:
example
…
u
N = A
A B C N
M C M