书签 分享 收藏 举报 版权申诉 / 46
上传文档赚钱

类型计算机图形学computergraphics课件14.pptx

  • 上传人(卖家):晟晟文业
  • 文档编号:4927504
  • 上传时间:2023-01-26
  • 格式:PPTX
  • 页数:46
  • 大小:963.60KB
  • 【下载声明】
    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

    19、ipping Scan conversion21OverviewAt end of the geometric pipeline,vertices have been assembled into primitivesMust clip out primitives that are outside the view frustum Algorithms based on representing primitives by lists of verticesMust find which pixels can be affected by each primitive Fragment ge

    20、neration Rasterization or scan conversion22Required TasksClippingRasterization or scan conversion We can get the pixels based on verticesSome tasks deferred until fragement processing Hidden surface removal AntialiasingProjectionFragmentsClippingShadingSurface hiddenTextureTransparency23Rasterizatio

    21、n Meta AlgorithmsConsider two approaches to rendering a scene with opaque objectsFor every pixel,determine which object that projects on the pixel is closest to the viewer and compute the shade of this pixel Ray tracing paradigmFor every object,determine which pixels it covers and shade these pixels

    22、 Pipeline approach Must keep track of depths24Clipping 2D against clipping window 3D against clipping volume Easy for line segments polygons Hard for curves and text Convert to lines and polygons first25Clipping 2D Line SegmentsBrute force approach:compute intersections with all sides of clipping wi

    23、ndow Inefficient:one division per intersection26Cohen-Sutherland AlgorithmIdea:eliminate as many cases as possible without computing intersectionsStart with four lines that determine the sides of the clipping windowx=xmaxx=xminy=ymaxy=ymin27The Cases Case 1:both endpoints of line segment inside all

    24、four lines Draw(accept)line segment as is Case 2:both endpoints outside all lines and on same side of a line Discard(reject)the line segmentx=xmaxx=xminy=ymaxy=ymin28The CasesCase 3:One endpoint inside,one outside Must do at least one intersectionCase 4:Both outside May have part inside Must do at l

    25、east one intersectionx=xmaxx=xminy=ymax29Defining OutcodesFor each endpoint,define an outcodeOutcodes divide space into 9 regionsComputation of outcode requires at most 4 subtractions(8 times for two endpoint)b0b1b2b3b0=1 if y ymax,0 otherwiseb1=1 if y xmax,0 otherwiseb3=1 if x xmin,0 otherwiseOutco

    26、des applicationCase I:o1,o2AB:o1=o2=030Outcodes applicationCase II:o1,o2CD:o1 0,o2=031Outcodes applicationCase III:o1,o2EF:o1&o2 032Outcodes applicationCase IV:o1,o2GH and IJ:o1&o2=0Compute the intersection points;Recompute the code of intersection points.3334The Cohen-Sutherland Line-Clipping Algor

    27、ithm(2)To perform trivial and reject tests,we extend the edges of the clip rectangle to divide the plane into nine regions,and encode each region a 4bit code.If both 4bit codes of the endpoint are zero,the line is Trivially Accepted If both endpoints lie in the outside halfplane of a particular edge

    28、,the line is Trivially rejected,and the l o g i c a l A N D o f t h e endpoints is not zero.35The Cohen-Sutherland Line-Clipping Algorithm(3)Compute the codes of both endpoints and check for trivial acceptance and rejection.If neither test is successful,find an endpoint that lies outside,and then te

    29、st the code to find the edge that is crossed and to determine the corresponding intersection point.Clip off the line segment from the outside endpoint to the intersection point by replacing the outside endpoint with the intersection point,and compute the code of this new endpoint to prepare for the

    30、next iteration.36EfficiencyIn many applications,the clipping window is small relative to the size of the entire data base Most line segments are outside one or more side of the window and can be eliminated based on their outcodesInefficiency when code has to be reexecuted for line segments that must

    31、 be shortened in more than one step37Cohen Sutherland in 3D Use 6bit outcodes When needed,clip line segment against planes38Parametric Lines and IntersectionsFor L1x=x0l1+t(x1l1 x0l1)y=y0l1+t(y1l1 y0l1)For L2x=x0l2+t(x1l2 x0l2)y=y0l2+t(y1l2 y0l2)The Intersection Point:x0l1+t1(x1l1 x0l1)=x0l2+t2(x1l2

    32、 x0l2)y0l1+t1(y1l1 y0l1)=y0l2+t2(y1l2 y0l2)39Clipping Lines Clipping Lines by Solving Simultaneous Equations Two sets of simultaneous equations of this parametric form can be solved for parameters tedge for the edge and tline for the line segment.The value of tedge and tline can be checked to see wh

    33、ether both lie in 0,1;if they do,the intersection point is a true cliprectangle intersection.Shortcoming:considerable calculation and testing40A Parametric Line-Clipping Algorithm(1)Liang-Barsky1.For each clip edge(to upright rectangle),we can easily calculate a value t corresponding to the intersec

    34、tion point between the edge and the line segment.2.We get four values of in t total.3.Intersections can be classified as PE or PL(How?)PE:Point Entering the clipping rectanglePL:Point Leaving the clipping rectangle41A Parametric Line-Clipping Algorithm(2)Liang-Barsky3.on the basis of the angle betwe

    35、en P0P1 and the normal of the edge.0)90,PE (Ni.D 0)4.Divide t into two groups(t0,t0”t1,t1”)according to its corresponding intersection belongs to PE or PL.5.We get t0=max(t0,t0”,0)t1=min(t1,t1”,1)If t0 tl)return nil;else return P(te)and P(tl)as true clip intersections;43AdvantagesCan accept/reject a

    36、s easily as with CohenSutherlandUsing values of a,we do not have to use algorithm recursively as with CSExtends to 3D44Clipping and NormalizationGeneral clipping in 3D requires intersection of line segments against arbitrary planeExample:oblique view45Plane-Line Intersections)()(121ppnppnao-0n)(1210-PPaPP46Normalized Formbefore normalizationafter normalizationNormalization is part of viewing(pre clipping)but after normalization,we clip against sides ofright parallelepipedTypical intersection calculation now requires onlya floating point subtraction,e.g.is x xmaxtop view

    展开阅读全文
    提示  163文库所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。
    关于本文
    本文标题:计算机图形学computergraphics课件14.pptx
    链接地址:https://www.163wenku.com/p-4927504.html

    Copyright@ 2017-2037 Www.163WenKu.Com  网站版权所有  |  资源地图   
    IPC备案号:蜀ICP备2021032737号  | 川公网安备 51099002000191号


    侵权投诉QQ:3464097650  资料上传QQ:3464097650
       


    【声明】本站为“文档C2C交易模式”,即用户上传的文档直接卖给(下载)用户,本站只是网络空间服务平台,本站所有原创文档下载所得归上传人所有,如您发现上传作品侵犯了您的版权,请立刻联系我们并提供证据,我们将在3个工作日内予以改正。

    163文库