Ambient and Diffuse Light

Similar documents
Specular Reflection. Lecture 19. Robb T. Koether. Hampden-Sydney College. Wed, Oct 4, 2017

The Model Stack. Lecture 8. Robb T. Koether. Hampden-Sydney College. Wed, Sep 6, 2017

The Critical-Path Algorithm

Shading Triangles. Lecture 37. Robb T. Koether. Hampden-Sydney College. Mon, Nov 30, 2015

Rotations and Translations

Scope and Parameter Passing

Minimal Spanning Trees

Scheduling and Digraphs

The Pairwise-Comparison Method

Sampling Distribution Examples Sections 15.4, 15.5

The Projection Matrix

The Mesh Class. Lecture 23. Robb T. Koether. Hampden-Sydney College. Wed, Oct 18, 2017

Density Curves Sections

The Graphics Pipeline

The Class Construct Part 1

Applying Textures. Lecture 27. Robb T. Koether. Hampden-Sydney College. Fri, Nov 3, 2017

The Graphics Pipeline

Scope and Parameter Passing

The Decreasing-Time Algorithm

Function Usage. Lecture 15 Sections 6.3, 6.4. Robb T. Koether. Hampden-Sydney College. Mon, Oct 1, 2018

The Traveling Salesman Problem Brute Force Method

while Loops Lecture 13 Sections Robb T. Koether Wed, Sep 26, 2018 Hampden-Sydney College

The string Class. Lecture 21 Sections 2.9, 3.9, Robb T. Koether. Wed, Oct 17, Hampden-Sydney College

Stack Applications. Lecture 27 Sections Robb T. Koether. Hampden-Sydney College. Wed, Mar 29, 2017

Solving Recursive Sequences by Iteration

The Class Construct Part 2

LR Parsing - Conflicts

Recursive Sequences. Lecture 24 Section 5.6. Robb T. Koether. Hampden-Sydney College. Wed, Feb 27, 2013

Street-Routing Problems

Recursive Sequences. Lecture 24 Section 5.6. Robb T. Koether. Hampden-Sydney College. Wed, Feb 26, 2014

Recognition of Tokens

Implementing Linked Lists

Pointers. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Mon, Jan 20, 2014

Pointers. Lecture 1 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 14, 2015

The Traveling Salesman Problem Nearest-Neighbor Algorithm

The Projection Matrix

Recursive Linked Lists

Webpage Navigation. Lecture 27. Robb T. Koether. Hampden-Sydney College. Mon, Apr 2, 2018

Operators. Lecture 12 Section Robb T. Koether. Hampden-Sydney College. Fri, Feb 9, 2018

Total Orders. Lecture 41 Section 8.5. Robb T. Koether. Hampden-Sydney College. Mon, Apr 8, 2013

Recursive Descent Parsers

Magnification and Minification

Programming Languages

Stack Applications. Lecture 25 Sections Robb T. Koether. Hampden-Sydney College. Mon, Mar 30, 2015

List Iterator Implementation

Boxplots. Lecture 17 Section Robb T. Koether. Hampden-Sydney College. Wed, Feb 10, 2010

The x86 Instruction Set

Linked Lists. Lecture 16 Sections Robb T. Koether. Hampden-Sydney College. Wed, Feb 22, 2017

Abstract Data Types. Lecture 23 Section 7.1. Robb T. Koether. Hampden-Sydney College. Wed, Oct 24, 2012

Binary Tree Applications

Boolean Expressions. Lecture 31 Sections 6.6, 6.7. Robb T. Koether. Hampden-Sydney College. Wed, Apr 8, 2015

XPath Lecture 34. Robb T. Koether. Hampden-Sydney College. Wed, Apr 11, 2012

Shader Programs. Lecture 30 Subsections 2.8.2, Robb T. Koether. Hampden-Sydney College. Wed, Nov 16, 2011

Integer Overflow. Lecture 8 Section 2.5. Robb T. Koether. Hampden-Sydney College. Mon, Jan 27, 2014

Recursion. Lecture 26 Sections , Robb T. Koether. Hampden-Sydney College. Mon, Apr 6, 2015

Array Lists. Lecture 15. Robb T. Koether. Hampden-Sydney College. Mon, Feb 22, 2016

The Plurality-with-Elimination Method

The Normal Distribution

XPath. Lecture 36. Robb T. Koether. Wed, Apr 16, Hampden-Sydney College. Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, / 28

Pointers. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Fri, Jan 18, 2013

The Coefficient of Determination

XQuery FLOWR Expressions Lecture 35

Pointer Arithmetic. Lecture 4 Chapter 10. Robb T. Koether. Hampden-Sydney College. Wed, Jan 25, 2017

Basic PHP. Lecture 19. Robb T. Koether. Hampden-Sydney College. Mon, Feb 26, 2108

The CYK Parsing Algorithm

Friends and Unary Operators

Stacks and their Applications

DTDs and XML Attributes

Array Lists. Lecture 15. Robb T. Koether. Hampden-Sydney College. Fri, Feb 16, 2018

Dynamic Allocation of Memory

The Mesh Class. Lecture 26. Robb T. Koether. Wed, Oct 28, Hampden-Sydney College

Programming Languages

List Iterators. Lecture 27 Section Robb T. Koether. Hampden-Sydney College. Wed, Apr 8, 2015

Introduction to Databases

Building the Abstract Syntax Trees

XML Attributes. Lecture 33. Robb T. Koether. Hampden-Sydney College. Wed, Apr 25, 2018

Regular Expressions. Lecture 10 Sections Robb T. Koether. Hampden-Sydney College. Wed, Sep 14, 2016

The Constructors. Lecture 7 Sections Robb T. Koether. Hampden-Sydney College. Wed, Feb 1, 2017

Binary Tree Implementation

List Iterators. Lecture 34 Section Robb T. Koether. Hampden-Sydney College. Wed, Apr 24, 2013

Mipmaps. Lecture 35. Robb T. Koether. Hampden-Sydney College. Wed, Nov 18, 2015

Binary Tree Implementation

Basic PHP Lecture 17

Inheritance: The Fundamental Functions

Displaying Distributions - Quantitative Variables

-=Bui Tuong Phong's Lighting=- University of Utah, but with shaders. Anton Gerdelan Trinity College Dublin

Recursion. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 17, 2018

Introduction to Databases

Function Definition Syntax Tree

Aggregation. Lecture 7 Section Robb T. Koether. Hampden-Sydney College. Wed, Jan 29, 2014

Fundamental Data Types

Functional Dependencies and Normal Forms

Functional Dependencies and Normal Forms

PHP Queries and HTML Forms Lecture 23

Basic CSS Lecture 17

LR Parsing - The Items

Dynamic Allocation of Memory

The Constructors. Lecture 6 Sections Robb T. Koether. Hampden-Sydney College. Fri, Jan 26, 2018

The View Frustum. Lecture 9 Sections 2.6, 5.1, 5.2. Robb T. Koether. Hampden-Sydney College. Wed, Sep 14, 2011

Introduction to Compiler Design

Transcription:

Ambient and Diffuse Light Lecture 20 Robb T. Koether Hampden-Sydney College Mon, Oct 12, 2015 Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 1 / 29

Outline 1 Lighting 2 Ambient Light 3 Diffuse Light 4 Programming the Shaders Ambient Light Model Diffuse Light Model Coordinate Systems 5 Assignment 12 6 Assignment Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 2 / 29

Outline 1 Lighting 2 Ambient Light 3 Diffuse Light 4 Programming the Shaders Ambient Light Model Diffuse Light Model Coordinate Systems 5 Assignment 12 6 Assignment Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 3 / 29

Lighting The lighting model includes three kinds of light. Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 4 / 29

Lighting The lighting model includes three kinds of light. Ambient light Source is from all directions. Independent of the surface s orientation. Reflected equally in all directions. Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 4 / 29

Lighting The lighting model includes three kinds of light. Ambient light Source is from all directions. Independent of the surface s orientation. Reflected equally in all directions. Diffuse light Source is from a specific direction. Dependent on the surface s orientation. Reflected equally in all directions. Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 4 / 29

Lighting The lighting model includes three kinds of light. Ambient light Source is from all directions. Independent of the surface s orientation. Reflected equally in all directions. Diffuse light Source is from a specific direction. Dependent on the surface s orientation. Reflected equally in all directions. Specular light Source is from a specific direction Dependent on the surface s orientation. Reflected more in some directions than in others. Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 4 / 29

Outline 1 Lighting 2 Ambient Light 3 Diffuse Light 4 Programming the Shaders Ambient Light Model Diffuse Light Model Coordinate Systems 5 Assignment 12 6 Assignment Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 5 / 29

Ambient Light Definition (Ambient Light) Ambient light has no specific source. It illuminates all surfaces equally. The intensity of the reflected light is independent of the angle of incidence and the angle of reflection. Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 6 / 29

Ambient Light Regardless of the orientation of the surface, the strength of the relection is the same. Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 7 / 29

Outline 1 Lighting 2 Ambient Light 3 Diffuse Light 4 Programming the Shaders Ambient Light Model Diffuse Light Model Coordinate Systems 5 Assignment 12 6 Assignment Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 8 / 29

Diffuse Light Definition (Diffuse Light) Diffuse light is reflected equally in all directions, but it depends the direction of the light source. The intensity of the reflection depends on the angle of incidence, but does not depend on the angle of reflection. Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 9 / 29

Diffuse Light The angle of incidence varies over a curved surface. The more the light direction deviates from the normal, the weaker the reflection. Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 10 / 29

Outline 1 Lighting 2 Ambient Light 3 Diffuse Light 4 Programming the Shaders Ambient Light Model Diffuse Light Model Coordinate Systems 5 Assignment 12 6 Assignment Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 11 / 29

Outline 1 Lighting 2 Ambient Light 3 Diffuse Light 4 Programming the Shaders Ambient Light Model Diffuse Light Model Coordinate Systems 5 Assignment 12 6 Assignment Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 12 / 29

Ambient Lighting Model Let color be an RGB vector that represents the surface s innate color. Let ambient be an RGB vector that represents the intensity of the ambient light. The ambient reflection is computed as color*ambient Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 13 / 29

Outline 1 Lighting 2 Ambient Light 3 Diffuse Light 4 Programming the Shaders Ambient Light Model Diffuse Light Model Coordinate Systems 5 Assignment 12 6 Assignment Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 14 / 29

Diffuse Lighting Model Let diffuse be an RGB vector that represents the intensity of the diffuse light. light_dir be a unit vector indicating the direction of the light source. norm be a unit vector normal to the surface. The diffuse reflection is computed as color*diffuse*dot(light_dir, norm) Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 15 / 29

Outline 1 Lighting 2 Ambient Light 3 Diffuse Light 4 Programming the Shaders Ambient Light Model Diffuse Light Model Coordinate Systems 5 Assignment 12 6 Assignment Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 16 / 29

Coordinate Systems Computing ambient shading is simple, but we must be very careful when computing diffuse shading. Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 17 / 29

Coordinate Systems Computing ambient shading is simple, but we must be very careful when computing diffuse shading. When computing the dot product L N of the light vector L and the normal N, we must be sure that they are in the same coordinate system. Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 17 / 29

Coordinate Systems Computing ambient shading is simple, but we must be very careful when computing diffuse shading. When computing the dot product L N of the light vector L and the normal N, we must be sure that they are in the same coordinate system. The light vector is initially in world coordinate system. Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 17 / 29

Coordinate Systems Computing ambient shading is simple, but we must be very careful when computing diffuse shading. When computing the dot product L N of the light vector L and the normal N, we must be sure that they are in the same coordinate system. The light vector is initially in world coordinate system. The normal vector is initially in model coordinates, so it must be transformed to world coordinates. Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 17 / 29

Coordinate Systems To make the vectors compatible, we must transform N into world coordinates, using the model matrix. However, vectors do not transform in the same way as vertices. Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 18 / 29

Coordinate Systems Let n be a vector and v = B A be a vector from a point B on a surface to a point A on the surface. Let M 1 be the model matrix and let M 2 be the transformation matrix for the normal vector. In model coordinates, we have n T v = 0, because n v. Therefore, we need to have (M 2 n) T M 1 v = 0 as well. Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 19 / 29

Coordinate Systems We have ( ) (M 2 n) T M 1 v = n T M T 2 M 1 v ( ) = n T M T 2 M 1 v If M T 2 M 1 is the identity matrix, then Therefore, M 2 n M 1 v. ( ) n T M T 2 M 1 v = n T Iv = n T v = 0. Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 20 / 29

Coordinate Systems Therefore, M 2 n M 1 v provided that M 2 = ( M T 1) 1. Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 21 / 29

Coordinate Systems It so happens that for any translation matrix T and for any rotation matrix R, ( T T) 1 = T, ( R T) 1 = R. However, for scaling matrices S, in general ( S T) 1 S. Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 22 / 29

The ModelStack Class The ModelStack Function GLfloat* invtrans(mat4 m); void toshader(gluint model_loc, GLuint norm_loc); The function invtrans() will take a 4 4 matrix m and return a pointer to 3 3 matrix that is the inverse transpose of m. In the ModelStack class, I have overloaded the toshader() function to pass both the model matrix and the normal matrix. Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 23 / 29

The ModelStack Class The ModelStack Function model_stack.toshader(model_loc, norm_loc); The above function call is typical of what we should use when programming the lighting model. Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 24 / 29

Outline 1 Lighting 2 Ambient Light 3 Diffuse Light 4 Programming the Shaders Ambient Light Model Diffuse Light Model Coordinate Systems 5 Assignment 12 6 Assignment Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 25 / 29

Assignment 12 Assignment 12 Add ambient and diffuse light to the Canal Boat program, lighting up the lock walls and the canal boat. Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 26 / 29

Outline 1 Lighting 2 Ambient Light 3 Diffuse Light 4 Programming the Shaders Ambient Light Model Diffuse Light Model Coordinate Systems 5 Assignment 12 6 Assignment Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 27 / 29

Assignment Assignment Read pp. 359-368, Classic Lighting Model. Robb T. Koether (Hampden-Sydney College) Ambient and Diffuse Light Mon, Oct 12, 2015 28 / 29