计算机图形学computer graphics课件18_第1页
计算机图形学computer graphics课件18_第2页
计算机图形学computer graphics课件18_第3页
计算机图形学computer graphics课件18_第4页
计算机图形学computer graphics课件18_第5页
已阅读5页,还剩54页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

TextureMappingSoftwareCollege,ShandongUniversityInstructor:ZhouYuanfengE-mail:yuanfeng.zhou@23ObjectivesIntroduceMappingMethodsTextureMappingEnvironmentMappingBumpMappingConsiderbasicstrategiesForwardvsbackwardmappingPointsamplingvsareaaveraging4TheLimitsofGeometricModelingAlthoughgraphicscardscanrenderover10millionpolygonspersecond,thatnumberisinsufficientformanyphenomenaCloudsGrassTerrainSkin,hairWaterandfire5ModelinganOrangeConsidertheproblemofmodelinganorange(thefruit)Startwithanorange-coloredsphereToosimpleReplacespherewithamorecomplexshapeDoesnotcapturesurfacecharacteristics(smalldimples)Takestoomanypolygonstomodelallthedimples6ModelinganOrange(2)Takeapictureofarealorange,scanit,and“paste”ontosimplegeometricmodelThisprocessisknownastexturemappingStillmightnotbesufficientbecauseresultingsurfacewillbesmoothNeedtochangelocalshapeBumpmapping+7ThreeTypesofMappingTextureMappingUsesimagestofillinsideofpolygonsEnvironment(reflectionmapping)UsesapictureoftheenvironmentfortexturemapsAllowssimulationofhighlyspecularsurfacesBumpmappingEmulatesalteringnormalvectorsduringtherenderingprocess8TextureMappinggeometricmodeltexturemapped9EnvironmentMapping10BumpMapping+=originalsurfacebumpmapmodifiedsurface11Wheredoesmappingtakeplace?MappingtechniquesareimplementedattheendoftherenderingpipelineVeryefficientbecausefewpolygonsmakeitpasttheclipper12Isitsimple?Althoughtheideaissimple---mapanimagetoasurface---thereare3or4coordinatesystemsinvolved2Dimage3Dsurface13CoordinateSystemsParametriccoordinatesMaybeusedtomodelcurvesandsurfacesTexturecoordinatesUsedtoidentifypointsintheimagetobemappedObjectorWorldCoordinatesConceptually,wherethemappingtakesplaceWindowCoordinatesWherethefinalimageisreallyproduced14TextureMappingparametriccoordinatestexturecoordinatesworldcoordinateswindowcoordinates15MappingFunctionsBasicproblemishowtofindthemapsConsidermappingfromtexturecoordinatestoapointasurfaceAppeartoneedthreefunctionsx=x(s,t)y=y(s,t)z=z(s,t)Butwereallywanttogotheotherwayst(x,y,z)16BackwardMappingWereallywanttogobackwardsGivenapixel,wewanttoknowtowhichpointonanobjectitcorrespondsGivenapointonanobject,wewanttoknowtowhichpointinthetextureitcorrespondsNeedamapoftheforms=s(x,y,z)t=t(x,y,z)Suchfunctionsaredifficulttofindingeneral

Parameterization1718Two-partmappingOnesolutiontothemappingproblemistofirstmapthetexturetoasimpleintermediatesurfaceExample:maptocylinder19CylindricalMappingparametriccylinderx=rcos(2piu)y=rsin(2piu)z=v/hmapsrectangleinu,vspacetocylinderofradiusrandheighthinworldcoordinatess=ut=vmapsfromtexturespaceCylindricalMapping20Mapping:

zz(a)texture(b)cylindricalxyrh(c)mappingxy(d)ba(c)11CylindricalMapping21Mapuandvtopointsa,b,c,d:(1)

:(2):(3):(4):Solving:Fromtexturetocylindricalparameters:Fromcylindricalparameterstotexture:22SphericalMappingWecanuseaparametricspherex=rcos2piuy=rsin2pucos2pivz=rsin2pusin2pivinasimilarmannertothecylinderbuthavetodecidewheretoputthedistortionSpheresareusedinenvironmentalmaps23BoxMappingEasytousewithsimpleorthographicprojectionAlsousedinenvironmentmapsPolycubemapping24ConformalmappingInmathematics,aconformalmapisafunctionwhichpreservesangles.2526SecondMappingMapfromintermediateobjecttoactualobjectNormalsfromintermediatetoactualNormalsfromactualtointermediateVectorsfromcenterofintermediate

intermediateactual27AliasingPointsamplingofthetexturecanleadtoaliasingerrorspointsamplesinu,v(orx,y,z)spacepointsamplesintexturespacemissbluestripes28AreaAveragingAbetterbutsloweroptionistouseareaaveragingNotethatpreimageofpixeliscurvedpixelpreimageCatmulltexturemappingSurfacesubdivision29PixeledSScreenSurfaceContinuousmapping30

(a)SphericalMapping(b)CylindricalMappingMip-map(1983,LanceWilliams)31Mip-mapActuallymip-mapisalookuptablefortexture32OpenGLTextureMapping34BasicStrategyThreestepstoapplyingatexturespecifythetexturereadorgenerateimageassigntotextureenabletexturingassigntexturecoordinatestoverticesPropermappingfunctionislefttoapplicationspecifytextureparameterswrapping,filtering35TextureMappingstxyzimagegeometrydisplay36TextureExampleThetexture(below)isa256x256imagethathasbeenmappedtoarectangularpolygonwhichisviewedinperspective37TextureMappingandtheOpenGLPipelinegeometrypipelineverticespixelpipelineimagerasterizerImagesandgeometryflowthroughseparatepipelinesthatjoinattherasterizer“complex”texturesdonotaffectgeometriccomplexity38Defineatextureimagefromanarrayof

texels(textureelements)inCPUmemory

Glubytemy_texels[512][512];DefineasanyotherpixelmapScannedimageGeneratebyapplicationcodeEnabletexturemappingglEnable(GL_TEXTURE_2D)OpenGLsupports1-4dimensionaltexturemapsSpecifyingaTextureImage1Dtexturemapping391Dtexturemappingunsignedcharcolorbar[1024];glTexImage1D(GL_TEXTURE_1D,0,GL_RGBA,256,0,GL_BGRA_EXT,GL_UNSIGNED_BYTE,colorbar);glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_WRAP_S,GL_CLAMP);Texturecoord:[0,1]4041DefineImageasaTextureglTexImage2D(target,level,components,

w,h,border,format,type,texels);

target:typeoftexture,e.g.GL_TEXTURE_2D level:usedformipmapping(discussedlater) components:elementspertexel w,h:widthandheightoftexelsinpixels border:usedforsmoothing(discussedlater) formatandtype:describetexels texels:pointertotexelarrayglTexImage2D(GL_TEXTURE_2D,0,3,512,512,0,GL_RGB,GL_UNSIGNED_BYTE,my_texels);42ConvertingATextureImageOpenGLrequirestexturedimensionstobepowersof2Ifdimensionsofimagearenotpowersof2gluScaleImage(format,w_in,h_in,

type_in,*data_in,w_out,h_out,

type_out,*data_out);data_in

issourceimagedata_out

isfordestinationimageImageinterpolatedandfilteredduringscaling43BasedonparametrictexturecoordinatesglTexCoord*()specifiedateachvertexst1,10,10,01,0(s,t)=(0.2,0.8)(0.4,0.2)(0.8,0.4)ABCabcTextureSpaceObjectSpaceMappingaTexture44TypicalCodeglBegin(GL_POLYGON); glColor3f(r0,g0,b0);//ifnoshadingused glNormal3f(u0,v0,w0);//ifshadingused glTexCoord2f(s0,t0); glVertex3f(x0,y0,z0); glColor3f(r1,g1,b1); glNormal3f(u1,v1,w1); glTexCoord2f(s1,t1); glVertex3f(x1,y1,z1); . .glEnd();Notethatwecanusevertexarraystoincreaseefficiency45InterpolationOpenGLusesinterpolationtofindpropertexelsfromspecifiedtexturecoordinatesCanbedistortionsgoodselectionoftexcoordinatespoorselectionoftexcoordinatestexturestretchedovertrapezoidshowingeffectsofbilinearinterpolation46TextureParametersOpenGLhasavarietyofparametersthatdeterminehowtextureisappliedWrappingparametersdeterminewhathappensifsandtareoutsidethe(0,1)rangeFiltermodesallowustouseareaaveraginginsteadofpointsamplesMipmappingallowsustousetexturesatmultipleresolutionsEnvironmentparametersdeterminehowtexturemappinginteractswithshading47WrappingModeClamping:ifs,t>1use1,ifs,t<0use0Repeating:uses,tmodulo1glTexParameteri(GL_TEXTURE_2D,

GL_TEXTURE_WRAP_S,GL_CLAMP)glTexParameteri(GL_TEXTURE_2D,

GL_TEXTURE_WRAP_T,GL_REPEAT)texturestGL_CLAMPwrappingGL_REPEATwrapping48MagnificationandMinificationTexturePolygonMagnificationMinificationPolygonTextureMorethanonetexelcancoverapixel(minification)ormorethanonepixelcancoveratexel(magnification)Canusepointsampling(nearesttexel)orlinearfiltering(2x2filter)toobtaintexturevalues49FilterModesModesdeterminedbyglTexParameteri(target,type,mode)

glTexParameteri(GL_TEXTURE_2D,GL_TEXURE_MAG_FILTER,GL_NEAREST);glTexParameteri(GL_TEXTURE_2D,GL_TEXURE_MIN_FILTER,GL_LINEAR);Notethatlinearfilteringrequiresaborderofanextratexelforfilteringatedges(border=1)50MipmappedTexturesMipmappingallowsforprefilteredtexturemapsofdecreasingresolutionsLessensinterpolationerrorsforsmallertexturedobjectsDeclaremipmaplevelduringtexturedefinitionglTexImage2D(GL_TEXTURE_*D,level,

…)GLUmipmapbuilderroutineswillbuildallthetexturesfromagivenimagegluBuild*DMipmaps(…)51Example

pointsamplingmipmappedpointsamplingmipmappedlinearfilteringlinearfiltering52TextureFunctionsControlshowtextureisappliedglTexEnv{fi}[v](

GL_TEXTURE_ENV,mode,param)

GL_TEXTURE_ENV_MODE

modesGL_MODULATE:modulateswithcomputedshade GL_BLEND:blendswithanenvironmentalcolor GL_REPLACE:useonlytexturecolorGL(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);Setblendcolorwith

GL_TEXTURE_ENV_COLORDemo53PerspectiveCorrectionHintTexturecoordinateandcolorinterpolationeitherlinearlyinscreenspaceorusingdepth/perspectivevalues(slower)Noticeableforpolygons“onedge”glHint(

GL_PERSPECTIVE_CORRECTION_HINT,hint

)wherehintisoneofGL_DONT_CAREGL_NICESTGL_FASTEST54GeneratingTextureCoordinatesOpenGLcangeneratetexturecoordinatesautomaticallyglTexGen{ifd}[v]()specifyaplanegeneratetexturecoordinatesbasedupondistancefromtheplanegenerationmodesGL_OBJECT_LINEARGL_EYE_LINEAR

GL_SPHERE_MAP(usedforenvironmentalmaps)LinearmappingTextureis“attached”toobject:GLfloatparams={A,B,C,D};glTexGenfv(GL_S,GL_OBJECT_PLANE,params);glTexGeni(

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论