CS 450: COMPUTER GRAPHICS BASIC ILLUMINATION SPRING 2015 DR. MICHAEL J. REALE.

Slides:



Advertisements
Similar presentations
1 Graphics CSCI 343, Fall 2013 Lecture 18 Lighting and Shading.
Advertisements

Virtual Realism LIGHTING AND SHADING. Lighting & Shading Approximate physical reality Ray tracing: Follow light rays through a scene Accurate, but expensive.
1 Computer Graphics By : Mohammed abu Lamdy ITGD3107 University of Palestine Supervision: Assistant Professor Dr. Sana’a Wafa Al-Sayegh.
Illumination and Shading
1. What is Lighting? 2 Example 1. Find the cubic polynomial or that passes through the four points and satisfies 1.As a photon Metal Insulator.
Based on slides created by Edward Angel
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Shading I.
Computer Graphics - Class 10
IMGD 1001: Illumination by Mark Claypool
Computer Graphics (Fall 2005) COMS 4160, Lecture 16: Illumination and Shading 1
(conventional Cartesian reference system)
1 CSCE 641: Computer Graphics Lighting Jinxiang Chai.
7M836 Animation & Rendering
Objectives Learn to shade objects so their images appear three- dimensional Learn to shade objects so their images appear three- dimensional Introduce.
CS 376 Introduction to Computer Graphics 03 / 30 / 2007 Instructor: Michael Eckmann.
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Shading Week 5, Wed 1 Oct 2003 recap: lighting shading.
Course Website: Computer Graphics 16: Illumination.
CS 480/680 Computer Graphics Shading I Dr. Frederick C Harris, Jr.
CS 445 / 645: Introductory Computer Graphics
Lecture 5: 3D Rendering Pipeline (II) Prof. Hsien-Hsin Sean Lee School of Electrical and Computer Engineering Georgia Institute of Technology.
Polygon Shading. Assigning color to a shape to make graphical scenes look realistic, or artistic, or whatever effect we’re attempting to achieve But first.
CS 445 / 645 Introduction to Computer Graphics Lecture 18 Shading Shading.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Shading (introduction to rendering). Rendering  We know how to specify the geometry but how is the color calculated.
COMPUTER GRAPHICS CS 482 – FALL 2014 AUGUST 27, 2014 FIXED-FUNCTION 3D GRAPHICS MESH SPECIFICATION LIGHTING SPECIFICATION REFLECTION SHADING HIERARCHICAL.
CSC418 Computer Graphics n Illumination n Lights n Lightinging models.
Computer Graphics I, Fall 2010 Shading in OpenGL.
Rendering Overview CSE 3541 Matt Boggus. Rendering Algorithmically generating a 2D image from 3D models Raster graphics.
CS 325 Introduction to Computer Graphics 03 / 26 / 2010 Instructor: Michael Eckmann.
Taku KomuraComputer Graphics Local Illumination and Shading Computer Graphics – Lecture 10 Taku Komura Institute for Perception, Action.
Advanced Computer Graphics Advanced Shaders CO2409 Computer Graphics Week 16.
Steve Sterley. Real World Lighting Physical objects tend to interact with light in three ways: Absorption (black body) Reflection (mirror) Transmission.
University of Texas at Austin CS 378 – Game Technology Don Fussell CS 378: Computer Game Technology Basic Rendering Pipeline and Shading Spring 2012.
CSE 381 – Advanced Game Programming GLSL Lighting.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Illumination and Shading
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E.
CS 325 Introduction to Computer Graphics 03 / 29 / 2010 Instructor: Michael Eckmann.
Lecture Fall 2001 Illumination and Shading in OpenGL Light Sources Empirical Illumination Shading Transforming Normals Tong-Yee Lee.
Specular Reflection Lecture 27 Mon, Nov 10, 2003.
Local Illumination and Shading
Where We Stand So far we know how to: –Transform between spaces –Rasterize –Decide what’s in front Next –Deciding its intensity and color.
1 CSCE 441: Computer Graphics Lighting Jinxiang Chai.
In the name of God Computer Graphics. Where We Stand So far we know how to: –Transform between spaces –Draw polygons Next –Deciding a pixel’s intensity.
Illumination and Shading Sang Il Park Sejong University.
OpenGL Shading. 2 Objectives Learn to shade objects so their images appear three-dimensional Introduce the types of light-material interactions Build.
Lighting and Reflection Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
1 CSCE 441: Computer Graphics Lighting Jinxiang Chai.
David Luebke3/16/2016 CS 551 / 645: Introductory Computer Graphics David Luebke
Computer Graphics Lecture 30 Mathematics of Lighting and Shading - IV Taqdees A. Siddiqi
1 CSCE 441: Computer Graphics Lighting Jinxiang Chai.
Computer Graphics Ken-Yi Lee National Taiwan University (the slides are adapted from Bing-Yi Chen and Yung-Yu Chuang)
Computer Graphics: Illumination
Illumination Models and Surface-Rendering Methods CEng 477 Introduction to Computer Graphics.
Computer Graphics Lecture 26 Mathematics of Lighting and Shading Part II Taqdees A. Siddiqi
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
Chapter 5. Lighting Computer Graphics (spring, 2009) School of Computer Science University of Seoul.
7. Illumination Phong Illumination Diffuse, Specular and Ambient
© University of Wisconsin, CS559 Spring 2004
Chapter 14 Shading Models.
CSE 470 Introduction to Computer Graphics Arizona State University
Chapter IX Lighting.
Computer Graphics Material Colours and Lighting
Computer Graphics (Fall 2003)
Chapter 14 Shading Models.
Illumination Model 고려대학교 컴퓨터 그래픽스 연구실.
Illumination Model 고려대학교 컴퓨터 그래픽스 연구실.
CS 480/680 Computer Graphics Shading.
Computer Graphics Shading in OpenGL
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science
Presentation transcript:

CS 450: COMPUTER GRAPHICS BASIC ILLUMINATION SPRING 2015 DR. MICHAEL J. REALE

INTRODUCTION Let’s say we have a triangle on the screen We’ve already projected it and let’s assume it’s entirely within the clipping window The rasterizer needs to fill in each of the fragments/pixels inside of this triangle If we need to fill in one color  straightforward, but not realistic-looking How do we make surfaces look realistic?

VERTEX ATTRIBUTES  PIXEL/FRAGMENT VALUES Most of the time, a model is broken up into a triangle mesh For a given triangle, each vertex can be given different values (attributes): Color Texture coordinates Normal vector Etc. These values are interpolated across the triangle to get the individual pixel/fragment values

BARYCENTRIC COORDINATES

Barycentric coordinates – parameterizes the space that can be formed as a weighted combination of a set of reference points In other words  any location is a weighted average of the reference points Weights all sum to 1 For 2 reference points: (u,v) = barycentric coordinates of P with respect to A and B P is on segment AB IFF 0 <= u <= 1 AND 0 <= v <= 1 Barycentric coordinates of A = (1,0) Barycentric coordinates of B = (0,1)

BARYCENTRIC COORDINATES: TRIANGLES For 3 reference points (triangles): (u,v,w) = barycentric coordinates of P with respect to A, B, and C A  (1,0,0) B  (0,1,0) C  (0,0,1) Inside or on triangle IFF 0 <= u,v,w <= 1 Centroid or barycenter = (1/3, 1/3, 1/3) le:TriangleBarycentricCoordinates.svg

BARYCENTRIC COORDINATES: WHY DO WE CARE? Given a point P in a triangle, the barycentric coordinates give us a weight for each vertex in the triangle  can use to interpolate vertex attribute values! Example: if each vertex has a different color (C 0, C 1, C 2, respectively), and the barycentric coordinates for P are (u,v,w), the interpolated color for P is given by:

BARYCENTRIC COORDINATES AS A PLANE One can rearrange the previous barycentric equations to form a point and two axes (effectively defining a plane): Note: We don’t really need u

SOLVING FOR BARYCENTRIC COORDINATES Let’s say we have a point P and we want to find the barycentric coordinates for it Let the following be true: Then we can rewrite our previous equation:

SOLVING FOR BARYCENTRIC COORDINATES We can turn this into a 2 x 2 system of linear equations by taking the dot product of both sides first with V 0 and then with V 1 :

SOLVING FOR BARYCENTRIC COORDINATES Fortunately, this can be solved using Cramer’s Rule!

SOLVING FOR BARYCENTRIC COORDINATES The following code is taken from “Real-Time Collision Detection” by Christer Ericson (pg ) void Barycentric(Point a, Point b, Point c, Point p, float &u, float &v, float &w) { Vector v0 = b – a, v1 = c – a, v2 = p – a; float d00 = Dot(v0,v0); float d01 = Dot(v0,v1); float d11 = Dot(v1,v1); float d20 = Dot(v2,v0); float d21 = Dot(v2,v1); float denom = d00 * d11 – d01 * d01; v = (d11 * d20 – d01 * d21) / denom; w = (d00 * d21 – d01 * d20) / denom; u = 1.0f – v – w; }

LIGHT SOURCES

LIGHTING MODEL AND LIGHTS Lighting model (or shading model) = used to calculate the color of an illuminated position on the surface of an object Light source (or “light”) = emits light (radiant energy)

TYPES OF LIGHT SOURCES There are three basic types of light sources: Point lights Directional lights “Spotlights”

POINT LIGHTS Point light Located at a single point in space Emit light in all directions

DIRECTIONAL LIGHT (“SUN”) Directional Light Emits light in one direction Position of light doesn’t matter  only the direction matters Simulates a light “infinitely” far away (e.g., the sun)

“SPOTLIGHTS” Spotlight Has a position, direction, and angle θ defining how wide the cone of light is If V light = direction of the light and V obj = direction to object, then:

RADIAL INTENSITY ATTENUATION Let’s say we have a point light source The farther an object is from the light  the less light reaches the object (less intense) Officially: attenuation factor = 1/d 2 In practice, however, this doesn’t look realistic: Objects close to light  too much intensity variation Objects far from light  very little variation Reason why it doesn’t look right: lights aren’t REALLY infinitesimal points  only an approximation Alternative: use inverse quadratic function with tunable parameters:

ATTENUATION AND DIRECTIONAL LIGHTS Attenuation doesn’t make sense with directional lights  since light is “infinitely” far away, all points in scene equidistant from light

ANGULAR INTENSITY ATTENUATION For spotlights, as angle between object and light direction gets larger  cosine gets smaller Can use as part of attenuation factor

BASIC LIGHTING MODEL

INTRODUCTION When light hits an opaque surface, part of it reflected and part of it absorbed For transparent surfaces, light is also transmitted through the surface We’ll start by assuming a monochrome world (i.e., only black-and-white-and-shades-of-gray) So, we’ll refer to the intensity of the light as a single value (we’ll deal with RGB color later) For simplicity, we often determine the shading of an object based on three factors: Diffuse reflection Ambient light Specular reflection

DIFFUSE REFLECTION Diffuse reflection = when white light hits an object, what we see as the “color” of an object Example: apple  absorbs all frequencies except red  has red diffuse color Underlying physics: surfaces with microfacets (bumpy, grainy, matte)  reflects light in lots of different directions Ideal diffuse reflectors or Lambertian reflectors Incident light scattered with equal intensity in ALL directions, INDEPENDENT of viewing angle Depends on angle between NORMAL and DIRECTION-to-LIGHT  angle of incidence

DIFFUSE REFLECTION: SIMPLE VERSION k d = diffuse intensity (“color”) of surface I = light intensity N = normal L = vector to light from point The larger the angle between N and L  the less light hits the surface (and gets reflected off) Use dot product of N and L (as long as it’s greater than 0)

DIFFUSE REFLECTION: DIFFERENT LIGHT SOURCES Point lights  L = vector from current position to light position Directional light  L = direction vector for light

AMBIENT LIGHT Ambient light = sets the overall brightness of the scene Applied to ALL objects equally Approximating global illumination (in real world, light bouncing around different objects) To compute ambient light contribution to point on surface: Sometimes graphics packages will use a separate ambient coefficient for the surface:

DIFFUSE + AMBIENT LIGHT Note: all these factors vary from 0 to 1

SPECULAR REFLECTION Specular reflection = when all (or almost all) of the incident light is reflected back A shiny or reflective spot Depends on: Normal N Light vector L View vector V = vector from point to camera R = ideal reflection angle When R is in line with V  most reflective

SPECULAR REFLECTION: DULL AND SHINY Different surfaces reflect light over finite range of viewing positions Shiny surfaces  narrow range Duller surfaces  wider range

SPECULAR RELFECTION: PHONG SPECULAR-REFLECTION MODEL Phong specular-reflection model Angle φ = angle between R and V n s = specular-reflection exponent Sometimes called “shininess” If we use a constant coefficent for specular reflection, then:

SPECULAR REFLECTION: GETTING R L projected onto N is the same as R projected onto N; therefore: Our specular component can then be computed by:

SPECULAR REFLECTION: A SIMPLER WAY A simplified way to calculate specular reflection is to look at the halfway vector H between L and V: Now, we just look at the angle between N and H (or rather the dot product between them): Problem: if V, L, and N are not coplanar  slightly off Another problem: need to check if V and L are on same side of N (L · V > L · N)  if so, don’t use specular effect

GETTING THE VIEW VECTOR To get the vector from the current point to the viewer, you need: 3D WORLD position P of the point on the polygon PROBLEM: In vertex/pixel shader, have NORMALIZED DEVICE COORDINATES SOLUTION: Also pass in INVERSE Model-View-Projection transform to UNDO transformation P = invMVP*position 3D position of camera E To get the vector to the camera:

DIFFUSE + AMBIENT + SPECULAR So, for a single point light source, our combined diffuse, ambient, and specular reflections from a position on an illuminated surface are given by: NOTE: If light is behind surface, only use ambient light ALSO NOTE: If V and L are on the same side of N, no specular effects

MULTIPLE LIGHT SOURCES To deal with multiple light sources, just sum all values up for diffuse and specular components (ambient light is only added once, however):

SURFACE LIGHT EMISSIONS In addition to lights, one can also have surfaces that emit light Examples: fluorescent light bulbs, neon signs, anything from Tron,… Have addition term k e that is handled like an ambient term (except that it is specific to the surface) TECHNICALLY, light coming from the surface should affect other objects in the world: Use directional light with cone/box around it to determine area of effect Use lots of point lights Ignore it to save time (more common) Radiosity model (covered later)

DIFFUSE + AMBIENT + SPECULAR + SURFACE EMISSION + ATTENUATION The general, monochromatic illumination model for surface reflection that includes: Multiple light sources Attenuation factors Point lights, directional lights, spotlights, and surface emissions …is given by:

THE ILLUMINATION FROM THIS PIXEL IS TOO HIGH! The final output intensity has to be between 0 and 1  how to do we keep it in that range when we have lots of lights, etc.? Set a max value for each term in equation If exceed max value, set to max Normalize individual terms by dividing each by magnitude of largest term More complicated: get ALL pixel intensities for scene, and then scale set of intensities to range [0,1]

RGB COLOR For color lights and surfaces, our intensity values now become vectors: Examples: Our equations now become vector equations

COLOR REFLECTIONS? In the original specular-reflection model, k s was set to a constant value INDEPENDENT of the surface color  usually same color as light Gives surface a “plastic” appearance For nonplastic surfaces  specular color may be different from both light color and diffuse color of object!

POLYGON SURFACE RENDERING

INTRODUCTION Given a surface’s color information (diffuse, specular, etc.) and the light color information, how do we actually render the polygon? There are three major approaches for this, and the difference between them is at what level we compute the lighting equation: Flat shading  per primitive (triangle) Gouraud shading  per vertex Phong shading  per pixel/fragment

FLAT SHADING Flat shading = compute shading per primitive (triangle) All pixels/fragments have the same color Basically use the same normal for the whole triangle Advantages: Fastest Accurate if surface that the polygon is part of is NOT a curved surface Disadvantages: Curved surfaces look terrible  transitions between polygons is sudden

GOURAUD SHADING Gouraud shading = compute shading per-vertex Interpolate COLOR values to fill in pixels Use per-vertex normal Pronounced “guh-row”

GOURAUD SHADING: PER-VERTEX NORMAL? Usually, we think of the POLYGON as having a normal For a CURVED surface: To get the per-vertex normal, we get the average of all normals from the polygons the vertex is a part of: For a NON-CURVED surface: Sometimes we actually don’t want the surface to smoothly transition from one polygon to another To address this, duplicate the vertex so that you get two different average normals: Curved surface Duplicate vertex to create crease

GOURAUD SHADING: PROS AND CONS Advantages: Looks better than flat shading for curved surfaces Fairly efficient Disadvantages: Depending on vertex tessellation (i.e., how many vertices/polygons), specular highlights don’t look right Kind of smearing the highlight across the polygon Fewer polygons  More polygons

PHONG SHADING Phong shading = compute shading per-pixel/fragment Interpolate NORMALS across surface (from vertex normals) Advantages: Highest quality rendering Disadvantages: More computationally intensive (have to compute shading formula at each pixel) Overkill for non-curved surfaces (and we will have to duplicate vertices to get the creases we want)

FLAT VS. GOURAUD VS. PHONG Flat shading - Fastest - Lowest quality - Bad for curved surfaces Gouraud shading - Not as fast - Better quality - Specular highlights may not look right Phong shading - Slowest - Highest quality

OPENGL? In legacy, handling lights, what kind of shading you were using, etc. was a LOT more complicated In modern OpenGL, you pretty much handle this yourself with the vertex/pixel shaders: Gouraud shading: Compute per-vertex color Pass to fragment shader to be interpolated Use interpolated color directly for fragment Phong shading: Pass per-vertex NORMAL to fragment shader to be interpolated Compute fragment color in fragment shader For flat shading, pass in same normal for all vertices that are part of the same triangle