Discover the Difference with
3ds Max 2015
Upgrade now and save
  • 1/2
You are here: Homepage /  Tutorials & Tips /  Tutorials / Controlling Primitives with a Texture Map
Controlling Primitives with a Texture Map
 
 
Posted: Feb 13, 2014
Published by: the area
Homepage: Visit the page
Software: Autodesk Maya
Category: Rendering
Skill: Intermediate
 
Tutorial Steps
1Expressions
2Create a texture map
3Texturing
4Density
5Further Examples (Texture maps used to drive sphere primitives)
6Additional Links
 
Scene formed of XGen 'archive' cube primitives driven by a texture map

Image Description: Scene formed of XGen 'archive' cube primitives driven by a texture map

Scene formed of XGen 'archive' cube primitives driven by a texture map

Image Description: Scene 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)

Image Description: 'Pyramid shape' archive distribution driven by a texture map (render)

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

Image Description: '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..

..to 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.

Expressions

Next, click on the Expression icon..

..to 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:

Image Attachment Code Listing
$a=map('${DESC}/paintmaps/length');#3dpaint,200.0

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.

Image Attachment Code Listing
$a=0.3*$a+0.02; 

...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..

..to 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.

tip Tip

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

Image Description: Sphere primitives rendered without texture map

Texturing

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

Image Description: Face image uses a 3d projection texture map

Density

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

Thanks to Pedro Fernando for his assistance with XGen.

In order to post any comments, you must be logged in!
Newest users comments View All 5 Comments
Posted by Gooshun on Aug 08, 2014 at 07:56 AM
dansidi3 I have the same problem, does anyone know how to automatically update the file texture? Thanks!
Posted by dansidi3 on Jul 16, 2014 at 10:00 PM
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

Posted by gusgogus on May 11, 2014 at 05:07 AM
Can't wait to try it out. thanks for the tutorial!
Posted by Tony Elmore on Mar 29, 2014 at 08:27 AM
Great tutorial! Is there any way to set a key on the Density option in the Xgen settings?
Posted by hleandre on Feb 13, 2014 at 06:35 PM
Awesome !