In this tutorial, you are going to regress to a fun part of your childhood when you may have enjoyed playing with toy soldiers. Unlike your childhood, you will be using XGen to arrange the soldiers into interesting formations using expressions and texture maps as masks. We will also cover ways to add color to the individual soldiers using expressions and texture maps. For some real world inspiration, you should also look at some of the work by this artist and also this artist. Both artists use toy soldiers, among other things, to create interesting works of art.

The tutorial is broken up into the following chapters:

 

Creating the Archive Files

Creating the XGen Description

Generator Attributes

Assigning Random Colors to the Soldiers using an Expression

Using an Expression as a Mask

Using a Texture Map as a Mask

Workflow issue - Primitive Bound

 

This video demonstrates IPR rendering of an XGen scene containing soldier primitive archives.

The toy soldier models are available to download here.

Remember to always share your toy soldiers with your friends and not hog them to yourself.

Creating the Archive Files

 

 

Creating the XGen Description

The number of XGen archive primitives is related to the number of subdivisions in the polygon plane. If you notice that your soldiers are not filling the entire size of the plane, then you will need to add more subdivisions to the polygon plane.

Polygon plane with only 1 subdivision. Soldiers do not fill the plane

Polygon plane with 5 subdivisions. Soldiers fill the size of the plane

 

 

 

Density


Positioning the Soldiers

Generator Attributes

When Generate Primitives is set to In uniform rows and columns the Spacing attribute replaces DensityIncreasing the Spacing attribute increases the distance between the primitives.

 

Assigning Random Colors to the Soldiers using an Expression

More information on how to do this can be found in the Assigning Random Colors to Primitives tutorial.

Ai UserData Color node connected to Color attribute of Standard Surface shader

 

Add the name 'color' to the Color Attr Name in the Ai UserData Color node

 

 

Custom Shader Parameters (bottom)

 

Custom Shader Parameters set to Color

 

$factor = 0.1920;

$a=[rand( 0.3, 0.65 ,$id)*$factor,rand( 0.4, 0.45 ,$id+1)*$factor,rand( 0.25, 0.55 ,$id+2)*$factor];#-1.0,1.0

$a

XGen Expression Editor for the custom color

 

 

Working with Masks

Using an Expression as a Mask

We can also use an expression to define how many soldiers appear on each polygon face. 

$border = 0.1150;
$u > $border && $u < (1-$border) && $v > $border && $v < (1-$border)

With each face, you can get the UV coordinates with $u and $v. With this expression, you only populate places where U is greater than 0.2, and less than 0.8 and V is greater than 0.2 and less than 0.8. This way we are getting a square in the middle of each face of the polygon plane.

 

Using a Texture Map as a Mask

We can also use a black and white grid texture to map out a formation for our army. 

 

 

The example below shows another example when using a color texture to drive the density mask. 

 

The map used for the mask is inverted, and therefore soldiers do not appear in the black areas.

 

 

Workflow issue - Primitive Bound  

In the render below, you can see some 'clipping' in the top right corner. This is because the bounding box area is set too low and the soldiers are not being rendered outside of this area. Increasing the Primitive Bound resolves this problem. This can be found in Output Settings under the Preview/Output tab.

Primitive Bound has not been set to a large enough value for the XGen archive primitives

 

Conclusion

That concludes this tutorial on how to create masks and colorize primitive archive toy soldier models in XGen. I hope you had fun with this tutorial. However, its now time to put your toy soldiers away and clean up your bedroom!

 

 

 

 

Thanks to Pedro Fernando Gómez for his assistance with XGen.