Академический Документы
Профессиональный Документы
Культура Документы
Search
DeveloperSiteHomepage DeveloperNewsHomepage DeveloperLogin Becomea RegisteredDeveloper DeveloperTools Documentation DirectX OpenGL GPUComputing Handheld EventsCalendar NewsletterSignUp Drivers Jobs(1) Contact LegalInformation SiteFeedback
GPUGems3
GPUGems3is nowavailablefor freeonline! Pleasevisitour RecentDocuments pagetoseeallthe latestwhitepapers andconferencepresentationsthatcan helpyouwithyourprojects. Youcanalsosubscribetoour DeveloperNewsFeedtoget notificationsofnewmaterialonthe site.
Chapter25.Rendering VectorArtontheGPU
CharlesLoop MicrosoftResearch JimBlinn MicrosoftResearch
25.1Introduction
Vectorrepresentationsarea resolutionindependentmeansof specifyingshape.Theyhavethe advantagethatatanyscale,content canbedisplayedwithouttessellation orsamplingartifacts.Thisisinstark contrasttoarasterrepresentation consistingofanarrayofcolorvalues. Rasterimagesquicklyshowartifacts underscaleorperspectivemappings. Ourgoalinthischapteristopresenta methodforacceleratingtherendering ofvectorrepresentationsontheGPU. Moderngraphicsprocessingunits excelatrenderingtrianglesand triangularapproximationstosmooth objects.Itissomewhatsurprisingto realizethatthesamearchitectureis ideallysuitedtorenderingsmooth vectorbasedobjectsaswell.Avector objectcontainslayersofclosedpaths andcurves.Thesepathsandcurves aregenerallyquadraticandcubic Bziersplinecurves,emittedbya drawingprogram.Wepresent algorithmsforrenderingthesespline curvesdirectlyintermsoftheir mathematicaldescriptions,sothat theyareresolutionindependentand haveaminimalgeometric representation.
http.developer.nvidia.com/GPUGems3/gpugems3_ch25.html
1/20
1/12/12
Themainingredientofouralgorithm isthenotionofimplicitization:the transformationfromaparametric [x(t)y(t)]toimplicitf(x,y)=0plane curve.Werendertheconvexhullof theBziercontrolpointsaspolygons, andapixelshaderprogram determinespixelinclusionby evaluatingthecurve'simplicitform. Thisprocessbecomeshighlyefficient byleveragingGPUinterpolation functionalityandchoosingjustthe rightimplicitform.Inadditionto resolvingin/outqueriesatpixels,we demonstrateamechanismfor performingantialiasingonthese curvesusinghardwaregradients. Muchofthisworkoriginallyappeared inLoopandBlinn2005.
25.2QuadraticSplines
Thebestwaytounderstandour algorithmistoshowhowitworkswith asimpleexample.Considertheletter "e"showninFigure251.Figure251a showstheTrueTypedatausedto describethisfontglyph.TrueType usesacombinationofquadraticB splinesandlinesegmentstospecify anorientedvectoroutline.Theregion ontheright0handsideofthecurveis consideredinsidebyconvention.The hollowdotsareBsplinecontrolpoints thatdefinecurvesthesoliddotsare pointsonthecurvethatcandefine discontinuitiessuchassharpcorners. Asapreprocess,weconverttheB splinerepresentationtoBzierform byinsertingnewpointsatthe midpointofadjacentBsplinecontrol points.EachBsplinecontrolpointwill correspondtoaquadraticBzier curve.Next,wetriangulatethe interioroftheclosedpathandforma triangleforeachquadraticBzier curve.Aftertriangulation,wewill haveinteriortriangles(shownin green)andboundarytrianglesthat containcurves(showninredand blue),asyoucanseeinFigure251b.
http.developer.nvidia.com/GPUGems3/gpugems3_ch25.html
2/20
1/12/12
Weuseashaderprogramto determineifpixelsareontheinside oroutsideofaclosedregion.Before gettingtothisshader,wemustassign [uv]coordinatestotheverticesofthe trianglesthatcontaincurves.An exampleisshowninFigure252. Whenthesetrianglesarerendered underanarbitrary3Dprojective transform,theGPUwillperform perspectivecorrectinterpolationof thesecoordinatesandprovidethe resulting[uv]valuestoapixelshader program.Insteadoflookingupa colorvalueasintexturemapping,we usethe[uv]coordinatetoevaluatea proceduraltexture.Thepixelshader computestheexpression u2v,
Figure252ProceduralTexture CoordinateAssignment usingthesignoftheresultto determinepixelinclusion.Forconvex curves,apositiveresultmeansthe pixelisoutsidethecurveotherwiseit isinside.Forconcavecurves,thistest isreversed. Thesizeoftheresulting representationisproportionaltothe sizeoftheboundarycurve description.Theresultingimageis freeofanyartifactscausedby tessellationorundersamplingbecause allthepixelcentersthatlieunderthe curvedregionarecoloredandno more. Theintuitionbehindwhythis algorithmworksisasfollows.The proceduraltexturecoordinates[00], [0],and[11](asshowninFigure 252)arethemselvesBziercontrol pointsofthecurve u(t)=t, v(t)=t2. Thisisclearlyaparameterizationfor thealgebraic(implicit)curveu2v= 0.SupposePisthecomposite transformfromu,vspacetocurve
http.developer.nvidia.com/GPUGems3/gpugems3_ch25.html
3/20
1/12/12
design(glyph)spacetoviewingand perspectivespacetoscreenspace. Ultimatelythiswillbeaprojective mappingfrom2Donto2D.Any quadraticcurvesegmentprojectedto screenspacewillhavesuchaP. WhentheGPUinterpolatesthetexture coordinates,itisineffectcomputing thevalueofP 1foreachpixel. Therefore,wecanresolvethe inside/outsidetestinu,vspacewhere theimplicitequationissimple, needingonlyonemultiplyandone add. Asanalternative,wecouldfindthe algebraicequationofeachcurve segmentinscreenspace.However, thiswouldrequiredozensof arithmeticoperationstocomputethe generalsecondorderalgebraiccurve coefficientsandrequiremany operationstoevaluateinthe correspondingpixelshader. Furthermore,thecoefficientsofthis curvewillchangeastheviewing transformchanges,requiring recomputation.Ourapproachrequires nosuchperframeprocessing,other thantheinterpolationof[uv] proceduraltexturecoordinatesdone bytheGPU. Quadraticcurvesturnouttobeavery simplespecialcase.Assignmentof theproceduraltexturecoordinatesis thesameforall(integral)quadratic curves,andtheshaderequationis simpleandcompact.However, drawingpackagesthatproducevector artworkoftenusemoreflexibleand smoothcubicsplines.Next,weextend ourrenderingalgorithmtohandle cubiccurves.Thegoodnewsisthat theruntimeshaderequationisalso simpleandcompact.Thebadnewsis thatthepreprocessingassignmentof proceduraltexturecoordinatesis nontrivial.
25.3CubicSplines
Ouralgorithmforrenderingcubic splinecurvesissimilarinspirittothe oneforrenderingquadraticcurves. Anorientedclosedpathisdefinedby cubicBziercurvesegments,each consistingoffourcontrolpoints.See Figure253a.Weassumetheright handsideofthecurvetobe consideredinside.Theconvexhullof thesecontrolpointsformseithera quadrilateralconsistingoftwo triangles,orasingletriangle.As before,wetriangulatetheinteriorof thepath,asshowninFigure253b. Theinteriortrianglesarefilledand renderednormally.Theinteresting partishowtogeneralizethe proceduraltexturetechniqueweused forquadratics.
http.developer.nvidia.com/GPUGems3/gpugems3_ch25.html
4/20
1/12/12
Figure253RenderingCubicSplines Unlikeparametricquadraticcurves, parametriccubicplanecurvesarenot allprojectivelyequivalent.Thatis, thereisnosingleprotocurvethatall otherscanbeprojectedfrom.Itis wellknownthatallrationalparametric planecurveshaveacorresponding algebraiccurveofthesamedegree. Itturnsoutthatthealgebraicformof aparametriccubicbelongstooneof threeprojectivetypes(Blinn2003), asshowninFigure254.Anyarbitrary cubiccurvecanbeclassifiedasa serpentine,cusp,orloop. Furthermore,aprojectivemapping existsthatwilltransformanarbitrary parametriccubiccurveontooneof thesethreecurves.Ifwemapthe Bziercontrolpointsofthecurve underthistransform,wewillgeta Bzierparameterizationofsome segmentofoneofthesethreecurves.
http.developer.nvidia.com/GPUGems3/gpugems3_ch25.html
5/20
1/12/12
written k3lmn=0, wherek,l,m,andnarelinear functionalscorrespondingtolinesk,l, m,andnasinFigure254.(The reasonlinendoesnotappearin Figure254willbemadeclear shortly.)Morespecifically,k=au+ bv+cw,where[uvw]arethe homogeneouscoordinatesofapoint intheplane,andk=[abc]T arethe coordinatesofalineandsimilarlyfor l,m,andn.Therelationshipofthe linesk,l,m,andntothecurveC(s, t)hasimportantgeometric significance.Aserpentinecurvehas inflectionpointsatk l,k m,
mandistangenttolineslandm atthispointk ncorrespondsto aninflectionpoint.Acuspcurvehasa cuspatthepointwherecoincident lineslandmintersectk,anditis tangenttolinel=matthispointand k ncorrespondstoaninflection point. Theproceduraltexturecoordinates arethevaluesofthek,l,m,andn functionalsateachcubicBzier controlpoint.Whenthe(triangulated) Bzierconvexhullisrendered,these coordinatesareinterpolatedbythe GPUandapixelshaderprogramis calledthatevaluatestheshader equationk3lmn.Thiswilldetermine ifapixelisinsideoroutsidethecurve basedonthesignoftheresult. Weworkinhomogeneouscoordinates wherepointsintheplaneare representedby3tuples[xyw]the 2DCartesiancoordinatesarex/wand y/w.Wealsoworkwitha homogeneouscurveparameterization wheretheparametervalueis representedbythepair[st]the1D scalarparameteriss/t.Weuse homogeneousrepresentations becausetheprojectivegeometric notionofpointsatinfinityiscaptured byw=0similarly,aninfinite parametervalueoccurswhent=0. Inprinciple,wecanrenderanyplanar cubicBziercurvedefinedthisway however,wemakesomesimplifying assumptionstoeasethederivation andimplementationofouralgorithm. ThefirstisthattheBziercontrol pointsareaffine,sow=1.This meansthatcurvesmustbeintegralas opposedtorational.Thisisnota severelimitation,becausemost drawingtoolssupportonlyintegral curves.Wewillstillbeabletorender
http.developer.nvidia.com/GPUGems3/gpugems3_ch25.html
6/20
1/12/12
thecorrectprojectedimageofan integralcubicplanecurve,butinthe planewherethecurveisdefinedit cannotberational.Forintegralcurves thelinen=[001]thatis,thelineat infinity.Allthreecubicprotocurvesin Figure254haveintegral representations,solinendoesnot appear.Thelinearfunctional correspondingtothelineatinfinityis n=1,sotheshaderequation simplifiesto k3lm. Althoughthissavesonlyonemultiply intheshader,itremovesanentire texturecoordinatefromavertex, leadingtopotentiallymoreefficient code.Theprimaryreasonfor assumingintegralcurves,however,is tosimplifycurveclassification.Our secondassumptionisthatthecontrol pointcoordinatesareexactfloating pointnumbers.Thisassumptionisnot strictlynecessary,butwecanavoid floatingpointroundofferrorsthat mightcropupintestsforequality. Thiscorrespondstoaninteractive drawingscenariowherecontrolpoints lieonaregulargrid. AcubicBziercurveinhomogeneous parametricformiswritten
wherethebiarecubicBziercontrol points. Thefirststepistocomputethe coefficientsofthefunctionI(s,t) whoserootscorrespondtoinflection pointsofC(s,t).Aninflectionpointis wherethecurvechangesitsbending direction,definedmathematicallyas parametervalueswherethefirstand secondderivativesofC(s,t)are linearlydependent.Thederivationof thefunctionIisnotneededforour currentpurposesseeBlinn2003for athoroughdiscussion.Forintegral cubiccurves, I(s,t)=t(3d1s23d2st+d3t
2 ),
http.developer.nvidia.com/GPUGems3/gpugems3_ch25.html
7/20
1/12/12
and a1=b0 a2=b1 a3=b2 (b3xb (b0xb3), (b1xb1). 2 ), ThefunctionIisacubicwiththree roots,notallnecessarilyreal.Itisthe numberofdistinctrealrootsofI(s,t) thatdeterminesthetypeofthecubic curve.Forintegralcubiccurves,[st] =[10]isalwaysarootofI(s,t).This meansthattheremainingrootsofI(s, t)canbefoundusingthequadratic formula,ratherthanbythemore generalsolutionofacubica significantsimplificationoverthe generalrationalcurvealgorithm. Ourcubiccurveclassificationreduces toknowingthesignofthe discriminantofI(s,t),definedas
Ifdiscr(I)ispositive,thecurveisa serpentineifnegative,itisaloop andifzero,acusp.Althoughitistrue thatallcubiccurvesareoneofthese threetypes,notallconfigurationsof fourBziercontrolpointsresultin cubiccurves.Itispossibleto representquadraticcurves,lines,or evensinglepointsincubicBzier form.Ourprocedurewilldetectthese cases,andourrenderingalgorithm canhandlethem.Wedon'tneedto consider(orrender)linesorpoints, becausetheconvexhulloftheBzier controlpointsinthesecaseshaszero areaand,therefore,nopixel coverage.Thegeneralclassificationof cubicBziercurvesisgivenbyTable 251.
Table251.CubicCurve Classification
Serpentine discr(I)>0 Cusp Loop Quadratic discr(I)=0 discr(I)<0 d1=d2=0 d1=d2=d3=0 b0=b1=b2=b3
Line
Point
http.developer.nvidia.com/GPUGems3/gpugems3_ch25.html
8/20
1/12/12
bedoneexactly.Thatis,thereisno ambiguitybetweencases,because discr(I)andallintermediatevariables canbederivedfromexactfloating representations. Onceacurvehasbeenclassified,we mustfindthetexturecoordinates[kili mi]correspondingtoeachBzier controlpointbi,i=0,1,2,3.Our approachistofindscalarvaluedcubic functions k(s,t)=k l(s,t),=l .C(s,t), .C(s,t), m(s,t)=m .C(s,t),
inBzierformthecoefficientsof thesefunctionswillcorrespondtoour proceduraltexturecoordinates. Becauseweknowthegeometryofthe linesk,l,andminFigure254,we couldfindpointsandtangentvectors ofC(s,t)andfromtheseconstructthe neededlines.Butlinesare homogeneous,scaleinvariant objectswhatweneedarethe correspondinglinearfunctionals, where(relative)scalematters. Ourstrategywillbetoconstructk(s, t),l(s,t),andm(s,t)bytaking productsoftheirlinearfactors.These linearfactorsarefoundbysolvingfor therootsofI(s,t)andarelated polynomialcalledtheHessianofI(s, t).Foreachcurvetype,wefindthe parametervalues[lslt ]and[msmt ] ofI(s,t)wherek landk m. Wedenotetheselinearfactorsbythe following:
L ),
(slt tls
M ).
(smt tms
Wecanreasonabouthowtoconstruct k(s,t),l(s,t),andm(s,t)fromLand Mbystudyingthegeometric relationshipofC(s,t)tolinesk,l,and m.Forexample,k(s,t)willhave rootsat[lslt ],[msmt ],andarootat infinity[10].Therefore,forallcubic curves: k(s,t)=LM. Findingthecubicfunctionsl(s,t)and m(s,t)foreachofthethreecurve typeshasitsownreasoning,tobe describedshortly. Oncethefunctionsk(s,t),l(s,t),and m(s,t)areknown,weconvertthem tocubicBzierformtoobtain
http.developer.nvidia.com/GPUGems3/gpugems3_ch25.html
9/20
1/12/12
where[kilimi]aretheprocedural texturecoordinatesassociatedwithbi ,i=0,1,2,3. Finally,tomakesurethatthecurve hasthecorrectorientationtothe rightisinsidewemayneedto reverseorientationbymultiplyingthe implicitequationby1.Thisis equivalenttosettingM where MO,
25.3.1Serpentine
Foraserpentinecurve,C(s,t)is tangenttolinelattheinflectionpoint wherek l.Thescalarvalued functionl(s,t)willalsohavean inflectionpointatthisparameter valuemeaningthatl(s,t)willhavea triplerootthere.Asimilaranalysis appliesform(s,t).Weformproducts ofthelinearfactorstoget k(s,t)= LM, l(s,t)=L 3, m(s,t)=M 3.
http.developer.nvidia.com/GPUGems3/gpugems3_ch25.html
10/20
1/12/12
25.3.2Loop
Foraloopcurve,C(s,t)istangentto linelandcrosseslinematoneofthe doublepointparameters.Thismeans thatl(s,t)willhaveadoublerootat [lslt ]andasinglerootat[msmt ].A similaranalysisholdsform(s,t).We thentakeproductsofthelinear factorstoget k(s,t)= LM, l(s,t)=L2 m(s,t)=LM 2. M,
Weconvertk(s,t),l(s,t),andm(s,t) tocubicBzierformtoget
http.developer.nvidia.com/GPUGems3/gpugems3_ch25.html
11/20
1/12/12
Arenderingartifactwilloccurifoneof thedoublepointparametersliesin theinterval[0/1,1/1].Tosolvethis problem,wesubdividethecurveat thedoublepointparametersee Figure255andreversethe orientationofoneofthesubcurves. Notethattheproceduraltexture coordinatesofthesubcurvescanbe foundbysubdividingtheprocedural texturecoordinatesoftheoriginal curve.Oncealoopcurvehasbeen subdividedatitsdoublepoint,the proceduraltexturecoordinateski,i= 0,...,3willhavethesamesign. Orientationreversal(M MO)is neededif(d1>0andsign(k1)<0) or(d1<0andsign(k1)>0).
Figure255CubicCurvewithaDouble Point
25.3.3Cusp
Acuspoccurswhendiscr(I)=0.This istheboundarybetweenthe serpentineandloopcases. Geometrically,thelineslandmare coincidenttherefore[lslt ]=[msmt ].Wecouldusetheprocedurefor eitherthelooportheserpentinecase, becausethetexturecoordinate matriceswillturnouttobethesame. Thereisanexception:whend1=0. Intheserpentineandloopcases,it mustbethatd1 0otherwise discr(I)=0andwewouldhavea cusp.Thecasewhered1=0andd2 0correspondstoacubiccurve thathasacuspattheparametric value[10]thatis,homogeneous infinity.Inthiscase,theinflection pointpolynomialreducesto I(s,t)=t2(d3t3d2s), whichhasadoublerootatinfinityand asingleroot[lslt ]=[d33d2].We find k(s,t)= L, l(s,t)=L 3,
m(s,t)=1.
ConvertingthesetoBzierformgives
http.developer.nvidia.com/GPUGems3/gpugems3_ch25.html
12/20
1/12/12
usthecolumnsofthematrix:
25.3.4Quadratic
Weshowedearlierthatquadratic curvescouldberenderedbyapixel shaderthatevaluatedtheexpression u2v.Switchingawayfromthecubic shaderwouldbeinefficientforthe GPU,andthereforeundesirable. However,ifweequatethecubic functionk(s,t) m(s,t),ourcubic shaderexpressioncanbewrittenas k3kl=k(k2l). Weseethatthepartinsidethe parenthesesisthequadraticshader expressionwithuandvreplacedwith kandl.Thesignofthisexpression willagreewiththequadraticshader, providedthevalueofkdoesnot changesigninsidetheconvexhullof thecurve.Wecandegreeelevatethe quadraticproceduraltexture coordinatestoget
25.4Triangulation
Ourtriangulationprocedurewasonly brieflydiscussedinSections25.2and 25.3intheinterestofsimplicity.An importantdetailnotpreviously mentionedisthatBzierconvexhulls cannotoverlap.Therearetwo reasonsforthis:oneisthat overlappingtrianglescauseproblems
http.developer.nvidia.com/GPUGems3/gpugems3_ch25.html
13/20
1/12/12
Figure256HandlingOverlapping Triangles Welocallytriangulateallnon overlappingBzierconvexhulls.For quadratics,theBzierconvexhullis uniquelyatriangle.Forcubics,the Bzierconvexhullmaybeaquador atriangle.Ifitisaquad,we triangulatebychoosingeither diagonal.Next,theinteriorofthe entireboundaryistriangulated.The detailsofthisprocedurearebeyond thescopeofthischapter.Any triangulationprocedurefora multicontourpolygonwillwork. Recently,Kokojimaetal.2006 presentedavariantonourapproach forquadraticsplinesthatusedthe stencilbuffertoavoidtriangulation. Theirideaistoconnectallpointson thecurvepathanddrawthemasa trianglefanintothestencilbufferwith theinvertoperator.Onlypixelsdrawn anoddnumberoftimeswillbe nonzero,thusgivingthecorrect imageofconcavitiesandholes.Next, theydrawthecurvesegments, treatingthemallasconvexquadratic elements.Thiswilleitheraddtoor carveawayacurvedportionofthe shape.Aquadlargeenoughtocover theextentofthestencilbufferisthen drawntotheframebufferwitha stenciltest.Theresultisthesameas ourswithouttriangulationor subdivision,andneedingonlyone quadraticcurveorientation. Furthermore,eliminatingthe triangulationstepsmakeshigh performancerenderingofdynamic curvespossible.Thedisadvantageof theirapproachisthattwopassesover thecurvedataareneeded.Forstatic curves,theyaretradingperformance forimplementationoverhead.
25.5Antialiasing
Wepresentanapproachto antialiasinginthepixelshaderbased onasigneddistanceapproximationto
http.developer.nvidia.com/GPUGems3/gpugems3_ch25.html
14/20
1/12/12
acurveboundary.Byreducingpixel opacitywithinanarrowbandthat containstheboundary,wecan approximateconvolutionwithafilter kernel.However,thisworksonly whenpixelsampleslieonbothsides ofaboundary,suchaspointswell insidetheBzierconvexhullofa curve.Forpointsneartriangleedges, orwhentheedgeofatriangleisthe boundary,thisschemebreaksdown. Fortunately,thisisexactlythecase thatishandledbyhardware multisampleantialiasing(MSAA). MSAAusesacoveragemaskderived asthepercentageofsamples(froma hardwaredependentsamplepattern) coveredbyatriangle.Onlyonepixel shadercallisinitiated,andthisis optionallylocatedatthecentroidof thecoveredsamples,asopposedto thepixelcenter,toavoidsampling outsidethetriangle'simageintexture space.Inourcase,outofgamut samplingisnotaproblem,because weuseaproceduraldefinitionofa texture(analgebraicequation). Therefore,centroidsamplingisnot recommended. Forantialiasingofcurvedboundaries ontheinterioroftheBzierconvex hull,weneedtoknowthescreen spacesigneddistancefromthe currentpixeltotheboundary.Ifthis distanceisapixel(anempirically determinedchoicethiscouldbeless ormore),thentheopacityofthepixel colorischangedrelativetothepixel's distancetothecurvedboundary. Computingthetruedistancetoa degreedpolynomialcurverequires thesolutiontoadegree2d1 equation.Thisisimpracticalon today'shardware,forperformance reasons. Instead,weuseanapproximate signeddistancebasedongradients. Forafunctionf(x,y),thegradientof fisavectoroperator f=[df/dx df/dy].TheGPUhashardwaresupport fortakinggradientsofvariablesin pixelshaderprogramsviathed x ) d( andd y ) d ( functions.Wedefinethe signeddistancefunctiontothe screenspacecurvef(x,y)=0tobe
Inourcase,theimplicitfunctionisnot definedinscreen(pixel)space. However,theprocessofinterpolating proceduraltexturecoordinatesin screenspaceis,ineffect,mapping screen[xy]spacetoprocedural texturecoordinatespace([uv]for quadratics,[klm]forcubics).In otherwords,wecanthinkofthe interpolatedproceduraltexture coordinatesasvectorfunctions
http.developer.nvidia.com/GPUGems3/gpugems3_ch25.html
15/20
1/12/12
[u(x, y)
v(x, y)]
or [k(x, l(x, y) y)
m(x, y)].
Eachofthesecoordinatefunctionsis actuallytheratiooflinearfunctionals whosequotientistakeninhardware (thatis,perspectivecorrection).An implicitfunctionofthesecoordinate functionsisacomposition,defininga screenspaceimplicitfunction. Therefore,oursigneddistance functioncorrectlymeasures approximatedistanceinpixelunits. Hardwaregradientsarebasedon differencesbetweenvaluesof adjacentpixels,sotheycanonly approximatethederivativesof higherorderfunctions.Althoughthis rarely(ifever)resultsinartifacts, withonlyafewadditionalmath operations,wecangetexact derivativesbyapplyingthechainrule toourshaderequations.Letthe following, q(x,y)=u(x,y)2v(x,y)=0and c(x,y)=k(x,y)3l(x,y)m(x,y)= 0, beourquadraticandcubicshader equations,respectively.Applyingthe chainrule,weget
Wecanwriteoursigneddistance functionas
wheref
qforquadraticsandf
http.developer.nvidia.com/GPUGems3/gpugems3_ch25.html
16/20
1/12/12
25.6Code
Listing251isHLSLcodeforour quadraticshader.Thecodeforthe cubicshaderissimilar.
Example251.QuadraticCurve PixelShader 0. 1 0. 2 0. 3 0. 4 0. 5 0. 6 0. 7 0. 8 0. 9 1. 0 1. 1 1. 2 1. 3 1. 4 1. 5 1. 6 1. 7 1. 8 1. 9 2. 0 2. 1 2. 2 la4QartcSfotECOD, fotudaiP(la2p:TXOR0 fotooOO0OO la4clr:CLR):CLR { /rdet /Gains la2pd() fotx=dxp; foty=dyp; la2pd() /hiue /Canrl lax=(*.)p.xy fotf2px*xxp.; fotf2px*yxp.; lay=(*.)p.yy /inddsac /Sgeitne lad=(.*..)sr(xfyf) fotspxpxpy/qtf*x+f*y; /ierapa /Lnalh lalh.d fotapa=05s; iapa>1/Isd f(lh)/nie clra=1 oo.; esf(lh)/Otie leiapa<0/usd lp) ci(1; es le /Naonay /erbudr clra=apa oo.lh; rtroo; eunclr }
25.7Conclusion
Wehavepresentedanalgorithmfor renderingvectorartdefinedbyclosed pathscontainingquadraticandcubic Bziercurves.Welocallytriangulate eachBzierconvexhullandglobally triangulatetheinterior(righthand side)ofeachpath.Weassign proceduraltexturecoordinatestothe verticesofeachBzierconvexhull. Thesecoordinatesencodelinear functionalsandareinterpolatedby thehardwareduringrasterization.The processofinterpolationmapsthe proceduraltexturecoordinatestoa spacewheretheimplicitequationof thecurvehasasimpleform:u2v= 0forquadraticsandk3lm=0for cubics.Apixelshaderprogram evaluatestheimplicitequation.The signoftheresultwilldetermineifa pixelisinside(negative)oroutside (positive).Weusehardwaregradients toapproximateascreenspacesigned distancetothecurveboundary.This signeddistanceisusedforantialiasing thecurvedboundaries.Wecanapply anarbitraryprojectivetransformto viewourplanecurvesin3D.The resulthasasmallandstaticmemory footprint,andtheresultingimageis resolutionindependent.Figure257 showsanexampleofsometext renderedinperspectiveusingour technique.
http.developer.nvidia.com/GPUGems3/gpugems3_ch25.html
17/20
1/12/12
Figure257OurAlgorithmIsUsedto Render2DTextwithAntialiasing Undera3DPerspectiveTransform Inthefuture,wewouldliketoextend thisrenderingparadigmtocurvesof degree4andhigher.Thiswouldallow ustoapplyfreeformdeformationsto lowordershapes(suchasfont glyphs)andhavetheresultinghigher ordercurveberesolution independent.TheworkofKokojimaet al.2006showedhowtorender dynamicquadraticcurveswewould liketoextendtheirapproachto handlecubiccurvesaswell.Thisis significantlymorecomplicatedthan thequadraticcase,becauseofthe proceduraltexturecoordinate assignmentphase.However,itshould bepossibletodothisentirelyonthe GPUusingDirectX10classhardware equippedwithageometryshader (Blythe2006).
25.8References
Blinn,Jim.2003.JimBlinn'sCorner: Notation,Notation,Notation.Morgan Kaufmann. Blythe,David.2006."TheDirect3D10 System."InACMTransactionson Graphics(ProceedingsofSIGGRAPH 2006)25(3),pp.724734. Kokojima,Yoshiyuki,KaoruSugita, TakahiroSaito,andTakashi Takemoto.2006."Resolution IndependentRenderingofDeformable VectorObjectsusingGraphics Hardware."InACMSIGGRAPH2006 Sketches. Loop,Charles,andJimBlinn.2005. "ResolutionIndependentCurve RenderingusingProgrammable GraphicsHardware."InACM TransactionsonGraphics (ProceedingsofSIGGRAPH2005) 24(3),pp.10001008. Salmon,George.1852.ATreatiseon theHigherOrderPlaneCurves. Hodges&Smith. Foreword Preface Contributors Copyright
http.developer.nvidia.com/GPUGems3/gpugems3_ch25.html
18/20
1/12/12
PartI:Geometry Chapter1.GeneratingComplex ProceduralTerrainsUsingtheGPU Chapter2.AnimatedCrowd Rendering Chapter3.DirectX10Blend Shapes:BreakingtheLimits Chapter4.NextGeneration SpeedTreeRendering Chapter5.GenericAdaptiveMesh Refinement Chapter6.GPUGenerated ProceduralWindAnimationsfor Trees Chapter7.PointBased VisualizationofMetaballsonaGPU PartII:LightandShadows Chapter8.SummedArea VarianceShadowMaps Chapter9.InteractiveCinematic RelightingwithGlobalIllumination Chapter10.ParallelSplitShadow MapsonProgrammableGPUs Chapter11.EfficientandRobust ShadowVolumesUsing HierarchicalOcclusionCullingand GeometryShaders Chapter12.HighQualityAmbient Occlusion Chapter13.VolumetricLight ScatteringasaPostProcess PartIII:Rendering Chapter14.AdvancedTechniques forRealisticRealTimeSkin Rendering Chapter15.PlayableUniversal Capture Chapter16.VegetationProcedural AnimationandShadinginCrysis Chapter17.RobustMultiple SpecularReflectionsand Refractions Chapter18.RelaxedCone SteppingforReliefMapping Chapter19.DeferredShadingin TabulaRasa Chapter20.GPUBased ImportanceSampling PartIV:ImageEffects Chapter21.TrueImpostors Chapter22.BakingNormalMaps ontheGPU Chapter23.HighSpeed,Off ScreenParticles Chapter24.TheImportanceof BeingLinear Chapter25.RenderingVector ArtontheGPU Chapter26.ObjectDetectionby Color:UsingtheGPUforReal TimeVideoImageProcessing Chapter27.MotionBlurasaPost ProcessingEffect Chapter28.PracticalPostProcess DepthofField PartV:PhysicsSimulation Chapter29.RealTimeRigidBody SimulationonGPUs Chapter30.RealTimeSimulation andRenderingof3DFluids Chapter31.FastNBody SimulationwithCUDA Chapter32.BroadPhaseCollision DetectionwithCUDA Chapter33.LCPAlgorithmsfor CollisionDetectionUsingCUDA
http.developer.nvidia.com/GPUGems3/gpugems3_ch25.html
19/20
1/12/12
Chapter34.SignedDistanceFields UsingSinglePassGPUScan ConversionofTetrahedra Chapter35.FastVirusSignature MatchingontheGPU PartVI:GPUComputing Chapter36.AESEncryptionand DecryptionontheGPU Chapter37.EfficientRandom NumberGenerationand ApplicationUsingCUDA Chapter38.ImagingEarth's SubsurfaceUsingCUDA Chapter39.ParallelPrefixSum (Scan)withCUDA Chapter40.Incremental ComputationoftheGaussian Chapter41.UsingtheGeometry ShaderforCompactandVariable LengthGPUFeedback
http.developer.nvidia.com/GPUGems3/gpugems3_ch25.html
20/20