Illumination and Shading

Slides:



Advertisements
Similar presentations
2IV60 Computer graphics set 8: Illumination Models and Surface-Rendering Methods Jack van Wijk TU/e.
Advertisements

Polygon Rendering Flat Rendering Goraud Rendering Uses Phong Reflectance Phong Rendering.
2 COEN Computer Graphics I Evening’s Goals n Discuss the fundamentals of lighting in computer graphics n Analyze OpenGL’s lighting model n Show.
CSPC 352: Computer Graphics
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.
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.
Illumination Model & Surface-rendering Method 박 경 와.
Computer Graphics - Class 10
OpenGL Son of the Survival Guide. Last Time on OpenGL Windowing … glut Rendering Primatives Transformations Projections State Management.
Shading in OpenGL CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
Shading in OpenGL Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Ray Casting Ray-Surface Intersections Barycentric Coordinates Reflection and Transmission [Shirley, Ch.9] Ray Tracing Handouts Ray Casting Ray-Surface.
1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok
Now Playing: Multiply Jamie Lidell from Multiply Released June 13, 2005.
CS5500 Computer Graphics March 26, Shading Reference: Ed Angel’s book.
CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.
CS425 OpenGL Materials. What Color Is It? green & blue absorbed white light Looks red.
Illumination and Shading
Basic Ray Tracing CMSC 435/634. Visibility Problem Rendering: converting a model to an image Visibility: deciding which objects (or parts) will appear.
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
Development of Interactive 3D Virtual World Applications
Computer Graphics Lighting.
1 Graphics CSCI 343, Fall 2013 Lecture 20 Lighting and Shading III.
Illumination & Reflectance Dr. Amy Zhang. Outline 2  Illumination and Reflectance  The Phong Reflectance Model  Shading in OpenGL.
Shading in OpenGL.
1 Chapter 6 Shading. 2 Objectives Learn to shade objects so their images appear three-dimensional Introduce the types of light-material interactions Build.
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.
Shading and Illumination. OpenGL Shading Without ShadingWith Shading.
Ray Tracing Sang Il Park SEjong University With lots of slides stolen from Jehee Lee, Doug James, Steve Seitz, Shree Nayar, Alexei Efros, Fredo Durand.
Computer Graphics I, Fall 2010 Shading in OpenGL.
Ray Tracing Chapter CAP4730: Computational Structures in Computer Graphics.
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.
Basic Ray Tracing CMSC 435/634. Visibility Problem Rendering: converting a model to an image Visibility: deciding which objects (or parts) will appear.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Shading I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
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);
Illumination and Shading
Basic Ray Tracing CMSC 435/634.
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E.
Chap 5 Global Illumination
Shading in OpenGL Shandong University Software College Instructor: Zhou Yuanfeng
Ray Tracing Fall, Introduction Simple idea  Forward Mapping  Natural phenomenon infinite number of rays from light source to object to viewer.
Lighting Dave Shreiner. 2 Lighting Principles Lighting simulates how objects reflect light Lighting simulates how objects reflect light material composition.
Illumination and Shading Sang Il Park Sejong University.
RENDERING : Global Illumination
Shading NOTE: Some of these slides are from Ed Angel’s presentation at SIGGRAPH February 27, 2008.
CS559: Computer Graphics Lecture 16: Shading and OpenGL Li Zhang Spring 2008.
Chapter 8 Three-dimensional Object Representations PART I
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.
Graphics Graphics Korea University kucg.korea.ac.kr 1 Lights & Material 고려대학교 컴퓨터 그래픽스 연구실.
CSC Graphics Programming
© University of Wisconsin, CS559 Spring 2004
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
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Shading in OpenGL Ed Angel
CSC461: Lecture 24 Lighting and Shading in OpenGL
Lighting Phong's Lighting Model normals
Illumination and Shading
Lighting and Materials
Lighting – Light Sources
Lighting – Material Properties
Last Time Liang-Barsky Details Weiler-Atherton clipping algorithm
Computer Graphics Shading in OpenGL
Presentation transcript:

Illumination and Shading Sang Il Park Sejong University

코딩 연습 Phone Illumination Model을 직접 구현해 본다 (GL_LIGHTING 을 끈 상태로 직접 색을 계산하여 그려본다) 조명을 설정한다. (위치(lx,ly,lz) 및 Intensity) 도형의 색을 설정 (ka, kd, ks) 카메라의 위치 설정 (vx, vy, vz) 그리고 있는 삼각형의 Normal Vector 계산 Phong Model의 각각의 성분 계산 (ambient, diffuse, specular) 계산

OpenGL Lighting Functions Using Illumination/Shading Model: Turn on/off Lights glEnable (GL_LIGHTING); glEnable (GL_LIGHT0); glEnable (GL_LIGHT1); … glEnable (GL_LIGHT7); glDisable (GL_LIGHT0); glDisable (GL_LIGHT1); … glDisable (GL_LIGHT7);

OpenGL Lighting Functions glLight * (lightName,lightProperty, propertyValue) lightName: GL_LIGHT0, GL_LIGHT1, GL_LIGHT2, …., GL_LIGHT7

OpenGL Lighting Functions Point Light Source: GLfloat light1pos [] = {2.0, 0.0, 3.0, 1.0}; GLfloat light2pos [] = {0.0, 1.0, 0.0, 0.0}; glLightfv (GL_LIGHT0, GL_POSITION, light1pos); glEnable (GL_LIGHT0); glLightfv (GL_LIGHT1, GL_POSITION, light2pos); glEnable (GL_LIGHT1); Default value: GLfloat light0pos [] = {0.0, 0.0, 1.0, 0.0};

OpenGL Lighting Functions Point Light Source Colors: GLfloat ambientColor[]={0.0,0.0,0.0,1.0}; GLfloat diffuseColor[]={1.0,1.0,1.0,1.0}; GLfloat specularColor[]={1.0,1.0,1.0,1.0}; glLightfv (GL_LIGHT0, GL_AMBIENT, ambientColor); glLightfv (GL_LIGHT0, GL_DIFFUSE, diffuseColor); glLightfv (GL_LIGHT0, GL_SPECULAR, specularColor);

OpenGL Lighting Functions Global Light Setting GLfloat globalAmbient[] = {0.2,0.2,0.2,1.0}; glLightModelfv (GL_LIGHT_MODEL_AMBIENT, globalAmbient);

OpenGL Lighting Functions Point Light Source Attenuation: glLightf (GL_LIGHT0, GL_CONSTANT_ATTENUATION, 1.5); glLightf (GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.75); glLightf (GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.4);

OpenGL Lighting Functions Spot Light Source: Glfloat dirVector [] = {1.0, 0.0, 0.0}; glLightfv (GL_LIGHT0, GL_SPOT_DIRECTION, dirVector); glLightfv (GL_LIGHT0, GL_SPOT_CUTOFF, 3.0); glLightfv (GL_LIGHT0, GL_SPOT_EXPONENT, 2.5);

OpenGL Material Functions glMaterial * (surface, sufProperty, propertyValue) GLfloat diffuseCoeff [] = {0.2,0.4,0.9,1.0}; GLfloat specularCoeff [] ={1.0,1.0,1.0,1.0}; glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, diffuseCoeff); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specularCoeff); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, 25.0);

OpenGL Material Functions How to apply some of the properties by glMeterial glColorMaterial(surface, mode) surface: GL_FRONT, GL_BACK, GL_FRONT_AND_BACK mode: GL_EMISSION, GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_AMBIENT_AND_DIFFUSE. ? glEnable(GL_COLOR_MATERIAL) VS. glDisable(GL_COLOR_MATERIAL)

OpenGL Lighting Model

Tips for a quick lighting setting 1 Set GL_LIGHT_0's position to something like 45 degrees to the 'vertical'. Coordinate (1,1,0) should work nicely in most cases. Set GL_LIGHT_0's Ambient color to 0,0,0,1 Set GL_LIGHT_0's Diffuse color to 1,1,1,1 Set GL_LIGHT_0's Specular color to 1,1,1,1 Set the glLightModel's global ambient to 0.2,0.2,0.2,1 (this is the default). Don't set any other glLight or glLightModel options - just let them default. Enable GL_LIGHTING and GL_LIGHT_0.

Tips for a quick lighting setting 1 Enable GL_COLOR_MATERIAL and set glColorMaterial to GL_AMBIENT_AND_DIFFUSE. This means that glMaterial will control the polygon's specular and emission colours and the ambient and diffuse will both be set using glColor. Set the glMaterial's Specular colour to 1,1,1,1 Set the glMaterial's Emission colour to 0,0,0,1 Set the glColor to whatever colour you want each polygon to basically appear to be. That sets the Ambient and Diffuse to the same value which is what you generally want.

Atmospheric Effects A hazy atmosphere makes colors fade and objects appear dimmer Hazy-atmosphere effect is often simulated with an exponential attenuation function such as Higher values for r produce a denser atmosphere

A solution for the trackball interface

How to use your mouse There is a callback function for mouse in GLUT Registration: Implementation button: GLUT_LEFT_BUTTON, GLUT_RIGHT_BUTTON action: GLUT_DOWN, GLUT_UP glutMouseFunc ( myMouse); void myMouse (GLint button, GLint action, GLint xpos, GLint ypos ); 교재 749page 참조

How to Rotate? Virtual trackball A trackball translates 2D mouse movements into 3D rotations This is done by projecting the position of the mouse on to an imaginary sphere behind the viewport As the mouse is moved the camera (or scene) is rotated to keep the same point on the sphere underneath the mouse pointer

How to Rotate? Virtual trackball

Review: OpenGL Geometric Transformations Getting the current matrix value: glGetFloatv (GL_MODELVIEW_MATRIX, GLfloat elems[16]); Column major 4 8 12 1 5 9 13 2 6 10 14 3 7 11 15 GLfloat mat [16]; glGetFloatv (GL_MODELVIEW_MATRIX, mat);

Review: OpenGL Geometric Transformations Matrix Direct Manipulation: glLoadMatrixf(GLfloat elems[16]); Column major glMultMatrixf(GLfloat elems[16]); The current matrix is postmultiplied by the matrix 4 8 12 1 5 9 13 2 6 10 14 3 7 11 15 glLoadIdentity(); glMultMatrixf (M1); glMultMatrixf (M2); M = M1∙M2

Sang Il Park SEjong University Ray Tracing Sang Il Park SEjong University With lots of slides stolen from Jehee Lee, Doug James, Steve Seitz, Shree Nayar, Alexei Efros, Fredo Durand and others

Local vs. Global Illumination Models Local illumination models Object illuminations are independent No light scattering between objects No real shadows, reflection, transmission Global illumination models Ray tracing (highlights, reflection, transmission) Radiosity (Surface interreflections) Photon mapping

Forward Ray Tracing Rays as paths of photons in world space Follow photon from light sources to viewer Problem: Many rays will not contribute to image

Backward Ray Tracing Trace rays backward from viewer to light sources One ray from center of projection through each pixel in image plane Ray casting Simplest form of ray tracing No recursion

Backward Ray Tracing Illumination Phong illumination Shadow rays Specular reflection Specular refraction Specular reflection and refraction are recursive

Shadow Rays Determine if light “really” hits surface point Cast shadow ray from surface point to light If shadow ray hits opaque object, no contribution

Specular Refraction (Snell’s law) , : index of refraction of each material (averaged over wavelengths and temperature)

Specular Refraction (Snell’s law) , : index of refraction of each material (averaged over wavelengths and temperature)

Specular Refraction Path shifts are ignored for thin objects From Snell’s law, we can obtain the unit transmission vector T in the direction

Interpolated transparency : transmission coefficient (0 for opaque objects, 1 for totally transparent objects) 2 1 line of sight

Binary Ray-Tracing Tree

Ray-surface Intersections Specialized algorithm for most commonly occurring shapes Sphere Polygon Quadric Splines Many shapes are represented in either implicit or parametric form

Ray-Implicit Surface Intersections Parametric ray equation Initial position Unit direction vector Implicit surface Consists of all points such that Substitute ray equation for Solve for s (univariate root finding)

Ray-Sphere Intersections Sphere equation Substitution Letting Solution

Ray-Polygon Intersections Bounding sphere and back face culling is useful Ray-Plane Intersections Plane equation containing the polygon Substitution Solution Perform inside-outside test to determine whether the intersection is inside the polygon

Acceleration Techniques Space-subdivision Uniform subdivision Adaptive subdivision (Octrees)