PV227 GPU programming Marek Vinkler Department of Computer Graphics and Design Points and vectors • points (before projection) are quadruples: (x, y, z, 1.0), • can be transformed with a 4 x 4 matrix, • vectors are also quadruples: (x, y, z, 0.0), • can be transformed with a4x4or3x3 matrix. 4 □ ► 4 fi> ► 4 PV227 GPU programming Normal transformation a points are transformed to eye space with modelview matrix, • vectors constructed from points (e.g. P2 - Pi) are also transformed with this matrix, • normals are not! Normal transformation Normal transformation • caused by non-uniform scale, • we need another matrix (N) for transforming normal n, • M is the modelview matrix, Ms tangent vector P2 - and / is identity. (M x t) ■ {N x n) = 0 (Mxt)T x (Nx n) = 0 TrxMTxNxn = 0 PV227 GPU programming 5/23 Normal transformation tTxMTxNxn = 0 t-n = 0^tTxn = O^MTxN=l MT x N= I (M7)-1 x MT x N = (Mr)~1 N= (M7)-1 PV227 GPU programming 6/23 Normal transformation a N is inverse transpose of M (3 x 3 submatrix of M), • for orthogonal matrices AT = A~1, rotation is orthogonal, • M is orthogonal M = (M7) 1 A/ = M. Renormalization • normals must be of unit length, • can be destroyed by normal transformation ->• must be normalized in vertex shader, • interpolation can also destroy vector length ->- must be normalized in fragment shader. Figure: Taken from lighthouse3d.com Lighting • computation of light's interaction with surfaces, • huge cheat, a ambient, diffuse and specular light, • flat, gouraud and phong lighting, • directional, point and spot light, • no shadow, no bouncing of light. Ambient lighting • approximates lighting after infinite number of bounces, • homogeneous, • prevents black areas that look unnatural, • usually chosen as fraction of the diffuse (material) color, • l = Ka. PV227 GPU programming Figure: Ambient spheres □ ► *o ► < s ► < i ► i -o -L Figure: Taken from lighthouse3d.com • amount of reflected light diminishes with increasing angle, • R = -L + 2(N-L) x N, • cos(/3) = R ■ Eye, • all vectors must be in same space, normalized. PV227 GPU programming 18/23 Blinn-Phong lighting Figure: Taken from lighthouse3d.com • amount of reflected light diminishes with increasing angle, • H = L + Eye, • cos(/3) = H ■ N, • all vectors must be in same space, normalized. PV227 GPU programming Combined lighting • light from various sources can be combined (added), • ambient, diffuse and specular form the baseline lighting, • l = Ka + cos(a) x Kd + cos(/3)s x Ks, • value should not be outside the [0.0,1.0] range. Figure: Ambient + Diffuse + Specular pawns Phong shading • per pixel lighting, • smooth lighting including details, • interpolation of vertex attributes (normal, eye, light). Figure: Per pixel lighting pawns Point light • light source inside the scene, • defined by a position vector (all directions), • can represent e.g. a lightbulb. Figure: Point light pawns, Taken from lighthouse3d.com PV227 GPU programming 22/23 Spot light • light source inside the scene, • only a directed cone is illuminated, • defined by a position vector, direction vector and angle, • can represent e.g. a flashlight. Figure: Spot light pawns PV227 GPU programming 23/23