Illumination and Shading Sang Il Park Sejong University
Review Illumination Model Shading Model
Review: Illumination Model An illumination model computes the lighting effects for a surface using the various optical properties Degree of transparency, color reflectance, surface texture The reflection (Phong illumination) model describes the way incident light reflects from an opaque surface Diffuse, ambient, specular reflections Simple approximation of actual physical models
Review: Diffuse Reflection Incident light is scattered with equal intensity in all directions Such surfaces are called ideal diffuse reflectors (also referred to as Lambertian reflectors)
Review: Diffuse Reflection : the intensity of the light source : diffuse reflection coefficient, : the surface normal (unit vector) : the direction of light source, (unit vector)
Review: Ambient Light Multiple reflection of nearby (light-reflecting) objects yields a uniform illumination A form of diffuse reflection independent of he viewing direction and the spatial orientation of a surface Ambient illumination is constant for an object : the incident ambient intensity : ambient reflection coefficient, the proportion reflected away from the surface
Review: Specular Reflection Perfect reflector (mirror) reflects all lights to the direction where angle of reflection is identical to the angle of incidence It accounts for the highlight Near total reflector reflects most of light over a range of positions close to the direction
Review: Specular Reflection Phong specular-reflection model Note that N, L, and R are coplanar, but V may not be coplanar to the others : intensity of the incident light : color-independent specular coefficient : the gloss of the surface
Review: Specular Reflection Specular-reflection coefficient ks is a material property For some material, ks varies depending on q ks =1 if q =90° Calcularing the reflection vector R
Polygon Rendering Methods We could use an illumination model to determine the surface intensity at every projected pixel position Or, we could apply the illumination model to a few selected points and approximate the intensity at the other surface positions Curved surfaces are often approximated by polygonal surfaces So, polygonal (piecewise planar) surfaces often need to be rendered as if they are smooth
Constant-Intensity Surface Rendering Constant (flat) shading Each polygon is one face of a polyhedron and is not a section of a curved-surface approximation mesh
Intensity-Interpolation Surface Rendering Gouraud shading Rendering a curved surface that is approximated with a polygon mesh Interpolate intensities at polygon vertices Procedure Determine the average unit normal vector at each vertex Apply an illumination model at each polygon vertex to obtain the light intensity at that position Linearly interpolate the vertex intensities over the projected area of the polygon
Intensity-Interpolation Surface Rendering Normal vectors at vertices Averaging the normal vectors for each polygon sharing that vertex 4 3 2 1 ) ( N v + =
Intensity-Interpolation Surface Rendering
Normal-Vector Interpolation Surface Rendering Phong shading Interpolate normal vectors at polygon vertices Procedure Determine the average unit normal vector at each vertex Linearly interpolate the vertex normals over the projected area of the polygon Apply an illumination model at positions along scan lines to calculate pixel intensities n1 n2 n3
Gouraud versus Phong Shading Gouraud shading is faster than Phong shading OpenGL supports Gouraud shading Phong shading is more accurate
코딩 연습 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 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) diffuseCoeff [] = {0.2,0.4,0.9,1.0}; 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};
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