Shading and Illumination. OpenGL Shading Without ShadingWith Shading.

Slides:



Advertisements
Similar presentations
CSPC 352: Computer Graphics
Advertisements

Virtual Realism LIGHTING AND SHADING. Lighting & Shading Approximate physical reality Ray tracing: Follow light rays through a scene Accurate, but expensive.
1 MAE152 Computer Graphics for Scientists and Engineers Lighting in OpenGL.
Illumination and Shading
1. What is Lighting? 2 Example 1. Find the cubic polynomial or that passes through the four points and satisfies 1.As a photon Metal Insulator.
Based on slides created by Edward Angel
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Shading I.
Computer Graphics - Class 10
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2008 Tamara Munzner Lighting/Shading III Week.
Shading in OpenGL CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
CS 4731: Computer Graphics Lecture 16: Illumination Models Part 2 Emmanuel Agu.
Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 11: OpenGL 3
Shading in OpenGL Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
1 CSCE 641: Computer Graphics Lighting Jinxiang Chai.
CS5500 Computer Graphics March 26, Shading Reference: Ed Angel’s book.
Computer Graphics (Spring 2008) COMS 4160, Lecture 14: OpenGL 3
Illumination and Shading
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Shading I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
CS 480/680 Computer Graphics Shading I Dr. Frederick C Harris, Jr.
Fundamentals of Computer Graphics Part 6 Shading prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared with Angel,E.:
Computer Graphics Lighting.
1 Graphics CSCI 343, Fall 2013 Lecture 20 Lighting and Shading III.
Shading (introduction to rendering). Rendering  We know how to specify the geometry but how is the color calculated.
COMPUTER GRAPHICS CS 482 – FALL 2014 AUGUST 27, 2014 FIXED-FUNCTION 3D GRAPHICS MESH SPECIFICATION LIGHTING SPECIFICATION REFLECTION SHADING HIERARCHICAL.
Shading in OpenGL.
19/17/ :25 UML Graphics: Conceptual Model Real Object Human Eye Display Device Graphics System Synthetic Model Synthetic Camera Real Light Synthetic.
Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.
Computer Graphics I, Fall 2010 Shading in OpenGL.
Lecture 9: Lighting and Shading 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271
Lecture 14 Shading models 1.Shading Constant Shading (to be implemented) Gouraud Shading Phong Shading 2.Light and shading with OpenGL 1.
08 |Lighting and Shading Eriq Muhammad Adams J |
Rendering Overview CSE 3541 Matt Boggus. Rendering Algorithmically generating a 2D image from 3D models Raster graphics.
Taku KomuraComputer Graphics Local Illumination and Shading Computer Graphics – Lecture 10 Taku Komura Institute for Perception, Action.
University of Texas at Austin CS 378 – Game Technology Don Fussell CS 378: Computer Game Technology Basic Rendering Pipeline and Shading Spring 2012.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Shading I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Chi-Cheng Lin, Winona State University CS430 Computer Graphics Lighting and Shading Part II.
OpenGL Color and Lighting 2003 Spring Keng Shih-Ling.
OpenGL Lighting Jian-Liang Lin 2002 Hidden-Surface Removal -1 Original Code: while (1) { get_viewing_point_from_mouse_position(); glClear(GL_COLOR_BUFFER_BIT);
11/04/04© University of Wisconsin, CS559 Fall 2004 Last Time Visibility –Z-Buffer and transparency –A-buffer –Area subdivision –BSP Trees –Exact Cell-Portal.
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E.
COMPUTER GRAPHICS Hochiminh city University of Technology Faculty of Computer Science and Engineering CHAPTER 6: Lighting and Shading.
RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program.
Lecture Fall 2001 Illumination and Shading in OpenGL Light Sources Empirical Illumination Shading Transforming Normals Tong-Yee Lee.
11/5/2002 (c) University of Wisconsin, CS 559 Last Time Local Shading –Diffuse term –Specular term –All together –OpenGL brief overview.
Local Illumination and Shading
Where We Stand So far we know how to: –Transform between spaces –Rasterize –Decide what’s in front Next –Deciding its intensity and color.
In the name of God Computer Graphics. Where We Stand So far we know how to: –Transform between spaces –Draw polygons Next –Deciding a pixel’s intensity.
Lighting and Reflection Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Shading NOTE: Some of these slides are from Ed Angel’s presentation at SIGGRAPH February 27, 2008.
Computer Graphics Ken-Yi Lee National Taiwan University (the slides are adapted from Bing-Yi Chen and Yung-Yu Chuang)
CS559: Computer Graphics Lecture 16: Shading and OpenGL Li Zhang Spring 2008.
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
Illumination Models and Surface-Rendering Methods CEng 477 Introduction to Computer Graphics.
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
Computer Graphics (fall,2010) School of Computer Science University of Seoul Minho Kim.
1 Dr. Scott Schaefer Lighting. 2/49 Lighting/Illumination Color is a function of how light reflects from surfaces to the eye Global illumination accounts.
Graphics Graphics Korea University kucg.korea.ac.kr 1 Lights & Material 고려대학교 컴퓨터 그래픽스 연구실.
CSC Graphics Programming
Shading To determine the correct shades of color on the surface of graphical objects.
Illumination and Shading
@ 2017 by Jim X. Chen George Mason University
Shading in OpenGL Ed Angel
Lighting and Shading Lab 8:.
Illumination and Shading
Lighting and Materials
Lighting – Light Sources
CS5500 Computer Graphics April 10, 2006.
Last Time Liang-Barsky Details Weiler-Atherton clipping algorithm
Computer Graphics (Fall 2003)
Presentation transcript:

Shading and Illumination

OpenGL Shading Without ShadingWith Shading

Physics

Bidirectional Reflectance Distribution Function (BRDF) n: Surface normal L: Radiance (“intensity along a ray”)

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

Rendering Equation Given any point x in a large environment, let L(x, ω) be the radiance along a ray, we have: Le: Emitted intensity (light source) Ω: A hemisphere over x

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 separates surface reflection into three components: Therefore, you should define three light intensities. Each of them contributes to a reflection component: Ambient Diffuse Specular OpenGL Light Intensity AmbientDiffuseSpecularTotal

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: 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 attenuation No spot light

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 separates surface reflection into three components: Therefore, you should define three material properties. Each of them contributes to a reflection component: Ambient Diffuse Specular OpenGL Material AmbientDiffuseSpecularTotal

Ambient Reflection Ambient Radiance (Pixel Intensity) Ambient Light 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/cosθ i θiθi

Diffuse Reflection θiθi Diffuse Radiance Diffuse Light Diffuse Surface Material Coefficient BrighterDarker

An Example K diffuse K ambient

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

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

Specular Reflection θiθi ϕ N L V R Given L, N and V, we first calculate the mirror reflection direction: Then we have: ϕ is the angle between V and R. n indicates surface shininess.

An Example K specular Shininess n

Total Reflection Illumination from a single light source i: Illumination from multiple light source:

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

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 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… glLightModelfv(property, value);

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) V0V0 V1V1 V2V2 E 10 =V 1 -V 0 E 20 =V 2 -V 0

Surface Normal for(int i=0; i<t_number; i++) { glNormal3f(…); glBegin(GL_TRIANGLES); glVertex3f(…); glEnd(); } We can define a triangle normal for the whole triangle. The result is a surface made of triangles.

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

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

Lighting and Shading OpenGL calculates reflection at each vertex. Rasterization Given a 3D primitive A 2D polygon, with 3D info Projection Pixels with 3D info OpenGL + GPU (Phong) Fragment Shader Pixels with intensities Raserization Given a 3D polygon A 2D polygon, with intensity info Projection Pixels with intensities OpenGL Lighting A 3D polygon, with intensity info

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

Flat Shading Flat shading uses one vertex’s intensity value for the whole polygon. glShadeModel(GL_FLAT) Vertex Normal + Flat Shading Triangle Normal + Smooth Shading What’s the difference?

Flat Shading VS. Smooth Shading Flat shading has this discontinuous artifact. It is fast, since only needs one calculation per polygon. Only useful when the polygons are very small. Smooth shading avoid the discontinuous artifact. Slightly 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 ShadingVertex Normal + Smooth Shading

Review: Linear Interpolation VpVp P Q VqVq R V r =? 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:

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 or bright?

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 ShadingGouraud ShadingPhong 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 inverse- projection+ray-intersection framework Examples: POV-Ray, new Pixar Renderman, PBRT… Slow, but handles global illumination Used for offline rendering, such as movie effects