Principles of Computer Graphics and Image Processing Shading and Lighting (04) RNDr. Martin Madaras, PhD. martin.madaras@stuba.sk
Overview Direct Illumination Emission at light sources Scattering at surfaces Gouraud shading Global Illumination Shadows Refractions Inter-object reflections 2
How the lectures should look like #1 Ask questions, please!!! - Be communicative - www.slido.com #PPGSO04 - More active you are, the better for you! - 3
Overview 𝐽 𝑀 (𝑦, 𝑧, 𝑨, 𝜄, 𝜒, 𝜇) describes intensity of energy, leaving a light source, ... arriving at location (x,y,z), ... from direction ( θ,φ), ... with wavelength λ 4
Light Source types Omnidirectional Spotlight Area Directional Object - what are the differences? 5
Light Source Models Simple mathematical models OpenGL support Point light Directional light Spot light 6
Point Light Source Models omni-directional source intensity (𝐽 0 ), position (𝑦, 𝑧, 𝑨), factors (𝑙 𝑑 , 𝑙 𝑚 , 𝑙 𝑟 ) for attenuation with distance (𝑒) 7
Directional Light Source Models point light source at infinity intensity (𝐽 0 ), direction (𝑒𝑦, 𝑒𝑧, 𝑒𝑨), no attenuation with distance 8
Spot Light Source Models point light source with direction intensity (𝐽 0 ), position (𝑦, 𝑧, 𝑨) , direction (𝑒) , attenuation 𝑙 𝑑 , 𝑙 𝑚 , 𝑙 𝑟 . 9
Overview Direct Illumination Emission at light sources Scattering at surfaces Gouraud shading Global Illumination Shadows Refractions Inter-object reflections 10
Elementary theory Light-surface interaction Reflection Refraction Snell’s law Surface normal vector Real world is a bit different 11
Surface types Reflective Diffuse – Lambertian Both 12
Surface types Mirror Matte directional indirectional component component 13
Light models Empiric – e.g. Phong lighting model cheap computation physically incorrect visually plausible Physically-based energy transfer, light propagation closer to real-world physics expensive 14
Local illumination models Fast but inaccurate Empirical (no physical background) Many physical effects are impossible to achieve Computer games, real-time rendering 15
Modeling Surface Reflectance Rs( θ,φ,γ,ψ,λ) ... describes the amount of incident energy, ... arriving from direction ( θ , φ ), ... leaving in direction ( γ , ψ ), ... with wavelength λ 16
OpenGL Reflectance Model Simple empirical model: diffuse reflection + specular reflection + emission + “ambient” Bui Tuong Phong, 1973 17
OpenGL Reflectance Model Simple empirical model: diffuse reflection + specular reflection + emission + “ambient” 18
Diffuse Reflection Assume surface reflects equally in all directions Examples: chalk, clay 19
Diffuse Reflection How is light reflected ? Depends on an angle of incident light 20
Diffuse Reflection How is light reflected ? Depends on an angle of incident light 21
Diffuse Reflection Lambertian model cosine law (dot product) 22
OpenGL Reflectance Model Simple empirical model: diffuse reflection + specular reflection + emission + “ambient” 23
Specular Reflection Reflection is strongest near mirror angle Examples: Mirrors, Metals 24
Specular Reflection How much light is seen ? Depends on: angle of incident light angle of viewer 25
Specular Reflection Phong Model cos( α )n This is a physically motivated hack! 26
OpenGL Reflectance Model Simple empirical model: diffuse reflection + specular reflection + emission + “ambient” 27
Emission Represents light emitted directly from surface 28
OpenGL Reflectance Model Simple empirical model: diffuse reflection + specular reflection + emission + “ ambient ” 29
Ambient term Represents reflection of all indirect illumination This is a total hack (avoids complexity of global illumination)! 30
OpenGL Reflectance Model Simple empirical model: diffuse reflection + specular reflection + emission + “ ambient ” 31
OpenGL Reflectance Model Simple empirical model: diffuse reflection + specular reflection + emission + “ ambient ” 32
OpenGL Reflectance Model Simple empirical model: diffuse reflection + specular reflection + emission + “ ambient ” 33
Diffuse light 34
Ambient light 35
Diffuse + Ambient light 36
Specular + Diffuse + Ambient light 37
Phong lighting model Ambient + Diffuse + Specular components without ambient with ambient Simulates global light scattered in the scene and reflected from other objects 38
Other lighting models Blinn-Phong generalization of Phong’s model Cook-Torrance microfacets Oren-Nayar rough surfaces Anisotropic microfacet distribution 39
Direct Illumination Single light source example 40
Direct Illumination Multiple light source example 41
3D rendering pipeline 3D polygons Modeling 1 Transformation Lighting Viewing Transformation Projection Transformation Clipping Scan Conversion Draw pixels 2D Image 42
Ray Casting Independent lighting calculation for each pixel Computationally expensive 43
Polygon Shading • Can take advantage of spatial coherence Illumination calculations of pixels of a triangle are related Scanline rasterization 44
Surface normal vector Perpendicular to the surface at the point Computation: Usually from tangent vectors = Vector cross product n u v Depends on the object representation n v u Vector n = ˆ normalization n n 45
Tangent vectors Parametric representation X = x(u,v) Y = y(u,v) Z = z(u,v) Partial derivation by u , v → vectors t u, t v Polygonal representation Tangent vectors are edge vectors Mind the orientation! 46
Overview Global Illumination Shadows Refractions Inter-object reflections Shading Flat Gouraud Phong 47
Flat Shading Fill triangles using single calculated color 48
Flat Shading One Illumination calculation per polygon Assign all pixels of each polygon the same color 49
Flat Shading Objects look like they are composed of polygons Ok for polyhedral objects Not so good for smooth surfaces 50
Gouraud Shading One lighting calculation per vertex Assign pixels inside polygon by interpolating colors computed at vertices 51
Gouraud Shading Bilinearly interpolate colors of triangle across scan line 52
Gouraud Shading Smooth shading over adjacent polygons Curved surfaces Illumination highlights Produces smoothly shaded polygonal mesh Fast linear approximation Needs fine mesh to capture subtle lighting effects 53
Gouraud Shading 54
Phong Shading NOT Phong lighting model One lighting calculation per pixel Approximate surface normals inside polygon using bilinear interpolation of normals from vertices 55
Phong Shading Bilinearly interpolate surface normals at vertices down and across scan lines 56
Polygon Shading Algorithms 57
Example: Wireframe scene 58
Example: Ambient only 59
Example: Flat shading with Diffuse 60
Example: Gouraud shading with Diffuse 61
Example: Gouraud shading with Specular 62
Example: Phong shading with Specular 63
Shading Issues Problems with interpolated shading Problems computing shared vertex normals Perspective distortion Problems at T -vertices 64
Shading Benefits Good performance and quality of output Excellent for hardware Works well with subdivision surfaces 65
How the lectures should look like #2 Ask questions, please!!! - Be communicative - www.slido.com #PPGSO04 - More active you are, the better for you! - 66
Overview Advanced Shading and Mapping Deferred Shading Shadow Mapping Normal Mapping Displacement Mapping Vector Displacement Mapping 67
Deferred Shading Compute Lighting in Screen-Space Two pass approach Decoupling of geometry and lighting G- Buffer stores positions, normals, materials … Lighting is a per-pixel operation Problems with transparency and G-buffer size O(objects+lights) 68
Deferred Shading Diffuse Color Z Buffer Surface Normals Final Composition 69
Recommend
More recommend