h16 mantra user guide packed primitives - sidefx · h16 mantra user guide copies of packed...

12
H16 Mantra User Guide Packed Primitives What Are Packed Primitives? Packed Primitives are a way to express a procedure to generate geometry at render time. Packed Primitives have information about other pieces of geometry embedded inside of them. This information could be an actual piece of geometry stored in memory, a reference to a smaller part of another piece of geometry, or even a path to geometry stored on disk. The information can then be used throughout Houdini to more efficiently represent geometry in the viewport, in the bullet solver, and in Mantra. The Types of Packed Primitives Packed Primitives can “embed” different types of data about geometry for use in different scenarios. Each of these Packed Primitive Types have advantages and limitations and are generally tailored to be used in specific circumstances. In Memory Packed Primitives An “In Memory” packed primitive is generated by “Packing” the geometry directly in a SOP network. This creates a Packed Geometry Primitive with an embedded reference to the current version of your geometry stored in RAM. In practice, the “embedded” geometry essentially becomes a single un-editable “primitive” with a single transform. Advantages Because the “embedded geometry” simply refers to a piece of geometry in memory, copying a packed primitive creates a copy of the reference rather than a copy of the geometry itself. This means that the referenced geometry is shared among all copies of the packed primitive. This stands in contrast to copying standard Houdini geometry, which creates duplicates of all points, primitives, etc., in the original piece of geometry.

Upload: others

Post on 17-Aug-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: H16 Mantra User Guide Packed Primitives - SideFX · H16 Mantra User Guide Copies of packed primitives use less memory, are simpler to transform, and can be drawn more efficiently

H16MantraUserGuide

PackedPrimitives

WhatArePackedPrimitives?PackedPrimitivesareawaytoexpressaproceduretogenerategeometryatrendertime.PackedPrimitiveshaveinformationaboutotherpiecesofgeometryembeddedinsideofthem.Thisinformationcouldbeanactualpieceofgeometrystoredinmemory,areferencetoasmallerpartofanotherpieceofgeometry,orevenapathtogeometrystoredondisk.TheinformationcanthenbeusedthroughoutHoudinitomoreefficientlyrepresentgeometryintheviewport,inthebulletsolver,andinMantra.

TheTypesofPackedPrimitivesPackedPrimitivescan“embed”differenttypesofdataaboutgeometryforuseindifferentscenarios.EachofthesePackedPrimitiveTypeshaveadvantagesandlimitationsandaregenerallytailoredtobeusedinspecificcircumstances.

InMemoryPackedPrimitives

An“InMemory”packedprimitiveisgeneratedby“Packing”thegeometrydirectlyinaSOPnetwork.ThiscreatesaPackedGeometryPrimitivewithanembeddedreferencetothecurrentversionofyourgeometrystoredinRAM.Inpractice,the“embedded”geometryessentiallybecomesasingleun-editable“primitive”withasingletransform.

AdvantagesBecausethe“embeddedgeometry”simplyreferstoapieceofgeometryinmemory,copyingapackedprimitivecreatesacopyofthereferenceratherthanacopyofthegeometryitself.Thismeansthatthereferencedgeometryissharedamongallcopiesofthepackedprimitive.ThisstandsincontrasttocopyingstandardHoudinigeometry,whichcreatesduplicatesofallpoints,primitives,etc.,intheoriginalpieceofgeometry.

Page 2: H16 Mantra User Guide Packed Primitives - SideFX · H16 Mantra User Guide Copies of packed primitives use less memory, are simpler to transform, and can be drawn more efficiently

H16MantraUserGuide

Copiesofpackedprimitivesuselessmemory,aresimplertotransform,andcanbedrawnmoreefficientlyintheviewportorrenderedbyMantra.Additionally,becausethegeometrycanexistinatraditionalSOPnetworkbeforebeingpacked,youcaneasilygenerateproceduralgeometrywhichadaptstoyourscene,usestampingtogeneratevariationsofyourpackedgeometry,ormakeinteractiveeditstoyourgeometrywhileviewingtheresultslive.Essentially,workingwith“InMemory”PackedPrimitivesisamoreinteractiveanduser-friendlyversionoftraditionalinstancingworkflows.Individualcopiesofan“InMemory”PackedPrimitivecanalsobe“Unpacked”inaSOPnetwork,loadingthereferencedgeometryintomemory.ThisallowsyoutogenerateproceduralworkflowswhichareahybridoftraditionalHoudinigeometryandPackedGeometryPrimitives.

AHelpfulReminder“Packing”geometryhasanassociatedmemorycost.SinceyouarestoringtheoriginalpieceofgeometryinRAMaswellasthememoryoverheadforthe“InMemory”PackedPrimitiveitself,asinglepackedprimitiveisnotnecessarilyanymoreefficientthantheoriginalpieceofgeometry.Thebenefitof“InMemory”PackedPrimitivescomesfromtheefficientrepresentationoflargenumberofcopieswherethereferencedgeometrycanbeshared.

Page 3: H16 Mantra User Guide Packed Primitives - SideFX · H16 Mantra User Guide Copies of packed primitives use less memory, are simpler to transform, and can be drawn more efficiently

H16MantraUserGuide

Thisisimportanttorememberwhencopy-stampingpackedgeometry.Ifeveryinstanceofyourpackedgeometryisunique,thenyouwillnotreceiveanyofthememoryorperformancebenefits.Infact,inthisscenarioyouwillusemorememorythanusingstandardHoudinigeometry,sinceeachpackedprimitivehasitsowndataontopoftheembeddedgeometry.TIP:It’spossibletosomewhatoffsetthecostofpackingstampedgeometrywhentherearelimitednumbersofstampedvariationsusingthe'cachestamping'parameter-seethehelpfortheCopySOPformoreinfo.

PackedDiskPrimitivesA“PackedDisk”Primitivehasanembedded“path”toafileondiskratherthanareferencetoapieceofgeometrystoredinRAM.Generallyspeaking,“PackedDisk”primitivesarestandardHoudiniGeometrywhichhavebeenwrittentodiskasa.bgeo,or.bgeo.scfilethenloadedintoHoudinithroughaFileSOPasa“PackedDiskPrimitive”.A“PackedDisk”primitivebehavesinaverysimilarfashionto“InMemory”PackedPrimitives,the“embedded”geometryisrepresentedasasingleun-editableprimitivewithasingletransform

AdvantagesMuchlikethe“InMemory”packedprimitives,a“PackedDisk”primitiveisanexcellentchoiceforefficientlyrepresentingcopiesofgeometryintheviewportandinMantra.Copyinga“PackedDisk”primitivecreatesacopyofthepathtothegeometryondiskratherthanaduplicateofthegeometryitself.Anotheradvantagesharedbetween“InMemory”and“PackedDisk”primitivescomesfromhowthegeometrycanberepresentedintheviewport.Theviewportdoesnotcopythegeometry,butsimplydrawsitmultipletimeswithdifferenttransforms.Thismeansthattheviewportcanalsorefertoasmallersubsetofthereferencedgeometryanddisplaythatinstead.

Page 4: H16 Mantra User Guide Packed Primitives - SideFX · H16 Mantra User Guide Copies of packed primitives use less memory, are simpler to transform, and can be drawn more efficiently

H16MantraUserGuide

Since“PackedDisk”primitives,bytheirnature,areloadedfrompre-generatedgeometrystoredondisktheyarelessdynamicthan“InMemory”packedprimitiveswhoseembeddedgeometrycanbegeneratedprocedurally.Theonlywaytomakeeditsto“PackedDisk”primitivesisto“unpack”them,howeverthiscausesthegeometrytobeloadedintomemoryasstandardHoudinigeometry,negatingthebenefits.Inthissense,“PackedDisk”primitivesarelessflexiblethan“InMemory”packedprimitivesandbestusedforstaticgeometry.However,thereareseveraladvantages“PackedDisk”primitiveshaveover“InMemory”packedprimitiveswhenusedatrendertime.WhengeneratinganIFD(AfilewhichcontainsacompletedescriptionofasceneandhowtorenderIt.),a“PackedDisk”primitivecanberepresentedsimplyaspathtothefileondisk.Incontrast,an“InMemory”primitivemusthavetheentirepieceofGeometrycopiedintotheIFDinordertobereferencedbyMantra.BothofthesemethodsaresuperiortostandardHoudinigeometrywhichmustincludeallofthegeometryaswellasalloftheduplicatesofthegeometryintheIFDfile.

Page 5: H16 Mantra User Guide Packed Primitives - SideFX · H16 Mantra User Guide Copies of packed primitives use less memory, are simpler to transform, and can be drawn more efficiently

H16MantraUserGuide

Page 6: H16 Mantra User Guide Packed Primitives - SideFX · H16 Mantra User Guide Copies of packed primitives use less memory, are simpler to transform, and can be drawn more efficiently

H16MantraUserGuide

Additionally,Mantraneverhastoloadintomemorya“PackedDisk”primitivewhichisn’tcurrentlybeingusedtorenderthescene.Instead,“PackedDisk”geometryisstreamedintothescenewhennecessaryandthenunloadedwhennolongerinuse.Thismeansthatsinglecopiesof“PackedDisk”primitivescanstillbeusefulatrendertime,savingmemoryintheIFDfile,aswellasreducingtheamountofgeometryMantraneedstoloadatanygiventime.Thelightweightrepresentationof“PackedDisk”primitivesmakesthemidealcandidatesforsceneassembly,especiallyforstaticbackgroundobjects.Thatsaid,theverysmallmemoryfootprintintheIFDfilealsomakesthemveryusefulforobjectswithlargeon-diskfootprints.(LikeFluid,Smoke,orRBDsimulations).

PackedFragmentsA“PackedFragment”primitiveisgeneratedby“Packing”somepieceofgeometryalongwitha"nameattribute”.Eachpieceofthegeometrywithaunique“nameattribute”willbecomea“PackedFragment”primitivewithanembeddedreferencetothe“complete”pieceofgeometrywhichissharedacrossall“Fragments”.Inpractice,each“Fragment”essentiallybecomesasingleun-editable“primitive”withasingletransform.

Page 7: H16 Mantra User Guide Packed Primitives - SideFX · H16 Mantra User Guide Copies of packed primitives use less memory, are simpler to transform, and can be drawn more efficiently

H16MantraUserGuide

Advantages“PackedFragment”primitivesareidealforrepresentingmanypiecesofagreater“complete”pieceofgeometry.Each“Fragment”referstosomesubsetoftheembeddedgeometrywhichissharedacrossall“Fragments”.When“Unpacked”,onlythesmallersubsetofgeometrywillbeloadedintomemory.Additionally,becauseeach“PackedFragment”representsasinglereferenceandatransform,theyareusefulforcaseswhereeach“Fragment”willreceivesomeuniquetransformationsuchasaRigidBodySimulation.ThisstandsincontrasttostandardHoudinigeometrywhichdoesnotshareitsgeometry,soeachindividualpiecemustbeconsidereditsownobject.

Page 8: H16 Mantra User Guide Packed Primitives - SideFX · H16 Mantra User Guide Copies of packed primitives use less memory, are simpler to transform, and can be drawn more efficiently

H16MantraUserGuide

“PackedFragment”primitivesuselessmemory,aresimplertotransform,andaremoreefficientlydisplayedintheviewport.

Page 9: H16 Mantra User Guide Packed Primitives - SideFX · H16 Mantra User Guide Copies of packed primitives use less memory, are simpler to transform, and can be drawn more efficiently

H16MantraUserGuide

AHelpfulReminderEach“PackedFragment”containsareferencetothelargerpieceofembeddedgeometrystoredinmemory.Whenyouhavemany“Fragments”,thisisaveryefficientwayofrepresentingthegeometrybecauseeach“Fragment”onlyreferstoasmallsubsetofthesharedGeometry.However,ifyouweretodeletemanyofyourfragments,leavingonlyasmallnumber,each“PackedFragment”isstillreferringtotheoriginal“complete”pieceofgeometrywhichisstoredinmemory.Thiscanpotentiallymeanalargeamountofmemoryoverheadwhichisnolongernecessary.Consider“Unpacking”yourfragmentswhenyouhavemuchfewer“Fragments”thanintheoriginalpieceofGeometry.

RenderingPackedPrimitivesPackedPrimitivesareextremelyusefulforrenderinginMantra.Ingeneral,theproperuseofpackedprimitiveswillallowyoutoincreasethespeedofyourrendersaswellasreducetheoverallamountofmemoryneeded.Additionally,IFDgenerationwillbefasteranduselesson-diskmemory.However,itisimportanttounderstandhowMantradealswithPackedPrimitivesandthedatastoredinsideoftheminordertotakefulladvantageofthematrendertime.

MaterialAssignmentWithstandardHoudinigeometry,Materialassignmentcanoccurattwolevels–theobjectlevel(OntheobjectNode),ortheprimitivesinsideoftheobject(UsingaMaterialSOP).Materialsassignedat“lowerlevels”overridematerialsinthehigherlevels.Whensendingascenetoberendered,itisfirstanalyzedtoseewhichmaterialswillactuallybeneededinthefinalrender.Houdinicheckstheobjectsforanymaterialassignments,alongwithanygeometryattributeswhichapplymaterials,thenmakessuretoincludetheappropriateShadersintheIFDfile.

Page 10: H16 Mantra User Guide Packed Primitives - SideFX · H16 Mantra User Guide Copies of packed primitives use less memory, are simpler to transform, and can be drawn more efficiently

H16MantraUserGuide

WhenusingPackedGeometry,thisprocessismademorecomplexbyaddingathirdlevelofmaterialassignment–materialsassignedbyattributesinsidethePackedPrimitive.Likethepreviousexample,materialsassignedat“lowerlevels”overrideMaterialsinthehigherlevels.However,inthiscase,whenthesceneissenttoberendered,thematerialassignments“inside”thepackedprimitivesarehiddenfromHoudini.(RememberthePackedGeometrymaysimplyrefertoanobjectondisk).ThismeansthatHoudiniwillbeunabletoaddtheappropriateShaderstotheIFDfileforuseatrendertime.Duringrendering,Mantrawillunpacktheobject,findthematerialassignment,butitwillnothavethenecessaryShaderstoapplytotheobject.

ThesolutiontothisproblemistotellHoudinitoincludetheShadersintheIFDregardlessofwhetherornottheyhavebeenassignedtoanyobjectsorprimitives.OntheMantranode,thereisanoptioncalled“SaveAllSHOPS”whichwillembedallShadersinyoursceneintheIFD.(Thiswillincreasetheon-disksizeofyourIFDbyasmallamount).Thisway,whenMantraunpacksthegeometryatrendertimeandfindsthematerialassignment,thenecessaryShaderswillbeavailable.

Page 11: H16 Mantra User Guide Packed Primitives - SideFX · H16 Mantra User Guide Copies of packed primitives use less memory, are simpler to transform, and can be drawn more efficiently

H16MantraUserGuide

Ingeneral,whenworkingwithPackedGeometry,itisimportanttorememberthat“packed”dataisonlyaccessibleonceithasbeenunpacked.Formoreinformationaboutassigningshadersandoverridingshadingparameters“inside”PackedGeometry,pleaseseethedocumentationonMaterialStyleSheets.

DisplacementandSubdivisionSurfacesIngeneral,whenusingPackedGeometry,displacementshadingandsubdivisionsurfacesarehandledinthesamewayaswithanyotherpieceofgeometry.However,ifyouareprimarilyusingyourPackedGeometryasinstancedgeometry,thensomecaremustbetakentogetthemostoutofyourworkflow.Beforerenderingadisplacedorasubdividedsurface,thegeometryis“diced”intosmallerprimitivessuchthattherewillbeoneprimitiveforeverypixel(withshadingqualitysetto1).Thismeansthatobjectsclosertothecamerawillbedicedmorethanobjectsinthedistance(whichhavelesspixelcoverage).However,forinstancing,thiscancauseaproblem.Asdiscussedpreviously,thebenefitofinstancingcomesfromthefactthatgeometryissharedacrossallinstances.Inthecaseofdisplacementsorsubdivisionsurfaces,theobjectsmustbeevaluatedanddicedindividuallywhichmeansthegeometryisnolongerbeingshared.Toavoidthisproblem,thereisarenderingpropertywhichcanbeaddedtotheobjectcontainingyourinstances–“vm_sharedisplace”.EnablingthisparameterwilltellMantratousethehighestlevelofdicingneededforthesceneononeobjectandthensharethedicedgeometryacrossallinstances.Keepinmindthatthismeansthatobjectsfarawayfromthecamerawillhavethesamelevelofdicingasobjectsveryclosetothecamera.Thereissomepotentialforthistocauseproblemsinyourrenders,however,thebenefitsofinstancingthegeometrymostlikelyoutweighanydownside.

Page 12: H16 Mantra User Guide Packed Primitives - SideFX · H16 Mantra User Guide Copies of packed primitives use less memory, are simpler to transform, and can be drawn more efficiently

H16MantraUserGuide

Intheworstcasescenario,where“incorrect”dicinglevelscauseproblemsinyourrendering,youcould“split”yourinstancesintotwoobjects,foregroundandbackground,sothatdistantobjectsareevaluatedseparatelyfromnearbyones.Alternatively,youcouldalsounpackanyobjectsclosetothecamera,essentiallyremovingthemfromtheinstancinghierarchy.