How can I create a diffuse texture for my rendered models or game assets ? If possible with a single node setup and no compositing needed.
Base color and blood color
We start with the base color and the Sub-Surface Scattering to add blood to the model. For the SSS, add an Input > Ambient Occlusion node, you can reduce the Samples for it to 8, you can reduce it even more if the amount of blood visible is subtle. Check Inside to invert it and Only Local. For the Distance use 0.4, it varies depending on the model, this is the size I will use with the Monkey mesh. Connect the AO output to a Color Mix RGB and connect it to the Factor. Set Color1 to R; 0.7 GB: 0.1. The Color2 will be the Base Color, add an Input > RGB and connect it.
Connect the Mix node to the Color1 of another Mix node set to Value. For the Color2 plug the RGB node of the base color. This will allow to have the blood with the same value of the base color, if you make the base color brighter the blood will be more visible.
Now add another Mix node for the amount of blood visible. In Color1 plug the RGB node, in Color2 plug the previous Value node. Set the Factor to 0 to have no blood by default.
Here is what our node setup looks like:
We then add an Ambient Occlusion node, you can enable Only Local if you want. To make it more realistic you can connect it to a mix node to add bluish shadows to fake ambient lighting, for that connect the AO output to the Factor of a Mix node. Set the Color1 to RG: 0 B: 0.1. Set the Color2 to white.
Add a Mix node and connect in the Color1 the node for the amount of blood and in Color2 the Ambient Occlusion effect. Set the node to Multiply and the Factor to 0.8.
The node setup:
The vertical gradient will darker the bottom part of your model to focus the attention at the top of your model. To create it add an Input > Texture Coordinate, connect the Generated output to a Converter > Separate RGB and use the Blue channel, that's all you have to do for this effect. Connect the gradient to a multiply node, in Color1 plug the AO amount and in Color2 the Vertical gradient, set the Factor to 0.5.
Here is the result you should get in the viewport (connect it to an Output > Material Output to see it):
For the fake top lighting effect add an Input > Texture Coordinate (or use the previous node), connect the Normal output to a Converter > Separate RGB, connect the Blue channel in the first Input of a Mix node set to Screen mode, for the second Input keep the grey color (RGB: 0.5), we do that to avoid to have completely dark areas. Then connect it again to a screen node in the first Input with the RGB 0.5 grey in the second color to make the image a bit brighter. Connect the vertical gradient and top lighting to a Soft Light node and set it to 0.8.
Here is the node setup:
And the current result:
For now it is too bright but we will correct the gamma later.
The curvature will add an hand painted effect to your texture. Add an Input > Geometry and connect the Pointiness output to a Converter > ColorRamp. Move the left cursor at 0.45 and the right at 0.55. Connect the fake lighting and curvature on an Overlay node and set it to 1.
The texture is too bright, by default Blender works in sRGB, it brighten everything, this was ideal for older screens. We need to fix this to have the middle grey displayed with half the luminosity. For that set the RGB node used for the base color to a value of 0.5 in HSV mode or type this Hexadecimal code: 7F7F7F.
The base grey color is now in Linear instead of sRGB, but in order to make it blend correctly with the other effects we need to add a node to set it to sRGB temporarly, for that add a Converter > Gamma, in Color connect the SSS node and in Gamma connect a Converter Math in Divide mode with Value 1: 0.5, Value 2: 2.2.
After the last node add a Converter > Gamma and set it to 2.2:
Here is the final result with the gamma corrected:
You can now tweak the different factor if you want to add more curvature, more lighting effect, etc. Change the amount of blood on organic models and the Inverted AO distance.
To make the Vertical Gradient and Top Lighting effect work correctly, apply the rotation with Ctrl + A.
You can now directly bake your game texture in Emit mode. If you connect it to the base color input of a shader you must bake in Diffuse mode and disable Direct and Indirect lighting in the baking settings.
You can create a node group, I suggest to replace the Input RGB by the Input of the node and to allow to change the amount of blood. The Blood color and the factor of the other settings aren't necessary.