您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 经营企划 > 第十三讲 Shading(II)
计算机图形学讲义-13Shading(II)Basedon[EA],Chapter6.姜明北京大学数学科学学院更新时间2020年1月30日星期四7时5分47秒计算机图形学讲义-13TheCompletePhongModelI1abdcd2(kdLd(ln)ksLs(rv))kaLaDistancetermAmbienttermDiffusetermSpeculartermYoucantryouttheLightingApplettoseetheeffectofPhongshading计算机图形学讲义-13VectorsUsedbythePhongLightingModelpisanarbitrarypointonasurface.nistheunitnormaltothesurfaceatp.lisaunitvectorinthedirectionofthelightsource.risaunitvectorinthedirectionofaperfectly(specular)reflectionvisaunitvectorinthedirectionoftheviewer.计算机图形学讲义-13Outline•ComputationofVectors•PolygonalShading•ApproximationofaSpherebyRecursiveSubdivision•LightSourcesinOpenGL•SpecificationofMaterialsinOpenGL•ShadingoftheSphereModel•GlobalRendering计算机图形学讲义-13ComputationofVectors•NormalVectors•AngleofReflection•UseoftheHalfwayVector•TransmittedLight计算机图形学讲义-13NormalVectors•Normalvectorsexistateverypointonsmoothsurfaces.,,0,fxffxyznfyfzImplicitformExplicitorparametricform(,),(,),(,),xxuvxxuvyyyyuvnuvzzuvzzuv计算机图形学讲义-130,aaxbyczdnbc0122010,,threenoncolinearpointsn=PPPPPPP•Theorderofthevectorsinthecrossproductdeterminestheorientationoftheplaneandhasaneffectonthelightingcalculation.•OpenGLrequirestheusertoprovidethenormalvectors.PlaneSpherecossin,,22coscos,coscos,or,sin,xuvxuyuvnuyuPnPvzuz计算机图形学讲义-13SpecificationoftheNormalinOpenGLInOpenGL,thecurrentnormalispartofthestateandisalteredthroughoneofthefunctions:glNormal3f(nx,ny,nz);glNormal3fv(pointer_to_normal_vector);Youhavetocalculatethenormalsyourself.•Anormalisdefinedbeforeasequenceofvertices(glVertex),thisnormalisassociatedwithallthevertices,andisusedforthelightingcomputationatallthevertices.ExceptionforGLUquadricsandBeziersurfaces.计算机图形学讲义-13AngleofReflection:r2221coscosAssume(1)12(2)(1),(2)2irirlnrlnnrrlnnrlnlnrlnrlnnlgreengreengreenbluebluerered2dlnnlllnnlnnlrlnnlnnllnnl计算机图形学讲义-13UseoftheHalfwayVectorforthemodifiedPhoneModel•Toavoidthecomputationofr·vateverypoint,wecanusethehalfwayvectorh.•Ifwereplacer·vwithn·h,weavoidcomputationofr.•Thehalfwayangleisusuallysmallerthanthatinthecoplanarcase.Thesizeofthespecularhighlightswillbesmaller.•Thiscanbemitigatedbyusinganothershininesscoefficient.whenallthevectorsarecoplanar2lvhlv计算机图形学讲义-1311•Replace(v·r)by(n·h).•ischosentomatchshineness.•ResultingmodelisknownasthemodifiedPhongorBlinnlightingmodel.•SpecifiedinOpenGLstandard.计算机图形学讲义-1312ExampleOnlydifferencesintheseteapotsaretheparametersinthemodifiedPhongmodel计算机图形学讲义-13TransmittedLight•Snell’sLaw,:indicesofrefractionsinsinltlltt计算机图形学讲义-13LNRitiTzyxSwcosNcosN1xNySLSNLNLysin,sincos,coscossinsin,ctgcosxT-xN(yz)ScosNNLycos1cosNsinNLsinsincosNttiitiiitiitittiiittxxwxwxwyyxwywxyzywyzycosNLcoscosNLiiriiittt计算机图形学讲义-13PolygonalShading•FlatShading•GouraudShading•PhongShading计算机图形学讲义-13FlatShading•Eachpointonthepolygonisassignedthesameshade.•Smalldifferencesinshadingbetweenadjacentpolygonsarevisible.•FlatshadingexaggeratesthevisualeffectoftheboundariesbetweenpolygonsduetotheMachbandeffect,evenforsmoothsurfaces.glShadeModel(GL_FLAT);OpenGLusesthenormalassociatedwiththefirstvertexofasinglepolygonfortheshadingcalculation.Refertothemanualformoredetails.计算机图形学讲义-13MachBands•Weperceivetheincreasesinbrightnessasovershootingononesideofanintensitystepandundershootingontheother.计算机图形学讲义-13InterpolativeandGouraudShadingGouraudShading:Normalatavertexisthenormalizedaverageofthenormalsofthepolygonsthatsharethatvertex.43214321nnnnnnnnn计算机图形学讲义-13FlatvsGourandShading计算机图形学讲义-13PhongShading•EvenGourandshadingmaynotpreventtheappearanceofMachbands.•Normalsareinterpolatedacrosseachpolygon.Itisalmostalwaysdoneoffline.•Thischangestheorientationofsurfaces,makessurfaceslookcurved,andreducesMachbands.DCBACnnnnnn)1(),()1()(()(1)(,)(1)CABCDnnnnnn-RecenthardwarecancarryoutPhongshadinginrealtime.计算机图形学讲义-13ApproximationofaSpherebyRecursiveSubdivision0123123acb计算机图形学讲义-13LightSourcesinOpenGLglLightf(source,pname,parameter);glLightfv(source,pname,parameter);sourceisoneofatleasteightlights:GL_LIGHTiParametername:GL_AMBIENTcontainsfourvaluesthatspecifytheambientRGBAintensityofthelight.Defaultis(0.0,0.0,0.0,1.0).GL_DIFFUSEcontainsfourvaluesthatspecifythediffuseRGBAintensityofthelight.Defaultis(1.0,1.0,1.0,1.0).GL_SPECULARcontainsfourvaluesthatspecifythesecularRGBAintensityofthelight.Defaultis(1.0,1.0,1.0,1.0).计算机图形学讲义-13GL_POSITIONspecifiesthepositionofthelightinhomogeneousobjectcoordinates.Ifthewcomponentiszero,thelightistreatedasadirectionalsource.GL_SPOT_DIRECTIONspecifiesthedirectionofthelightinhomogeneousobjectcoordinates.Defaultis(0.0,0.0,-1.0)GL_SPOT_EXPONENTspotlightexponent,default0.0GL_SPOT_CUTOFFspotcutoffanglein[0,90]or180.GL_CONSTANT_ATTENUATIONconstantatten.factor,default1.0GL_LINE
本文标题:第十三讲 Shading(II)
链接地址:https://www.777doc.com/doc-3396681 .html