For the final part of this guide I will write about the few things I added to the material and my approach to do outlines which take in account the base color.
This part is optional you already have everything you need.
If you are still interested continue reading this part will have more pictures in it. :>
This is the whole basic material. There is not much stuff in it yet and it’s up to you to extend it. On the left side we can see the color parameter or the base texture. Let’s component mask it so we don’t include our alpha in further calculations. The alpha goes directly into opacity / opacity mask. Even if the output pin is deactivated we can still make use of it later by overwriting the blending model inside of the material instance.
For the normal input either plug in a normal map or leave it at default (0, 0, 1). You could also do static switches for baseTexture and normalMap that switch between color input and texture input.
Create parameters for Specular, Metallic, Roughness and Smoothness and plug them into their pins. Smoothness goes into the ClearCoat pin.
The fresnel gets connected as above. For it’s values I used exponent: 2.0 and base reflect fraction: 0.0. The smoothstep node doesn’t exist so we have to create it ourselves. Add a custom node and set it’s output type to float1. Add two inputs. Add the following code into it:
return smoothstep(0.5 - Threshold, 0.5 + Threshold, IN);
The multiply after this takes the base color / texture we masked as second input. Also add another scalar parameter called FresnelIntensity so that we can turn down it’s value.
For the colored shadow add a scalar parameter called ColoredShadow. This will control how much color will be added to the emissive. Keep in mind the closer rgb gets to 1 the smaller the effect of the power node will be. (Multiplying 1 x 1 = 1) Play around with the exp value of the power node. For me a value of 2.5 looked best for characters having light skin tone textures.
Lastly add the results of fresnel and colored shadow together and plug them into the emissive input. As you might have guessed this will make not only the shadow brighter but also the base texture but for now I don’t know of a better way to colorize shadows except doing that in a post process by somehow faking the calculated light.
Now for the colored outlines. This is basically a modified version of the outline highlighter post process that Epic used in the example content.
This part is for creating the offset of the outline. If you ever did any sobel outline or bluring or something similar you should be familiar with the concept. By comparing the basic renderTexture to offsetted versions of it we can find out the difference between neighbouring pixels.
Here we will do exactly that to compare the scene depth. We use the scene depth instead of the custom depth so that our outlines are not rendered in front of other geometry.
This part is quite a mess. We offset the base color and the custom depth. The custom depth is used as a mask for the color so that we can separate the objects that should have the outline from the ones that shouldn’t. I decided to combine the colors by using the max node so that the brighter color will prevail. Once we have the offsetted colored silhouette of the base color we do some calculations to make it darker. We also combine and clamp all the custom depths to make a mask of the colored area. This part is probably not optimal as it uses quite a lot of texture lookups but I don’t now another way around it so if someone has a suggestion feel free to post a comment. :>
The final part of the post process is simple: We multiply the lower half with the custom depth mask we just created and use this as alpha for a lerp between our outline color and a SceneTexture that renders the scene as it is (PostProcessInput0). At the end we plug in everything into our emissive pin.
And that’s it. We created a custom shading model, wrote it’s shader code, made changes to it’s material and set up an outline. I hope someone finds this helpfulsomehow and would feel glad for any feedback may that be suggestions, critique or additions.