While the dev team take some well earned time off over the festive break, I've been tinkering with the main character shader used in Folk Tale, looking at ways we can introduce character customization after we've shipped the demo.
One of the design objectives for the final game is to add variety to characters so they don't all look like they came off a drone factory line. While some of that will come from varying geometry such as hair styles, clothing and props, there are a number of simple old-school tricks we can do at the shader level.
Both skin tone and clothing colors can be varied by converting areas of the artists original diffuse texture to grayscale and applying one or more tint colors in the shader. By painting vertices in the geometry with differing levels of red, we can determine not only which parts of the model are tinted, but the influence level too. However, this tends to result in a fairly obvious tinted look ( as seen in the middle ), so I plan to add some variety by introducing color tints directly onto the texture map. That way we should be able to get some nice color gradient blends happening on clothing.
Using the green vertex color channel we can define areas of influence for scaling out the vertices along it's normal, allowing us to bulk up muscle areas. For testing purposes I've just splashed on vertex color, but hopefully the technical artists ( familiar with painting bone influence weights during the skinning process ) will exert finer control and produce more natural results.
This is just a float value applied to the height of every vertex. I still need to offset this so that character scales upwards from the pivot point between their feet rather than the center of the character which causes them to scale into the terrain. I'll also replace this with a vector, since only scaling the y-axis can produce unnatural results.
I want to explore how much variation we can get into faces. Being an RTS with quite a few characters on screen at once, we don't have a heap of polys to play with in the faces. DX11 tessellation might help out when the camera is up close, but at the moment we're keeping Folk Tale on DX9 so that's not an option. As part of previous R&D the shader already supports tessellation with a DX9 fallback, but it remains commented out.
The vertex color blue and alpha channels free, so I plan to bring those into play.
I would like to be able to define a hard edge and not have the influence bleed over into the faces the other side of the edge. I've tried flood filling a selection of faces which looks correct in 3ds Max, but it's still not producing the desired results in Unity.
Finally I'll add a scale influence float to provide better control over muscle bulking.
The height float value has been replaced with a vector to allow scaling on all three axis. Because scaling is done in model space, I needed to offset the geometry height based on y-scale and original geometry height so that the characters feet remain in the correct position. The w value of the Scaling parameter is free, so I'll set that when the customized character is initialized.
I've added a Muscle Bulk Factor parameter to allow dampening of how much influence a 100% green vertex color has. This should enable us to vary the muscle bulk per character instance.
I've reverted back to the artist's original diffuse map to see how well a non-grayscale texture combines with the color tint. Seems to work quite nicely, but I'll have to discuss how we proceed with the artists to ensure the system supports their needs. I've also added a lerp for a nicer blend between tinted and non-tinted vertices.
To get rid of the unwanted bleed associated with using vertex colors, I've requested our technical artist Tom adds double edge loops where skin changes to cloth, slightly extruding the cloth. This should significantly reduce the visual impact.