CS452/552; EE465/505. Intro to Lighting

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

Shading I Computer Graphics I, Fall 2008

Comp 410/510 Computer Graphics. Spring Shading

Introduction to Computer Graphics with WebGL

Illumination & Shading

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

Computer Viewing. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

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

Lecture 15: Shading-I. CITS3003 Graphics & Animation

Introduction to Computer Graphics 7. Shading

CS452/552; EE465/505. Lighting & Shading

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

Computer Viewing. Prof. George Wolberg Dept. of Computer Science City College of New York

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

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

Overview. Viewing and perspectives. Planar Geometric Projections. Classical Viewing. Classical views Computer viewing Perspective normalization

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

CS 4600 Fall Utah School of Computing

Course no. DIS4566 National Chiao Tung Univ, Taiwan By: I-Chen Lin, Assistant Professor

Three-Dimensional Graphics V. Guoying Zhao 1 / 55

Why we need shading?

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

Virtual Reality for Human Computer Interaction

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

Three-Dimensional Graphics III. Guoying Zhao 1 / 67

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

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

Computer Viewing and Projection. Overview. Computer Viewing. David Carr Fundamentals of Computer Graphics Spring 2004 Based on Slides by E.

CS5620 Intro to Computer Graphics

ECS 175 COMPUTER GRAPHICS. Ken Joy.! Winter 2014

Lighting. Figure 10.1

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

Fundamental Types of Viewing

Models and Architectures

Shading II. CITS3003 Graphics & Animation

Computer Graphics. Illumination and Shading

Illumination & Shading I

Chapter 2 A top-down approach - How to make shaded images?

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

Reflection and Shading

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

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

Lighting and Shading. Slides: Tamar Shinar, Victor Zordon

Objectives. Shading II. Distance Terms. The Phong Reflection Model

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

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

Pipeline Operations. CS 4620 Lecture 10

CS452/552; EE465/505. Review & Examples

Illumination Models & Shading

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

Illumination & Shading: Part 1

Shading. Brian Curless CSE 557 Autumn 2017

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

w Foley, Section16.1 Reading

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

Three Main Themes of Computer Graphics

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

Pipeline Operations. CS 4620 Lecture 14

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

Simple Lighting/Illumination Models

Illumination and Shading

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

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

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

Introduction to Visualization and Computer Graphics

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

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

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

Lab 9 - Metal and Glass

Illumination in Computer Graphics

Supplement to Lecture 16

Shading. Brian Curless CSE 457 Spring 2017

Introduction to Computer Graphics with WebGL

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

CHAPTER5. We have learned to build three-dimensional graphical models and to LIGHTING AND SHADING

Graphics for VEs. Ruth Aylett

Global Rendering. Ingela Nyström 1. Effects needed for realism. The Rendering Equation. Local vs global rendering. Light-material interaction

Global Illumination CS334. Daniel G. Aliaga Department of Computer Science Purdue University

One or more objects A viewer with a projection surface Projectors that go from the object(s) to the projection surface

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

CPSC 314 LIGHTING AND SHADING

Visualisatie BMT. Rendering. Arjan Kok

Virtual Cameras & Their Matrices

C P S C 314 S H A D E R S, O P E N G L, & J S RENDERING PIPELINE. Mikhail Bessmeltsev

CITSTUDENTS.IN VIEWING. Computer Graphics and Visualization. Classical and computer viewing. Viewing with a computer. Positioning of the camera

Turn on the Lights: Reflectance

Classical and Computer Viewing. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Shading 1: basics Christian Miller CS Fall 2011

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

Local Reflection Models

CS559 Computer Graphics Fall 2015

Shading. CSE 457 Winter 2015

Objectives. Continue discussion of shading Introduce modified Phong model Consider computation of required vectors

CHAPTER 1 Graphics Systems and Models 3

Illumination and Shading

Raytracing CS148 AS3. Due :59pm PDT

Computer Graphics. Illumination and Shading

Color and Light CSCI 4229/5229 Computer Graphics Fall 2016

Sung-Eui Yoon ( 윤성의 )

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

Transcription:

CS452/552; EE465/505 Intro to Lighting 2-10 15

Outline! Projection Normalization! Introduction to Lighting (and Shading) Read: Angel Chapter 5., sections 5.4-5.7 Parallel Projections Chapter 6, sections 6.1-6.3 Lighting & Shading Lab2: use ASDW to move a 2D shape around

From model to viewing Consider the vertex shaders for each of these examples:! Coordinate systems (from Chastine)! ColorCube example (from Matsuda)! perspective example (from Angel) 3

From model to view: Chastine in vec4 vposition; // The vertex in the local coordinate system uniform mat4 mm; // The matrix for the pose of the model uniform mat4 mv; // The matrix for the pose of the camera uniform mat4 mp; // The projection matrix (perspective) void main () { gl_position = mp*mv*mm*vposition; } New position in NDC Original (local) position (c) 2015 Jeff Chastine

ColoredCube Vertex Shader attribute vec4 a_position; attribute vec4 a_color; uniform mat4 u_mvpmatrix; varying vec4 v_color; void main() { gl_position = u_mvpmatrix * a_position; v_color = a_color; }

Angel: perspective2.html attribute vec4 vposition; attribute vec4 vcolor; varying vec4 fcolor; uniform mat4 modelviewmatrix; uniform mat4 projectionmatrix; void main() { gl_position = projectionmatrix*modelviewmatrix*vposition; fcolor = vcolor; }

WebGL Orthogonal Viewing ortho(left,right,bottom,top,near,far) near and far measured from camera

WebGL Perspective frustum(left,right,bottom,top,near,far)

Using Field of View! With frustum it is often difficult to get the desired view perpective(fovy, aspect, near, far) often provides a better interface front plane aspect = w/h

Computing Matrices! Compute in JS file, send to vertex shader with gl.uniformmatrix4fv! Dynamic: update in render() or shader

Projection Normalization! Rather than derive a different projection matrix for each type of projection, we can convert all projections to orthogonal projections with the default view volume! This strategy allows us to use standard transformations in the pipeline and makes for efficient clipping

Pipeline View modelview transformation projection transformation perspective division 4D 3D clipping projection against default cube 3D 2D

Notes! We stay in four-dimensional homogeneous coordinates through both the modelview and projection transformations Both these transformations are nonsingular Default to identity matrices (orthogonal view)! Normalization lets us clip against simple cube regardless of type of projection! Delay final projection until end Important for hidden-surface removal to retain depth information as long as possible

Orthogonal Normalization ortho(left,right,bottom,top,near,far) normalization find transformation to convert specified clipping volume to default

Orthogonal Matrix! Two steps Move center to origin T(-(left+right)/2, -(bottom+top)/2,(near+far)/2)) Scale to have sides of length 2 S(2/(left-right),2/(top-bottom),2/(near-far)) P = ST = # 2 right left & % 0 0 right left right left ( % ( % 2 top + bottom 0 0 ( % top bottom top bottom ( % 2 far + near ( % 0 0 near far far near ( % ( $ 0 0 0 1 '

Final Projection! Set z =0! Equivalent to the homogeneous coordinate transformation M orth = & 1 $ $ 0 $ 0 $ % 0 0 1 0 0 0 0 0 0 0# 0!! 0!! 1"! Hence, general orthogonal projection in 4D is P = M orth ST

Oblique Projections! The OpenGL/WebGL projection functions cannot produce general parallel projections oblique parallel projections are useful an oblique projection is characterized by the angle the projectors make with the projection plane! However if we look at the example of the cube it appears that the cube has been sheared! Oblique Projection = Shear + Orthogonal Projection

General Shear side view top view

Shear Matrix xy shear (z values unchanged) H(θ,φ) = & 1 $ $ 0 $ 0 $ % 0 0 1 0 0 cot θ cot φ 1 0 0# 0!! 0!! 1" Shearing matrix Projection matrix General case: P = M orth H(θ,φ) P = M orth STH(θ,φ)

Simple Perspective Consider a simple perspective with the COP at the origin, the near clipping plane at z = -1, and a 90 degree field of view determined by the planes x = ±z, y = ±z

Perspective Matrices Simple projection matrix in homogeneous coordinates M = & 1 $ $ 0 $ 0 $ % 0 0 1 0 0 0 0# 0 0!! 1 0!! 1 0" Note that this matrix is independent of the far clipping plane

Generalization N = & 1 $ $ 0 $ 0 $ % 0 0 1 0 0 0 0# 0 0!! α β!! 1 0" after perspective division, the point (x, y, z, 1) goes to x = x/z y = y/z Z = -(α+β/z) which projects orthogonally to the desired point regardless of α and β

Picking α and β If we pick α = β = near + far far near 2near far near far the near plane is mapped to z = -1 the far plane is mapped to z =1 and the sides are mapped to x = ± 1, y = ± 1 Hence the new clipping volume is the default clipping volume

Normalization Transformation original clipping volume distorted object projects correctly original object new clipping volume

Normalization and Hidden-Surface Removal! Although our selection of the form of the perspective matrices may appear somewhat arbitrary, it was chosen so that if z 1 > z 2 in the original clipping volume then the for the transformed points z 1 > z 2! Thus hidden surface removal works if we first apply the normalization transformation! However, the formula z = -(α+β/z) implies that the distances are distorted by the normalization which can cause numerical problems especially if the near distance is small

WebGL Perspective gl.frustum allows for an unsymmetric viewing frustum (although gl.perspective does not)

OpenGL Perspective Matrix! The normalization in frustum requires an initial shear to form a right viewing pyramid, followed by a scaling to get the normalized perspective volume. Finally, the perspective matrix results in needing only a final orthogonal transformation P = NSH our previously defined perspective matrix shear and scale

Why do we do it this way?! Normalization allows for a single pipeline for both perspective and orthogonal viewing! We stay in four dimensional homogeneous coordinates as long as possible to retain three-dimensional information needed for hidden-surface removal and shading! We simplify clipping

Perspective Matrices frustum perspective # 2* near right left % 0 0 right left right left % % 2* near top + bottom 0 0 P = % top bottom top bottom % far + near % 0 0 far near % $ 0 0 1 0 # near % 0 0 0 right % % near 0 0 0 P = % top % far + near % 0 0 far near % $ 0 0 1 0 2 * far * near far near 2* far * near far near & ( ( ( ( ( ( ( ' & ( ( ( ( ( ( ( '

Lighting

What is Light? A very complex process Find a dark area how is it being lit? Light bounces (mirrors, shiny objects) Light refracts through other media (water, heat) Light comes from everywhere (Global Illumination) Light bounces off of lakes in weird ways (Fresnel effect) THUS We re forced to make approximations Tradeoff between time and realism If it looks good, it is good Michael Abrash http://en.wikipedia.org/wiki/file:global_illumination.jpg http://darrentakenaga.com/3d.html Jeff Chastine

Lighting Principles! Lighting simulates how objects reflect light material composition of object light s color and position global lighting parameters! Lighting functions deprecated in 3.1! Can implement in Application (per vertex) Vertex or fragment shaders

Shading! Why does the image of a real sphere look like! Light-material interactions cause each point to have a different color or shade! Need to consider Light sources Material properties Location of viewer Surface orientation

Scattering! Light strikes A Some scattered Some absorbed! Some of scattered light strikes B Some scattered Some absorbed! Some of this scattered light strikes A a n d s o o n

Rendering Equation! The infinite scattering and absorption of light can be described by the rendering equation Cannot be solved in general Ray tracing is a special case for perfectly reflecting surfaces! Rendering equation is global and includes Shadows Multiple scattering from object to object

Global Effects shadow translucent surface multiple reflection

Local vs Global Rendering! Correct shading requires a global calculation involving all objects and light sources Incompatible with pipeline model which shades each polygon independently (local rendering)! However, in computer graphics, especially real time graphics, we are happy if things look right Exist many techniques for approximating global effects

Light-Material Interaction! Light that strikes an object is partially absorbed and partially scattered (reflected)! The amount reflected determines the color and brightness of the object A surface appears red under white light because the red component of the light is reflected and the rest is absorbed! The reflected light is scattered in a manner that depends on the smoothness and orientation of the surface

Light Sources General light sources are difficult to work with because we must integrate light coming from all points on the source

Simple Light Sources! Point source Model with position and color Distant source = infinite distance away (parallel)! Spotlight Restrict light from ideal point source! Ambient light Same amount of light everywhere in scene Can model contribution of many sources and reflecting surfaces

Surface Types! The smoother a surface, the more reflected light is concentrated in the direction a perfect mirror would reflected the light! A very rough surface scatters light in all directions smooth surface rough surface

Phong Model! A simple model that can be computed rapidly! Has three components Diffuse Specular Ambient! Uses four vectors To source To viewer Normal Perfect reflector

Ideal Reflector! Normal is determined by local orientation! Angle of incidence = angle of reflection! The three vectors must be coplanar r = 2 (l n ) n - l

Lambertian Surface! Perfectly diffuse reflector! Light scattered equally in all directions! Amount of light reflected is proportional to the vertical component of incoming light reflected light ~cos θ i cos θ i = l n if vectors normalized There are also three coefficients, k r, k b, k g that show how much of each color component is reflected

Specular Surfaces! Most surfaces are neither ideal diffusers nor perfectly specular (ideal reflectors)! Smooth surfaces show specular highlights due to incoming light being reflected in directions concentrated close to the direction of a perfect reflection specular highlight

Modeling Specular Relections! Phong proposed using a term that dropped off as the angle between the viewer and the ideal reflection increased I r ~ k s I cos α φ φ reflected intensity shininess coef incoming intensity absorption coef

The Shininess Coefficient! Values of α between 100 and 200 correspond to metals! Values between 5 and 10 give surface that look like plastic cos α φ -90 φ 90

Modified Phong Model! Computes a color or shade for each vertex using a lighting model (the modified Phong model) that takes into account Diffuse reflections Specular reflections Ambient light Emmision! Vertex shades are interpolated across polygons by the rasterizer

The Modified Phong Model! The model is a balance between simple computation and physical realism! The model uses Light positions and intensities Surface orientation (normals) Material properties (reflectivity) Viewer location! Computed for each source and each color component

Surface Normals! Normals define how a surface reflects light Application usually provides normals as a vertex atttribute Current normal is used to compute vertex s color Use unit normals for proper lighting scaling affects a normal s length

Material Properties! Define the surface properties of a primitive you can have separate materials for front and back Property Diffuse Specular Ambient Emission Shininess Description Base object color Highlight color Low-light color Glow color Surface smoothness

A BASIC LIGHTING CONCEPT How can we determine how much light should be cast onto a triangle from a directional light? P 0 Directional light - position doesn t matter - triangle is almost fully lit P 1 P 2 JEFF CHASTINE 52

A BASIC LIGHTING CONCEPT How can we determine how much light should be cast onto a triangle from a directional light? P 0 (Triangle less lit) P 1 P 2 JEFF CHASTINE 53

A BASIC LIGHTING CONCEPT How can we determine how much light should be cast onto a triangle from a directional light? P 0 P 1 P 2 JEFF CHASTINE (Little to no light hits the surface) 54

A BASIC LIGHTING CONCEPT How can we determine how much light should be cast onto a triangle from a directional light? P 0 (Directional light) P 1 P 2 JEFF CHASTINE 55

A BASIC LIGHTING CONCEPT How can we determine how much light should be cast onto a triangle from a directional light? P 0 (Directional light) P 1 P 2 JEFF CHASTINE 56

A BASIC LIGHTING CONCEPT How can we determine how much light should be cast onto a triangle from a directional light? Lesson learned: Lighting depends on angles between vectors! P 0 (Directional light) P 1 P 2 JEFF CHASTINE 57

A BASIC LIGHTING CONCEPT How can we determine how much light should be cast onto a triangle from a directional light? P 0 (Directional light) P 1 P 2 JEFF CHASTINE Assuming N and L are normalized, and N L isn t negative 58

BASIC LIGHTING Four independent components: Diffuse the way light falls off of an object Specular the shininess of the object Ambient a minimum amount of light used to simulate global illumination Emit a glowing effect Only diffuse JEFF CHASTINE 59

BASIC LIGHTING Four independent components: Diffuse the way light falls off of an object Specular the shininess of the object Ambient a minimum amount of light used to simulate global illumination Emit a glowing effect Diffuse+Specular JEFF CHASTINE 60

BASIC LIGHTING Four independent components: Diffuse the way light falls off of an object Specular the shininess of the object Ambient a minimum amount of light used to simulate global illumination Emit a glowing effect Diffuse+Specular+Ambient Ambient JEFF CHASTINE 61

BASIC LIGHTING Four independent components: Diffuse the way light falls off of an object Specular the shininess of the object Ambient a minimum amount of light used to simulate global illumination Emit a glowing effect D+S+A+Emit JEFF CHASTINE Note: emit does not produce light! 62

INTERACTION BETWEEN MATERIAL AND LIGHTS Final color of an object is comprised of many things: The base object color (called a material ) The light color Example: a purple light on a white surface Any textures we apply (later) Materials and lights have four individual components Diffuse color (c d and l d ) Specular color (c s and l s ) Ambient color (c a and l a ) Emit color (c e and l e ) c d * l d = [c d.r *l d.r, c d.g *l d.g, c d.b *l d.b ] // R, G, B JEFF CHASTINE 63

GENERAL LIGHTING Primary vectors l the incoming light vector n the normal of the plane/vertex r the reflection vector v the viewpoint (camera) l n v r θ θ JEFF CHASTINE

LAMBERTIAN REFLECTANCE (DIFFUSE COMPONENT) l n θ JEFF CHASTINE

LAMBERTIAN REFLECTANCE (DIFFUSE COMPONENT) scalar 3 parts (R, G, B) l n θ Note: final_color diffuse has R, G, B JEFF CHASTINE

LAMBERTIAN REFLECTANCE (DIFFUSE COMPONENT) l n θ JEFF CHASTINE

BLINN-PHONG REFLECTION (SPECULAR COMPONENT) Describes the specular highlight and is dependent on viewpoint v Also describes a half-vector h that is halfway between v and l h n v l θ θ r JEFF CHASTINE

BLINN-PHONG REFLECTION (SPECULAR COMPONENT) h n v l θ θ r Note: vectors should be normalized JEFF CHASTINE

BLINN-PHONG REFLECTION (SPECULAR COMPONENT) h n v l θ θ r JEFF CHASTINE

s = ~1 s = ~30 s = ~255 JEFF CHASTINE

AMBIENT AND EMIT COMPONENTS JEFF CHASTINE

FINAL COLOR To determine the final color (excluding textures) we sum up all components: + final_color diffuse final_color specular final_color ambient final_color emit final_color http://en.wikipedia.org/wiki/phong_reflection_model JEFF CHASTINE

WHAT ABOUT MULTIPLE LIGHTS? JEFF CHASTINE