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

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

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

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

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

CSE 167: Lecture 11: Textures 2. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

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

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

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

Texture mapping. Computer Graphics CSE 167 Lecture 9

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

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

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

Surface shading: lights and rasterization. Computer Graphics CSE 167 Lecture 6

CMSC427 Shading Intro. Credit: slides from Dr. Zwicker

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

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

Pipeline Operations. CS 4620 Lecture 14

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

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

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

Shading and Illumination

ECS 175 COMPUTER GRAPHICS. Ken Joy.! Winter 2014

Pipeline Operations. CS 4620 Lecture 10

Computer Graphics. Illumination and Shading

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

CEng 477 Introduction to Computer Graphics Fall

CPSC / Illumination and Shading

Light Sources. Spotlight model

CS 130 Final. Fall 2015

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

CS 354R: Computer Game Technology

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

Computer Graphics. Illumination and Shading

Illumination & Shading: Part 1

LIGHTING AND SHADING

Virtual Reality for Human Computer Interaction

Shading. Brian Curless CSE 457 Spring 2017

Exercise Max. Points Total 90

Introduction to Computer Graphics 7. Shading

Chapter 7 - Light, Materials, Appearance

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

Illumination and Shading

INF3320 Computer Graphics and Discrete Geometry

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

Projections and Hardware Rendering. Brian Curless CSE 557 Fall 2014

Visualisatie BMT. Rendering. Arjan Kok

CS451Real-time Rendering Pipeline

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

CHAPTER 1 Graphics Systems and Models 3

CSE 167: Introduction to Computer Graphics Lecture #4: Vertex Transformation

3D Programming. 3D Programming Concepts. Outline. 3D Concepts. 3D Concepts -- Coordinate Systems. 3D Concepts Displaying 3D Models

The Rasterizer Stage. Texturing, Lighting, Testing and Blending

Module Contact: Dr Stephen Laycock, CMP Copyright of the University of East Anglia Version 1

Illumination Models & Shading

Textures. Texture coordinates. Introduce one more component to geometry

The Rasterization Pipeline

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

Rasterization Overview

CSE 167: Introduction to Computer Graphics Lecture #11: Visibility Culling

Deferred Rendering Due: Wednesday November 15 at 10pm

Texture Mapping. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

Comp 410/510 Computer Graphics. Spring Shading

CS5620 Intro to Computer Graphics

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

CS452/552; EE465/505. Texture Mapping in WebGL

Illumination and Shading

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

Shading 1: basics Christian Miller CS Fall 2011

CPSC 314 LIGHTING AND SHADING

Topics and things to know about them:

Shading I Computer Graphics I, Fall 2008

3D Rasterization II COS 426

Texture Mapping and Sampling

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

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

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

Shading, Advanced Rendering. Week 7, Wed Feb 28

Color and Light CSCI 4229/5229 Computer Graphics Fall 2016

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

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

Lecture 19: OpenGL Texture Mapping. CITS3003 Graphics & Animation

Computer Graphics I Lecture 11

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

Sung-Eui Yoon ( 윤성의 )

Announcements. Written Assignment 2 out (due March 8) Computer Graphics

CS 428: Fall Introduction to. Texture mapping and filtering. Andrew Nealen, Rutgers, /18/2010 1

Graphics Hardware and Display Devices

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

Rendering. Converting a 3D scene to a 2D image. Camera. Light. Rendering. View Plane

CSE 167: Introduction to Computer Graphics Lecture #10: View Frustum Culling

CS 325 Computer Graphics

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

Topic 12: Texture Mapping. Motivation Sources of texture Texture coordinates Bump mapping, mip-mapping & env mapping

Reflection and Shading

CS 464 Review. Review of Computer Graphics for Final Exam

Phong Lighting & Materials. Some slides modified from: David Kabala Others from: Andries Van Damm, Brown Univ.

Introduction to Visualization and Computer Graphics

CS 4620 Program 3: Pipeline

Lecture 2. Shaders, GLSL and GPGPU

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

Transcription:

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

Announcements Project 2 due Friday, Oct. 24 th Midterm Exam Thursday, Oct. 30 th 2

Lecture Overview OpenGL Light Sources Types of Geometry Shading Shading in OpenGL Fixed-Function Shading Programmable Shaders Vertex Programs Fragment Programs GLSL 3

Light Sources Real light sources can have complex properties Geometric area over which light is produced Anisotropy (directionally dependent) Reflective surfaces act as light sources (indirect light) OpenGL uses a drastically simplified model to allow real-time rendering 4

OpenGL Light Sources At each point on surfaces we need to know Direction of incoming light (the L vector) Intensity of incoming light (the c l values) Standard light sources in OpenGL Directional: from a specific direction Point light source: from a specific point Spotlight: from a specific point with intensity that depends on direction 5

Directional Light Light from a distant source Light rays are parallel Direction and intensity are the same everywhere As if the source were infinitely far away Good approximation of sunlight Specified by a unit length direction vector, and a color 6 Light source Receiving surface

Point Lights Similar to light bulbs Infinitely small point radiates light equally in all directions Light vector varies across receiving surface What is light intensity over distance proportional to? Intensity drops off proportionally to the inverse square of the distance from the light Reason for inverse square falloff: Surface area A of sphere: A = 4 π r 2 7

Point Lights in Theory p c src Light source At any point v on the surface: c l v c l Receiving surface v 8

Point Lights in OpenGL OpenGL model for distance attenuation: Attenuation parameters: k c = constant attenuation, default: 1 k l = linear attenuation, default: 0 k q = quadratic attenuation, default: 0 Default: no attenuation: c l =c src Change attenuation parameters with: GL_CONSTANT_ATTENUATION 9 c l = GL_LINEAR_ATTENUATION c src k c + k l p v + k q p v 2 GL_QUADRATIC_ATTENUATION

Lecture Overview OpenGL Light Sources Spotlights Types of Geometry Shading Shading in OpenGL Fixed-Function Shading Programmable Shaders Vertex Programs Fragment Programs GLSL 10

Spotlights Like point source, but intensity depends on direction Parameters Position: location of light source Spot direction: center axis of light source Falloff parameters: Beam width (cone angle) The way the light tapers off at the edges of the beam (cosine exponent) 11

Spotlights Light source Receiving surface 12

Spotlights Photograph of real spotlight Spotlights in OpenGL 13

Video C++ OpenGL Lesson on Basic Lighting http://www.youtube.com/watch?v=g_0yv7jzvgg 14

Lecture Overview OpenGL Light Sources Types of Geometry Shading Shading in OpenGL Fixed-Function Shading Programmable Shaders Vertex Programs Fragment Programs GLSL 15

Types of Shading Per-triangle Per-vertex Per-pixel 16

Per-Triangle Shading A.k.a. flat shading Evaluate shading once per triangle Advantage Fast Disadvantage Faceted appearance 17

Per-Vertex Shading Known as Gouraud shading (Henri Gouraud, 1971) Interpolates vertex colors across triangles Advantages Fast Smoother surface appearance than with flat shading Disadvantage Problems with small highlights 18

Per-Pixel Shading A.k.a. Phong Interpolation (not to be confused with Phong Illumination Model) Rasterizer interpolates normals (instead of colors) across triangles Illumination model is evaluated at each pixel Simulates shading with normals of a curved surface Advantage Higher quality than Gouraud shading Disadvantage Slow 19 Source: Penny Rheingans, UMBC

Gouraud vs. Per-Pixel Shading Gouraud shading has problems with highlights when polygons are large More triangles improve the result, but reduce frame rate Gouraud Per-Pixel 20

Lecture Overview OpenGL Light Sources Types of Geometry Shading Shading in OpenGL Fixed-Function Shading Programmable Shaders Vertex Programs Fragment Programs GLSL 21

Shading with Fixed-Function Pipeline Fixed-function pipeline only allows Gouraud (pervertex) shading We need to provide a normal vector for each vertex Shading is performed in camera space Position and direction of light sources are transformed by GL_MODELVIEW matrix If light sources should be in object space: Set GL_MODELVIEW to desired object-to-camera transformation Use object space coordinates for light positions More information: http://glprogramming.com/red/chapter05.html http://www.falloutsoftware.com/tutorials/gl/gl8.htm 22

Tips for Transforming Normals If you need to (manually) transform geometry by a transformation matrix M, which includes shearing or scaling: Transforming the normals with M will not work: transformed normals are no longer perpendicular to surfaces Solution: transform the normals differently: Either transform the end points of the normal vectors separately Or transform normals with OpenGL does this automatically if the following command is used: glenable(gl_normalize) More details on-line at: http://www.oocities.com/vmelkon/transformingnormals.html 23

Lecture Overview OpenGL Light Sources Types of Geometry Shading Shading in OpenGL Fixed-Function Shading Programmable Shaders Vertex Programs Fragment Programs GLSL 24

Programmable Shaders in OpenGL Initially, OpenGL only had a fixed-function pipeline for shading Programmers wanted more flexibility, similar to programmable shaders in raytracing software (term shader first introduced by Pixar in 1988) First shading languages came out in 2002: Cg (C for Graphics, created by Nvidia) HLSL (High Level Shader Language, created by Microsoft) They supported: Fragment shaders: allowed per-pixel shading Vertex shaders: allowed modification of geometry 25

Programmable Shaders in OpenGL OpenGL 2.0 supported the OpenGL Shading Language (GLSL) in 2003 Geometry shaders were added in OpenGL 3.2 Tessellation shaders were added in OpenGL 4.0 Programmable shaders allow real-time: Shadows, environment mapping, per-pixel lighting, bump mapping, parallax bump mapping, HDR, etc. 26

Demo NVIDIA Froggy http://www.nvidia.com/coolstuff/demos#!/froggy Bump mapping shader for Froggy s skin Physically-based lighting model simulating sub-surface scattering Supersampling for scene anti-aliasing Raytracing shader for irises to simulate refraction for wet and shiny eyes Dynamically-generated lights and shadows 27

Lecture Overview Texture Mapping Overview Wrapping Texture coordinates Anti-aliasing 28

Large Triangles Pros: Often sufficient for simple geometry Fast to render Cons: Per vertex colors look boring and computer-generated 29

Texture Mapping Map textures (images) onto surface polygons Same triangle count, much more realistic appearance 30

Texture Mapping Goal: map locations in texture to locations on 3D geometry Texture coordinate space Texture pixels (texels) have texture coordinates (s,t) Convention Bottom left corner of texture is at (s,t) = (0,0) Top right corner is at (s,t) = (1,1) (1,1) t (0,0) s Texture coordinates 31

Texture Mapping Store 2D texture coordinates s,t with each triangle vertex v 1 (s,t) = (0.65,0.75) (1,1) v 0 (s,t) = (0.6,0.4) (0.65,0.75) v 2 (s,t) = (0.4,0.45) Triangle in any space before projection t (0.4,0.45) (0.6,0.4) 32 (0,0) Texture coordinates s

Texture Mapping Each point on triangle gets color from its corresponding point in texture v 1 (s,t) = (0.65,0.75) (1,1) (0.65,0.75) v 0 (s,t) = (0.6,0.4) t (0.4,0.45) (0.6,0.4) v 2 (s,t) = (0.4,0.45) Triangle in any space before projection (0,0) Texture coordinates s 33

Texture Mapping Primitives Modeling and viewing transformation Shading Projection Rasterization Fragment processing Includes texture mapping Frame-buffer access (z-buffering) 34 Image

Texture Look-Up Given interpolated texture coordinates (s, t) at current pixel Closest four texels in texture space are at (s 0,t 0 ), (s 1,t 0 ), (s 0,t 1 ), (s 1,t 1 ) How to compute pixel color? t 1 t t 0 s 0 s s 1 35

Nearest-Neighbor Interpolation Use color of closest texel t 1 t t 0 s 0 s s 1 Simple, but low quality and aliasing 36

Bilinear Interpolation 1. Linear interpolation horizontally: Ratio in s direction r s : s s0 r s = s s 1 0 c top = tex(s 0,t 1 ) (1-r s ) + tex(s 1,t 1 ) r s c bot = tex(s 0, t 0 ) (1-r s ) + tex(s 1,t 0 ) r s t 1 t c top c bot t 0 s 0 s s 1 37

Bilinear Interpolation 2. Linear interpolation vertically Ratio in t direction r t : t t0 r t = t1 t0 c = c bot (1-r t ) + c top r t t 1 c top t c c bot t 0 s 0 s s 1 38

Lecture Overview Texture Mapping Wrapping Texture coordinates Anti-aliasing 39

Wrap Modes Texture image extends from [0,0] to [1,1] in texture space What if (s,t) texture coordinates are beyond that range? Texture wrap modes 40

Repeat Repeat the texture Creates discontinuities at edges unless texture designed to line up (1,1) t (0,0) s Seamless brick wall texture (by Christopher Revoir) 41 Texture Space

Clamp Use edge value everywhere outside data range [0..1] Or, ignore the texture outside [0..1] (1,1) t (0,0) s 42 Texture Space

Wrap Mode Specification in OpenGL Default: gltexparameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); gltexparameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); Options for wrap mode: GL_CLAMP (requires border to be set) GL_CLAMP_TO_EDGE (repeats last pixel in texture), GL_REPEAT 43