电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

计算机图形学computer graph(12)

47页
  • 卖家[上传人]:资****亨
  • 文档编号:480717625
  • 上传时间:2024-05-07
  • 文档格式:PPT
  • 文档大小:4.24MB
  • / 47 举报 版权申诉 马上下载
  • 文本预览
  • 下载提示
  • 常见问题
    • 1、Shading in OpenGLShandong University Software CollegeInstructor:Zhou Yuanfeng E-mail:yuanfeng.zhougmail ObjectivesIntroduce the OpenGL shading functionsDiscuss polygonal shadingFlatSmoothGouraud2Steps in OpenGL shading1.Enable shading and select model2.Specify normals3.Specify material properties4.Specify lights3NormalsIn OpenGL the normal vector is part of the stateSet by glNormal*()glNormal3f(x,y,z);glNormal3fv(p);Usually we want to set the normal to have unit length so cosine calculations are

      2、 correctLength can be affected by transformationsNote that scaling does not preserved lengthglEnable(GL_NORMALIZE)allows for autonormalization at a performance penalty4Normal for Trianglep0p1p2nPlane n (p-p0)=0n=(p2-p0)(p1-p0)normalize n n/|n|pNote that right-hand rule determines outward face5Enabling ShadingShading calculations are enabled byglEnable(GL_LIGHTING)Once lighting is enabled,glColor()ignoredglEnable(GL_COLOR_MATERIAL);Must enable each light source individuallyglEnable(GL_LIGHTi)i=0,

      3、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 SourceFor each light source,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

      4、=1.0,2.0,3,0,1.0;glEnable(GL_LIGHTING);glEnable(GL_LIGHT0);glLightv(GL_LIGHT0,GL_POSITION,light0_pos);glLightv(GL_LIGHT0,GL_AMBIENT,ambient0);glLightv(GL_LIGHT0,GL_DIFFUSE,diffuse0);glLightv(GL_LIGHT0,GL_SPECULAR,specular0);7Distance and DirectionThe source colors are specified in RGBAThe position is given in homogeneous coordinatesIf w=1.0,we are specifying a finite locationIf w=0.0,we are specifying a parallel source with the given direction vectorThe coefficients in the distance terms are by

      5、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_SPOT_DIRECTIONCutoff GL_SPOT_CUTOFFAttenuation GL_SPOT_EXPONENTProportional to cosafq-qf9Global Ambient LightAmbient light depends on color of light sourcesA 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 that is often he

      6、lpful 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;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

      7、,GL_CONSTANT_ATTENUATION,constantAttenuation_light2);glLightf(GL_LIGHT2,GL_SPOT_CUTOFF,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 canMove the light source(s)with the object(s)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

      8、 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);glLightfv(GL_LIGHT0,GL_POSITION,light_position);glPopMatrix();auxSolidTorus(0.275,0.85);glPopMatrix();glFlush();/旋转光源14Material PropertiesMaterial properties are also part of the OpenGL state and match the terms in the modified Phong modelSet by glMaterialv()GLfloat ambient=0.2,0.2,0.2,1.0;GLfloat diffuse=1.0,0.8,0.0,

      9、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 FacesThe default is shade only front faces which works correctly for convex objectsIf we set two sided lighting,OpenGL will shade both sides of a surfaceEach side can have its own properties which are set by using GL_FRONT,GL_BACK,or GL_FRONT_AND_BACK in glMate

      10、rialfback faces not visibleback faces visible16Emissive TermWe can simulate a 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 the surface translucentThe default is that all surfaces are opaque regardless of ALater we will enable blending and use this

      《计算机图形学computer graph(12)》由会员资****亨分享,可在线阅读,更多相关《计算机图形学computer graph(12)》请在金锄头文库上搜索。

      点击阅读更多内容
    关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
    手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
    ©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.