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

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

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

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

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

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

8 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, );

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

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

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

12 OpenGL Lighting Model

13 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.

14 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.

15 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

16 A solution for the trackball interface

17 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 참조

18 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

19 How to Rotate? Virtual trackball

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

21 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

22 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

23 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

24 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

25 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

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

27 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

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

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

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

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

32 Binary Ray-Tracing Tree

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

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

35 Ray-Sphere Intersections
Sphere equation Substitution Letting Solution

36 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

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


Download ppt "Illumination and Shading"

Similar presentations


Ads by Google