CS Surface Rendering

Similar documents
Three-Dimensional Graphics V. Guoying Zhao 1 / 55

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

Why we need shading?

Display Issues Week 5

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

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

Shading and Illumination

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

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?

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

5.2 Shading in OpenGL

INF3320 Computer Graphics and Discrete Geometry

Computer Graphics. Illumination and Shading

Illumination and Shading

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

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

Lecture 4 Advanced Computer Graphics (CS & SE )

Graphics and Visualization

Lighting. CSC 7443: Scientific Information Visualization

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

CEng 477 Introduction to Computer Graphics Fall

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

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

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

Illumination and Shading ECE 567

Shading. Brian Curless CSE 457 Spring 2015

Light Sources. Spotlight model

Shading. CSE 457 Winter 2015

Computer Graphics Lighting

Computer Graphics Lighting. Why Do We Care About Lighting?

CS 4600 Fall Utah School of Computing

Virtual Reality for Human Computer Interaction

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

CS 418: Interactive Computer Graphics. Basic Shading in WebGL. Eric Shaffer

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

Illumination and Shading

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

Lights, Colour and Materials In OpenGL

Projections and Hardware Rendering. Brian Curless CSE 557 Fall 2014

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

Illumination and Shading

ECS 175 COMPUTER GRAPHICS. Ken Joy.! Winter 2014

Surface Rendering Methods

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

Lighting/Shading III. Week 7, Wed Mar 3

Shading , Fall 2004 Nancy Pollard Mark Tomczak

Pipeline Operations. CS 4620 Lecture 10

CS452/552; EE465/505. Lighting & Shading

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

CS Computer Graphics: Illumination and Shading I

CS Computer Graphics: Illumination and Shading I

Illumination & Shading: Part 1

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

Pipeline Operations. CS 4620 Lecture 14

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

LIGHTING AND SHADING

Light Transport Baoquan Chen 2017

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

Sung-Eui Yoon ( 윤성의 )

Lecture 15: Shading-I. CITS3003 Graphics & Animation

2D and 3D Viewing Basics

CS Rasterization. Junqiao Zhao 赵君峤

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

Shading I Computer Graphics I, Fall 2008

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

Illumination Models & Shading

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

CS 148, Summer 2012 Introduction to Computer Graphics and Imaging

Introduction to Computer Graphics. Farhana Bandukwala, PhD Lecture 14: Light Interacting with Surfaces

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

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

Introduction to OpenGL

Comp 410/510 Computer Graphics. Spring Shading

9. Illumination and Shading

Introduction to Computer Graphics 7. Shading

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

Reflection and Shading

Shading. Slides by Ulf Assarsson and Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology

Illumination and Shading

Illumination and Shading

CS Illumination and Shading. Slide 1

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

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

Lighting/Shading II. Week 7, Mon Mar 1

CPSC 314 LIGHTING AND SHADING

CS5620 Intro to Computer Graphics

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

Realtime 3D Computer Graphics & Virtual Reality. Shading and Color. Introduction to Lighting and Shading

CS 432 Interactive Computer Graphics

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

Computer Graphics. Illumination and Shading

CS452/552; EE465/505. Intro to Lighting

Virtual Reality for Human Computer Interaction

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

API for creating a display window and using keyboard/mouse interations. See RayWindow.cpp to see how these are used for Assignment3

hw1-2 review hw 3 questions?

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

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

CS 130 Final. Fall 2015

From Graphics to Visualization

Transcription:

CS10101001 Surface Rendering Junqiao Zhao 赵君峤 Department of Computer Science and Technology College of Electronics and Information Engineering Tongji University

Surface rendering How do we choose a color for each filled pixel if the object is represented in a set of polygonal meshes? Recall Rasterization Simplest shading approach is to perform independent lighting calculation for every pixel m

Surface rendering Common used shading algorithms Flat shading Smooth shading Gouraud shading Phong shading

Flat shading The simplest one, also called as constant intensity surface rendering One illumination calculation per polygon Assign all pixels inside each polygon the same color, therefore reveal polygons and fast OK for polyhedral objects, Not good for smooth surfaces

Examples of flat shading

Examples of flat shading 1

Examples of flat shading 1

Examples of flat shading

Gourand shading Named after Henri Gouraud (1971) Produce continuous shading of surfaces represented by polygon meshes An interpolation method

Gourand shading Step 1: Normal averaging estimate the normal of each vertex by averaging the surface normals of the polygons that meet at each vertex N v n k 1 n k 1 N k N k N 1 N 2 N v N 4 N 3

Gourand shading Step 2: Vertex Lighting compute the color for each vertex based on a shading model (e.g., Phong reflection model) m Used to model mirrors, metals, etc. i=1 Surface normal Direction of reflection I = L a k a + (L d,i k d max(l n,0) +L s,i k s (r i v) α ) L N R to viewpoint V k s = spe

Gourand shading Step3: Interpolation for each screen pixel that represents the polygonal mesh, color is interpolated from the color values calculated at the vertices Bilinear interpolation or barycentric coordinates scan line I 1 I 2 I 3 a I b I I p y 1 y s y 2 y 3 2 1 1 2 2 1 2 1 y y y y I y y y y I I s s a 3 1 1 3 3 1 3 1 y y y y I y y y y I I s s b a b a p b a b p b a p x x x x I x x x x I I

q

q

Gourand shading q h"p://dylancodes.net/school/cps511

Gourand shading Not good at highlights

Phong shading Named after Bui Tuong Phong (1973) Also produce continuous shading of surfaces represented by polygon meshes Also an interpolation method But

Phong shading Different from Gouraud shading, Phong shading interpolate normals rather than colors It interpolates surface normals across rasterized polygons and computes pixel colors based on the interpolated normals and a reflection model

Phong shading Always captures specular highlights, but computationally expensive At each pixel, n is recomputed and normalized Then l is computed at each pixel (lighting model is more expensive than interpolation algorithms) Not available in fixed pipeline, but now can be implemented in hardware (per fragment shading)

h"ps://cg2010studio.files.wordpress.com

1

h"p://www.cosc.brocku.ca/offerings/3p98

OpenGL shading 1. Enable shading and select model 2. Specify normals 3. Specify material properties 4. Specify lights Angel: Interactive Computer Graphics 4E Addison-Wesley 2005

Normals In OpenGL the normal vector is part of the state Set by glnormal*() glnormal3f(x, y, z); glnormal3fv(p); Usually we want to set the normal to have unit length so cosine calculations are correct Length can be affected by transformations Note that scaling does not preserved length glenable(gl_normalize) allows for autonormalization at a performance penalty

Normal for Triangle n plane n (p - p 0 ) = 0 p 2 n = (p 2 - p 0 ) (p 1 - p 0 ) normalize n n/ n p p 0 p 1 Note that right- hand rule determines outward face Angel: Interactive Computer Graphics 4E Addison-Wesley 2005

Enabling Shading Shading calculations are enabled by glenable(gl_lighting) Once lighting is enabled, glcolor() ignored Must enable each light source individually glenable(gl_lighti) i=0,1.. Can choose light model parameters gllightmodeli(parameter, GL_TRUE) GL_LIGHT_MODEL_LOCAL_VIEWER do not use simplifying distant viewer assumption in calculation GL_LIGHT_MODEL_TWO_SIDED shades both sides of polygons independently Angel: Interactive Computer Graphics 4E Addison-Wesley 2005

Defining a Point Light Source For each light source, we can set an RGBA for the diffuse, specular, and ambient components, and for the position GL float diffuse0[]={1.0, 0.0, 0.0, 1.0}; GL float ambient0[]={1.0, 0.0, 0.0, 1.0}; GL float specular0[]={1.0, 0.0, 0.0, 1.0}; Glfloat light0_pos[]={1.0, 2.0, 3,0, 1.0}; glenable(gl_lighting); glenable(gl_light0); gllightv(gl_light0, GL_POSITION, light0_pos); gllightv(gl_light0, GL_AMBIENT, ambient0); gllightv(gl_light0, GL_DIFFUSE, diffuse0); gllightv(gl_light0, GL_SPECULAR, specular0); Angel: Interactive Computer Graphics 4E Addison-Wesley 2005

Distance and Direction The source colors are specified in RGBA The position is given in homogeneous coordinates If w =1.0, we are specifying a finite location If w =0.0, we are specifying a parallel source with the given direction vector The coefficients in the distance terms are by default a=1.0 (constant terms), b=c=0.0 (linear and quadratic terms). Change by a= 0.80; gllightf(gl_light0, GLCONSTANT_ATTENUATION, a); Angel: Interactive Computer Graphics 4E Addison-Wesley 2005

Spotlights Use gllightv to set Direction GL_SPOT_DIRECTION Cutoff GL_SPOT_CUTOFF Attenuation GL_SPOT_EXPONENT Proportional to cos α φ -θ φ θ Angel: Interactive Computer Graphics 4E Addison-Wesley 2005

Global Ambient Light Ambient light depends on color of light sources A red light in a white room will cause a red ambient term that disappears when the light is turned off OpenGL also allows a global ambient term that is often helpful for testing gllightmodelfv(gl_light_model_ambient, global_ambient) Angel: Interactive Computer Graphics 4E Addison-Wesley 2005

Moving Light Sources Light sources are geometric objects whose positions or directions are affected by the modelview matrix Depending on where we place the position (direction) setting function, we can Move the light source(s) with the object(s) Fix the object(s) and move the light source(s) Fix the light source(s) and move the object(s) Move the light source(s) and object(s) independently Angel: Interactive Computer Graphics 4E Addison-Wesley 2005

Material Properties Material properties are also part of the OpenGL state and match the terms in the modified Phong model Set by glmaterialv() GLfloat ambient[] = {0.2, 0.2, 0.2, 1.0}; GLfloat diffuse[] = {1.0, 0.8, 0.0, 1.0}; GLfloat specular[] = {1.0, 1.0, 1.0, 1.0}; GLfloat shine = 100.0 glmaterialf(gl_front, GL_AMBIENT, ambient); glmaterialf(gl_front, GL_DIFFUSE, diffuse); glmaterialf(gl_front, GL_SPECULAR, specular); glmaterialf(gl_front, GL_SHININESS, shine); Angel: Interactive Computer Graphics 4E Addison-Wesley 2005

Front and Back Faces The default is shade only front faces which works correctly for convex objects If we set two sided lighting, OpenGL will shade both sides of a surface Each side can have its own properties which are set by using GL_FRONT, GL_BACK, or GL_FRONT_AND_BACK in glmaterialf back faces not visible back faces visible Angel: Interactive Computer Graphics 4E Addison-Wesley 2005

Emissive Term We can simulate a light source in OpenGL by giving a material an emissive component This component is unaffected by any sources or transformations GLfloat emission[] = 0.0, 0.3, 0.3, 1.0); glmaterialf(gl_front, GL_EMISSION, emission); Angel: Interactive Computer Graphics 4E Addison-Wesley 2005

Transparency Material properties are specified as RGBA values The A value can be used to make the surface translucent The default is that all surfaces are opaque regardless of A Later we will enable blending and use this feature Angel: Interactive Computer Graphics 4E Addison-Wesley 2005

Efficiency Because material properties are part of the state, if we change materials for many surfaces, we can affect performance We can make the code cleaner by defining a material structure and setting all materials during initialization typedef struct materialstruct { GLfloat ambient[4]; GLfloat diffuse[4]; GLfloat specular[4]; GLfloat shineness; } MaterialStruct; We can then select a material by a pointer Angel: Interactive Computer Graphics 4E Addison-Wesley 2005

Polygonal Shading Shading calculations are done for each vertex Vertex colors become vertex shades By default, vertex shades are interpolated across the polygon glshademodel(gl_smooth); If we use glshademodel(gl_flat); the color at the first vertex will determine the shade of the whole polygon Angel: Interactive Computer Graphics 4E Addison-Wesley 2005

References Lin Zhang, Computer Graphics, Tongji Unviersity Steve Marschner, CS4620/5620 Computer Graphics, Cornell Eg Angel, CS433, New Mexico Tom Thorne, COMPUTER GRAPHICS, The University of Edinburgh Elif Tosun, Computer Graphics, The University of New York

Questions?