CPSC 314 LIGHTING AND SHADING

Similar documents
Lighting/Shading III. Week 7, Wed Mar 3

University of British Columbia CPSC 314 Computer Graphics Sep-Dec Tamara Munzner (guest lecturing) Lighting/Shading

Lighting/Shading II. Week 7, Mon Mar 1

CS5620 Intro to Computer Graphics

Today. Global illumination. Shading. Interactive applications. Rendering pipeline. Computergrafik. Shading Introduction Local shading models

Today. Global illumination. Shading. Interactive applications. Rendering pipeline. Computergrafik. Shading Introduction Local shading models

Topic 9: Lighting & Reflection models. Lighting & reflection The Phong reflection model diffuse component ambient component specular component

Illumination Models & Shading

Computer Graphics. Illumination and Shading

Topic 9: Lighting & Reflection models 9/10/2016. Spot the differences. Terminology. Two Components of Illumination. Ambient Light Source

Illumination & Shading: Part 1

Computer Graphics. Illumination and Shading

CSE 167: Introduction to Computer Graphics Lecture #6: Lights. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2016

w Foley, Section16.1 Reading

CPSC / Illumination and Shading

Illumination and Shading

Computer Graphics. Shading. Based on slides by Dianna Xu, Bryn Mawr College

Computer Graphics (CS 543) Lecture 7b: Intro to lighting, Shading and Materials + Phong Lighting Model

Computer Graphics (CS 4731) Lecture 16: Lighting, Shading and Materials (Part 1)

Illumination and Shading

OpenGl Pipeline. triangles, lines, points, images. Per-vertex ops. Primitive assembly. Texturing. Rasterization. Per-fragment ops.

Reading. Shading. An abundance of photons. Introduction. Required: Angel , 6.5, Optional: Angel 6.4 OpenGL red book, chapter 5.

CMSC427 Shading Intro. Credit: slides from Dr. Zwicker

Illumination & Shading

Recollection. Models Pixels. Model transformation Viewport transformation Clipping Rasterization Texturing + Lights & shadows

Shading. Brian Curless CSE 457 Spring 2017

CSE 167: Lecture #7: Color and Shading. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

Reading. Shading. Introduction. An abundance of photons. Required: Angel , Optional: OpenGL red book, chapter 5.

ECS 175 COMPUTER GRAPHICS. Ken Joy.! Winter 2014

Lighting and Shading

CS Illumination and Shading. Slide 1

Illumination in Computer Graphics

Objectives. Introduce Phong model Introduce modified Phong model Consider computation of required vectors Discuss polygonal shading.

Comp 410/510 Computer Graphics. Spring Shading

Shading I Computer Graphics I, Fall 2008

CS770/870 Spring 2017 Color and Shading

Reflection and Shading

Shading. Brian Curless CSE 557 Autumn 2017

CS 325 Computer Graphics

Shading 1: basics Christian Miller CS Fall 2011

Sung-Eui Yoon ( 윤성의 )

Shading, Advanced Rendering. Week 7, Wed Feb 28

Lecture 15: Shading-I. CITS3003 Graphics & Animation

Introduction to Computer Graphics 7. Shading

Illumination and Shading

Local Illumination. CMPT 361 Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller

Rendering. Illumination Model. Wireframe rendering simple, ambiguous Color filling flat without any 3D information

Simple Lighting/Illumination Models

Visualisatie BMT. Rendering. Arjan Kok

Shading. Reading. Pinhole camera. Basic 3D graphics. Brian Curless CSE 557 Fall Required: Shirley, Chapter 10

Lighting affects appearance

Computer Graphics. Illumination Models and Surface-Rendering Methods. Somsak Walairacht, Computer Engineering, KMITL

Introduction Rasterization Z-buffering Shading. Graphics 2012/2013, 4th quarter. Lecture 09: graphics pipeline (rasterization and shading)

Complex Shading Algorithms

Shading and Illumination

Introduction to Computer Graphics. Farhana Bandukwala, PhD Lecture 14: Light Interacting with Surfaces

Introduction. Lighting model Light reflection model Local illumination model Reflectance model BRDF

Chapter 10. Surface-Rendering Methods. Somsak Walairacht, Computer Engineering, KMITL

Today s class. Simple shadows Shading Lighting in OpenGL. Informationsteknologi. Wednesday, November 21, 2007 Computer Graphics - Class 10 1

S U N G - E U I YO O N, K A I S T R E N D E R I N G F R E E LY A VA I L A B L E O N T H E I N T E R N E T

CSE 681 Illumination and Phong Shading

CSE 167: Introduction to Computer Graphics Lecture #6: Colors. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2013

CS 4600 Fall Utah School of Computing

Interpolation using scanline algorithm

Rendering: Reality. Eye acts as pinhole camera. Photons from light hit objects

CS 5625 Lec 2: Shading Models

surface: reflectance transparency, opacity, translucency orientation illumination: location intensity wavelength point-source, diffuse source

Interactive Real-Time Raycasting

WHY WE NEED SHADING. Suppose we build a model of a sphere using many polygons and color it with glcolor. We get something like.

Pipeline Operations. CS 4620 Lecture 10

Shading. Why we need shading. Scattering. Shading. Objectives

CS130 : Computer Graphics Lecture 8: Lighting and Shading. Tamar Shinar Computer Science & Engineering UC Riverside

Scan Conversion- Polygons

Mach band effect. The Mach band effect increases the visual unpleasant representation of curved surface using flat shading.

Today we will start to look at illumination models in computer graphics

Overview. Shading. Shading. Why we need shading. Shading Light-material interactions Phong model Shading polygons Shading in OpenGL

Pipeline Operations. CS 4620 Lecture 14

Raytracing. COSC 4328/5327 Scott A. King

Turn on the Lights: Reflectance

Raytracing CS148 AS3. Due :59pm PDT

Orthogonal Projection Matrices. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Illumination and Shading

Shading. CSE 457 Winter 2015

CMSC427 Advanced shading getting global illumination by local methods. Credit: slides Prof. Zwicker

Lighting/Shading I, II, III. Week 3, Tue May 24

Introduction to Visualization and Computer Graphics

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

How do we draw a picture?

Three-Dimensional Graphics V. Guoying Zhao 1 / 55

Shading. Brian Curless CSE 457 Spring 2015

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

Computer Vision Systems. Viewing Systems Projections Illuminations Rendering Culling and Clipping Implementations

Illumination & Shading

Illumination. Illumination CMSC 435/634

Lighting affects appearance

CEng 477 Introduction to Computer Graphics Fall

Rendering Light Reflection Models

Lessons Learned from HW4. Shading. Objectives. Why we need shading. Shading. Scattering

Homework #2. Shading, Ray Tracing, and Texture Mapping

CS452/552; EE465/505. Intro to Lighting

Transcription:

CPSC 314 LIGHTING AND SHADING UGRAD.CS.UBC.CA/~CS314 slide credits: Mikhail Bessmeltsev et al 1

THE RENDERING PIPELINE Vertices and attributes Vertex Shader Modelview transform Per-vertex attributes Vertex Post-Processing Viewport transform Clipping Rasterization Scan conversion Interpolation Fragment Shader Texturing/... Lighting/shading Per-Sample Operations Depth test Framebuffer Blending 2

LIGHTING/SHADING Goal Model the interaction of light with surfaces to render realistic images Generate per (pixel/vertex) color 3

FACTORS Light sources Location, type & color Surface materials How surfaces reflect light Transport of light How light moves in a scene Viewer position 4

FACTORS Light sources Location, type & color Surface materials How surfaces reflect light Transport of light How light moves in a scene Viewer position How can we do this in the pipeline? 5

ILLUMINATION MODELS/ALGORITHMS Local illumination - Fast Ignore real physics, approximate the look Interaction of each object with light Compute on surface (light to viewer) Global illumination Slow Physically based Interactions between objects 6

THE BIG PICTURE (BASIC) Light: energy in a range of wavelengths White light all wavelengths Colored (e.g. red) subset of wavelengths Surface color reflected wavelength White reflects all lengths Black absorbs everything Colored (e.g. red) absorbs all but the reflected color Multiple light sources add (energy sums) 7

MATERIALS Surface reflectance: Illuminate surface point with a ray of light from different directions How much light is reflected in each direction? 8

BASIC TYPES 9

REFLECTANCE DISTRIBUTION MODEL Most surfaces exhibit complex reflectances Vary with incident and reflected directions. Model with combination known as BRDF BRDF: Bidirectional Reflectance Distribution Function + + = 10

BRDF MEASUREMENTS/PLOTS 2D slice 11

SURFACE ROUGHNESS at a microscopic scale, all real surfaces are rough cast shadows on themselves mask reflected light: shadow shadow Masked Light 12

SURFACE ROUGHNESS notice another effect of roughness: each microfacet is treated as a perfect mirror. incident light reflected in different directions by different facets. end result is mixed reflectance. smoother surfaces are more specular or glossy. random distribution of facet normals results in diffuse reflectance. 13

PHYSICS OF DIFFUSE REFLECTION ideal diffuse reflection very rough surface at the microscopic level real-world example: chalk microscopic variations mean incoming ray of light equally likely to be reflected in any direction over the hemisphere what does the reflected intensity depend on? 14

LAMBERT S COSINE LAW ideal diffuse surface reflection the energy reflected by a small portion of a surface from a light source in a given direction is proportional to the cosine of the angle between that direction and the surface normal reflected intensity independent of viewing direction depends on surface orientation wrt light often called Lambertian surfaces 15

DIFFUSE (LAMBERT) Intuitively: cross-sectional area of the beam intersecting an element of surface area is smaller for greater angles with the normal. 16

COMPUTING DIFFUSE REFLECTION Depends on angle of incidence: angle between surface normal and incoming light I diffuse = k d I light cos θ In practice use vector arithmetic I diffuse = k d I light (n l) l θ n Scalar (B/W intensity) or 3-tuple (color) k d : diffuse coefficient, surface color I light : incoming light intensity I diffuse : outgoing light intensity (for diffuse reflection) NB: Always normalize vectors used in lighting!! n, l should be unit vectors 17

DIFFUSE LIGHTING EXAMPLES Lambertian sphere from several lighting angles: need only consider angles from 0 to 90 18

DIFFUSE INTERREFLECTION 19

SPECULAR HIGHLIGHTS Michiel van de Panne 20

PHYSICS OF SPECULAR REFLECTION Geometry of specular (perfect mirror) reflection Snell s law special case: Law of Reflection n l (n l)n r = -l+2(n l)n α α -l 21

PHYSICS OF SPECULAR REFLECTION Geometry of specular (perfect mirror) reflection Snell s law special case: Law of Reflection In GLSL: use reflect(-l,n) n l (n l)n r = -l+2(n l)n α α -l 22

CALCULATING R VECTOR P = N cos θ L N projection of L onto N P = N cos θ L, N are unit length P = N ( N L ) 2 P = R + L 2 P L = R 2 (N ( N L )) - L = R L N θ P P L R 23

EMPIRICAL APPROXIMATION Snell s law = perfect mirror-like surfaces But.. few surfaces exhibit perfect specularity Gaze and reflection directions never EXACTLY coincide Expect most reflected light to travel in direction predicted by Snell s Law But some light may be reflected in a direction slightly off the ideal reflected ray As angle from ideal reflected ray increases, we expect less light to be reflected 24

EMPIRICAL APPROXIMATION Angular falloff How to model this falloff? 25

PHONG LIGHTING Most common lighting model in computer graphics (Phong Bui-Tuong, 1975) I specular = k s I light (cosφ) n s I specular = k s I light (v r) n s ϕ: angle between r and view direction v n s : purely empirical constant, varies rate of falloff k s : specular coefficient, highlight color no physical basis, plastic look 26 reminder: normalize all vectors: n,l,r,v v

PHONG EXAMPLES varying light position varying n s 27

ALTERNATIVE MODEL Blinn-Phong model (Jim Blinn, 1977) Variation with better physical interpretation h: halfway vector; r: roughness I specular = ks light 1/ r ( h n) I ; with h = ( l + v) / 2 l h n v α α 28

Light is linear If multiple rays illuminate the surface point the result is just the sum of the individual reflections for each ray MULTIPLE LIGHTS ) ) ( ) ( ( n p s p d p p v r k l n k I + 29

AMBIENT LIGHT Non-directional light environment light Object illuminated with same light everywhere Looks like silhouette Illumination equation I = I a k a I a - ambient light intensity - fraction of this light reflected from surface k a 30

LIGHT SOURCES ambient lights no identifiable source or direction hack for replacing true global illumination (diffuse interreflection: light bouncing off from other objects) 31

ILLUMINATION EQUATION (PHONG) If we take the previous formula and add ambient component: I a k a + I p (k d (n l p )+ k s (r p v) n ) p 32

LIGHT Light has color Interacts with object color (r,g,b) I = I k, I, I, k, I, I, k Blue light on white surface? Blue light on red surface? I k I a a a = ( I = ( k = ( I r a ar ar g ag ag b ) ab ab ) ) = ( I ar k ar, I ag k ag, I ab k ab ) 33

LIGHT AND MATERIAL SPECIFICATION Light source: amount of RGB light emitted value = intensity per channel e.g., (1.0,0.5,0.5) every light source emits ambient, diffuse, and specular light Materials: amount of RGB light reflected value represents percentage reflected e.g., (0.0,1.0,0.5) Interaction: multiply components Red light (1,0,0) x green surface (0,1,0) = black (0,0,0) 34

WHITEBOARD EXAMPLE 35

WHITEBOARD EXAMPLE 36

LIGHT SOURCE TYPES Point Light light originates at a point Directional Light (point light at infinity) light rays are parallel Rays hit a planar surface at identical angles Spot Light point light with limited angles 37

LIGHT SOURCE TYPES Point Light light originates at a point defined by location only Directional Light (point light at infinity) light rays are parallel Rays hit a planar surface at identical angles defined by direction only Spot Light point light with limited angles defined by location, direction, and angle range 38

LIGHT SOURCES area lights light sources with a finite area more realistic model of many light sources much more complex! 39

WHICH LIGHTS/MATERIALS ARE USED HERE? 40

LIGHT SOURCE FALLOFF Quadratic falloff (point- and spot lights) Brightness of objects depends on power per unit area that hits the object The power per unit area for a point or spot light decreases quadratically with distance Area 4πr 2 Area 4π(2r) 2 41

For multiple light sources: - distance between surface and light source + distance between surface and viewer, A attenuation function ILLUMINATION EQUATION WITH ATTENUATION ) ) ( ) ( ( ) ( n p s p d p p p a a v r k l n k d A I k I I + + = d p 42

WHEN TO APPLY LIGHTING MODEL? per polygon flat shading per vertex Gouraud shading per pixel per pixel lighting Phong shading Image Intergraph Computer Systems 43

LIGHTING VS. SHADING lighting process of computing the luminous intensity (i.e., outgoing light) at a particular 3-D point, usually on a surface shading the process of assigning colors to pixels (why the distinction?) 44

APPLYING ILLUMINATION we now have an illumination model for a point on a surface if surface defined as mesh of polygonal facets, which points should we use? fairly expensive calculation several possible answers, each with different implications for visual quality of result 45

APPLYING ILLUMINATION polygonal/triangular models each facet has a constant surface normal if light is directional, diffuse reflectance is constant across the facet why? 46

FLAT SHADING simplest approach calculates illumination at a single point for each polygon obviously inaccurate for smooth surfaces 47

FLAT SHADING APPROXIMATIONS if an object really is faceted, is this accurate? no! for point sources, the direction to light varies across the facet for specular reflectance, direction to eye varies across the facet 48

IMPROVING FLAT SHADING what if evaluate Phong lighting model at each pixel of the polygon? better, but result still clearly faceted for smoother-looking surfaces we introduce vertex normals at each vertex usually different from facet normal used only for shading think of as a better approximation of the real surface that the polygons approximate 49

VERTEX NORMALS vertex normals may be provided with the model computed from first principles approximated by averaging the normals of the facets that share the vertex 50

GOURAUD SHADING most common approach perform Phong lighting at the vertices linearly interpolate the resulting colors over faces along edges along scanlines edge: mix of c 1, c 2 C 1 does this eliminate the facets? C 3 interior: mix of c1, c2, c3 C 2 edge: mix of c1, c3 51

GOURAUD SHADING ARTIFACTS often appears dull, chalky lacks accurate specular component if included, will be averaged over entire polygon C 1 C 1 C 3 C 3 C 2 this interior shading missed! C 2 this vertex shading spread over too much area 52

GOURAUD SHADING ARTIFACTS Mach bands eye enhances discontinuity in first derivative very disturbing, especially for highlights 53

GOURAUD SHADING ARTIFACTS Mach bands C 1 C 4 C 3 C 2 Discon;nuity in rate of color change occurs here 54

GOURAUD SHADING ARTIFACTS perspective transformations affine combinations only invariant under affine, not under perspective transformations thus, perspective projection alters the linear interpolation! Image plane Z into the scene 55

GOURAUD SHADING ARTIFACTS perspective transformation problem colors slightly swim on the surface as objects move relative to the camera usually ignored since often only small difference usually smaller than changes from lighting variations to do it right either shading in object space or correction for perspective foreshortening expensive thus hardly ever done for colors 56

PHONG SHADING linearly interpolating surface normal across the facet, applying Phong lighting model at every pixel same input as Gouraud shading pro: much smoother results con: considerably more expensive not the same as Phong lighting common confusion Phong lighting: empirical model to calculate illumination at a point on a surface 57

PHONG SHADING linearly interpolate the vertex normals compute lighting equations at each pixel can use specular component N 1 # lights i=1 I total = k a I ambient + I i k d n l i ( ( ) + k s ( v r i ) n ) shiny remember: normals used in diffuse and specular terms N 4 N 2 N 3 disconenuity in normal s rate of change harder to detect 58

PHONG SHADING DIFFICULTIES more computationally expensive per-pixel vector normalization and lighting computation! floating point operations required straightforward with shaders lighting after perspective projection messes up the angles between vectors have to keep eye-space vectors around 59

SHADING ARTIFACTS: SILHOUETTES polygonal silhouettes remain Gouraud Phong 60

SHADING ARTIFACTS: ORIENTATION interpolation dependent on polygon orientation view dependence! A B D Rotate - 90 o and color same point C B i! A C Interpolate between AB and AD D Interpolate between CD and AD 61

Shading Ar+facts: Shared Ver+ces D C H vertex B shared by two rectangles on the right, but not by the one on the leo B G first poreon of the scanline is interpolated between DE and AC E A F second poreon of the scanline is interpolated between BC and GH a large disconenuity could arise 62

SHADING MODELS SUMMARY flat shading compute Phong lighting once for entire polygon Gouraud shading compute Phong lighting at the vertices and interpolate lighting values across polygon Phong shading compute averaged vertex normals interpolate normals across polygon and perform Phong lighting across polygon 63

SHUTTERBUG: FLAT SHADING 64

SHUTTERBUG: GOURAUD SHADING 65

SHUTTERBUG: PHONG SHADING 66

NON-PHOTOREALISTIC SHADING cool-to-warm shading k w = 1+ n l 2,c = k w c w + (1 k w )c c http://www.cs.utah.edu/~gooch/sig98/paper/drawing.html 67

NON-PHOTOREALISTIC SHADING draw silhouettes: if draw creases: if (e n 0 )(e n 1 ) 0 (n 0 n 1 ) threshold, e=edge-eye vector http://www.cs.utah.edu/~gooch/sig98/paper/drawing.html 68