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 (rollover image)
You are 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 Generate> Create Description. This will open up the Create XGen Description below.
- Choose Spheres primitive. Leave the other default settings alone and select 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 a large number of primitives generated.
- Click on the downward pointing arrow to the right of Length. Select Create Map...
Ensure that the original Maya shader is assigned to the XGen description. Otherwise, this step will not work! After you have created the map, you can then convert it to a different shader.
- 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 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:
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 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.
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 recognizable 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:
Distribution of spheres based on grayscale ramp
- 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 thedisk 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 a Standard Surface 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.
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.
Texture maps used to drive sphere primitives
Thanks to Pedro Fernando Gómez for his assistance with XGen.