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

Similar documents
Computer Graphics. Illumination and Shading

To Do. Demo for mytest3. Methodology for Lecture. Importance of Lighting. Brief primer on Color. Computer Graphics

To Do. Demo for mytest3. Methodology for Lecture. Importance of Lighting. Brief primer on Color. Foundations of Computer Graphics (Spring 2012)

Shading and Illumination

INF3320 Computer Graphics and Discrete Geometry

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

Illumination and Shading

Light Sources. Spotlight model

CS Computer Graphics: Illumination and Shading I

CS Computer Graphics: Illumination and Shading I

Why we need shading?

Lighting. CSC 7443: Scientific Information Visualization

Illumination and Shading

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

Three-Dimensional Graphics V. Guoying Zhao 1 / 55

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

Illumination & Shading I

CS Surface Rendering

CS 4731: Computer Graphics Lecture 16: Phong Illumination and Shading. Emmanuel Agu

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

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

5.2 Shading in OpenGL

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

Illumination & Shading: Part 1

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

CS 148, Summer 2012 Introduction to Computer Graphics and Imaging

Light Transport Baoquan Chen 2017

OpenGL Lighting Computer Graphics Spring Frank Palermo

Shading. Brian Curless CSE 457 Spring 2015

Shading. CSE 457 Winter 2015

Lecture 4 Advanced Computer Graphics (CS & SE )

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

Illumination and Shading

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

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

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

Sung-Eui Yoon ( 윤성의 )

CEng 477 Introduction to Computer Graphics Fall

Illumination and Shading ECE 567

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

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: Lecture #8: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

CS 4600 Fall Utah School of Computing

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

Shading , Fall 2004 Nancy Pollard Mark Tomczak

Virtual Reality for Human Computer Interaction

Illumination and Reflection in OpenGL CS 460/560. Computer Graphics. Shadows. Photo-Realism: Ray Tracing. Binghamton University.

Computer Graphics (CS 543) Lecture 8a: Per-Vertex lighting, Shading and Per-Fragment lighting

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

LIGHTING AND SHADING

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

Virtual Reality for Human Computer Interaction

Display Issues Week 5

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

Computer graphic -- Programming with OpenGL 2

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

Lighting/Shading III. Week 7, Wed Mar 3

ECS 175 COMPUTER GRAPHICS. Ken Joy.! Winter 2014

Computer Graphics Lighting

Computer Graphics Lighting. Why Do We Care About Lighting?

Pipeline Operations. CS 4620 Lecture 14

Objectives. Introduce the OpenGL shading Methods 1) Light and material functions on MV.js 2) per vertex vs per fragment shading 3) Where to carry out

CS452/552; EE465/505. Lighting & Shading

CS5620 Intro to Computer Graphics

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?

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

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

Illumination & Shading

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

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

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

Graphics and Visualization

CS452/552; EE465/505. Intro to Lighting

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

CS 4620 Program 3: Pipeline

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

Projections and Hardware Rendering. Brian Curless CSE 557 Fall 2014

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

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

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

CHAPTER 1 Graphics Systems and Models 3

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

Color and Light CSCI 4229/5229 Computer Graphics Fall 2016

OpenGL: Open Graphics Library. Introduction to OpenGL Part II. How do I render a geometric primitive? What is OpenGL

CPSC 314 LIGHTING AND SHADING

Models and Architectures

Shading. Brian Curless CSE 557 Autumn 2017

The Rasterization Pipeline

Illumination Models & Shading

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

Lecture 15: Shading-I. CITS3003 Graphics & Animation

Pipeline Operations. CS 4620 Lecture 10

Lights, Colour and Materials In OpenGL

Shading I Computer Graphics I, Fall 2008

Shading. Brian Curless CSE 457 Spring 2017

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

Comp 410/510 Computer Graphics. Spring Shading

Deferred Rendering Due: Wednesday November 15 at 10pm

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

Introduction Rasterization Z-buffering Shading. Graphics 2012/2013, 4th quarter. Lecture 09: graphics pipeline (rasterization and shading)

Transcription:

Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 11: OpenGL 3 http://inst.eecs.berkeley.edu/~cs184 Methodology for Lecture Lecture deals with lighting (teapot shaded as in HW1) Some Nate Robbins tutor demos in lecture Briefly explain OpenGL color, lighting, shading Also talk a little about programmable shaders Demo Lecture corresponds chapter 5 (and some of 4) But of course, better off doing rather than reading Importance of Lighting Important to bring out 3D appearance (compare teapot now to in previous demo) Important for correct shading under lights The way shading is done also important Outline glshademodel(gl_flat) glshademodel(gl_smooth) Brief primer on Color Red, Green, Blue primary colors Can be thought of as vertices of a color cube R+G = Yellow, B+G = Cyan, B+R = Magenta, R+G+B = White Each color channel (R,G,B) treated separately RGBA 32 bit mode (8 bits per channel) often used A is for alpha for transparency if you need it Colors normalized to 0 to 1 range in OpenGL Often represented as 0 to 255 in terms of pixel intensities Also, color index mode (not so important) Shading Models So far, lighting disabled: color explicit at each vertex This lecture, enable lighting Calculate color at each vertex (based on shading model, lights and material properties of objects) Rasterize and interpolate vertex colors at pixels Flat shading: single color per polygon (one vertex) Smooth shading: interpolate colors at vertices Wireframe: glpolygonmode (GL_FRONT, GL_LINE) Also, polygon offsets to superimpose wireframe Hidden line elimination? (polygons in black ) 1

Demo and Color Plates See OpenGL color plates 1-8 Demo Question: Why is blue highlight jerky even with smooth shading, while red highlight is smooth? Lighting Rest of this lecture considers lighting on vertices In real world, complex lighting, materials interact We study this more formally in next unit OpenGL is a hack that efficiently captures some qualitative lighting effects. But not physical Modern programmable shaders allow arbitrary lighting and shading models (briefly covered) Types of Light Sources Point Position, Color [separate diffuse/specular] Attenuation (quadratic model) 1 atten k k d k d c l q Directional (w=0, infinitely far away, no attenuation) Spotlights Spot exponent Spot cutoff All parameters: page 215 (should have already read HW1; see there for page numbers in previous editions) 2 Material Properties Need normals (to calculate how much diffuse, specular, find reflected direction and so on) Four terms: Ambient, Diffuse, Specular, Emissive Specifying Normals Normals are specified through glnormal Normals are associated with vertices Specifying a normal sets the current normal Remains unchanged until user alters it Usual sequence: glnormal, glvertex, glnormal, glvertex, glnormal, glvertex Usually, we want unit normals for shading glenable( GL_NORMALIZE ) This is slow either normalize them yourself or don t use glscale Evaluators will generate normals for curved surfaces Such as splines. GLUT does it automatically for teapot, cylinder, Outline 2

LightMaterial Demo Emissive Term I Emission material Only relevant for light sources when looking directly at them Gotcha: must create geometry to actually see light Emission does not in itself affect other lighting calculations Ambient Term Hack to simulate multiple bounces, scattering of light Assume light equally from all directions Ambient Term Associated with each light and overall light E.g. skylight, with light from everywhere n I ambient * ambient ambient * ambient * atten global material light i material i i 0 Most effects per light involve linearly combining effects of light sources Diffuse Term Rough matte (technically Lambertian) surfaces Light reflects equally in all directions -L N I N L Diffuse Term Rough matte (technically Lambertian) surfaces Light reflects equally in all directions -L N I N L n I diffuselight i * diffusematerial * atteni *[max( L N,0)] i 0 Why is diffuse of light diff from ambient, specular? 3

Specular Term Glossy objects, specular reflections Light reflects close to mirror direction Specular Term Glossy objects, specular reflections Light reflects close to mirror direction Consider half-angle between light and viewer N s n I specular * specular * atten *[max( N s,0)] i 0 light i material i shininess Demo What happens when we make surface less shiny? What happens to jerkiness of highlights? Outline Source Code (in display) /* New for Demo 3; add lighting effects */ /* See hw1 and the red book (chapter 5) for details */ { GLfloat one[] = {1, 1, 1, 1}; // GLfloat small[] = {0.2, 0.2, 0.2, 1}; GLfloat medium[] = {0.5, 0.5, 0.5, 1}; GLfloat small[] = {0.2, 0.2, 0.2, 1}; GLfloat high[] = {100}; GLfloat light_specular[] = {1, 0.5, 0, 1}; GLfloat light_specular1[] = {0, 0.5, 1, 1}; GLfloat light_position[] = {0.5, 0, 0, 1}; GLfloat light_position1[] = {0, -0.5, 0, 1}; /* Set Material properties for the teapot */ glmaterialfv(gl_front, GL_AMBIENT, one); glmaterialfv(gl_front, GL_SPECULAR, one); glmaterialfv(gl_front, GL_DIFFUSE, medium); glmaterialfv(gl_front, GL_SHININESS, high); Source Code (contd( contd) /* Set up point lights, Light 0 and Light 1 */ /* Note that the other parameters are default values */ gllightfv(gl_light0, GL_SPECULAR, light_specular); gllightfv(gl_light0, GL_DIFFUSE, small); gllightfv(gl_light0, GL_POSITION, light_position); gllightfv(gl_light1, GL_SPECULAR, light_specular1); gllightfv(gl_light1, GL_DIFFUSE, medium); gllightfv(gl_light1, GL_POSITION, light_position1); /* Enable and Disable everything around the teapot */ /* Generally, we would also need to define normals etc. */ /* But glut already does this for us */ glenable(gl_lighting) ; glenable(gl_light0) ; glenable(gl_light1) ; if (smooth) glshademodel(gl_smooth) ; else glshademodel(gl_flat); } 4

Outline Moving a Light Source Lights transform like other geometry Only modelview matrix (not projection). The only real application where the distinction is important See types of light motion pages 222- Stationary light: set the transforms to identity before specifying it Moving light: Push Matrix, move light, Pop Matrix Moving light source with viewpoint (attached to camera). Can simply set light to 0 0 0 so origin wrt eye coords (make modelview matrix identity before doing this) Lightposition demo Pixel or Fragment Pipeline Rasterization (scan conversion) Texture Mapping Z-buffering Framebuffer These fixed function stages can be replaced by a general per-fragment calculation using fragment shaders in modern programmable hardware Shading Languages Shader Setup Vertex / Fragment shading described by small program Written in language similar to C but with restrictions Long history. Cook s paper on Shade Trees, Renderman for offline rendering Stanford Real-Time Shading Language, work at SGI Cg from NVIDIA, HLSL GLSL directly compatible with OpenGL 2.0 (So, you can just read the OpenGL Red Book to get started) Cliff Lindsay web.cs.wpi.edu/~rich/courses/imgd4000-d09/lectures/gpu.pdf 5

Cliff Lindsay web.cs.wpi.edu/~rich/courses/imgd4000-d09/lectures/gpu.pdf Cliff Lindsay web.cs.wpi.edu/~rich/courses/imgd4000-d09/lectures/gpu.pdf 6