Today I started working on a fake volumetric particle shader that simulates lights from six directions. I wanted to make some improvements to just using the default lit particle shading in unreal, its nice but has a very flat appearance.
The first thing I did was add contrast and gamma controls for the user in order to quite drastically alter the amount of light that appears to hit parts of the billboard. This gives us the ability to make quite different looking particle effects from the same texture sheet. This is particularly important as this technique requires two textures and therefore is more memory intensive than a single flipbook sheet.
I just used a contrast node in UE4, here’s the contrast being adjusted. Contrast tends towards extremes, lengthening the distance between the darkest blacks and brightest whites.
For gamma I just raised the texture to a power. This tends to affect midtones more. A higher gamma value boosts the darker parts of the image, while one less than 0 make the dark regions lighter. Default gamma for most displays is 2.2, but a value of 1.2 was pretty nice. I’d done some gamma correction in Houdini which might be throwing things off.
This is the interesting part! To create that volumetric look, we want to know how far from our imaginary 6 lights that each pixel of the billboard is, in order to determine its intensity.
To do that, we take the texture, and dot it with a unit vector. As the texture is not normalized, we are projecting the texture onto the light direction which returns the length of that projection.
Diving the texture by this result gives us varied intensity based on distance – when the pixel is receiving less light (based on the texture), the intensity is raised.
Here’s what the effect with adjusted gamma and contrast looks like with and without the light direction adjustment.
The current result looks something like this! Next is figuring out how to blend my textures with the particle colour!