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

Similar documents
CS452/552; EE465/505. Intro to Lighting

Shading I Computer Graphics I, Fall 2008

Introduction to Computer Graphics with WebGL

Lecture 15: Shading-I. CITS3003 Graphics & Animation

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

Comp 410/510 Computer Graphics. Spring Shading

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

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

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

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

Introduction to Computer Graphics 7. Shading

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

Three-Dimensional Graphics III. Guoying Zhao 1 / 67

Three-Dimensional Graphics V. Guoying Zhao 1 / 55

CS 4600 Fall Utah School of Computing

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

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

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

Why we need shading?

Fundamental Types of Viewing

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

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

Models and Architectures

Lighting and Shading. Slides: Tamar Shinar, Victor Zordon

Virtual Reality for Human Computer Interaction

Virtual Cameras & Their Matrices

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

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

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

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

5.8.3 Oblique Projections

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

Supplement to Lecture 16

Shading. Brian Curless CSE 557 Autumn 2017

CS5620 Intro to Computer Graphics

Introduction to Computer Graphics 4. Viewing in 3D

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

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

ECS 175 COMPUTER GRAPHICS. Ken Joy.! Winter 2014

CHAPTER 1 Graphics Systems and Models 3

Shading II. CITS3003 Graphics & Animation

Computer Graphics. Illumination and Shading

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

Lighting. Figure 10.1

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

Interactive Computer Graphics A TOP-DOWN APPROACH WITH SHADER-BASED OPENGL

CMSC427: Computer Graphics Lecture Notes Last update: November 21, 2014

Introduction to Computer Graphics with WebGL

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

Reflection and Shading

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

On the Midterm Exam. Monday, 10/17 in class. Closed book and closed notes. One-side and one page cheat sheet is allowed. A calculator is allowed

Visualisatie BMT. Rendering. Arjan Kok

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

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

Lets assume each object has a defined colour. Hence our illumination model is looks unrealistic.

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

Graphics for VEs. Ruth Aylett

Illumination Models & Shading

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

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

CS230 : Computer Graphics Lecture 4. Tamar Shinar Computer Science & Engineering UC Riverside

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

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

Illumination & Shading: Part 1

Pipeline Operations. CS 4620 Lecture 10

Introduction to Visualization and Computer Graphics

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

Shading. Brian Curless CSE 457 Spring 2017

GLOBAL EDITION. Interactive Computer Graphics. A Top-Down Approach with WebGL SEVENTH EDITION. Edward Angel Dave Shreiner

Rasterization Overview

CS 381 Computer Graphics, Fall 2008 Midterm Exam Solutions. The Midterm Exam was given in class on Thursday, October 23, 2008.

Models and Architectures. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

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

CS 130 Exam I. Fall 2015

Three Main Themes of Computer Graphics

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

Graphics for VEs. Ruth Aylett

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

Illumination and Shading

Illumination & Shading I

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

Topics and things to know about them:

CPSC 314 LIGHTING AND SHADING

w Foley, Section16.1 Reading

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

CS 130 Exam I. Fall 2015

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

CS 4620 Program 3: Pipeline

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

Game Architecture. 2/19/16: Rasterization

Blue colour text questions Black colour text sample answers Red colour text further explanation or references for the sample answers

CS 130 Final. Fall 2015

Computergrafik. Matthias Zwicker. Herbst 2010

TSBK03 Screen-Space Ambient Occlusion

Computer Graphics I Lecture 11

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

Transcription:

Orthogonal Projection Matrices 1

Objectives Derive the projection matrices used for standard orthogonal projections Introduce oblique projections Introduce projection normalization 2

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 3

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

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 5

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

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 0 0 2 top bottom 0 0 0 0 2 near 0 far right left right left top + bottom top bottom far + near far near 1 7

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 8

Oblique Projections The OpenGL projection functions cannot produce general parallel projections such as However if we look at the example of the cube it appears that the cube has been sheared Oblique Projection = Shear + Orthogonal Projection 9

General Shear top view side view 10

Shear Matrix xy shear (z values unchanged) Projection matrix H(θ,φ) = 1 0 0 1 0 0 0 0 cot θ cot φ 1 0 0 0 0 1 General case: P = M orth H(θ,φ) P = M orth STH(θ,φ) 11

Equivalency 12

Effect on Clipping The projection matrix P = STH transforms the original clipping volume to the default clipping volume object top view z = 1 DOP clipping volume near plane far plane x = -1 DOP x = 1 z = -1 distorted object (projects correctly) 13

Perspective Projection Matrices 14

Objectives Derive the perspective projection matrices used for standard WebGL projections 15

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 16

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 17

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 18 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 19

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

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 21

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

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 23

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 hiddensurface removal and shading We simplify clipping 24

Perspective Matrices frustum 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 2 * far * near far near perspective 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 25

Meshes 26

Objective Introduce techniques for displaying polygonal meshes 27

Meshes Polygonal meshes are the standard method for defining and displaying surfaces Approximations to curved surfaces Directly from CAD packages Subdivision Most common are quadrilateral and triangular meshes Triangle strips and fans 28

Height Fields For each (x, z) there is a unique y Sampling leads to an array of y values Display as quadrilateral or triangular mesh using strips 29

Honolulu Plot Using Line Strips 30

Plot 3D Old 2D method uses fact that data are ordered and we can render front to back Regard each plane of constant z as a flat surface that can block (parts of) planes behind it Can proceed iteratively maintaining a visible top and visible bottom Lots of little line intersections Lots of code but avoids all 3D 31

Lines on Back and Hidden Faces sombrero or Mexican hat function (sin πr)/(πr) 32

Using Polygons We can use four adjacent data points to form a quadrilateral and thus two triangles which can be shaded But what if we want to see the grid? We can display each quadrilateral twice First as two filled white triangles Second as a black line loop 33

Hat Using Triangles and Lines 34

Polygon Offset Even though we draw the polygon first followed by the lines, small numerical errors cause some of fragments on the line to be display behind the corresponding fragment on the triangle Polygon offset (gl.polygonoffset) moves fragments slight away from camera Apply to triangle rendering 35

Hat with Polygon Offset 36

Other Mesh Issues How do we construct a mesh from disparate data (unstructured points) Technologies such as laser scans can produced tens of millions of such points Chapter 12: Delaunay triangulation Can we use one triangle strip for an entire 2D mesh? Mesh simplification 37

Shadows 38

Objectives Introduce Shadow Algorithms Projective Shadows Shadow Maps Shadow Volumes 39

Flashlight in the Eye Graphics When do we not see shadows in a real scene? When the only light source is a point source at the eye or center of projection Shadows are behind objects and not visible Shadows are a global rendering issue Is a surface visible from a source May be obscured by other objects 40

Shadows in Pipeline Renders Note that shadows are generated automatically by a ray tracers feeler rays will detect if no light reaches a point need all objects to be available Pipeline renderers work an object at a time so shadows are not automatic can use some tricks: projective shadows multi-rendering: shadow maps and shadow volumes 41

Projective Shadows Oldest methods Used in flight simulators to provide visual clues Projection of a polygon is a polygon called a shadow polygon Given a point light source and a polygon, the vertices of the shadow polygon are the projections of the original polygon s vertices from a point source onto a surface 42

Shadow Polygon 43

Computing Shadow Vertex 1. Source at (x l, y l, z l ) 2. Vertex at (x, y, z) 3. Consider simple case of shadow projected onto ground at (x p, 0, z p ) 4. Translate source to origin with T(-x l, -y l, -z l ) 5. Perspective projection 1 0 0 0 6. Translate back M = 0 1 0 0 0 0 1 0 1 0 y 0 0 l 44

Shadow Process 1. Put two identical triangles and their colors on GPU (black for shadow triangle) 2. Compute two model view matrices as uniforms 3. Send model view matrix for original triangle 4. Render original triangle 5. Send second model view matrix 6. Render shadow triangle Note shadow triangle undergoes two transformations Note hidden surface removal takes care of depth issues 45

Generalized Shadows Approach was OK for shadows on a single flat surface Note with geometry shader we can have the shader create the second triangle Cannot handle shadows on general objects Exist a variety of other methods based on same basic idea We ll pursue methods based on projective textures 46

Image Based Lighting We can project a texture onto the surface in which case the are treating the texture as a slide projector This technique the basis of projective textures and image based lighting Supported in desktop OpenGL and GLSL through four dimensional texture coordinates Not yet in WebGL 47

Shadow Maps If we render a scene from a light source, the depth buffer will contain the distances from the source to nearest lit fragment. We can store these depths in a texture called a depth map or shadow map Note that although we don t care about the image in the shadow map, if we render with some light, anything lit is not in shadow. Form a shadow map for each source 48

Shadow Mapping 49

Final Rendering During the final rendering we compare the distance from the fragment to the light source with the distance in the shadow map If the depth in the shadow map is less than the distance from the fragment to the source the fragment is in shadow (from this source) Otherwise we use the rendered color 50

Implementation Requires multiple renderings We will look at render-to-texture later gives us a method to save the results of a rendering as a texture almost all work done in the shaders 51

Shadow Volumes light source far clipping plane shadow volume near clipping plane COP 52

Lighting and Shading I 53 E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 2012

Objectives Learn to shade objects so their images appear three-dimensional Introduce the types of light-material interactions Build a simple reflection model---the Phong model--- that can be used with real time graphics hardware 54 E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 2012

Why we need shading Suppose we build a model of a sphere using many polygons and color it with glcolor. We get something like But we want 55 E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 2012

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 56 E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 2012

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 and so on 57 E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 2012

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 58 E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 2012

Global Effects shadow multiple reflection translucent surface 59 E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 2012

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 60 E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 2012

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 61 E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 2012

Light Sources General light sources are difficult to work with because we must integrate light coming from all points on the source 62 E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 2012

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 63 E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 2012

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 64 E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 2012

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 65 E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 2012

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 66 E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 2012

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 67 E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 2012

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 68 E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 2012

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 shininess coef intensity incoming intensity absorption coef φ 69 E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 2012

The Shininess Coefficient Values of α between 100 and 200 correspond to metals Values between 5 and 10 give surface that look like plastic cos α φ 70 φ 90-90 E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley 2012