Looking at the layered material documentation here:
there’s an example picture of a character w/ skin and other materials (fabric etc). How is this accomplished?
In all the examples I’ve seen (such as ContentExamples and here: https://udn.unrealengine.com/docs/ue4/int/engine/rendering/materials/howto/creatinglayeredmaterials/index.html)
it appears that the material function nodes eventually converge into a material w/ the layer functions and a material attribute node. That last node has a single choice for shadingModel.
Is there a way to build these layered shading networks so they write the shading model ID (for instance into the deferred buffer)? Since that’s an integer in ShadingModels.usf::SurfaceShading, is there any meaning to lerp’ing between two models?
A layered material is still just a single material which has a single shading model. As you imply, it’s not possible to lerp the shading model value, because interpolating that integer value doesn’t really make much sense.
If you’re using layered materials and you need to achieve a complex shading model (e.g. skin) on certain layers, you’d need to use the more complex shading model for the whole material, and then fade off the contribution in the areas that don’t need it (for example, for skin you could reduce the subsurface colour to black). Obviously this is not particularly efficient for the GPU, and it’s not possible to achieve all combinations of shading models in this way.
Ultimately, layered materials are a tradeoff between CPU and GPU performance. Using them can reduce draw call counts, significantly in some cases, but the final shaders will tend to be significantly more complex, so the pixel shader cost can increase. Whether this will actually be cheaper will depend on whether you’re CPU or GPU bound. (In reality, it’s not quite that simple, draw call counts can also have a GPU overhead in some cases).
this is very helpful – thanks for the detail esp. about tradeoffs in the explanation.