Personal tools

MantraInstancing

From Odwiki

Jump to: navigation, search

Contents

[edit] What is instancing?

Instancing is the technique for re-using (potentially heavy) geometry many times over in a scene efficiently without duplicating the geometry defintion and incurring the memory hit for it. The geometry is defined once and then is supplied new transforms for various occurrences of the geometry in the scene.

There are several ways to define instancing in Houdini:

  • Geo Instancing
  • Point Instancing

[edit] When to instance and when not to instance

Instancing is most suited for duplicating fairly large sets of geometry around. You certainly can instance small geometry but the savings become more questionable since mantra has to store a fair amount of data per instance - a transform, shader strings, etc. So if you're trying to instance tiny geometry (of say, 10 points/polys each) 10k /100k times over then the data storage overhead in mantra will not be worth it. Its more suited to thousands of pieces of geometry of thousands of primitives.

Here is an easy scale:

  • one character - CHILLY
  • 2 identical characters - COLD
  • 5 identical characters - WARM
  • 50 identical characters - TOASTY
  • 200 cars - HOT
  • 1000 birds - VERY HOT
  • 35000 flowers - VERY HOT
  • 200000 hairs - COLD
  • 1000000 points (maybe rain) - FREEZING

FYI - inside of mantra, every object is instanced - often only once, but it's an instance internally. You don't have to worry about this though because it doesn't affect you ultimately - there is nothing special you have to do. Unless, of course, you're into hacking apart IFD files.

[edit] Instancing In Mantra

When specifying instances, you have to have an object which is instanced at a point. This object can be specified by the "instance" string attribute on a point or in the parameter in the object. If only some points have the "instance" attribute defined, the parameter from the object will be used for all points which don't have the attribute set.

[edit] Geo Instancing

Any object can be an instance of another object, like a clone. You can find a parameter in the Render tab of the GeometryObject called Geo Instance and here you can select another object that will be used for the geometry definition of this object. One big difference of geometry instancing versus point instancing is that the geo instance geometry will appear in the viewport as if it were a copy. This technique of instancing is intended to be for a small number of copies of the original geometry. Point instancing is intended for large numbers of copies where it would be impossible or too slow to display so much geometry in the viewport. You might want to use Geo Instancing for things like a few characters or buildings.

[edit] Point Instancing

Say you have a field of thousands of flowers. The field is the Points object where there will be a single point per flower and the individual flower object is the Model. The field (Points) object has many points with the instance attribute with the full path to the flower (Model) object. This attribute can be added easily using the PointSOP or, if you wish to assign the instance from within a particle simulation you can use the InstancePOP. The instance attribute is merely a string type GeometryAttribute which contains the full path to a GeometryObject which will be stamped onto the point. e.g. an instance attribute might be "/obj/boat". View the attibutes with the GeometrySpreadSheet.

Shader assignments for instances

When instancing geometry, shaders are dealt with as follows:
  • If the Points has per-point shader attributes, these are picked up for the surface shaders of the Model instances.
  • If there are no per-point shader attributes on the Points object (or if there are points which don't have the attribute defined), the surface shader of the Points object is used for each instance.
  • If the Model has primitive shader attributes, they override any other shaders which might be bound. Even if there is a shader attribute, but it's not defined for some primitives, these primitives will inherit their shaders using the above two steps.
In other words, the shader at the Model object is never referenced.

Passing attributes to shaders for instances

  • Currently (mantra7) for point instances, the attributes are never passed to the shaders. Thus if you want different shader parameter values for the point instances, you either have to assign different shaders or to hand munge your own point shader attribute strings.
  • One way to workaround this limitation is to use an AttribCreate SOP that reproduces the vm_surface attribute using as reference, the output from a Shader SOP that has Point Instancing turned on and Indirect References turned off.

Instancing archives

When the geometry is determined for the instancing operation (i.e. the Model object has the geometry), the "Render As" options for the Model object are used to determine how the geometry is defined. For example, if the Model Object has "Render Polygons As Subdivision Surfaces" turned on, the geometry will be rendered as sub-division surfaces regardless of what the geometry settings in the Points object are set to.
This allows you to create bounded archives which are instanced at each point. Simply save the Model geometry to a .bgeo file. Create a BoxSOP which bounds the archived geometry. Turn on the "Render from Bounded Disk File" option in the Render tab of the Model object and instead of saving the SOP from the Model object to the IFD stream, mantra will instead load the file from disk. This can be a huge performance gain since
  • Houdini doesn't have to save out the geometry
  • Houdini doesn't necessarily have to load the geometry file into memory (RAM) at all

[edit] How are instances aligned to points or particles?

Instancing and the CopySOP both use the same algorithm to align geometry to particles/points/templates. You can have varying amounts of information available and the algorithm will attempt to make a solid transform.

  • In all cases the geometry is transformed relative to it's zero position. If you wish the object to be transformed relative to its centroid or something, you have to ensure that the object is moved so that its centroid rests at the local objects space (0,0,0) beforehand.
  • If only the Normal point attribute exists, N, the shortest rotation from the -Z axis of the geometry is aligned to it. This is the least you can do to specify a rotation and a single axis is not really enough to define a good rotation. However this works surprisingly well, especially for modeling tasks with the CopySOP.
  • If the Normal and VelocityAttribute (v) exists, the object will point down it's -Z axis down N and if motion blur is used will be blurred in the direction of v.
  • If the Normal, the VelocityAttribute and UpVector - up - exists, the object will be aligned to N and up and the v will be used to describe the direction of movement for MotionBlur only. This is necessary for when you have objects that you don't want pointing in the same direction of the motion (like rockets and birds and arrows) - for example for tumbling debris pieces and asteroids.
  • If the Rotation Quaternion (rot) attribute exists - which is generated by some POPs - exists, then the rot attribute will describe the alignment and the v attribute will define the vector for MotionBlur.
  • It also takes into account the pscale (float) and scale (float[3]) attributes for scaling the instance.
  • To translate (offset) the instance you can use the (trans) attribute which is a vector type.

[edit] Instancing Attributes

Attrib  - Data Type
-----------------------------
orient  - float4 (quaternion)
pscale  - float
scale   - float3
N       - vector
up      - vector
v       - vector
rot     - float4 (quaternion)
trans   - vector

http://www.sidefx.com/components/com_forum/files/instancing_273.jpg