Shading Algorithms. Ron Goldman Department of Computer Science Rice University

Similar documents
Lecture 21: Shading. put your trust in my shadow. Judges 9:15

CS5620 Intro to Computer Graphics

Illumination and Shading

CS Illumination and Shading. Slide 1

Shading. Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller/Fuhrmann

How do we draw a picture?

9. Illumination and Shading

Illumination Models & Shading

Visualisatie BMT. Rendering. Arjan Kok

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

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

ECS 175 COMPUTER GRAPHICS. Ken Joy.! Winter 2014

University of Victoria CSC 305 Shading. Brian Wyvill 2016

Objectives Shading in OpenGL. Front and Back Faces. OpenGL shading. Introduce the OpenGL shading methods. Discuss polygonal shading

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

Graphics and Interaction Surface rendering and shading

Lecture outline Graphics and Interaction Surface rendering and shading. Shading techniques. Introduction. Surface rendering and shading

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

Illumination and Shading

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

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

Illumination and Shading

Shading Techniques Denbigh Starkey

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

Rendering Light Reflection Models

w Foley, Section16.1 Reading

CEng 477 Introduction to Computer Graphics Fall

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

Computer Graphics. Illumination and Shading

Reflection and Shading

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

CPSC / Illumination and Shading

Dithering and Rendering. CS116B Chris Pollett Apr 18, 2004.

CS770/870 Spring 2017 Color and Shading

Computer Graphics (CS 543) Lecture 8a: Per-Vertex lighting, Shading and Per-Fragment lighting

CS 130 Final. Fall 2015

CS 4731: Computer Graphics Lecture 16: Phong Illumination and Shading. Emmanuel Agu

Computer Graphics MTAT Raimond Tunnel

Comp 410/510 Computer Graphics. Spring Shading

Lecture 15: Shading-I. CITS3003 Graphics & Animation

Introduction to Visualization and Computer Graphics

Shading and Illumination

CPSC 314 LIGHTING AND SHADING

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

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

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

Shading I Computer Graphics I, Fall 2008

Interpolation using scanline algorithm

Illumination and Shading

Graphics Hardware and Display Devices

Graphics for VEs. Ruth Aylett

Pipeline Operations. CS 4620 Lecture 10

CS 130 Exam I. Fall 2015

Computer Science 426 Midterm 3/11/04, 1:30PM-2:50PM

Illumination Model. The governing principles for computing the. Apply the lighting model at a set of points across the entire surface.

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

Lighting and Shading II. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

CS 325 Computer Graphics

CS Surface Rendering

Rasterizing triangles

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

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

Temporal Face Normal Interpolation

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

Introduction to Computer Graphics 7. Shading

CSE Intro to Computer Graphics. ANSWER KEY: Midterm Examination. November 18, Instructor: Sam Buss, UC San Diego

Light Reflection Models

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Lighting and Shading

Lets assume each object has a defined colour. Hence our illumination model is looks unrealistic.

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

Shading Models. Simulate physical phenomena

Rendering Light Reflection Models

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

Shading. Shading = find color values at pixels of screen (when rendering a virtual 3D scene).

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

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

Illumination & Shading

Computer Graphics 1. Chapter 7 (June 17th, 2010, 2-4pm): Shading and rendering. LMU München Medieninformatik Andreas Butz Computergraphik 1 SS2010

Chapter 7 - Light, Materials, Appearance

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

Graphics for VEs. Ruth Aylett

Computer Graphics (CS 4731) Lecture 18: Lighting, Shading and Materials (Part 3)

Lighting and Shading Computer Graphics I Lecture 7. Light Sources Phong Illumination Model Normal Vectors [Angel, Ch

Surface Rendering Methods

Shading Intro. Shading & Lighting. Light and Matter. Light and Matter

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

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

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

CS 130 Exam I. Fall 2015

Illumination & Shading: Part 1

Fast Phong Shading by Gary Bishop

CSE 681 Illumination and Phong Shading

Computer Graphics: 3-Local Illumination Models

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

Color and Light CSCI 4229/5229 Computer Graphics Fall 2016

Computer Graphics. Illumination and Shading

Color and Light. CSCI 4229/5229 Computer Graphics Summer 2008

Transcription:

Shading Algorithms Ron Goldman Department of Computer Science Rice University

Illumination and Shading Standard Assumptions Curved surfaces are approximated by planar polygons. All light sources are point light sources (at infinity). Illumination Models Ambient Light Diffuse Reflection (Scattering) Specular Reflection Shading Models Uniform (Flat) Gouraud Phong

Shading Algorithms Uniform -- constant intensity for each polygon (Flat) Gouraud -- linear interpolation of intensity for each polygon along scan lines Phong -- linear interpolation of normal vectors (non-linear interpolation of intensity) for each polygon along scan lines Coordinate Dependent Methods Speed vs. Generality

Uniform Shading Assumptions 1. The surfaces really are polygonal. N = surface normal = constant 2. Light source at infinity L = vector to light source = constant L N = constant R = 2(L N)N L = constant 3. Eye at infinity V = vector to eye = constant N V = constant R V = constant

Polygon Normals Normal to a Polygon N = (P k O) (P k +1 O) = P k P k +1 P k O + P k +1 O Newell s Formula m N = P k P k +1 k =0 N = 2 Area(Polygon) (Green s Theorem) Avoids problem of collinear vertices P 2 P1 P 3 O

Uniform Shading (continued) Intensity I uniform = { I a k a + I pk d (L N) 1424 3 ambient diffuse + I p k s (R V) n 1 42 44 3 specular N, L, R,V constant I uniform constant along each polygon L N R V θ θ α Surface Mach Bands Discontinuities in intensity along polygon edges. Individual polygons highly visible. Heightened by physiological effects of the eye.

Purpose To Reduce Mach Bands Gouraud Shading Method Linear Interpolation of Intensities Incremental Computations -- Only One Addition per Pixel (Fast!) Strategy 1. Compute intensity at vertices, using an average unit normal vector. N vertex = vertex Polygon N polygon vertex Polygon N polygon (Normalized Average) 2. Interpolate intensity along edges. 3. Interpolate intensity along scan lines. Observation Polygon intensities agree along common edges. Integrates well with hidden surface scan line algorithm.

Polygon Vertex Edge Vertex Edge Vertex Scan Line Scan Line Edge Edge Vertex Vertex Vertex Edge Edge

Linear Interpolation Points Intensities L(t) = (1 t)p 1 + tp 2 I(t) = (1 t)i 1 + ti 2 L(t) = P 1 + t(p 2 P 1 ) I(t) = I 1 + t(i 2 I 1 ) L(t + Δt) = P 1 +(t + Δt)(P 2 P 1 ) I(t + Δt) = I 1 +(t + Δt)(I 2 I 1 ) ΔL = Δt(P 2 P 1 ) ΔI = Δt(I 2 I 1 ) Δx = Δt(x 2 x 1 ) I new = I old + ΔI Δy = Δt(y 2 y 1 ) Δz = Δt(z 2 z 1 ) Observation: If we know Δt, then we can compute ΔI.

Along a Scan Line Incremental Intensity Computation } I 1 Δx = 1 I 2 P 1 = (x 1, y 1,z 1 ) P 2 = (x 2, y 2, z 2 ) (x, y, z) (x + Δx, y + Δy, z + Δz) Δx = 1 Δt = 1/(x 2 x 1 ) ΔI = (I 2 I 1 )Δt = (I 2 I 1 )/(x 2 x 1 ) Next Scan Line I 2 I 1 P 1 = (x 1, y 1,z 1 ) (x, y, z) (x + Δx, y + Δy, z + Δz) P 2 = (x 2, y 2, z 2 ) Δy =1 Δt =1/(y 2 y 1 ) { ΔI = (I 2 I 1 )Δt = (I 2 I 1 )/(y 2 y 1 ) Δy =1

Orientation Dependence and Independence Problem Gouraud (Phong) Shading is Orientation Dependent Solution Subdivide the Polygons into Triangles Gouraud (Phong) Shading for Triangles is Orientation Independent Note Shading Algorithm Depends on the Particular Triangular Subdivision Shading Algorithm Gives Different Results for Different Subdivisions

Coordinate Dependence White White White White All White White Not All White Gray Black White Black

Barycentric Coordinates and Coordinate Independence (1 t)i 1 +ti 2 I 1 (1 s)i 1 + si 3 I I 2 I 3 β 3 I 1 β 2 I β 1 I 2 I 3 I = (1 u) ((1 t)i 1 +ti 2 ) +u ((1 s)i 1 + si 3 ) I = β 1 I 1 +β 2 I 2 + β 3 I 3 ( ) I = (1 u)(1 t)+u(1 s) I 144424 443 1 + (1 u)t 14 24 3 I 2 +(us) { I 3 β 1 ( ) β 2 β 3 Barycentric Coordinates β 1 +β 2 +β 3 =1 P = β 1 P 1 + β 2 P 2 +β 3 P 3 = P 1 + β 2 (P 2 P 1 )+β 3 (P 3 P 1 ) β 1,β 2,β 3 unique

Purpose To Reduce Mach Bands To Mimic Curved Surfaces Naive Phong Shading Method Linear Interpolation of Normal Vectors Incremental Computation of Normal Vectors Strategy 1. Compute unit normals at vertices by averaging the unit normals of the polygons to which the vertex belongs. N vertex = vertex Polygon N polygon vertex Polygon N polygon (Normalized Average) 2. Interpolate normals along edges. (Renormalize) 3. Interpolate normals along scan lines. (Renormalize) 4. Use normals to calculate intensities.

Linear Interpolation Points Normals L(t) = (1 t)p 1 + tp 2 N(t) = (1 t)n 1 + tn 2 L(t) = P 1 + t(p 2 P 1 ) N(t) = N 1 + t(n 2 N 1 ) L(t + Δt) = P 1 +(t + Δt)(P 2 P 1 ) N(t + Δt) = N 1 + (t + Δt)(N 2 N 1 ) ΔL = Δt(P 2 P 1 ) ΔN = Δt(N 2 N 1 ) Δx = Δt(x 2 x 1 ) N new = N old + ΔN N old + ΔN Δy = Δt(y 2 y 1 ) Δz = Δt(z 2 z 1 ) Observation: If we know Δt, then we can compute ΔN.

Along a Scan Line Incremental Normal Computation } N 1 Δx = 1 N 2 P 1 = (x 1, y 1,z 1 ) P 2 = (x 2, y 2, z 2 ) (x, y, z) (x + Δx, y + Δy, z + Δz) Δx = 1 Δt = 1/(x 2 x 1 ) ΔN = (N 2 N 1 )Δt = (N 2 N 1 )/(x 2 x 1 ) Next Scan Line N 2 N 1 P 1 = (x 1, y 1,z 1 ) (x, y, z) (x + Δx, y + Δy, z + Δz) P 2 = (x 2, y 2, z 2 ) Δy =1 Δt =1/(y 2 y 1 ) { Δy =1 ΔN = (N 2 N 1 )Δt = (N 2 N 1 )/(y 2 y 1 )

Clever Implementation -- Diffuse Reflection Diffuse Reflection I diffuse = I p k d (L N) = I p k d (1 t)(l N 1 )+t(l N 2 ) (1 t)n 1 +t N 2 J(t) = (1 t)(l 12 N 43 1 ) +t(l 14 2 N 43 2) J 1 J 2 -- Similar to Gouraud (Scalars) -- Avoids Dot Products Along Scan Lines N(t) = (1 t)n 1 +t N 2 -- N next = N current +ΔN -- Update Normal Vector Incrementally -- d next = N next = N next N next -- Normalization by Newton s Method

Normalization by Newton s Method Square Root by Newton s Method x 2 2 d next = 0 -- x 0 = d current -- x n+1 = x n x n 2 d next 2 2x n

Clever Implementation -- Specular Reflection Specular Reflection I specular = I p k s (RV) n -- R = 2(L N)N L I specular = I p k s ( 2(L N)(N V ) (L V)) n -- N = (1 t)n 1 +t N 2 2 {(1 t)(l N 1 )+t(l N 2 )} {(1 t)(v N 14444 244443 1 )+t(v N 2 )} 144442 44443 Similar to Gouraud Similar to Gouraud I specular = I p k s 2 (1 t)n 1 +t N 2 (LV 12 3 ) Constant n -- (1 t)n 1 +t N 2 2 = N + ΔN 2 = (N + ΔN)(N +ΔN) -- No Square Root

Spherical Linear Interpolation Slerp slerp(n 1,N 2,t) = sin ((1 t)φ) sin( tφ) N 1 + sin(φ) sin(φ) N 2 cos(φ) = N 1 N 2 -- sin(φ) = 1 (N 1 N 2 ) 2 slerp maps unit vectors to unit vectors more natural than linear interpolation -- avoids square roots Expand incrementally Expand Δsine and Δcosine Precompute sin(δtφ) and cos(δt φ)

Interpolating Unit Vectors Vector Interpolation Problem N 1 N t φ tφ N 0 N 0, N 1 = unit vectors Vector Interpolation Formula N t = sin ((1 t)φ) sin( tφ) N 0 + sin(φ) sin(φ) N 1

Incremental Spherical Linear Interpolation Slerp slerp(n 1,N 2,t) = sin ((1 t)φ) sin( tφ) N 1 + sin(φ) sin(φ) N 2 cos(φ) = N 1 N 2 sin(φ) = 1 (N 1 N 2 ) 2 Incremental Computation slerp(n 1,N 2,t +Δt) = sin ((1 t Δt)φ ) N 1 + sin(φ) sin ((t +Δt)φ) N 2 sin(φ) -- sin ((t +Δt)φ ) = sin(tφ)cos(δtφ)+ cos(tφ)sin(δtφ) -- sin ((1 t Δt)φ) = sin((1 t )φ)cos(δt φ) cos((1 t)φ)sin(δt φ) -- cos ((t + Δt)φ) = cos(tφ)cos(δtφ) sin(tφ)sin(δtφ) -- cos ((1 t Δt)φ ) = cos((1 t )φ)cos(δt φ)+sin((1 t)φ)sin(δt φ)

Fast Phong Shading with SLERP Diffuse Reflection I diffuse = I p k d (L N) = I p k d sin(φ) ( sin ((1 t)φ ) L N 1 +sin( tφ) L N 2 ) Specular Reflection I specular = I p k s (RV) n -- R = 2(L N)N L I specular = I p k s ( 2(L N)(N V ) (L V)) n 2 I specular = I p k s sin 2 (φ) ( ) sin (1 t)φ sin ( (1 t)φ )L N 1 + sin( tφ)l N 2 ( ( )V N 1 + sin( tφ)v N 2 ) (L 12 V) 3 Constant n

Comparison to Gouraud Shading Similar to Gouraud Shading Intensity calculations replaced by normal calculations Integrates well with hidden surface scan line algorithm Coordinate dependent method Slower than Gouraud Shading Intensities must be recalculated at each point from the normal vector I = { I a k a + I pk d (L N) 1424 3 ambient diffuse + I p k s (R V) n 1 42 4 3 N is different for each point R is different for each point specular More Accurate than Gouraud Shading Simulates curved surfaces (varying normal vectors) Further reduces Mach Bands Tighter highlights (and spotlights) than Gouraud shading Gouraud shading interpolates intensities -- smoothes out highlights

Problems with Gouraud and Phong Shading Orientation Dependence Problem: Linear Interpolation for Polygons is Orientation Dependent Visual Effect: Shading Changes Abruptly During Animation Solution: Subdivide into Triangles