INF3320 Computer Graphics and Discrete Geometry

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

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

Shading and Illumination

Three-Dimensional Graphics V. Guoying Zhao 1 / 55

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

Why we need shading?

Lighting. CSC 7443: Scientific Information Visualization

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

Illumination and Shading

Illumination and Shading ECE 567

Computer Graphics. Illumination and Shading

CS Surface Rendering

Graphics and Visualization

Virtual Reality for Human Computer Interaction

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

CS Computer Graphics: Illumination and Shading I

CS Computer Graphics: Illumination and Shading I

Lecture 4 Advanced Computer Graphics (CS & SE )

CEng 477 Introduction to Computer Graphics Fall

Illumination and Shading

Light Transport Baoquan Chen 2017

Illumination & Shading: Part 1

Light Sources. Spotlight model

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

Computer Graphics Lighting

Computer Graphics Lighting. Why Do We Care About Lighting?

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

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

Illumination and Shading

Illumination & Shading I

Shading. Brian Curless CSE 457 Spring 2015

Sung-Eui Yoon ( 윤성의 )

Shading. CSE 457 Winter 2015

LIGHTING AND SHADING

Lights, Colour and Materials In OpenGL

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

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

Display Issues Week 5

Surface Rendering Methods

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?

Projections and Hardware Rendering. Brian Curless CSE 557 Fall 2014

hw1-2 review hw 3 questions?

CS 148, Summer 2012 Introduction to Computer Graphics and Imaging

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

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

Comp 410/510 Computer Graphics. Spring Shading

Introduction to Computer Graphics 7. Shading

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

Virtual Reality for Human Computer Interaction

Shading , Fall 2004 Nancy Pollard Mark Tomczak

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

Reflection and Shading

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

CS 4600 Fall Utah School of Computing

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

ECS 175 COMPUTER GRAPHICS. Ken Joy.! Winter 2014

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

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

Shading. Slides by Ulf Assarsson and Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology

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.

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

Lecture 15: Shading-I. CITS3003 Graphics & Animation

Illumination & Shading

Illumination in Computer Graphics

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

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

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

Visualisatie BMT. Rendering. Arjan Kok

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

Understand how real-world lighting conditions are approximated by OpenGL

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

Introduction to Visualization and Computer Graphics

CS5620 Intro to Computer Graphics

5.2 Shading in OpenGL

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

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

CPSC 314 LIGHTING AND SHADING

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

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

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

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

CS452/552; EE465/505. Intro to Lighting

Lighting. Chapter 5. Chapter Objectives. After reading this chapter, you'll be able to do the following:

Lighting/Shading III. Week 7, Wed Mar 3

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

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

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

Color and Light CSCI 4229/5229 Computer Graphics Fall 2016

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

From Graphics to Visualization

Illumination and Shading

API for creating a display window and using keyboard/mouse interations. See RayWindow.cpp to see how these are used for Assignment3

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

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

Problem Set 4 Part 1 CMSC 427 Distributed: Thursday, November 1, 2007 Due: Tuesday, November 20, 2007

CS452/552; EE465/505. Lighting & Shading

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

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

Shading 1: basics Christian Miller CS Fall 2011

Transcription:

INF3320 Computer Graphics and Discrete Geometry Visual appearance Christopher Dyken and Martin Reimers 23.09.2009 Page 1

Visual appearance Real Time Rendering: Chapter 5 Light Sources and materials Shading Transparency, alpha and compositing Gamma correction The Red Book: Lighting (Chapter 5) Page 2

The OpenGL Pipeline revisited Page 3

Recap and preview Previously: modeling vertex transformations triangles transformed into view / device coordinates The next step in the pipeline is to rasterize primitives Shading amounts to colouring the pixels For that we can use lighting models, texturing, shaders,... Page 4

The shading determines the visual appearance Here, the same set of triangles are subjected to different shaders: Hidden line Plain Phong Shiny Phong Parallax GS particle occlusion map fire Page 5

Lighting Page 6

To set up lighting in OpenGL OpenGL has a built in simple lighting model: 1. Determine one normal per vertex 2. Set up a number of light sources 3. Set up lighting model 4. Determine material properties Lighting calculated per vertex, pixels shaded by linear interpolation Geometry Lighting Shading Page 7

To set up lighting in OpenGL - example Render a lit sphere: GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat mat_shininess[] = { 50.0 }; GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 }; glclearcolor (0.0, 0.0, 0.0, 0.0); glshademodel (GL_SMOOTH); glmaterialfv(gl_front, GL_SPECULAR, mat_specular); glmaterialfv(gl_front, GL_SHININESS, mat_shininess); gllightfv(gl_light0, GL_POSITION, light_position); glenable(gl_lighting); glenable(gl_light0);... glutsolidsphere(1,0,20,0,16.0); Check out Nate Robins lighting tutorial Page 8

Light sources Directional light Point light Spot light cut off angle light direction Emit light The light vector points toward the source Light color is the intensity in RGB components Types of light: (local) ambient, diffusive and specular Attenuation: the intensity decays with distance In addition there is (global) ambient light Page 9

Light sources II A number of lights can be used (8 required in OpenGL) Use GL_LIGHT0, GL_LIGHT1 etc. Position light in world coordinates Modelview transforms affect light position and direction Check out Nate Robins lightposition tutorial Page 10

Light and matter Page 11

Materials Materials interact with light in essentially two ways Absorbtion: light energy changes form Scattering: light changes direction, e.g. reflection and refraction (transmission) Materials have mixed properties wrt. these interactions, no materials are perfect: there will always be some absorption, reflection and refraction. There are no perfect mirrors. Page 12

Diffuse reflection A perfectly diffuse surface that reflects light isotropically (equally in all directions) is called Lambertian (e.g. chalk) l θ n Lambert s cosine law The fraction of outgoing light intensity I (exitance) for a Lambertian surface with normal n and light vector l equals I = n l n l = cos(θ) Note: no dependency on view direction! Page 13

Mirror Reflection Reflection law for perfect mirrors the incoming light direction is mirrored about the surface normal ( (l, n) = (r, n)) and all three vectors lie in the same plane Example: reflection vector Let n = 1. Then l projected onto n is halfway between l and r. l θ n θ r which gives l+r 2 = (l n)n r = 2(l n)n l. Page 14

Specular Reflection Specular Reflection model the fraction of outgoing specular intensity (=exitance) along v depends on the angle between the half vector h = (v + l)/ v + l and the surface normal: (n h) s = (cos(θ)) s where s is a shininess factor and θ = (n, h) The specular exitance depends on l n θ h v n, v, l and s, as well as irradiance (incoming intensity) Note: depends on view direction v! Page 15

Refraction Light is bent when it passes the boundary of two different media. The index of refraction η is the speed of light in vacuum c divided by the speed of light in the material v, i.e. η = c v. Let η i and η r be the refractive indices of material i and r, and let θ i and θ r be the angle between the light ray and surface normal for the incident and the refracted ray. i η i θ i n Snell s law says η r η i sin θ i = η r sin θ r. θ r r Page 16

If η i is larger than η r, e.g. from glass to air: We get total reflection when the incident angle is larger than the critical angle. In this case, the light is not refracted, but reflected back into the material. The critical angle θ c is given by Material η Vacuum 1.00000 Air 1.00029 CO 2 1.000449 H 2 O @20 C 1.33335 H 2 O @100 C 1.31819 Alcohol 1.329 Ice 1.31 Sapphire 1.77 Diamond 2.417 sin θ c = η r η i. Page 17

Material color Specifies the fraction of incoming light that is reflected. A red object is red because it absorbs all colors but read when lit by white light (what about blue light?) Page 18

Material color Specifies the fraction of incoming light that is reflected. A red object is red because it absorbs all colors but read when lit by white light (what about blue light?) Materials have ambient, diffuse and specular colors (i.e. they reflect the corresponding light in different ways) Diffuse color: THE color Ambient color: reflected off of other surfaces Specular color: the color of reflected light (often white-ish) In addition, materials can have an emissive color Page 19

Light and Material interaction The different types of light color and material color interact:... material color scales the light color Suppose the ambient light color (intensity) of a light source is c = (LR, LG, LB) and the ambient material color (reflected proportion) of the material is m = (MR, MG, MB), then the resulting reflected light is m c = (LR MR, LG MG, LB MB) Light is scaled according to reflectance model, e.g. diffusive m c n l n l Outgoing light intensity add up (clamped to 1) Page 20

Lighting and Shading Page 21

What is the difference between lighting and shading? Lighting The interaction between material and light sources, yields the amount of light in a point in space. Shading The coloring of a fragment/pixel, e.g. based on a lighting model Phong lighting and Phong shading The Phong lighting models refers to a method to light a point not to be confused with Phong shading, which is to interpolate the normal vector over a surface. Page 22

Geometry Flat shading Gouraud shading Phong shading shading interpolation Flat shading evaluates the lighting model once for each triangle, and fills the triangle with that colour. Gouraud shading evaluates the lighting model at each of the three vertices and interpolates the colour to determine the fragment colours inside the triangle. Phong shading evaluates the lighting model per fragment. The normal vector is interpolated (and normalized) over the triangle. Page 23

Phong Lighting Model Page 24

The Phong lighting model is composed of three components: ambient component, diffuse component, specular component. Remember: Looking good with a cheap evaluation is more important than physical correctness. Vectors used by the Phong lighting model n n is the surface normal at p. v l is light source direction. l r r is l reflected about n. p v points towards the viewer. Page 25

Ambient component The ambient term simulates indirect lighting, light bouncing off surfaces onto other surfaces It is the same regardless of orientation, and is modeled with a constant. Diffuse component Diffuse component models Lambert s law, i = n l If negative, surface is facing away. To avoid negative intensity, i diff = max(n l, 0) Page 26

Specular component Specular component models light reflected directly by the surface. Half-vector: h = l+v l+v, so i spec = max(h n, 0) s, where s models the shininess, Alternative approach From law of reflection, r = 2(l n)n l i spec = max(r v, 0) s (this is less realistic, see RTR 7.5.7 for an explanation) Page 27

Light attenuation Light intensity is approximately proportional to the inverse of the square of the distance d from p to the light source: f (d) = 1 a+bd+cd 2, We can manipulate the attenuation model by a, b, and c. Only the diffuse and the specular component is attenuated. Material and light properties are modeled through ambient, diffuse, and specular colours. Thus, the whole equation is z } { z } { c = m a l a + f (d) max(n l, 0)m d l d + max(h n, 0) s m s l s where denotes element-by-element multiplication Page 28

The OpenGL fixed-function lighting model Page 29

To set up lighting in OpenGL 1. Set up one normal pr vertex 2. Set up lights 3. Set up lighting model 4. Determine material properties Example: http://glprogramming.com/red/chapter05.html#name3 Page 30

The OpenGL fixed-function lighting model OpenGL carries out lighting calculations in eye-coords (after modelview transform, but before perspective transform). OpenGL fixed function lighting API Lighting calculations enabled with glenable(gl_lighting). Global light model properties like ambient colors and if the viewer is infinitely far away is specified with gllightmodel. Per light properties like light colours, type, position, direction, and attenuation coefficients are specified with gllight. Material properties like colours and shininess with glmaterial The Phong Lighting equation is calculated for each vertex using the normal vector specified by glnormal. Page 31

Which values are used in the calculation? vertex position in eye coords normal vector in eye coords eye position in eye coords light position in eye coords glcolor*() current colour glmaterial*(*, AMBIENT) glmaterial*(*, DIFFUSE) lighting vertex color out glmaterial*(*, SPECULAR) glenable(gl_lighting) glcolormaterial() glmaterial*(*, EMISSION) Note: light properties are missing! Shading mode glshademodel specifies if colors are constant over each primitive (GL_FLAT) or Gouraud shaded (GL_SMOOTH). Page 32

Normals are specified per vertex by glnormal*( normal ) or in arrays with glnormalpointer Normals should be normalized Some transformations changes length use glenable(gl_normalize) or glenable(gl_rescale) Page 33

Light model is specified by gllightmodel*(pname, *params) where pname controls the following parameters: GL_LIGHT_MODEL_AMBIENT specifies the ambient RGBA-color. GL_LIGHT_MODEL_COLOR_CONTROL specifies if the specular part is applied after texturing GL_LIGHT_MODEL_LOCAL_VIEWER specifies if the viewer is infinitely far away or not in specular computations (local viewer is more expensive) GL_LIGHT_MODEL_TWO_SIDE controls two-sided lighting Page 34

Lights are specified by gllight*(gl_lighti, pname, param) where GL_LIGHTi with 0 i <GL_MAX_LIGHTS (min 8) the parameters pname GL_AMBIENT, GL_DIFFUSE, or GL_SPECULAR, then param specifies the RGBA ambient, diffuse, or specular color of light. GL_POSITION specifies the homogeneous position of source 1 GL_CONSTANT_ATTENUATION, GL_LINEAR_ATTENUATION, or GL_QUADRATIC_ATTENUATION specifies a,b,c GL_SPOT_DIRECTION, GL_SPOT_EXPONENT, or GL_SPOT_CUTOFF specifies spotlight parameters 1 w = 0 implies directional light Page 35

Material properties are specified by glmaterial*(face, pname, param) where face is GL_FRONT, GL_BACK, or GL_FRONT_AND_BACK, and specifies the material properties: GL_AMBIENT, GL_DIFFUSE, or GL_SPECULAR, specifies the material RGBA ambient, diffuse, or specular color. GL_SHININESS specifies the specular exponent m shi Page 36

glcolormaterial When lighting is enabled, the color of glcolor is ignored unless you override with glcolormaterial( face, mode) Let you override the color specified by glmaterial with the color specified by glcolor. The following modes can be used: GL_EMISSION, GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, and GL_AMBIENT_AND_DIFFUSE. Page 37

Transparency, Alpha and compositing Page 38

Transparency and Alpha Semi-transparent objects can be rendered by view based or light based methods Screen-door transparency: render checkerboard pattern, every other pixel is foreground. Best at 50% transparency and one object Alpha Blending: foreground (transparent) color blenden with background color, using the over operator and the (fourth) alpha channel in RGBA: c = αc s + (1 α)c d where c s and c d are source and destination colors. Need to render back to front, i.e. need to sort the geometry (nontrivial) There are many applications, blending modes etc... later Page 39

Gamma Correction Screen intensity is usually not a linear function of input voltage. To represent color correctly we modify input signal by V out = V γ in Page 40

The last slide More about transparency, blending etc. later Next time: more appearance, antialiasing, texturing Page 41