Xgen is one of the most used groom tools for both professional artists and also students. But the comprehensive information about the usage of the expressions, which is one of the most important parts of the software and whats makes it so strong. So after the request from the Patrons on the channel, I decided to make this guide on how to use some of the most basic expressions that will give you more control over the groom.
The expressions for xgen are based on seexpr that was developed by the Disney. And xgen uses this language as part of his core for the different behaviors, noises and patterns. You can find more information on the RenderMan SeeXpr page and of course Autodesk help page with a guide for the available commands and possible usages. Some other useful links Intro to Xgen Expressions.
On this case we will use my personal library of expressions, developed trough trial and error and with the help of amazing artist and developers.
Reference Videos on Xgen Expressions
Density mask * Mask Expression
One of the most important and basic expressions is the multiply/divide operation. This will let you merge, add or subtract any values just as the layers operators in Photoshop or any complex composite system. On this case we will use the * expression to get a multiplier between the mask and a density mask so we can have more control over the borders of the groom.
This expression should be written into the mask slot, and when you run it should create two maps one for the “mask” and one for your “density”. Remember to save your iff files when painting and also the ptex files.
The mask map should be black and white with no fall off or middle values. This mask defines the area were the groom grows. It should be bigger than the actual area of the hair, as the density will define the actual amount of hairs that grows on the specific area.
The density mask defines the amount of hairs that should spawn on a specific area of the hair. This mask can have middle values and can go from black ( No hair ) to white ( Maximum hair density). As rule of thumb you should block your density with a 0.5 ( Gray ) value first and block the main amount of hairs like that.
If you liked the seriesSUpport me on Patreon
One of the most common expressions that has a big impact of the final result of the grooms is the random. This is a really simple expression but you need to make it properly to avoid flickering or weird behaviors. The basic expression should look like this.
$randValue = and(floatmin,floatmax,seed);
Where the “rand” is the function, the “floatmin”defines the minimum value that will result from the expression, “floatmax” defines the maximum value and “seed” will be the distribution of those values, if you change the seed number the values will distribute on a different arrangement.
To properly use this expression I do a simple change to create every value as an slider which give much more control over the distribution of the noise and min and max values.
$randmin = 0.7000; #0.000,0.050
$randMax = 1.0000; #0.000,0.050
$seed = 154.0000;
$randValue = rand($randmin,$randMax,$seed);
When creating a mask, not always is necessary to create a map. I normally use the percentage mask for flyaway and other basic effects of the noise when I want my mask just to affect percentage of the hairs. On this cases the this expression is really useful. Expression by Fabio Messina.
$percentage = 0.1500; #0.000,1.000
$randValue = rand(0,1)<$percentage
This expression is the combination of a random function with a basic minor than ($percentage value defined on the slider, were a value of 1 meants 100% and a value of 0 means 0%. You can always add a seed value if you need to change the distribution of the hairs being affected.
Normally xgen has the stray() value where you can define a float to affect just a percentage of the hair, the problem with this value is an unique value, so you can not create different percentages, and if you call the stray() value its always going to be the same. Making the percentage expression a real need to create believable characters with different levels of strays and percentage masks.
No mask applied, the noise is affecting 100% of the hairs
Mask applied to a 15 % of the hairs
On this tutorial you can find an example of another percentage expression that will give you the same result, on this case we are using it to create the fly-aways on a basic groom.