CS 480/680 Computer Graphics Shading.

Slides:



Advertisements
Similar presentations
Computer Graphics - Shading -
Advertisements

Computer Graphics I, Fall 2010 Shading II.
1 Graphics CSCI 343, Fall 2013 Lecture 18 Lighting and Shading.
CS 480/680 Computer Graphics Shading 2 Dr. Frederick C Harris, Jr.
Virtual Realism LIGHTING AND SHADING. Lighting & Shading Approximate physical reality Ray tracing: Follow light rays through a scene Accurate, but expensive.
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.
University of New Mexico
Computer Graphics - Class 10
IMGD 1001: Illumination by Mark Claypool
Lighting and Shading Wen-Chieh (Steve) Lin
Objectives Learn to shade objects so their images appear three- dimensional Learn to shade objects so their images appear three- dimensional Introduce.
6.1 Vis_04 Data Visualization Lecture 6 - A Rough Guide to Rendering.
CS5500 Computer Graphics March 26, Shading Reference: Ed Angel’s book.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Shading I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
LIGHTING Part One - Theory based on Chapter 6. Lights in the real world Lights bounce off surfaces and reflect colors, scattering light in many directions.
Shading Surface can either (both) 1.Emit light. E.g. light bult 2.Reflect light. E.g. Mirror.
CS 480/680 Computer Graphics Shading I Dr. Frederick C Harris, Jr.
Fundamentals of Computer Graphics Part 6 Shading prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared with Angel,E.:
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Shading I Shandong University Software College Instructor: Zhou Yuanfeng
COMPUTER GRAPHICS CS 482 – FALL 2014 AUGUST 27, 2014 FIXED-FUNCTION 3D GRAPHICS MESH SPECIFICATION LIGHTING SPECIFICATION REFLECTION SHADING HIERARCHICAL.
19/17/ :25 UML Graphics: Conceptual Model Real Object Human Eye Display Device Graphics System Synthetic Model Synthetic Camera Real Light Synthetic.
1 Illumination and Shading Day 6, 2013 © Jeff Parker.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
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.
Shading Chapter 6. CS 480/680 2Chapter 6 -- Shading Introduction: Introduction: We have learned to build three-dimensional models and to display them.
Illumination and Shading
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E.
1 Graphics CSCI 343, Fall 2015 Lecture 21 Lighting and Shading III.
Lecture Fall 2001 Illumination and Shading in OpenGL Light Sources Empirical Illumination Shading Transforming Normals Tong-Yee Lee.
Shading. For Further Reading Angel 7 th Ed: ­Chapter 6 2.
Local Illumination and Shading
1 CSCE 441: Computer Graphics Lighting Jinxiang Chai.
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
Computer Graphics Lecture 25 Fasih ur Rehman. Last Class Shading.
Illumination Models. Introduction 1 Illumination model: Given a point on a surface, what is the perceived color and intensity? Known as Lighting Model,
Computer Graphics: Illumination
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
Illumination : Hearn & Baker Ch. 10
Shading To determine the correct shades of color on the surface of graphical objects.
Introduction to Computer Graphics with WebGL
CS 480/680 Computer Graphics Shading.
Prof. Harriet Fell Spring 2007 Lecture 26 – March 19, 2007
Unit-7 Lighting and Shading
Models and Architectures
CSC461: Lecture 23 Shading Computation
Introduction to Computer Graphics with WebGL
CSE 470 Introduction to Computer Graphics Arizona State University
Illumination and Shading
Fundamentals of Computer Graphics Part 6 Shading
CS5500 Computer Graphics April 10, 2006.
Isaac Gang University of Mary Hardin-Baylor
Chapter IX Lighting.
CS5500 Computer Graphics May 29, 2006
Advanced Computer Graphics
Lighting and Shading (I)
GR2 Advanced Computer Graphics AGR
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
Lighting Calculations
Presentation transcript:

CS 480/680 Computer Graphics Shading

The Phong Reflection Model Although we could approach light-material interactions through physical models, we have chosen to use a model that leads to efficient computations and to be a close enough approximation to physical reality to produce good renderings under a variety of lighting conditions and material properties.

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 This is determined by n and l

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 qi cos qi = l · n if vectors normalized There are also three coefficients, kr, kb, kg 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 the angle f is the angle between r and the reflector v Ir ~ ks I cosaf shininess coef reflected intensity incoming intensity absorption coef

The Shininess Coefficient Values of a between 100 and 200 correspond to metals Values between 5 and 10 give surface that look like plastic cosa f -90 f 90

Computation of Vectors The illumination and reflection models that we have derived are sufficiently general that they can be applied to either curved or flat surfaces, to parallel or perspective views, and to distant or near surfaces. Most require vectors and dot products. In this section we see what additional techniques can be applied when our objects are composed of flat polygons.

Vectors - Normal Plane Typically the definition is given as ax+ by+ cz + d = 0 It could also be given as n . (p-p0) = 0 If we were given 3 noncollinear points, we could find the normal by n = (p2-p0) x (p1-p0) we must be careful about the order of the vectors. Reversing the order changes the surface from outward pointing to inward pointing.

Vectors - Normal Curved Surfaces We could go through the math of how a sphere is defined. We could go through parametric equations of a sphere But we are only interested in the direction of the normal, so if the sphere is centered at the origin, we can say the normal is p

Vectors – Ange of Reflection Once we have calculated the normal at a point, we can use this normal and the direction of light to compute the direction of a perfect reflection angle of incidence is equal to the angle of reflection

Vectors – Half Way Vector If we use the Phong model with specular reflections in our rendering, the dot product r.v should be recalculated at every point on the surface We can obtain an interesting approximation by using the unit vector halfway between the viewer vector and the light-source vector:

Vectors – Ange of Reflection If we replace r.v with n.h, we avoid calculation of r However, the halfway angle is smaller than the angle used for specular computation, so if we use the same exponent e in (n.h)e the specular highlights will be smaller, so we use a different value of e to fix this.

Transmitted Light Consider a surface that transmits all the light that strikes it If the speed of light differs in the two materials, the light is bent at the surface Let hl and ht be the indices of refraction Snell’s law states that

Transmitted Light Therefore, we can calculate the direction of the transmitted light. A more general expression for what happens at a transmitting surface corresponds to this figure some light is transmitted, some is reflected, and the rest is absorbed.

Polygonal Shading Assuming that we can compute normal vectors, given a set of light sources and a viewer, both the lighting and illumination models that we have developed can be applied at every point on a surface. Consider the polygon mesh shown here. We will consider three ways to shade the polygons: flat, interpolative or Gourand, and Phong shading

Flat Shading The three vectors - l, n, and v - can vary but for a flat polygon, n is constant if we assume the viewer does not change, v is constant if the light source is distance, l is constant If all three are constant, the shading calculations only need to be carried out once for each polygon.

Interpolative and Gourand Shading The normals are computed at each vertex. Colors and intensities of interior points are interpolated between vertices. Problem: normals are discontinuous at the vertex Solution: average them

Phong Shading Even the smoothness introduced by Gourand shading may not prevent bands. Phong proposed that instead of interpolating the intensities, interpolate the normals and then do calculation of intensities using the interpolated normal (typically at scan conversion) This is much smoother, but at a greater computational cost.

Lighting Examples Which one is which?

Global Rendering There are limitations imposed by the local lighting model that we have used. Consider, for example, an array of spheres

Global Rendering Our lighting model cannot handle these situations. It also cannot produce shadows. If these effects are important, than we can use a more sophisticated (and slower) rendering technique, such as ray tracing and radiosity. Ray Tracing works well for highly specular surfaces; for example, in scenes composed of highly reflective and translucent objects, such as glass balls. Radiosity is best suited for scenes with perfectly diffuse surfaces, such as the interior of buildings.

Suggested Readings The use of lighting and reflection in computer graphics has followed two parallel paths: the physical and the computational Foley (90) gives a great discussion on these models. Phong put together his model in 1975 Ray tracing was introduced to computer graphics by Appel in 1968. Radiosity is based upon a method first used in heat transfer (Sie 81) and was applied to computer graphics in 1984. The OpenGL Programmer’s Guide contains many good hints on effective use of OpenGL’s rendering capability.

Vertex Lighting Shaders I // vertex shader in vec4 vPosition; in vec3 vNormal; out vec4 color; //vertex shade // light and material properties uniform vec4 AmbientProduct, DiffuseProduct, SpecularProduct; uniform mat4 ModelView; uniform mat4 Projection; uniform vec4 LightPosition; uniform float Shininess;

Vertex Lighting Shaders II void main() { // Transform vertex position into eye coordinates vec3 pos = (ModelView * vPosition).xyz; vec3 L = normalize( LightPosition.xyz - pos ); vec3 E = normalize( -pos ); vec3 H = normalize( L + E ); // Transform vertex normal into eye coordinates vec3 N = normalize( ModelView*vec4(vNormal, 0.0) ).xyz;

Vertex Lighting Shaders III // Compute terms in the illumination equation vec4 ambient = AmbientProduct; float Kd = max( dot(L, N), 0.0 ); vec4 diffuse = Kd*DiffuseProduct; float Ks = pow( max(dot(N, H), 0.0), Shininess ); vec4 specular = Ks * SpecularProduct; if( dot(L, N) < 0.0 ) specular = vec4(0.0, 0.0, 0.0, 1.0); gl_Position = Projection * ModelView * vPosition; color = ambient + diffuse + specular; color.a = 1.0; }

Vertex Lighting Shaders IV // fragment shader in vec4 color; void main() { gl_FragColor = color; }

Fragment Lighting Shaders I // vertex shader in vec4 vPosition; in vec3 vNormal; // output values that will be interpolatated per-fragment out vec3 fN; out vec3 fE; out vec3 fL; uniform mat4 ModelView; uniform vec4 LightPosition; uniform mat4 Projection;

Fragment Lighting Shaders II void main() { fN = vNormal; fE = vPosition.xyz; fL = LightPosition.xyz; if( LightPosition.w != 0.0 ) { fL = LightPosition.xyz - vPosition.xyz; } gl_Position = Projection*ModelView*vPosition;

Fragment Lighting Shaders III // fragment shader // per-fragment interpolated values from the vertex shader in vec3 fN; in vec3 fL; in vec3 fE; uniform vec4 AmbientProduct, DiffuseProduct, SpecularProduct; uniform mat4 ModelView; uniform vec4 LightPosition; uniform float Shininess;

Fragment Lighting Shaders IV void main() { // Normalize the input lighting vectors vec3 N = normalize(fN); vec3 E = normalize(fE); vec3 L = normalize(fL); vec3 H = normalize( L + E ); vec4 ambient = AmbientProduct;

Fragment Lighting Shaders V float Kd = max(dot(L, N), 0.0); vec4 diffuse = Kd*DiffuseProduct; float Ks = pow(max(dot(N, H), 0.0), Shininess); vec4 specular = Ks*SpecularProduct; // discard the specular highlight if the light's behind the vertex if( dot(L, N) < 0.0 ) specular = vec4(0.0, 0.0, 0.0, 1.0); gl_FragColor = ambient + diffuse + specular; gl_FragColor.a = 1.0; }