13 Lighting and Shading II Based on EA
计算机图形学讲义-13 Lighting and Shading (II) 姜明 北京大学数学科学学院 Based on [EA], Chapter 5. 更新时间 2020/11/3 6: 55: 08
计算机图形学讲义-13 The Complete Phong Model Diffuse term Distance term Specular term Ambient term You can try out the Lighting Applet to see the effect of Phong shading http: //www. comp. hkbu. edu. hk/~sci 3750/lect 7 -02. ppt
计算机图形学讲义-13 Vectors Used by the Phong Lighting Model p n l r is an arbitrary point on a surface. is the unit normal to the surface at p. is a unit vector in the direction of the light source. is a unit vector in the direction of a perfectly (specular) reflection v is a unit vector in the direction of the viewer.
计算机图形学讲义-13 Outline • • Computation of Vectors Polygonal Shading Approximation of a Sphere by Recursive Subdivision Light Sources in Open. GL Specification of Materials in Open. GL Shading of the Sphere Model Global Rendering
计算机图形学讲义-13 Computation of Vectors • • Normal Vectors Angle of Reflection Use of the Halfway Vector Transmitted Light
计算机图形学讲义-13 Normal Vectors • Normal vectors exist at every point on smooth surfaces. Implicit form Explicit or parametric form
计算机图形学讲义-13 Plane • The order of the vectors in the cross product determines the orientation of the plane and has an effect on the lighting calculation. • Open. GL requires the user to provide the normal vectors. Sphere
计算机图形学讲义-13 Specification of the Normal in Open. GL In Open. GL, the current normal is part of the state and is altered through one of the functions: gl. Normal 3 f (nx, ny, nz); gl. Normal 3 fv (pointer_to_normal_vector); • A normal is defined before a sequence of vertices (gl. Vertex), this normal is associated with all the vertices, and is used for the lighting computation at all the vertices. You have to calculate the normals yourself. Exception for GLU quadrics and Bezier surfaces.
计算机图形学讲义-13 Angle of Reflection: r
计算机图形学讲义-13 Use of the Halfway Vector for the modified Phone Model • To avoid the computation of r·v at every point, we can use the halfway vector h. • If we replace r·v with n·h, we avoid computation of r. • The halfway angle is usually smaller than that in the coplanar case. The size of the specular highlights will be smaller. • This can be mitigated by using another shininess coefficient.
计算机图形学讲义-13 • Replace (v · r )a by (n · h )b. • b is chosen to match shineness. • Resulting model is known as the modified Phong or Blinn lighting model. • Specified in Open. GL standard. 11
计算机图形学讲义-13 Example Only differences in these teapots are the parameters in the modified Phong model 12
计算机图形学讲义-13 Transmitted Light • Snell’s Law
计算机图形学讲义-13 Polygonal Shading • • • Flat Shading Gouraud Shading Phong Shading
计算机图形学讲义-13 Flat Shading • Each point on the polygon is assigned the same shade. • Small differences in shading between adjacent polygons are visible. • Flat shading exaggerates the visual effect of the boundaries between polygons due to the Mach band effect, even for smooth surfaces. gl. Shade. Model (GL_FLAT); Open. GL uses the normal associated with the first vertex of a single polygon for the shading calculation. Refer to the manual for more details.
计算机图形学讲义-13 Mach Bands • We perceive the increases in brightness as overshooting on one side of an intensity step and undershooting on the other.
计算机图形学讲义-13 Interpolative and Gouraud Shading: Normal at a vertex is the normalized average of the normals of the polygons that share that vertex.
计算机图形学讲义-13 Flat vs Gourand Shading http: //www. comp. hkbu. edu. hk/~sci 3750/lect 7 -02. ppt
计算机图形学讲义-13 Phong Shading • Even Gourand shading may not prevent the appearance of Mach bands. • Normals are interpolated across each polygon. It is almost always done off line. • This changes the orientation of surfaces, makes surfaces look curved, and reduces Mach bands. - Recent hardware can carry out Phong shading in real time.
计算机图形学讲义-13 Approximation of a Sphere by Recursive Subdivision 1 2 0 a 1 3 b 2 3 c
计算机图形学讲义-13 Light Sources in Open. GL gl. Lightf (source, pname, parameter); gl. Lightfv (source, pname, parameter); source is one of at least eight lights: GL_LIGHTi Parameter name: GL_AMBIENT contains four values that specify the ambient RGBA intensity of the light. Default is (0. 0, 1. 0). GL_DIFFUSE contains four values that specify the diffuse RGBA intensity of the light. Default is (1. 0, 1. 0). GL_SPECULAR contains four values that specify the secular RGBA intensity of the light. Default is (1. 0, 1. 0). http: //www. comp. hkbu. edu. hk/~sci 3750/lect 7 -02. ppt
计算机图形学讲义-13 GL_POSITION specifies the position of the light in homogeneous object coordinates. If the w component is zero, the light is treated as a directional source. GL_SPOT_DIRECTION specifies the direction of the light in homogeneous object coordinates. Default is (0. 0, -1. 0) GL_SPOT_EXPONENT spotlight exponent, default 0. 0 GL_SPOT_CUTOFF spot cutoff angle in [0, 90] or 180. GL_CONSTANT_ATTENUATION constant atten. factor, default 1. 0 GL_LINEAR_ATTENUATION linear atten. factor, default 0. 0 GL_QUADRATIC_ATTENUATION linear atten. factor, default 0. 0 http: //www. comp. hkbu. edu. hk/~sci 3750/lect 7 -02. ppt
计算机图形学讲义-13 Specification of Materials in Open. GL gl. Materialf (face, pname, parameter); gl. Materialfv (face, pname, parameter); Modal face is GL_FRONT, GL_BACK, or GL_FRONT_AND_BACK. Parameter name: GL_AMBIENT four values that specify the ambient RGBA reflectance of the material. (0. 2, 1. 0) GL_DIFFUSE four values that specify the diffuse RGBA reflectance of the material. (0. 8, 1. 0) GL_SPECULAR four values that specify the specular RGBA reflectance of the material. (0. 0, 1. 0) GL_SHININESS a value that specifies the specular exponent of the material. 0. 0 http: //www. comp. hkbu. edu. hk/~sci 3750/lect 7 -02. ppt
计算机图形学讲义-13 Shading of the Sphere Model • sphere. c
- Slides: 25