计算机图形学computergraphics课件14.pptx
- 【下载声明】
1. 本站全部试题类文档,若标题没写含答案,则无答案;标题注明含答案的文档,主观题也可能无答案。请谨慎下单,一旦售出,不予退换。
2. 本站全部PPT文档均不含视频和音频,PPT中出现的音频或视频标识(或文字)仅表示流程,实际无音频或视频文件。请谨慎下单,一旦售出,不予退换。
3. 本页资料《计算机图形学computergraphics课件14.pptx》由用户(晟晟文业)主动上传,其收益全归该用户。163文库仅提供信息存储空间,仅对该用户上传内容的表现方式做保护处理,对上传内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知163文库(点击联系客服),我们立即给予删除!
4. 请根据预览情况,自愿下载本文。本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
5. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007及以上版本和PDF阅读器,压缩文件请下载最新的WinRAR软件解压。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 图形学 computergraphics 课件 14
- 资源描述:
-
1、1ObjectivesIntroduce the OpenGL shading functionsDiscuss polygonal shading Flat Smooth Gouraud2Steps in OpenGL shading1.Enable shading and select model2.Specify normals3.Specify material properties4.Specify lights3Normals In OpenGL the normal vector is part of the state Set by glNormal*()glNormal3f(
2、x,y,z);glNormal3fv(p);Usually we want to set the normal to have unit length so cosine calculations are correct Length can be affected by transformations Note that scaling does not preserved lengthglEnable(GL_NORMALIZE)allows for autonormalization at a performance penalty4Normal for Trianglep0p1p2nPl
3、ane n (p-p0)=0n=(p2-p0)(p1-p0)normalize n n/|n|pNote that right-hand rule determines outward face5Enabling Shading Shading calculations are enabled byglEnable(GL_LIGHTING)Once lighting is enabled,glColor()ignored glEnable(GL_COLOR_MATERIAL);Must enable each light source individuallyglEnable(GL_LIGHT
4、i)i=0,1.Can choose light model parametersglLightModeli(parameter,GL_TRUE)GL_LIGHT_MODEL_LOCAL_VIEWER do not use simplifying distant viewer assumption in calculation(infinite viewer)GL_LIGHT_MODEL_TWO_SIDED shades both sides of polygons independently6Defining a Point Light Source For each light sourc
5、e,we can set an RGBA for the diffuse,specular,and ambient components,and for the positionGLfloat diffuse0=1.0,0.0,0.0,1.0;GLfloat ambient0=1.0,0.0,0.0,1.0;GLfloat specular0=1.0,0.0,0.0,1.0;Glfloat light0_pos=1.0,2.0,3,0,1.0;glEnable(GL_LIGHTING);glEnable(GL_LIGHT0);glLightv(GL_LIGHT0,GL_POSITION,lig
6、ht0_pos);glLightv(GL_LIGHT0,GL_AMBIENT,ambient0);glLightv(GL_LIGHT0,GL_DIFFUSE,diffuse0);glLightv(GL_LIGHT0,GL_SPECULAR,specular0);7Distance and Direction The source colors are specified in RGBA The position is given in homogeneous coordinates If w=1.0,we are specifying a finite location If w=0.0,we
7、 are specifying a parallel source with the given direction vector The coefficients in the distance terms are by default a=1.0(constant terms),b=c=0.0(linear and quadratic terms).Change bya=0.80;glLightf(GL_LIGHT0,GLCONSTANT_ATTENUATION,a);1/(a+bdL+cdL2)8SpotlightsUse glLightv to set Direction GL_SPO
8、T_DIRECTION Cutoff GL_SPOT_CUTOFF Attenuation GL_SPOT_EXPONENT Proportional to cosafq-qf9Global Ambient LightAmbient light depends on color of light sources A red light in a white room will cause a red ambient term that disappears when the light is turned offOpenGL also allows a global ambient term
9、that is often helpful for testingglLightModelfv(GL_LIGHT_MODEL_AMBIENT,global_ambient)10glLightfv(light,pname,param)11LIGHT_TYPE_SPOT(Demo Ogl-lighting)case LIGHT_TYPE_SPOT:GLfloat diffuse_light2=1.0f,1.0f,1.0f,1.0f;GLfloat position_light2=2.0f*x,2.0f*y,2.0f*z,1.0f;GLfloat spotDirection_light2=x,y,z
10、;GLfloat constantAttenuation_light2=1.0f;glLightfv(GL_LIGHT2,GL_DIFFUSE,diffuse_light2);glLightfv(GL_LIGHT2,GL_POSITION,position_light2);glLightfv(GL_LIGHT2,GL_SPOT_DIRECTION,spotDirection_light2);glLightfv(GL_LIGHT2,GL_CONSTANT_ATTENUATION,constantAttenuation_light2);glLightf(GL_LIGHT2,GL_SPOT_CUTO
11、FF,45.0f);glLightf(GL_LIGHT2,GL_SPOT_EXPONENT,25.0f);12Moving Light Sources(Demo)Light sources are geometric objects whose positions or directions are affected by the modelview matrixDepending on where we place the position(direction)setting function,we can Move the light source(s)with the object(s)
12、Fix the object(s)and move the light source(s)Fix the light source(s)and move the object(s)Move the light source(s)and object(s)independently13void display(GLint spin)GLfloat light_position=0.0,0.0,1.5,1.0;glPushMatrix();glTranslatef(0.0,0.0,5.0);glPushMatrix();glRotated(GLdouble)spin,1.0,0.0,0.0);gl
13、Lightfv(GL_LIGHT0,GL_POSITION,light_position);glPopMatrix();auxSolidTorus(0.275,0.85);glPopMatrix();glFlush();/旋转光源14Material Properties Material properties are also part of the OpenGL state and match the terms in the modified Phong model Set by glMaterialv()GLfloat ambient=0.2,0.2,0.2,1.0;GLfloat d
14、iffuse=1.0,0.8,0.0,1.0;GLfloat specular=1.0,1.0,1.0,1.0;GLfloat shine=100.0glMaterialf(GL_FRONT,GL_AMBIENT,ambient);glMaterialf(GL_FRONT,GL_DIFFUSE,diffuse);glMaterialf(GL_FRONT,GL_SPECULAR,specular);glMaterialf(GL_FRONT,GL_SHININESS,shine);15Front and Back Faces The default is shade only front face
15、s which works correctly for convex objects If we set two sided lighting,OpenGL will shade both sides of a surface Each side can have its own properties which are set by using GL_FRONT,GL_BACK,or GL_FRONT_AND_BACK in glMaterialfback faces not visibleback faces visible16Emissive TermWe can simulate a
16、light source in OpenGL by giving a material an emissive componentThis component is unaffected by any sources or transformationsGLfloat emission=0.0,0.3,0.3,1.0);glMaterialf(GL_FRONT,GL_EMISSION,emission);17TransparencyMaterial properties are specified as RGBA valuesThe A value can be used to make th
17、e surface translucentThe default is that all surfaces are opaque regardless of ALater we will enable blending and use this feature18Efficiency Because material properties are part of the state,if we change materials for many surfaces,we can affect performance We can make the code cleaner by defining
18、 a material structure and setting all materials during initialization We can then select a material by a pointertypedef struct materialStruct GLfloat ambient4;GLfloat diffuse4;GLfloat specular4;GLfloat shineness;MaterialStruct;19IMPLEMENTATION I20ObjectivesIntroduce basic implementation strategiesCl
展开阅读全文