Shading and Illumination

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

Illumination and Shading

CS Computer Graphics: Illumination and Shading I

CS Computer Graphics: Illumination and Shading I

Lighting. CSC 7443: Scientific Information Visualization

Illumination and Shading ECE 567

INF3320 Computer Graphics and Discrete Geometry

CS 148, Summer 2012 Introduction to Computer Graphics and Imaging

Light Sources. Spotlight model

Illumination & Shading I

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

Computer Graphics. Illumination and Shading

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

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

5.2 Shading in OpenGL

CEng 477 Introduction to Computer Graphics Fall

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

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

Shading , Fall 2004 Nancy Pollard Mark Tomczak

CS Surface Rendering

Illumination and Shading

Illumination & Shading: Part 1

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

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

Illumination and Shading

Why we need shading?

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

Surface Rendering Methods

Sung-Eui Yoon ( 윤성의 )

Shading. Brian Curless CSE 457 Spring 2015

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

LIGHTING AND SHADING

Shading. CSE 457 Winter 2015

Virtual Reality for Human Computer Interaction

Computer Graphics Lighting

Computer Graphics Lighting. Why Do We Care About Lighting?

CS5620 Intro to Computer Graphics

Illumination and Shading

Graphics and Visualization

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

Computer Graphics. Illumination and Shading

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

Lighting/Shading III. Week 7, Wed Mar 3

CS 4600 Fall Utah School of Computing

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

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

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

Light Transport Baoquan Chen 2017

Lecture 4 Advanced Computer Graphics (CS & SE )

CPSC 314 LIGHTING AND SHADING

CPSC / Illumination and Shading

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

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?

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

Illumination Models & Shading

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

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

ECS 175 COMPUTER GRAPHICS. Ken Joy.! Winter 2014

Projections and Hardware Rendering. Brian Curless CSE 557 Fall 2014

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

Chapter 7 - Light, Materials, Appearance

CENG 477 Introduction to Computer Graphics. Ray Tracing: Shading

CMSC427 Shading Intro. Credit: slides from Dr. Zwicker

Illumination & Shading

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

Lights, Colour and Materials In OpenGL

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

Shading 1: basics Christian Miller CS Fall 2011

Comp 410/510 Computer Graphics. Spring Shading

6. Illumination, Lighting

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

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

Virtual Reality for Human Computer Interaction

Final Project: Real-Time Global Illumination with Radiance Regression Functions

Global Illumination CS334. Daniel G. Aliaga Department of Computer Science Purdue University

Reflection and Shading

Display Issues Week 5

Lighting and Shading

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

Lecture 15: Shading-I. CITS3003 Graphics & Animation

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

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

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

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

Shading I Computer Graphics I, Fall 2008

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

S U N G - E U I YO O N, K A I S T R E N D E R I N G F R E E LY A VA I L A B L E O N T H E I N T E R N E T

INFOGR Computer Graphics. J. Bikker - April-July Lecture 10: Shading Models. Welcome!

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

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

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

Chapter 3. Illumination Models and Surface-Rendering Methods. Department of Computer Science and Engineering

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

Lighting/Shading II. Week 7, Mon Mar 1

OpenGL Lighting Computer Graphics Spring Frank Palermo

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

Introduction to Computer Graphics 7. Shading

A Brief Overview of. Global Illumination. Thomas Larsson, Afshin Ameri Mälardalen University

CS452/552; EE465/505. Lighting & Shading

Transcription:

Shading and Illumination

OpenGL Shading Without Shading With Shading

Physics

Bidirectional Reflectance Distribution Function (BRDF) f r (ω i,ω ) = dl(ω ) L(ω i )cosθ i dω i = dl(ω ) L(ω i )( ω i n)dω i n: Surface normal L: Radiance ( intensity along a ray ) θ i ω

Light Events Reflection Refraction Bidirectional Reflectance Distribution Function (BRDF) Bidirectional transmittance Distribution Function (BTDF) Bidirectional Scattering Distribution Function (BSDF) Scattering Scattering Function

Rendering Equation Given any point xin a large environment, let L(x, ω) be the radiance along a ray, we have: f r (ω i,ω ) = dl(ω ) L(ω i )( ω i n)dω i L(x,ω ) = L e (x,ω ) + f r ( x,ω i,ω )L(x,ω i )( ω i n)dω i Ω Le: Emitted intensity (light source) Ω: A hemisphere over x θ i ω

Light Transport The rendering equation describes a light transport problem: Each point has an integral equation. Light can be reflected multiple times, so those integral equations are highly related. Solution: global illumination. Methods: ray tracing, radiosity.

Example: Caustics

Example: Color Bleeding

OpenGL Illumination Unfortunately, OpenGL doesn t support global illumination. Instead, it only considers local illumination: light can only be reflected once. Even for local illumination, OpenGL is not physically based. It only provides an approximation. To accurately get multiple reflections, you need to better rendering algorithms. You can approximate some global illumination effects using GPU programmable shaders.

OpenGL Illumination Light sources Surface material properties Surface normal Incoming (light) and outgoing (eye) directions

Point Light Source GLfloat light_position[] = {1.0, 1.0, 1.0}; gllightfv(gl_light0, GL_POSITION, light_position);

Directional Light Source GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0}; gllightfv(gl_light0, GL_POSITION, light_position);

Spot Light Source GLfloat light_position[] = {1.0, 1.0, 1.0}; gllightfv(gl_light0, GL_POSITION, light_position); Glfloat spot_position[] = {1.0, 1.0, 1.0}; gllightfv(gl_light0, GL_SPOT_DIRECTION, spot_position); Glfloat EXPONENT=10; gllightfv(gl_light0, GL_SPOT_EXPONENT, EXPONENT); Glfloat cutoff=30; gllightfv(gl_light0, GL_SPOT_CUTOFF, cutoff);

OpenGL Light Intensity OpenGL separates surface reflection into three components: Ambient Diffuse Specular Total Therefore, you should define three light intensities. Each of them contributes to a reflection component: Ambient Diffuse Specular

OpenGL Light Source //To specify the light position and intensity Glfloat LightPosition []={100, 0.0, 100}; Glfloat LightAmbient []={0.2, 0.2, 0.2}; Glfloat LightDiffuse []={1.0, 1.0, 1.0}; Glfloat LightSpecular []={0.4, 0.4, 0.4}; gllightfv(gl_light1, GL_POSITION, LightPosition); gllightfv(gl_light1, GL_AMBIENT, LightAmbient); gllightfv(gl_light1, GL_DIFFUSE, LightDiffuse); gllightfv(gl_light1, GL_SPECULAR, LightSpecular);

OpenGL Light Source For a point light source, the light intensity drops when the light moves away from the source. So OpenGL multiplies the intensity with an attenuation factor: attenuation = 1 A constant + da linear + d 2 A quadratic gllightf(gl_light0, GL_CONSTANT_ATTENUATION, 2.0); gllightf(gl_light0, GL_LINEAR_ATTENUATION, 1.0); gllightf(gl_light0, GL_QUADRATIC_ATTENUATION, 0.5);

Default Values No ambient Unit diffuse Unit specular Directional light along z No spot light No attenuation

Multiple Light Sources //Specify the position and properties for GL_LIGHT0 glenable(gl_light0); //Specify the position and properties for GL_LIGHT1 glenable(gl_light1); //Create other light sources here. glenable(gl_lighting); //You can turn on and off lights like this: gldisable(gl_light0); glenable(gl_light0); gldisable(gl_lighting); glenable(gl_lighting);

OpenGL Light Source The light source is subject to the MODELVIEW matrix as well. You can create the light source in the eye space, so it always attached to the camera. You can create the light source after camera motion, so it is fixed in the world space. You can even apply extra transformation/animation to light source.

OpenGL Material OpenGL separates surface reflection into three components: Ambient Diffuse Specular Total Therefore, you should define three material properties. Each of them contributes to a reflection component: Ambient Diffuse Specular

Ambient Reflection Ambient Light L ambient = I ambient K ambient Ambient Radiance (Pixel Intensity) Ambient Surface Material Coefficient The object will have a uniform color. It looks similar to the result without lighting. The color is not directly assigned. It s controlled by the light source and surface reflection coefficient.

Diffuse Reflection Diffuse reflection assumes that the light is equally reflected in every direction. In other words, if the light source and the object has fixed positions in the world space, the camera motion doesn t affect the appearance of the object. The reflection only depends on the incoming direction. It is independent of the outgoing (viewing) direction. Real objects with only a diffuse reflection property are called: Lambertian Surfaces, for example, clay.

Diffuse Reflection Lambert s law says that the outgoing radiance depends on the cosine of the incident angle. Because the irradiance (photons per unit surface area) becomes smaller (as in the rendering function before). da da θ i da da/cosθ i

Diffuse Reflection Diffuse Light L diffuse = I diffuse K diffuse cosθ i Diffuse Radiance Diffuse Surface Material Coefficient θ i Brighter Darker

An Example Kdiffuse Kambient

Specular Reflection Some materials, such as plastic and metal, can have shiny highlight spots. This is due to a glossy mirrorlike reflection. Materials have different shininess/glossiness.

Specular Reflection For a mirror, the light is reflected into a single direction. θ i N θ i Specular reflection assumes that the glossy surface is not even, so the light is reflected into a small cone. N If your viewing direction is close to the mirror direction, you receive high radiance. θ i ϕ

Specular Reflection Given L, N and V, we first calculate the mirror reflection direction: R=2(L N)N-L Then we have: L specular = I specular K specular cos n φ ϕ is the angle between V and R. cosφ = V R n indicates surface shininess. L θ i N ϕ V R

An Example K specular Shininess n

Total Reflection Illumination from a single light source i: L ambient = I ambient K ambient L diffuse = I diffuse K diffuse cosθ i L specular = I specular K specular cos n φ i L total i = L ambient i + L diffuse i + L specular Illumination from multiple light source: 0 L total = L globalamibient + L total 1 + L total 2 + L total +L

OpenGL Material OpenGL defines material properties like this: glmaterialfv("face, "property, value ) Face: GL_FRONT, GL_BACK, or GL_FRONT_AND_BACK Property: GL_AMBIENT, GL_DIFFUSE, Value: A vector array

For Example Glfloat mat_amb_diff[]={1.0, 0.5, 0.8, 10.0}; Glfloat mat_specular[]={1.0, 1.0, 1.0, 1.0}; Glfloat shiniess []={5.0}; glmaterialfv(gl_front, GL_AMBIENT_AND_DIFFUSE, mat_amb_diff); glmaterialfv(gl_front, GL_SPECULAR, mat_specular); glmaterialfv(gl_front, GL_SHININESS, shininess); Specular highlights are usually in the light source s color. Ambient and diffuse can be defined together or separately. If you don t mind dark shadow, just ignore ambient. Shininess is from 0 (dull) to 128 (shiny).

Light Model gllightmodelfv(property, value); Enable two sided lighting Property=GL_LIGHT_MODEL_TWO_SIDE If value=0, only GL_FRONT is rendered; If value=1, both GL_FRONT and GL_BACK are rendered Global ambient color Property=GL_LIGHT_MODEL_AMBIENT Value is a color array And more

Surface Normal Normals are used in calculating reflection. Normals are also used to decide the surface front and back side. (x, y, z) It s normal is normalized(x, y, z) E 20 =V 2 -V 0 N = E 10 E 20 E 10 E 20 V 2 V 0 E 10 =V 1 -V 0 V 1

Surface Normal We can define a triangle normal for the whole triangle. The result is a surface made of triangles. for(int i=0; i<t_number; i++) { glnormal3f( ); glbegin(gl_triangles); glvertex3f( ); glvertex3f( ); glvertex3f( ); glend(); }

Surface Normal But the mesh represents a smooth surface. We define a normal for each vertex, by taking the normalized average of its adjacent triangle normals. for(int i=0; i<t_number; i++) { glbegin(gl_triangles); glnormal3f( ); //XN0 glvertex3f( ); //X0 glnormal3f( ); //XN1 glvertex3f( ); //X1 glnormal3f( ); //XN2 glvertex3f( ); //X2 glend(); }

Lighting and Shading Each pixel corresponds to a visible 3D point. We need to calculate the pixel intensity for that 3D point, based on the reflection model. Given a 2D Pixel Location Inverse Projection Selection Ray Intersection Test A 3D point on a primitive Reflection Calculation Ray Tracing Given a 3D primitive Projection A 2D primitive Rasterization ti A number of pixels The Graphics Pipeline

Lighting and Shading OpenGL does reflection calculation only for each vertex (unless using GPU shaders). Given a 3D primitive Projection A 2D primitive (with 3D info) Rasterization A number of pixels (with 3D info) Fragment Shader Pixels with intensities OpenGL + GPU Given a 3D polygon Lighting A 3D polygon, with intensity info Projection A 2D polygon, with intensity info Interpolation/Raserization Pixels with intensities OpenGL

OpenGL Shading Now given a 2D polygon with intensity information on each vertex, how to get the value for each pixel? Flat shading Gouraud Shading* Phong Shading* Given a 3D polygon Lighting A 3D polygon, with intensity info Projection A 2D polygon, with intensity info Interpolation/Raserization Pixels with intensities *: Both were proposed by researchers at the University of Utah in 1970s.

Flat Shading Flat shading uses one vertex information for the whole primitive. glshademodel(gl_flat) What s the difference? Vertex Normal + Flat Shading Triangle Normal + Smooth Shading

Flat Shading VS. Smooth Shading Flat shading has this discontinuous artifact. This is fast, since only needs one calculation per polygon. Only useful when the polygons are very small. Smooth shading avoid the discontinuous artifact. Slower More realistic.

Smooth Shading OpenGL uses a smooth Gouraud shading technique. The basic idea is to calculate the color intensity at each vertex, and then interpolate over the polygon. To use smooth shading: glshademodel(gl_smooth) Vertex Normal + Flat Shading Vertex Normal + Smooth Shading

Review: Linear Interpolation Given a line segment with two end points (P and Q) and a sample point R, we can interpolate a value function V over the line as: V r = Q R V p + P R V q P Q V p P V r =? R V q Q

OpenGL Interpolation OpenGL does 2D interpolation in a scanline way. The result is identical to the interpolation using barycentric coordinates. But the scanline method is faster. Why? For every scanline

Gouraud Shading Gouraud shading calculates the color per vertex. It has artifacts too. To solve it, use smaller polygons. dark dark dark dark or bright? dark

Phong Shading Instead of interpolating the color (light intensity), Phong shading interpolates surface normals, and then calculates the 3D reflection per 2D pixel. OpenGL doesn t support it, since 3D information needs to be carried through the whole pipeline. GPU supports it. You can use OpenGL shading language (GLSL). It s still under the projection+scanline framework, but its result is comparable to ray tracing. Flat Shading Gouraud Shading Phong Shading

Summary The projection+scanline graphics pipeline is also called rasterization based rendering. Examples: OpenGL, Pixar Renderman, GPU Fast, but difficult to handle global illumination Widely used in games Alternatively, ray tracing is based on the inverseprojection+ray intersection framework Examples: POV Ray, new Pixar Renderman, PBRT Slow, but handles global illumination Used for offline rendering, such as movie effects