Controlling Primitives with a Texture Map

By the area
Login to Follow
- 13 Feb, 2014
  • Film & VFX
  • Rendering
  • Maya
Skill Level
  • Intermediate
Scene formed of XGen 'archive' cube primitives driven by a texture mapScene formed of XGen 'archive' cube primitives driven by a texture map

XGen is a powerful tool that offers many creative opportunities for positioning an arbitrary number of primitives either randomly or uniformly placed. You can use texture files with XGen Descriptions to specify the location and density of primitive generation as well as to control the number of primitive attributes. This tutorial will show you how you can very easily use a texture map to 'drive' the length, width and depth of an XGen primitive. These primitives can range from spheres, splines or as in the example below, geometry that has been exported as an archive.

'Pyramid shape' archive distribution driven by a texture map (render)'Pyramid shape' archive distribution driven by a texture map (hardware render)

You are really only limited to your imagination as to what you can achieve using this method. Uses for this tutorial could range from using a map to drive the position of some trees on a landscape or as in this case, be used to create an odd looking face:

Start off by creating a polygon plane and increase its Subdivisions Width and Subdivisions Height to 10. We will use this plane to assign the XGen description.

Select the polygon plane and go to XGen>Create Description. This will open up the Create XGen Description below.

Choose the Spheres primitive. Leave the other default setting alone and click on Create.

It is good practice to lower the Percent value in the Preview/Output tab before continuing. If the Percent value is too high you may find that your computer will stall due to the large number of primitives generated.

Click on the downward pointing arrow.. the right of Length. Select Create Map... (It is important to note that this will only work if the plane has a Maya shader assigned to it).

The Map Name should say 'length'. Increase the Map Resolution to around 200. This sets the resolution of the PTEX map in texels per-face. When using high resolution textures, use larger Map Resolution values. After you have done that, click on Create.


Next, click on the Expression icon.. the right of the Length slider control.

You should see the following length expression text in the Expression Editor. In the Expression Text Field you should see the following text:


This is used to define the length attribute using the texture map and 200 is the Map Resolution that we defined earlier.

Add the following line in the Expression Editor.


...where 0.5 (0.3 + 0.2) is the maximum length of the sphere and 0.02 is the minimum size. Your length Expression Editor should look like the following image. Copy the expression text. We will use the same expression for the Width and Depth settings for the sphere primitives. Click Accept when you are done.

Next, click on the Expression icon.. the right of the Width slider control to see the expression created by the PTEX map in the XGen Expression Editor.

Paste the same expression that we used for the length here. Do the same for the Depth attribute.

Create a texture map

Now we want to add our texture map. Click on the paint icon to the right of the slider control..

You should see in the Hypershade and Node Editor windows that a file texture has been connected to the plane.

Select the file texture and open the texture map that you want to use to drive the scale of the sphere primitives. Make sure to choose a texture map that has a lot of contrast and whose features are recognisable even at a small size. Too much incidental detail in the image will not transfer across well to the spheres. You can see in the example below, the effect that a grayscale ramp has on the length, width and depth scale of the sphere primitives:

Before we render the scene we must first tell XGen to update the file texture. Do this by clicking on the disk icon..

..for each length, width and depth attribute. Create a light and render the scene.

Remember to select the disk icon after updating the file texture used to define the primitive attributes, otherwise XGen will not update it and the render will not change.Sphere primitives rendered without texture map

The next step is to add the color texture file. Assign an Ai Standard shader to the XGen collection. Assign a color file texture to the Diffuse Color attribute. Make sure it is a projected file texture map so that we can align it with the polygon plane. Select the place3dTexture node and select Fit to Group BBox. The place3dTexture should snap to the size of the polygon plane.

Face image uses a 3d projection texture map

You may need to change the Density value depending on the values that you have used in the Expression Editor. If the spheres are too densely packed together, you may want to reduce the Density value. Conversely, if the spheres are too far apart, you may want to either increase the density or increase the maximum length size in the Expression Editor. The images below show the effect that increasing the Density has on the number of primitives created by XGen.

Further Examples (Texture maps used to drive sphere primitives)

That concludes this tutorial on controlling XGen primitives with a texture map. This is just one example of what this powerful tool is capable of. Below are some further examples of different images used to drive the distribution of primitives. Try experimenting with different texture maps and have a go at using different primitive types such as splines and archives.

Additional Links
Lee Griggs SOLIDANGLE Arnold Support (Maya)

Thanks to Pedro Fernando for his assistance with XGen.

Posted By
  • Maya
  • Rendering
To post a comment please login or register
Hounnaké Léandre | 4 years ago
Awesome !
Anthony Elmore | 3 years ago
Great tutorial! Is there any way to set a key on the Density option in the Xgen settings?
Gustavo Gonzalez | 3 years ago
Can't wait to try it out. thanks for the tutorial!
Daniel Sidi | 3 years ago
This is fantastic! Now, has anyone got this to animate using a file sequence? I have tried but updating the file texture is not automatic, it requires the 'disk icon' button to be pressed in the UI. How can I automate this? Many thanks
Goo-Shun Wang | 3 years ago
dansidi3 I have the same problem, does anyone know how to automatically update the file texture? Thanks!
Christoph Katz | 2 years ago
Great Tuorial! I use it for creating patterns in product design. It works really well with the 3dpaint and pictures, but I want to controll the attributes by using a ramp instead a .iff file. Because I nead exact patterns... for clean fade outs... Is there a workflow? Thanks Chris
Masha Starec | 2 years ago
This looks great, but I couldn't figure out where you create the Texture Map. When you say: "Now we want to add our texture map. Click on the paint icon to the right of the slider control..", do you refer to the length slider? If I do so the cursor transforms into a paint brush and I am able to paint on the plane. But where do I add the texture? Thank you!
Christopher Hartt | 20 days ago
And if you motion blur it? Does it blur...