PV227 GPU Rendering 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 Rendering Transformation • 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! PV227 GPU Rendering 3/23 Normal Transformation Error P'2 Figure: Taken from lighthouse3d.com PV227 GPU Rendering 4/23 Normal Transformation Solution • caused by non-uniform scale, • M is the modelview matrix, Ms tangent vector (P2 - P-i) and / is identity, • we need another matrix (N) for transforming normal n. (M x t) • {N x n) = 0 (Mxt)T x (Nx n) = 0 TrxMTxNxn = 0 PV227 GPU Rendering 5/23 Normal Transformation Solution (cont.) tTxMTxNxn = 0 t*n = 0=^tTxn = O^MTxN=l MT xN= I (M7)-1 x MT x N = (Mr)~1 N= (M7)-1 PV227 GPU Rendering 6/23 Normal Transformation Result • 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 N = M. PV227 GPU Rendering 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, • ambient, diffuse and specular lighting, • flat, gouraud and phong shading, • directional, point and spot light, • no shadow, no bouncing of light. 4 □ ► 4 fi> ► 4 PV227 GPU Rendering 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 Rendering Figure: Ambient spheres □ ► *o ► < s ► < i ► i -o ► 4 PV227 GPU Rendering Gouraud Shading • per vertex shading, • interpolation of vertex colors, • unable to capture lighting details inside polygons. 4 □ ► 4 fi> ► 4 PV227 GPU Rendering Diffuse Lighting • simulate light's interaction with perfectly diffuse material, • light angle dependent, • significant color component, • / = cos(a) • Kd. Figure: Diffuse spheres PV227 GPU Rendering 13/23 Diffuse Lighting Figure: Taken from lighthouse3d.com • amount of incoming light diminishes with increasing angle, • C0S(a) = • normalized vectors: / = (£• N) ■ Kd, • all vectors must be in same space (usually defined in world space, computation in camera space). PV227 GPU Rendering 14/23 Flat Shading • per primitive shading, • no interpolation, • unable to capture smooth changes in light intensity. Figure: Flat shading PV227 GPU Rendering 15/23 Combined Lighting • light from various sources can be combined (added), • combination of ambient and diffuse prevents black areas, • 1 = Ka + cos(a) • Kd, • value should not be outside the [0.0,1.0] range. Figure: Ambient + Diffuse spheres PV227 GPU Rendering 16/23 Specular Lighting • simulate light's interaction with reflective material, • view angle dependent, • highlight of the light's color, not material color, • / = cos(/3)s • Ks, s controls size of the highlight. Figure: Specular spheres (Phong vs Blinn-Phong) PV227 GPU Rendering 17/23 Phong Lighting L *W R L \ a N a d = L|cos(a) ! Eye 3> -L Figure: Taken from lighthouse3d.com • amount of reflected light diminishes with increasing angle, • R = -L + 2-(N*L)-N, 9 cos(/3) = R • Eye, • all vectors must be in same space, normalized. PV227 GPU Rendering 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. 4 □ ► 4 fi> ► 4 PV227 GPU Rendering Basic Lighting • ambient, diffuse and specular form the baseline lighting, • 1 = Ka + cos(a) • Kd + cos(/3)s • Ks, • light from various sources can be combined (added), • value should not be outside the [0.0,1.0] range. Figure: Ambient + Diffuse + Specular pawns PV227 GPU Rendering 20/23 Phong Shading • per pixel shading, • smooth lighting including details, • interpolation of vertex attributes (normal, eye, light). Figure: Per pixel lighting pawns PV227 GPU Rendering 21/23 Point Light • light source inside the scene, • defined by a position vector (all directions), • can represent e.g. a lightbulb. Figure: Taken from lighthouse3d.com Point light pawns. PV227 GPU Rendering 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 Rendering 23/23