版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
FromVerticestoFragmentsSoftwareCollege,ShandongUniversityInstructor:ZhouYuanfengE-mail:yuanfeng.zhou@ReviewShadinginOpenGL;Lights&Material;Fromvertextofragment:Cohen-Sutherland2ProjectionFragmentsClippingShadingBlackboxSurfacehiddenTextureTransparency3ObjectivesGeometricProcessing:Cyrus-BeckclippingalgorithmLiang-BarskyclippingalgorithmIntroduceclippingalgorithmforpolygonsRasterization:DDA&BresenhamCohen-SutherlandIncaseIV:o1&o2=0Intersection:ClippingLinesbySolvingSimultaneousEquations4SolvingSimultaneousEquationsEquationofaline:Slope-intercept:y=mx+hdifficultforverticallineImplicitEquation:Ax+By+C=0Parametric:Linedefinedbytwopoints,P0andP1P(t)=P0+(P1-P0)tx(t)=x0+(x1-x0)ty(t)=x0+(y1-y0)t6ParametricLinesandIntersectionsForL1:x=x0l1+t(x1l1–x0l1)y=y0l1+t(y1l1–y0l1)ForL2:x=x0l2+t(x1l2–x0l2)y=y0l2+t(y1l2–y0l2)TheIntersectionPoint:x0l1+t1(x1l1–x0l1)
=x0l2+t2(x1l2–x0l2)y0l1+t1
(y1l1–y0l1)
=y0l2+t2(y1l2–y0l2)Cyrus-Beckalgorithm(1978)forpolygonsMikeCyrus,JayBeck."Generalizedtwo-andthree-dimensionalclipping".Computers&Graphics,1978:23-28.GivenaconvexpolygonR:7Cyrus-BeckAlgorithmP1P2ANRparatsparate0≤t≤1,then
isinsideofR;,then
isonRorextension;,then
isoutsideofR.HowtogettsandteCyrus-BeckAlgorithmIntersection:NL
●(P(t)–A)=0SubstitutelineequationforP(t)P(t)=P0+t(P1-P0)Solvefortt=NL
●(P0–A)/-NL
●
(P1-P0)ANLP(t)InsideOutsideP0P1Cyrus-BeckAlgorithmComputetforlineintersectionwithalledges;Discardall(t<0)and(t>1);ClassifyeachremainingintersectionasPotentiallyEnteringPoint(PE)PotentiallyLeavingPoint(PL)(How?)NL●(P1-P0)<0impliesPLNL●(P1-P0)>0impliesPENotethatwecomputedthisterminwhencomputingtCyrus-BeckAlgorithmForeachedge:10L1L2L3L4L5P0P1t1t2t5t3t4paratsparateComputePEwithlargesttComputePLwithsmallesttCliptothesetwopointsCyrus-BeckAlgorithmWhen;thenifif11ThenP0P1isinvisible;Thengotonextedge;Programming:12for(k
edgesofclippingpolygon){solveNi·(p1-p0);
solveNi·(p0-Ai);if(
Ni·(p1-p0)
==0)//parallelwiththeedge{
if(Ni·(p0-Ai)<0)break;//invisibleelsegotonextedge;
}else//Ni·(p1-p0)!=0{
solveti;if(Ni·(p1-p0)<0)else}}Output:if(ts>te)returnnil;elsereturnP(ts)andP(te)asthetrueclipintersections;Input:If(P0=P1)Lineisdegeneratesoclipasapoint;Liang-BarskyAlgorithm(1984)13TheONLYalgorithmnamedforChinesepeopleinComputerGraphicscoursebooksLiang,Y.D.,andBarsky,B.,"ANewConceptandMethodforLineClipping",
ACMTransactionsonGraphics,3(1):1-22,January1984.Becauseofhorizontalandverticalcliplines:ManycomputationsreduceNormalsPickconstantpointsonedgessolutionfort:tL=-(x0-xleft)/(x1-x0)tR=(x0-xright)/-(x1-x0)tB=-(y0-ybottom)/(y1-y0)tT=(y0-ytop)/-(y1-y0)Liang-BarskyAlgorithm(1984)PEPLP1PLPEP0(-1,0)(1,0)(0,-1)(0,1)15EdgeInnernormalAP1-ALeftx=XL(1,0)(XL,y)(x1-XL,y1-y)Rightx=XR(-1,0)(XR,y)(x1-XR,y1-y)Bottomy=YB(0,1)(x,YB)(x1-x,y1-YB)Topy=YT(0,-1)(x,YT)(x1-x,y1-YT)Liang-BarskyAlgorithm(1984)Whenrk<0,tkisenteringpoint;whenrk>0,tkisleavingpoint.Ifrk=0andsk<0,thenthelineisinvisible;elseprocessotheredges16Liang-BarskyAlgorithm(1984)Let∆x=x2-x1,∆y=y2-y1:ComparisonCohen-Sutherland:RepeatedclippingisexpensiveBestusedwhentrivialacceptanceandrejectionispossibleformostlinesCyrus-Beck:Computationoft-intersectionsischeapComputationof(x,y)clippointsisonlydoneonceAlgorithmdoesn’tconsidertrivialaccepts/rejectsBestwhenmanylinesmustbeclippedLiang-Barsky:OptimizedCyrus-BeckNicholletal.:Fastest,butdoesn’tdo3D18ClippingasaBlackBoxCanconsiderlinesegmentclippingasaprocessthattakesintwoverticesandproduceseithernoverticesortheverticesofaclippedlinesegment19PipelineClippingofLineSegmentsClippingagainsteachsideofwindowisindependentofothersidesCanusefourindependentclippersinapipeline20ClippingandNormalizationGeneralclippingin3DrequiresintersectionoflinesegmentsagainstarbitraryplaneExample:obliqueview21Plane-LineIntersectionsPoint-to-PlaneTestDotproductisrelativelyexpensive3multiplies5additions1comparison(to0,inthiscase)Thinkabouthowyoumightoptimizeorspecial-casethis?23NormalizedFormbeforenormalizationafternormalizationNormalizationispartofviewing(preclipping)butafternormalization,weclipagainstsidesofrightparallelepipedTypicalintersectioncalculationnowrequiresonlyafloatingpointsubtraction,e.g.isx>xmaxtopviewClippingPolygonsClippingpolygonsismorecomplexthanclippingtheindividuallinesInput:polygonOutput:polygon,ornothing25PolygonClippingNotassimpleaslinesegmentclippingClippingalinesegmentyieldsatmostonelinesegmentClippingapolygoncanyieldmultiplepolygonsHowever,clippingaconvexpolygoncanyieldatmostoneotherpolygon26TessellationandConvexityOnestrategyistoreplacenonconvex(concave)polygonswithasetoftriangularpolygons(atessellation)Alsomakesfilleasier(wewillstudylater)TessellationcodeinGLUlibrary,thebestisConstrainedDelaunayTriangulation27PipelineClippingofPolygonsThreedimensions:addfrontandbackclippersStrategyusedinSGIGeometryEngineSmallincreaseinlatencySutherland-HodgmanClippingIvanSutherland,GaryW.Hodgman:ReentrantPolygonClipping.CommunicationsoftheACM,vol.17,pp.32-42,1974Basicidea:ConsidereachedgeoftheviewportindividuallyClipthepolygonagainsttheedgeequationSutherland-HodgmanClippingBasicidea:ConsidereachedgeoftheviewportindividuallyClipthepolygonagainsttheedgeequationAfterdoingallplanes,thepolygonisfullyclippedSutherland-HodgmanClippingBasicidea:ConsidereachedgeoftheviewportindividuallyClipthepolygonagainsttheedgeequationAfterdoingallplanes,thepolygonisfullyclippedSutherland-HodgmanClippingBasicidea:ConsidereachedgeoftheviewportindividuallyClipthepolygonagainsttheedgeequationAfterdoingallplanes,thepolygonisfullyclippedSutherland-HodgmanClippingBasicidea:ConsidereachedgeoftheviewportindividuallyClipthepolygonagainsttheedgeequationAfterdoingallplanes,thepolygonisfullyclippedSutherland-HodgmanClippingBasicidea:ConsidereachedgeoftheviewportindividuallyClipthepolygonagainsttheedgeequationAfterdoingallplanes,thepolygonisfullyclippedSutherland-HodgmanClippingBasicidea:ConsidereachedgeoftheviewportindividuallyClipthepolygonagainsttheedgeequationAfterdoingallplanes,thepolygonisfullyclippedSutherland-HodgmanClippingBasicidea:ConsidereachedgeoftheviewportindividuallyClipthepolygonagainsttheedgeequationAfterdoingallplanes,thepolygonisfullyclippedSutherland-HodgmanClippingBasicidea:ConsidereachedgeoftheviewportindividuallyClipthepolygonagainsttheedgeequationAfterdoingallplanes,thepolygonisfullyclippedSutherland-HodgmanClippingBasicidea:ConsidereachedgeoftheviewportindividuallyClipthepolygonagainsttheedgeequationAfterdoingallplanes,thepolygonisfullyclippedWillthisworkfornon-rectangularclipregions?Whatwould3-D
clippinginvolve?Sutherland-HodgmanClippingInput/outputforalgorithm:Input:listofpolygonverticesinorderOutput:listofclippedpoygonverticesconsistingofoldvertices(maybe)andnewvertices(maybe)Note:thisisexactlywhatweexpectfromtheclippingoperationagainsteachedgeSutherland-HodgmanClippingSutherland-Hodgmanbasicroutine:GoaroundpolygononevertexatatimeCurrentvertexhaspositionp
Previousvertexhadpositions,andithasbeenaddedtotheoutputifappropriateSutherland-HodgmanClippingEdgefromstop
takesoneoffourcases:(Graylinecanbealineoraplane)insideoutsidesppoutputinsideoutsidespnooutputinsideoutsidespioutputinsideoutsidespioutput
poutputSutherland-HodgmanClippingFourcases:sinsideplaneandpinsideplaneAddptooutputNote:shasalreadybeenaddedsinsideplaneandpoutsideplaneFindintersectionpointiAdditooutputsoutsideplaneandp
outsideplaneAddnothings
outsideplaneandpinsideplaneFindintersectionpointiAdditooutput,followedbypSutherland-HodgmanClipping42Point-to-PlanetestAverygeneraltesttodetermineifapointpis“inside”aplaneP,definedbyqandn: (p-q)•n<0: pinsideP (p-q)•n=0: ponP (p-q)•n>0: poutsidePPnpqPnpqPnpq44BoundingBoxesRatherthandoingclippingonacomplexpolygon,wecanuseanaxis-alignedboundingboxorextentSmallestrectanglealignedwithaxesthatenclosesthepolygonSimpletocompute:maxandminofxandy45BoundingBoxesCanusuallydetermineaccept/rejectbasedonlyonboundingboxrejectacceptrequiresdetailedclippingEllipsoidcollisiondetection46RasterizationRasterization(scanconversion)DeterminewhichpixelsthatareinsideprimitivespecifiedbyasetofverticesProducesasetoffragmentsFragmentshavealocation(pixellocation)andotherattributessuchcolor,depthandtexturecoordinatesthataredeterminedbyinterpolatingvaluesatverticesPixelcolorsdeterminedlaterusingcolor,texture,andothervertexproperties.47ScanConversionofLineSegmentsStartwithlinesegmentinwindowcoordinateswithintegervaluesforendpointsAssumeimplementationhasawrite_pixelfunctiony=mx+hScanConversionofLineSegments48Onepixel49DDAAlgorithmDigitalDifferentialAnalyzer(1964)DDAwasamechanicaldevicefornumericalsolutionofdifferentialequationsLiney=mx+hsatisfiesdifferentialequationdy/dx=m=Dy/Dx=y2-y1/x2-x1AlongscanlineDx=1For(x=x1;x<=x2,x++){y+=m;//note:misfloatnumberwrite_pixel(x,round(y),line_color);}50ProblemDDA=foreachxplotpixelatclosestyProblemsforsteeplines51UsingSymmetryUsefor1
m
0Form>1,swaproleofxandyForeachy,plotclosestx52Bresenham’sAlgorithmDDArequiresonefloatingpointadditionperstepWecaneliminateallfpthroughBresenham’salgorithmConsideronly1
m
0OthercasesbysymmetryAssumepixelcentersareathalfintegers(OpenGLhasthisdefinition)
Bresenham,J.E.(1January1965)."Algorithmforcomputercontrolofadigitalplotter".IBMSystemsJournal4(1):25–30.Bresenham’sAlgorithmObserving:Ifwestartatapixelthathasbeenwritten,thereareonlytwocandidatesforthenextpixeltobewrittenintotheframebuffer5354CandidatePixels1
m
0lastpixelcandidatesNotethatlinecouldhavepassedthroughanypartofthispixel55DecisionVariable-d=△x(a-b)disanintegerd<0useupperpixeld>0uselowerpixelHowtocomputeaandb?b-a=(yi+1–yi,r)-(yi,r+1-yi+1)=2yi+1–yi,r–(yi,r+1)=2yi+1–2yi,r–1ε(xi+1)=yi+1–yi,r–0.5=BC-AC=BA=B-A=yi+1–(yi,r+yi,r+1)/2ABCIncrementalForm56ifε(xi+1)≥0,yi+1,r=yi,r+1,pickpixelD,thenextpixelis(
xi+1,yi,r+1)yi,ryi,r+1ABxixi+1DCd1d2yi,ryi,r+1Axixi+1DCd1d2ifε(xi+1)<0,yi+1,r=yi,r,pickpixelC,thenextpixelis(
xi+1,yi,r)Improvementanew=alast–manew=alast–(m-1)bnew=blast+mbnew=blast+(m-1)57----d=△x(a-b)Improvement58Moreefficientifwelookatdk,thevalueofthedecisionvariableatx=kdk+1=dk–2△y,ifdk>0dk+1=dk–2(△y-△x),otherwiseForeachx,weneeddoonlyanintegeradditionandatestSingleinstructionongraphicschipsmultiply2issimple.59BSPdisplayTypeTreeTree*front;Faceface;Tree*back;EndAlgorithmDrawBSP(TreeT;point:w)//w为视点IfTisnullthenreturn;endifIfwisinfrontofT.facethenDrawBSP(T.back,w);Draw(T.face,w);DrawBSP(T.front,w);Else//wisbehindoronT.faceDrawBSP(T.front,w);Draw(T.face,w);DrawBSP(T.back,w);Endifend60HiddenSurfaceRemovalObject-spaceapproach:usepairwisetestingbetweenpolygons(objects)WorstcasecomplexityO(n2)fornpolygonspartiallyobscuringcandrawindependently61ImageSpaceApproachLookateachprojector(nmforann
x
mframebuffer)andfindclosestofkpolygonsComplexityO(nmk)Raytracingz-buffer62Painter’sAlgorithmRenderpolygonsabacktofrontordersothatpolygonsbehindothersaresimplypaintedoverBbehindAasseenbyviewerFillBthenA63DepthSortRequiresorderingofpolygonsfirstO(nlogn)calculationfororderingNoteverypolygoniseitherinfrontorbehindallotherpolygonsOrderpolygonsanddealwitheasycasesfirst,harderlaterPolygonssortedbydistancefromCOP64EasyCases(1)AliesbehindallotherpolygonsCanrender(2)PolygonsoverlapinzbutnotineitherxoryCanrenderindependently65HardCases(3)Overlapinalldirectionsbutcanoneisfullyononesideoftheothercyclicoverlappenetration(4)66Back-FaceRemoval(Culling)
faceisvisibleiff90
-90equivalentlycos
0or
v
•n
0planeoffacehasformax+by+cz+d=0butafternormalization
n=(0010)T
needonlytestthesignofcInOpenGLwecansimplyenablecullingbutmaynotworkcorrectlyifwehavenonconvexobjects67z-BufferAlgorithmUseabuffercalledthezordepthbuffertostorethedepthoftheclosestobjectateachpixelfoundsofarAswerendereachpolygon,comparethedepthofeachpixeltodepthinzbufferIfless,placeshadeofpixelincolorbufferandupdatezbuffer68EfficiencyIfweworkscanlinebyscanlineaswemoveacrossascanline,thedepthchangessatisfya
x+b
y+c
z=0Alongscanline
y=0
z=-
xInscreenspace
x=1
69Scan-LineAlgorithmCancombineshadingandhsrthroughscanlinealgorithmscanlinei:noneedfordepthinformation,canonlybeinnooronepolygonscanlinej:needdepthinformationonlywheninmorethanonepolygon70ImplementationNeedadatastructuretostoreFlagforeachpolygon(inside/outside)IncrementalstructureforscanlinesthatstoreswhichedgesareencounteredParametersforplanes71VisibilityTestingInmanyrealtimeapplications,suchasgames,wewanttoeliminateasmanyobjectsaspossiblewithintheapplicationReduceburdenonpipelineReducetrafficonbusPartitionspacewithBinarySpatialPartition(BSP)Tree72SimpleExampleconsider6parallelpolygonstopviewTheplaneofAseparatesBandCfromD,EandF73BSPTreeCancontinuerecursivelyPlaneofCseparatesBfromAPlaneofDseparatesEandFCanputthisinformationinaBSPtreeUseforvisibilityandocclusiontesting74PolygonScanConversionScanConversion=FillHowtotellinsidefromoutsideConvexeasyNonsimpledifficultOddeventestCountedgecrossingsWindingnumberodd-evenfill75Wind
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 绝缘套管制造工QC管理测试考核试卷含答案
- 2026年水产加工合同(1篇)
- 乳品配料工岗前理论知识考核试卷含答案
- 2026年饲料购买合同(1篇)
- 飞机结构胶接装配工安全管理能力考核试卷含答案
- 应用安全检查评估办法
- 博物馆项目绿色施工专项方案
- 【完整版】水库除险加固工程监理大纲
- 管廊热力管道安装施工工艺流程
- 车险行业晋升方案
- 2026年西医医师定期考核练习题库附答案详解(精练)
- 2026届山西省吕梁市高三下学期第三次模拟考试历史试题(含答案)
- 2026安徽宣城市国有资本投资运营控股集团有限公司社会招聘13人备考题库含答案详解
- 2026年事业单位结构化面试真题及答案解析
- 20KV及以下配电网工程建设预算编制与计算规定
- 肺结核病人健康指导宣传手册
- 叶酸车间的工艺流程及危险源控制
- 社会保险业务申报表(申报1表)
- GA 1205-2014灭火毯
- 《大学生劳动教育》第四章 创造性劳动
- 新教材人教版高中化学选择性必修1全册各章节知识点考点重点难点归纳总结汇总
评论
0/150
提交评论