Status – Week 277
Victor Moya
Lightning
Diffuse Lightning.
Light Sources.
Specular Lightning.
Emission.
Gouraud Shading.
Phong Shading.
Bump Mapping.
OpenGL Lightning.
Light Sources
Ambient Light.
Directional Light Sources
Infinite light source (parallel rays).
No attenuation.
Point Light Sources.
1
C
All directions.
Kc Kl Kq d 2
Attenuation.
Spot Light Sources.
max{ UL,0}
Cone of light.
C
2
K
c
K
l
K
qd
Attenuation.
Kc, Kl and Kq are constant, linear and quadratic attenuation values.
U: Direction of the spot light.
L: Unit direction vector from surface point to light spot.
Diffuse Lighting
n
Kdiffuse DTA DT Ci max{ NLi ,0}
i 1
A: Ambient light
T: Texture sample.
D: Surface diffuse reflection color.
Ci: Intensity of the i light at the surface point.
N: Normal vector of the surface.
Li: Unit direction vector to the light source I.
Specular Lighting
n
Kspecular SG Ci max{ NHi,0}
i 1
S: Surface specular color.
Ci: Intensity of the incident light.
m: specular exponent (larger, sharper hightlight).
G: Gloss map sample.
N: Normal vector at the surface.
L: Unit direction to light vector.
Hi: Halfway vector (V + L).
V: Unit direction to viewer vector.
m
( NL 0 )
Emission
Kemission = EM
E: Surface emission color.
M: Emission map sample.
Gouraud Shading
Lighting is calculated at each vertex and
interpolated across the triangle.
n
Kprimary E DA D Ci max{ NLi ,0}
n
i 1
Ksecondary S Ci max{ NHi,0}
m
( NL 0 )
i 1
K = Kprimary * T1 * T2 * ... * Tk + Ksecondary
Ti : Color samples for one of k texture maps.
* : One of several available texture combination operations
Phong Shading
Interpolate vertex normals and evaluates the lighting
formula at each pixel.
K = Kemission + Kdiffuse + Kspecular
Problem: interpolation of normals produce non unit
vectors. Use normalization cube maps.
Flat, Gouraud and Phong Shading
Bump Mapping
A hardware implementation of Phong
Shading.
Uses a texture map to perturb the normal
vector at each pixel (not interpolated).
Bump Map: 2D arrays of 3D vectors. Direction
of the normal vector relative to the
interpolated normal vector at the pixel.
Uses tangent space for storing the
perturbations. Object to tanget space
transformation (3x3 matrix multiplication).
Bump Mapping
OpenGL Lighting
Calculated at vertex, interpolated inside
the triangle (Gouraud).
Bump mapping supported by propietary
extensions.
Pixel Shaders for programmable per
pixel lighting.
OpenGL Lighting
OpenGL Lighting
OpenGL Lighting
Hardware Pipeline
Command Processor.
Vertex Shader.
Rasterization.
Pixel Shader.
Fragment Operations and Tests.
vertex data (16x4D):
1 pos
1 weight
1 normal
2 colors
1 fog coord
8 texture coords
Vertex Output (15x4D):
1 Homogeneous pos
4 colors
1 fog coord
1 point size
8 texture coord
Fragment 10x4D)
2 colors
8 texture coords
Fragment Output (10x4D)
1 color
1 depth coordinate
Fragment Coords
Fragment Coords
Framebuffer
Fragment
Operations
and Tests
Pixel
Shader
Rasterization
Vertex
Shader
Command
Processor
CPU
Memory
OGLState
Vertex Program
and Constants
OGLState
Fragment
Program and Texture
Memory
Constants
OGLState
Color Buffer
ZBuffer
Stencil Buffer
Command Processor
Recieves commands from the CPU
(driver, OpenGL/Direct3D).
Fetches data from memory: vertex data
(DMA).
Updates and stores OpenGL/Direct3D
render state.
Vertex Shader
Transforms and lits vertex streams.
Vertex shader program (from GPU
memory?).
Vertex shader constans (from GPU
memory?).
Inputs: vertex data 16x4D
Outputs: vertex data 14x4D
Rasterization
Includes:
Clipping
Divide by w
Affine transform
Primitive assembly
Culling
Setup
Fragment generation.
Recieves vertexs and produces fragments.
Uses OpenGL/Direct3D render state.
Input: vertex (15x4D).
Output: fragments (10x4D).
Pixel Shader
Shades fragments: calculate texture address,
read texture, color operations.
Pixel Shader program and constants (from
GPU memory?).
Texture read: TMU (texture sample, filter
unit, texture cache, GPU memory).
Optional:
Modify depth coordinate (1 Z output).
Render to texture (up to 4 colors outputs).
Input: fragment (12x4D).
Output: color (2x4D).
Fragment Operations and Tests
Includes (OpenGL):
Fog.
Color Sum.
Ownership Test.
Scissor Test.
Alpha Test.
Stencil Test.
Depth Test.
Blend.
Logic Operation.
Accesses framebuffer (GPU memory). Updates framebuffer.
Framebuffer: color, Z and stencil.
OpenGL/Direct3D render state defines operations.
Input: color.
Output: FB updated.
Others
Antialiasing
Anisotropic Filtering (textures).
Line Antialiasing.
Edge Antialiasing
Full Screen Antialiasing (FSAA):
Supersampling.
MultiSampling.
TBDR: Tile Based Deferred Rendering (STMicro PowerVR).
HOS (High Order Surfaces): N-Patches, Bezier, Displacement
Mapping, TruForm, Tesselation.
© Copyright 2026 Paperzz