Shading , Fall 2004 Nancy Pollard Mark Tomczak

Similar documents
5.2 Shading in OpenGL

Shading in OpenGL. Outline. Defining and Maintaining Normals. Normalization. Enabling Lighting and Lights. Outline

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

Shading and Illumination

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

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

CEng 477 Introduction to Computer Graphics Fall

Illumination and Shading

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

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

Computer Graphics. Illumination and Shading

CS5620 Intro to Computer Graphics

Illumination & Shading: Part 1

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

Lighting. CSC 7443: Scientific Information Visualization

Illumination Models & Shading

Light Transport Baoquan Chen 2017

Why we need shading?

Illumination and Shading

Shading. Brian Curless CSE 457 Spring 2015

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

Shading. CSE 457 Winter 2015

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

Virtual Reality for Human Computer Interaction

Illumination and Shading

CS Computer Graphics: Illumination and Shading I

CS Computer Graphics: Illumination and Shading I

Illumination and Shading ECE 567

Illumination & Shading I

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

Lecture 15: Shading-I. CITS3003 Graphics & Animation

CSE 167: Lecture #8: Lighting. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

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

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

Three-Dimensional Graphics V. Guoying Zhao 1 / 55

INF3320 Computer Graphics and Discrete Geometry

Methodology for Lecture. Importance of Lighting. Outline. Shading Models. Brief primer on Color. Foundations of Computer Graphics (Spring 2010)

Ambient reflection. Jacobs University Visualization and Computer Graphics Lab : Graphics and Visualization 407

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

Light Sources. Spotlight model

Virtual Reality for Human Computer Interaction

w Foley, Section16.1 Reading

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

Lighting/Shading III. Week 7, Wed Mar 3

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

CS 148, Summer 2012 Introduction to Computer Graphics and Imaging

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

Lighting and Shading. Slides: Tamar Shinar, Victor Zordon

OpenGL Lighting Computer Graphics Spring Frank Palermo

Sung-Eui Yoon ( 윤성의 )

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

LIGHTING AND SHADING

Projections and Hardware Rendering. Brian Curless CSE 557 Fall 2014

Ligh%ng and Shading. Ligh%ng and Shading. q Is this a plate or a ball? q What color should I set for each pixel?

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

Shading I Computer Graphics I, Fall 2008

ECS 175 COMPUTER GRAPHICS. Ken Joy.! Winter 2014

CS Surface Rendering

Illumination and Shading

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

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

CPSC 314 LIGHTING AND SHADING

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

Illumination & Shading

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

Computer Graphics. Illumination and Shading

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

Lecture 4 Advanced Computer Graphics (CS & SE )

Shading. Brian Curless CSE 557 Autumn 2017

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

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

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

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

CPSC / Illumination and Shading

CMSC427 Shading Intro. Credit: slides from Dr. Zwicker

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

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

Interactive Real-Time Raycasting

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

Comp 410/510 Computer Graphics. Spring Shading

Color and Light CSCI 4229/5229 Computer Graphics Fall 2016

Shading. Brian Curless CSE 457 Spring 2017

Visualisatie BMT. Rendering. Arjan Kok

Computer Graphics I Lecture 11

University of Victoria CSC 305 Shading. Brian Wyvill 2016

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

CS770/870 Spring 2017 Color and Shading

Display Issues Week 5

CS230 : Computer Graphics Lighting and Shading. Tamar Shinar Computer Science & Engineering UC Riverside

CS 325 Computer Graphics

C O M P U T E R G R A P H I C S. Computer Graphics. Three-Dimensional Graphics V. Guoying Zhao 1 / 65

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

CS452/552; EE465/505. Intro to Lighting

Illumination & Shading

Lighting. Figure 10.1

How do we draw a picture?

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

Graphics and Visualization

Illumination and Shading

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

Transcription:

15-462, Fall 2004 Nancy Pollard Mark Tomczak Shading Shading Concepts Shading Equations Lambertian, Gouraud shading Phong Illumination Model Non-photorealistic rendering [Shirly, Ch. 8]

Announcements Written assignment #2 due Tuesday Handin at beginning of class Programming assignment #2 out Tuesday

Why Shade? Human vision uses shading as a cue to form, position, and depth Total handling of light is very expensive Shading models can give us a good approximation of what would really happen, much less expensively Average and approximate

Outline Lighting models (OpenGL oriented) Light styles Lambertian shading Gouraud shading Reflection models (Phong shading) Non-Photorealistic rendering

Common Types of Light Sources Ambient light: no identifiable source or direction Point source: given only by point Distant light: given only by direction Spotlight: from source in direction Cut-off angle defines a cone of light Attenuation function (brighter in center) Light source described by a luminance Each color is described separately I = [I r I g I b ] T (I for intensity) Sometimes calculate generically (applies to r, g, b)

Ambient Light Intensity is the same at all points This light does not have a direction (or.. it is the same in all directions)

Point Source Given by a point p 0 Light emitted from that point equally in all directions Intensity decreases with square of distance

One Limitation of Point Sources Shading and shadows inaccurate Example: penumbra (partial soft shadow)

Distant Light Source Given by a vector v Intensity does not vary with distance (all distances are the same.. infinite!)

Spotlight Most complex light source in OpenGL Light still emanates from point Cut-off by cone determined by angle q

Spotlight Attenuation Spotlight is brightest along l s Vector v with angle f from p to point on surface Intensity determined by cos f Corresponds to projection of v onto I s Spotlight exponent e determines rate of dropoff for e = 1 for e > 1 curve narrows

The Life of a Photon What can happen to a photon that interacts with an object?

Surface Reflection When light hits an opaque surface some is absorbed, the rest is reflected (some can be transmitted too--but never mind for now) The reflected light is what we see Reflection is not simple and varies with material the surface s micro structure define the details of reflection variations produce anything from bright specular reflection (mirrors) to dull matte finish (chalk) Incident Light Reflected Light Camera Surface

Basic Calculation Calculate each primary color separately Start with global ambient light Add reflections from each light source Clamp to [0, 1] Reflection decomposed into Ambient reflection Diffuse reflection Specular reflection Based on ambient, diffuse, and specular lighting and material properties

Lambertian (Diffuse) Reflection Diffuse reflector scatters light Assume equally all direction Called Lambertian surface Diffuse reflection coefficient k d, 0 k d 1 Angle of incoming light still critical

Lambert s Law Intensity depends on angle of incoming light Recall l = unit vector to light n = unit surface normal q = angle to normal cos q = l * n I d = k n (l * n) L d With attenuation: q = distance to light source, L d = diffuse component of light

Small problem Too dark! Everything is very starkly lit Spooky Why?

Ambient Light Reflected light (even diffuse reflection) reflects off of other surfaces Light is scattered by the air; does not always travel a straight path Modeling all that reflection and distortion would be very complicated Simplify, Simplify --Henry David Thoreau

Ambient Reflection Pretend some minimum light energy incident on every point in space from every direction Intensity of ambient light uniform at every point Ambient reflection coefficient k a, 0 <= k a <= 1 May be different for every surface and r,g,b Determines reflected fraction of ambient light L a = ambient component of light source Ambient intensity I a = k a L a Note: L a is not a physically meaningful quantity

Specular Reflection Specular reflection coefficient k s, 0 k s 1 Shiny surfaces have high specular coefficient Used to model specular highlights Do not get mirror effect (need other techniques) specular reflection specular highlights

Shininess Coefficient L s is specular component of light r is vector of perfect reflection of l about n v is vector to viewer f is angle between v and r I s = k s L s cos a f a is shininess coefficient Compute cos f = r * v Requires r = v = 1 Multiply distance term Equation look familiar? Higher a is narrower

Flat Shading Assessment Inexpensive to compute Appropriate for objects with flat faces Less pleasant for smooth surfaces

Flat Shading and Perception Lateral inhibition: exaggerates perceived intensity Mach bands: perceived stripes along edges

Interpolative Shading Enable with glshademodel(gl_smooth); Calculate color at each vertex Interpolate color in interior Compute during scan conversion (rasterization) Much better image (see Assignment 1) More expensive to calculate Consider two types: Gouraud and Phong

Gouraud Shading Special case of interpolative shading How do we calculate vertex normals? Gouraud: average all adjacent face normals Requires knowledge about which faces share a vertex adjacency info

Data Structures for Gouraud Shading Sometimes vertex normals can be computed directly (e.g. height field with uniform mesh) More generally, need data structure for mesh Key: which polygons meet at each vertex

Icosahedron with Sphere Normals Interpolation vs flat shading effect

One Subdivision

Two Subdivisions Each time, multiply number of faces by 4

Three Subdivisions Reasonable approximation to sphere

Lighting in OpenGL Very similar to color But different

Enabling Lighting and Lights Lighting in general must be enabled glenable(gl_lighting); Each individual light must be enabled glenable(gl_light0); OpenGL supports at least 8 light sources More depending on graphics card What if you need more than the card supports?

Global Ambient Light Set ambient intensity for entire scene GLfloat al[] = {0.2, 0.2, 0.2, 1.0}; gllightmodelfv(gl_light_model_ambient, al); The above is default Also: properly light backs of polygons gllightmodeli(gl_light_model_two_sided, GL_TRUE)

Defining a Light Source Use vectors {r, g, b, a} for light properties Beware: light source will be transformed! GLfloat light_ambient[] = {0.2, 0.2, 0.2, 1.0}; GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 1.0}; GLfloat light_specular[] = {1.0, 1.0, 1.0, 1.0}; GLfloat light_position[] = {-1.0, 1.0, -1.0, 0.0}; gllightfv(gl_light0, GL_AMBIENT, light_ambient); gllightfv(gl_light0, GL_DIFFUSE, light_diffuse); gllightfv(gl_light0, GL_SPECULAR, light_specular); gllightfv(gl_light0, GL_POSITION, light_position);

Point Source vs Directional Source Directional light given by position vector GLfloat light_position[] = {-1.0, 1.0, -1.0, 0.0}; gllightfv(gl_light0, GL_POSITION, light_position); Point source given by position point GLfloat light_position[] = {-1.0, 1.0, -1.0, 1.0}; gllightfv(gl_light0, GL_POSITION, light_position);

Spotlights Create point source as before Specify additional properties to create spotlight GLfloat sd[] = {-1.0, -1.0, 0.0}; gllightfv(gl_light0, GL_SPOT_DIRECTION, sd); gllightf (GL_LIGHT0, GL_SPOT_CUTOFF, 45.0); gllightf (GL_LIGHT0, GL_SPOT_EXPONENT, 2.0);

Defining Material Properties Material properties stay in effect (like color) Set both specular coefficients and shininess GLfloat mat_a[] = {0.1, 0.5, 0.8, 1.0}; GLfloat mat_d[] = {0.1, 0.5, 0.8, 1.0}; GLfloat mat_s[] = {1.0, 1.0, 1.0, 1.0}; GLfloat low_sh[] = {5.0}; glmaterialfv(gl_front, GL_AMBIENT, mat_a); glmaterialfv(gl_front, GL_DIFFUSE, mat_d); glmaterialfv(gl_front, GL_SPECULAR, mat_s); glmaterialfv(gl_front, GL_SHININESS, low_sh); Diffuse component is analogous

Defining and Maintaining Normals Define unit normal before each vertex glnormal3f(nx, ny, nz); glvertex3f(x, y, z); Length changes under some transformations Ask OpenGL to re-normalize (always works) glenable(gl_normalize); Ask OpenGL to re-scale normal (works for uniform scaling, rotate, translate) glenable(gl_rescale_normal);

A Demonstration

So what doesn t it do? Sphere can look a bit off close up Specular reflection not quite right Why? We interpolate colors linearly, but specular result is non-linear

Phong Illumination Model Interpolate normals instead of colors (barycentric coordinates) Calculate color for arbitrary point on surface Basic inputs are material properties and l, n, v: l = vector to light source n = surface normal v = vector to viewer r = reflection of l at p (determined by l and n)

Summary of Phong Model Light components for each color: Ambient (L_a), diffuse (L_d), specular (L_s) Material coefficients for each color: Ambient (k_a), diffuse (k_d), specular (k_s) Distance q for surface point from light source l = vector from light n = surface normal r = l reflected about n v = vector to viewer

Phong Shading Results Michael Gold, Nvidia Why not always use Phong? Phong Lighting Gouraud Shading Phong Lighting, Phong Shading

Raytracing Example Martin Moeck, Siemens Lighting

Radiosity Example Restaurant Interior. Guillermo Leal, Evolucion Visual

Non-photorealistic rendering Human brain is an amazing pattern recognition system Throws out most detail Basic idea: Simplify a model to convey specific information This is Not a face

NPR techniques Sihlouette generation Crease rendering Cool-to-warm shading

Silhouettes Generate an outline of the object Where is edge of object relative to viewer? Amy Gooch - Bruce Gooch - Peter Shirley - Elaine Cohen SIGGRAPH 98

Silhouettes Consider adjacent polygons, p 1 and p 2, with normals n 1 and n 2 Compute (e* n 1 ) (e* n 2 ) If <= 0, one poly is toward viewer, the other is away So, draw silhouette n 2 top view e n 1

Corners and creases Sharp changes in shape should be highlighted But, we can t just highlight every shared edge (wireframe mode) Compare normals of adjacent edges If n 1 * n 2 < threshold, draw edge Doug DeCarlo, Adam Finkelstein, Szymon Rusinkiewicz, Anthony Santella, ACM Transactions on Graphics, July 2003

Cool-to-warm shading Simple way to highlight surface curvature Rather than using shadow and non-shadow, shade between two contrasting colors (redblue) k w = (1+n*l) / 2 C=k w c w + (1-k w )c c

Related technique: Cel shading Similar to basic non-photorealistic technique Only allow shading colors to be drawn from a small palette Cartoonish models greatly help (tmzs)

Questions?