Presentation is loading. Please wait.

Presentation is loading. Please wait.

Illumination and Shading

Similar presentations


Presentation on theme: "Illumination and Shading"— Presentation transcript:

1 Illumination and Shading
Sang Il Park Sejong University

2 Review Illumination Model Shading Model

3 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

4 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)

5 Review: Diffuse Reflection
: the intensity of the light source : diffuse reflection coefficient, : the surface normal (unit vector) : the direction of light source, (unit vector)

6 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

7 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

8 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

9 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

10

11 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

12 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

13 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

14 Intensity-Interpolation Surface Rendering
Normal vectors at vertices Averaging the normal vectors for each polygon sharing that vertex 4 3 2 1 ) ( N v + =

15 Intensity-Interpolation Surface Rendering

16 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

17 Gouraud versus Phong Shading
Gouraud shading is faster than Phong shading OpenGL supports Gouraud shading Phong shading is more accurate

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

19 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);

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

21 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};

22 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);

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

24 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);

25 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};

26 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


Download ppt "Illumination and Shading"

Similar presentations


Ads by Google