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

Similar documents
CS Computer Graphics: Illumination and Shading I

CS Computer Graphics: Illumination and Shading I

Graphics and Visualization

INF3320 Computer Graphics and Discrete Geometry

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

Illumination & Shading I

Illumination and Shading

Surface Rendering Methods

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

Three-Dimensional Graphics V. Guoying Zhao 1 / 55

Illumination and Shading

Why we need shading?

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

Computer Graphics. Illumination and Shading

LIGHTING AND SHADING

CS5620 Intro to Computer Graphics

Illumination and Shading ECE 567

Shading and Illumination

CEng 477 Introduction to Computer Graphics Fall

Reflection and Shading

蔡侑庭 (Yu-Ting Tsai) National Chiao Tung University, Taiwan. Prof. Wen-Chieh Lin s CG Slides OpenGL 2.1 Specification

CSCI 4620/8626. Computer Graphics Illumination Models and Surface Rendering Methods (Chapter 17)

Comp 410/510 Computer Graphics. Spring Shading

Light Sources. Spotlight model

Illumination & Shading

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

Introduction to Computer Graphics 7. Shading

Virtual Reality for Human Computer Interaction

Sung-Eui Yoon ( 윤성의 )

Computer Graphics Lighting

Computer Graphics Lighting. Why Do We Care About Lighting?

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

CS Surface Rendering

Virtual Reality for Human Computer Interaction

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

Illumination & Shading: Part 1

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

Illumination and Shading

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

Illumination Models & Shading

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

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

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

Visualisatie BMT. Rendering. Arjan Kok

Shading I Computer Graphics I, Fall 2008

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

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

Lighting. CSC 7443: Scientific Information Visualization

CPSC 314 LIGHTING AND SHADING

Lecture 15: Shading-I. CITS3003 Graphics & Animation

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

Color and Light CSCI 4229/5229 Computer Graphics Fall 2016

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

Computer Graphics. Illumination and Shading

Lighting/Shading III. Week 7, Wed Mar 3

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

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

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

CS Illumination and Shading. Slide 1

CS 4600 Fall Utah School of Computing

Illumination and Shading

w Foley, Section16.1 Reading

ECS 175 COMPUTER GRAPHICS. Ken Joy.! Winter 2014

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

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

Illumination in Computer Graphics

Interpolation using scanline algorithm

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

CPSC / Illumination and Shading

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

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

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

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

Light Transport Baoquan Chen 2017

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

CS 325 Computer Graphics

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

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

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

CS452/552; EE465/505. Intro to Lighting

Lights, Colour and Materials In OpenGL

Computer Graphics. Lecture 13. Global Illumination 1: Ray Tracing and Radiosity. Taku Komura

Illumination and Shading

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

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

CS3500 Computer Graphics Module: Lighting and Shading

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 the OpenGL shading Methods 1) Light and material functions on MV.js 2) per vertex vs per fragment shading 3) Where to carry out

COMP3421. Hidden surface removal Illumination

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

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

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

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

Simple Lighting/Illumination Models

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

Computer Graphics and GPGPU Programming

Pipeline Operations. CS 4620 Lecture 10

CSE 681 Illumination and Phong Shading

CS770/870 Spring 2017 Color and Shading

Lighting and Shading

Transcription:

Today s class Simple shadows Shading Lighting in OpenGL Wednesday, November 21, 27 Computer Graphics - Class 1 1

Simple shadows Simple shadows can be gotten by using projection matrices Consider a light source and the shadows it will cause on the floor (e.g. the xz-plane, y=) Here the shadow will be a flat polygon The shadow polygon is the projection of the original object onto the surface Wednesday, November 21, 27 Computer Graphics - Class 1 2

Shadow setup Let the light source be located at (x l, y l, z l ), where y l is positive Let the projection plane be y = Translate the light source to the origin Now have a perspective projection through the origin (like we did previously for z = d), but the projection plane is now y = -y l Translate back Wednesday, November 21, 27 Computer Graphics - Class 1 3

Wednesday, November 21, 27 Computer Graphics - Class 1 4 Shadow projection matrix The three transformation matrices are: It will be easy to implement this as 3 transformations in OpenGL 1 1 1 1 1 1 1 1 1 1 1 1 l l l l l l l z y x y z y x

Example program RotatingCubeShadow.cpp shows an example of generating a simple shadow Wednesday, November 21, 27 Computer Graphics - Class 1 5

Shading models Shading models combine information about light sources with data about roughness and color of a face s surface to approximate how the actual light reflects from the surface of the face Wednesday, November 21, 27 Computer Graphics - Class 1 6

Two approaches Flat shading Model is applied to only one point on the face The shade determined there fills the entire face Smooth shading Model applied to several points on the face Shades blended to yield shade at each point Wednesday, November 21, 27 Computer Graphics - Class 1 7

A simple model Total light = point light sources + ambient light I = I src + I amb I src consists of two components - diffuse and specular I src = I d + I sp Wednesday, November 21, 27 Computer Graphics - Class 1 8

Geometry of light hitting an object light n r s θ φ v p r is reflected light ray = -s+2(s u n )u n Wednesday, November 21, 27 Computer Graphics - Class 1 9

Diffuse light Uniformly reemitted from a surface after absorbing incident light Brightness is proportional to surface orientation (Lambert s law; depends on cos θ) I d = I s r d (u s u n ) I s is the intensity of the light source r d is the diffuse reflection coefficient, usually chosen by trial and error Wednesday, November 21, 27 Computer Graphics - Class 1 1

Specular light Light reflected from a surface Intensity eye sees is proportional to angle between reflected ray and eye (φ) I sp = I s r s (u r u v ) f r s is the specular reflection coefficient, usually chosen by trial and error f is usually between 1 and 2 Wednesday, November 21, 27 Computer Graphics - Class 1 11

Ambient light Soft, non-directional light Assigned an intensity (I a ), experimentally chosen Assigned a reflection coefficient (r a ), usually the same as r d Total ambient light for a surface is I amb =I a r a Wednesday, November 21, 27 Computer Graphics - Class 1 12

Total light Combining the terms just developed gives the total light for a point: I = I src + I amb = I d + I sp + I amb = I s [r d (u s u n ) + r s (u r u v ) f ] + I a r a Wednesday, November 21, 27 Computer Graphics - Class 1 13

Flat shading Total intensity is an expensive number (computationally) to compute Want to do it as infrequently as possible Calculate it once per face and use this value to color the face Wednesday, November 21, 27 Computer Graphics - Class 1 14

Flat shading algorithm For each visible face: Choose a point p on the face (easiest choice is a vertex, but a better approximation would be the center - just average the vertices) Find the normal to the face Compute I at p using the equation Fill the projected polygon with the computed shade Wednesday, November 21, 27 Computer Graphics - Class 1 15

Flat shading pros/cons Advantages to flat shading Fast Simple Disadvantages Image is not very realistic Highlights are rendered poorly A large specular component at a point is spread over the entire face Wednesday, November 21, 27 Computer Graphics - Class 1 16

Flat shading in OpenGL glshademodel (GL_FLAT); Color of object is determined by color of: Last vertex for GL_LINES, GL_TRIANGLES, GL_QUADS First vertex for GL_POLYGON Wednesday, November 21, 27 Computer Graphics - Class 1 17

Ray tracing At the other extreme, we can evaluate I at every point on the face This gives rise to very realistic images at the expense of a huge computational time Wednesday, November 21, 27 Computer Graphics - Class 1 18

Smooth shading Two approaches to smooth shading Gouraud shading Phong shading Wednesday, November 21, 27 Computer Graphics - Class 1 19

Gouraud shading Interpolates intensities over the face Assumes polygon face is not planar Computes true intensities at each vertex Takes a scan line approach Interpolates intensities at each end of scan line Interpolates across scan line Wednesday, November 21, 27 Computer Graphics - Class 1 2

Gouraud shading (cont.) At each vertex, several faces meet To find normal at each vertex, average normal for each face that meets at that vertex Due to interpolation, highlights are poorly handled here as well Wednesday, November 21, 27 Computer Graphics - Class 1 21

Phong shading Instead of interpolating intensities, the normals are interpolated The interpolated normals are used to compute intensities at each pixel Since better normals are used we get a better effect from specular components Wednesday, November 21, 27 Computer Graphics - Class 1 22

Color and the lighting model Each light source can be considered to be the sum of red, green and blue components Specular reflection is independent of the color of the object; thus, specularly reflected light is the same color as the incident light Diffuse and ambient components depend upon the color of the surface Wednesday, November 21, 27 Computer Graphics - Class 1 23

Color and the lighting model (cont.) Define r dr, r dg, and r db as the diffuse reflection coefficients, which measure the percentage of their respective colors that are reflected The amount of red light that reaches the eye is therefore I R = I sr [r dr (u s u n ) + r s (u r u v ) f ] + I ar r ar r ar is usually set equal to r dr Wednesday, November 21, 27 Computer Graphics - Class 1 24

Lighting in OpenGL Light in a scene comes from several light sources Lighting is divided into four components which are independently computed and added together emitted ambient diffuse specular Wednesday, November 21, 27 Computer Graphics - Class 1 25

Lighting in OpenGL (cont.) Emitted light originates from an object and is unaffected by any light sources Ambient light is from a source that has been scattered so much by the environment that its direction is impossible to determine Wednesday, November 21, 27 Computer Graphics - Class 1 26

Lighting in OpenGL (cont.) Diffuse light comes from one direction, but once it hits a surface it is scattered equally in all directions, so it appears equally bright no matter where the eye is located Specular light comes from one direction and bounces off a surface in a preferred direction Wednesday, November 21, 27 Computer Graphics - Class 1 27

Lighting in OpenGL (cont.) A light source delivers a single distribution of frequencies However, the ambient, diffuse, and specular components might be different You can specify the RGB values for each component of light independently RGB values are in [., 1.]. For multiple lights the RGB values are summed and clamped to 1. Wednesday, November 21, 27 Computer Graphics - Class 1 28

Enabling light in OpenGL Enable lighting with glenable (GL_LIGHTING); Enable a particular light with glenable (GL_LIGHT); glenable (GL_LIGHT1); etc. Each OpenGL implementation must provide a minimum of 8 light sources Do the enabling after setting the lights properties Wednesday, November 21, 27 Computer Graphics - Class 1 29

Light properties in OpenGL gllight* (light, parameter, value); GL_AMBIENT specifies RGBA values for ambient portion of light GL_DIFFUSE GL_SPECULAR GL_POSITION specifies x, y, z, w for position of light w = is a directional light w is a positional light Wednesday, November 21, 27 Computer Graphics - Class 1 3

Global ambient light gllightmodel* (GL_LIGHT_MODEL_AMBIENT, value); provides global ambient light that is not from a particular light source Wednesday, November 21, 27 Computer Graphics - Class 1 31

Material properties RGB values correspond to the reflected proportions of the colors glmaterial* (face, parameter, value); specifies properties of objects in the scene face is one of GL_FRONT GL_BACK GL_FRONT_AND_BACK Wednesday, November 21, 27 Computer Graphics - Class 1 32

glmaterial* parameters GL_AMBIENT specifies RGBA values for ambient color GL_DIFFUSE GL_AMBIENT_AND_DIFFUSE GL_SPECULAR GL_SHININESS specifies specular exponent GL_EMISSION specifies RGBA values for emissive color Wednesday, November 21, 27 Computer Graphics - Class 1 33

What reaches the eye? For a particular lighting component, the light that reaches the eye is the product of the light value and the material value Wednesday, November 21, 27 Computer Graphics - Class 1 34

Example program sphere.cpp is an example program showing different lighting models The program generates a sphere from a tetrahedron using a technique known as recursive subdivision Wednesday, November 21, 27 Computer Graphics - Class 1 35