Surface Rendering Methods 6 th Week, 2008 Sun-Jeong Kim Polygon Rendering Methods Determining the surface intensity at every projected pixel position using an illumination model Light-material interactions Polygonal shading Flat shading Gouraud shading Phong shading 2
Flat Shading (1) Constant-intensity surface rendering Assigning the same color to all projected surface positions Determining the intensity (RGB color) at a single surface position (ex. a vertex or the polygon centroid) Fast and simple method One rendering calculation for each polygon 3 Assumptions: Flat Shading (2) The polygon is one face of a polyhedron (not a section of curved surface) All light sources are sufficiently far from the surface N L and attenuation constant Viewing position is sufficiently far from the polygon V R constant Flat Shading Smooth Shading 4
Gouraud Shading (1) Intensity-interpolation surface rendering Linearly interpolating vertex intensity values across the polygon faces Vertex normal vector One rendering calculation for each vertex Averaging the surface normal vectors of all polygons sharing that vertex n N k = 1 k NV = n N N V = N N 1 1 k = 1 + N + N 2 2 k + N + N 3 3 + N + N 4 5 4 Procedures: Gouraud Shading (2) Determine the average unit normal vector at each vertex of the polygon Apply an illumination model at each polygon vertex to obtain the light intensity Linearly interpolate the vertex intensity over the projected area of the polygon y4 y2 y1 y4 I 4 = I1 + I 2 y y y y I p = x x 1 2 1 y 2 x x x 5 p p 4 I 4 + 5 x4 x5 x4 I 5 6
Gouraud Shading (3) Wireframe Flat Shading Gouraud Shading 7 Phong Shading (1) Normal-vector interpolation rendering More accurate interpolation method more realistic One rendering calculation for each pixel More computation than Gouraud method Procedures: Determine the average unit normal vector at each vertex of the polygon Linearly interpolate t the vertex normals over the projected area of the polygon Apply an illumination model at positions along scan lines to calculate pixel intensities 8
Phong Shading (2) Wireframe Flat Gouraud Phong 9 Local vs. Global Rendering Local lighting model cannot handle: Blocking some of the light source from reaching the other spheres Scattering some light among spheres Global Lighting Model Local Lighting Model 10
Global Effects Shadow Translucent Surface Multiple Reflection 11 Ray Tracing Continuing to bounce the pixel ray around in the scene to collect the various intensity contribution Generalization of the basic ray casting procedure Global refection and transmission effects Highly realistic and photo-realistic ti display 12
Basic Ray Tracing Algorithm (1) The coordinate system for ray tracing Collecting the intensity contributions for a particular pixel by tracing a light path backward from the pixel position into the scene 13 Basic Ray Tracing Algorithm (2) Primary rays ray casting Visible surface detection Secondary rays reflection and refraction rays Repeating the ray-processing procedures for the secondary rays 14
Basic Ray Tracing Algorithm (3) Ray tracing tree The list of surfaces intersecting ray for each pixel Left reflection, right refraction Maximum depth a user option Terminating a path in the binary tree for a pixel if any one of the following conditions is satisfied: The ray intersects no surfaces The ray intersects a light source The tree has been generated to its maximum allowable depth 15 Basic Ray Tracing Algorithm (4) Reflection R = u ( 2u N)N Refraction (transparency) T η i ηi u cosθ r cosθi N ηr ηr = i Snell s law: η sin θ = η sin θ r r i i η r η i 16
Basic Ray Tracing Algorithm (5) 17 Radiosity More precisely lighting effects Considering the physical laws governing the radiant- energy transfers Accurately describing diffuse reflections from a surface Radiosity The quantity of radiant flux per unit area that is leaving a surface Radiance The radiant flux or the radiosity per unit solid angle (t (steradian) 18
Basic Radiosity Model Computing radiant-energy intersections between all surfaces in a scene Radiosity equation B k = E k + ρ n k j= 1 B j F jk B k : radisoity of surface k E k : emission of surface k F j A surfk j πr 2 jk = ρ k : reflectivity of surface k surf j F jk : form factor for surfaces j and k 1 cosφ cosφk da da The fractional amount of radiant energy from surface j that reaches surface k k j 19 Progressive Refinement Radiosity (1) Disadvantage of radiosity method Considerable processing time to calculate the form factors Tremendous storage requirements Progressive refinement First, light sources are chosen (the highest h radient energy) Other patches are selected based on the amount of light received from the light sources 20
Progressive Refinement Radiosity (2) 1 iteration 2 iterations 24 iterations 100 iterations 21 Progressive Refinement Radiosity (3) 22
OpenGL Surface-Property Function Material reflectivity properties of a surface glmaterial{if}(glenum face, GLenum name, TYPE value); glmaterial{if}v(glenum face, GLenum name, TYPE *value); face GL_FRONT, GL_BACK, GL_FRONT_AND_BACK name GL_DIFFUSE, GL_SPECLAR, GL_AMBIENT, GL_AMBIENT_AND_DIFFUSE, GL_EMISSION, GL_SHININESS 23 Default Light & Material 24
Result Default Light & Material 25 Specifying Material (1) 26
Result Specifying Material (1) 27 Specifying Material (2) 28
Result Specifying Material (2) 29 Specifying Material (3) 30
Result Specifying Material (3) 31 Exercises (1) 새로운 Material 값들을설정하시오. 각 Parameter 의의미를파악하시오. 자신이만든조명과함께 Rendering 하시오. 어떻게보이는가? 32
Specifying Material (4) 33 Specifying Material (5) 34
Specifying Material (6) 35 Specifying Material (7) 36
What s Happening? 37 Exercises (2) Cone 에자신이만든 Material 을지정해보시오. 반드시 4 개 Object 가다른 Material 을가지고있어야함 38
Color Material (1) Specifying a material by the color referred to by all following calls to glcolor*( ) glenable(gl_color_material); glcolormaterial(glenum face, GLenum name); face GL_FRONT, GL_BACK, GL_FRONT_AND_BACK name GL_DIFFUSE, GL_SPECLAR, GL_AMBIENT, GL_AMBIENT_AND_DIFFUSE, GL_EMISSION 39 Color Material (2) 40
Color Material (3) 41 Result Color Material 42
Shading Model in OpenGL Computing a color for only the first vertex in a polygon glshademodel( GL_FLAT ); Performing the lighting calculation at each vertex and then interpolating i vertex colors across the polygon ( default) glshademodel( GL_SMOOTH ); Enabling automatic normalization Incurring a performance penalty glenable( GL_NORMALIZE ); 43 Flat Shading in OpenGL Constant shading glshademodel(gl_flat); p 1 n p 0 glbegin(gl_triangles); glnormal3fv(n); glvertex3fv(p1); glvertex3fv(p2); glvertex3fv(p3); glend(); glvertex3fv(p3); n = ( p 1 p 0 ) ( p 2 p 0 ) p 2 44
Smooth Shading in OpenGL Gouraud shading default glshademodel(gl_smooth); glbegin(gl_triangles); glnormal3fv(n1); glvertex3fv(p1); glnormal3fv(n2); glvertex3fv(p2); glnormal3fv(n3); glvertex3fv(p3); glend(); n = n n + 1 + n2 + n3 + n4 1 + n2 + n3 + n4 Note silhouette edge 45 Flat Shading 46
Result Flat Shading 47 Exercises (3) 서로다른재질을사용하여모델링하시오. 48