Part 3: Making it glow! For this tutorial we'll start with a new, completely blank material.
In he beginning we'll figure out how to make a simple blink effect, combine that with an emissive texture, spice up the result with other textures, and finally refine the effect to make it look a bit more natural.
The materials we've created before were constant materials, they looked exactly the same independently of what time you looked at them.
The blink effect differs from those, as it changes the appearance of the mesh based on the game time.
For this purpose, the editor provides a "Time" node, which has exactly one float output, the current time.
The time value is a monotonically increasing value (for every frame that the game renders it's guaranteed to be larger than it was in the previous frame).
When you connect the Time node to the material color outputs (ie. Diffuse or Emissive) the material will become completely white.
This is because the Time value is so large that all color components will become saturated (> 1.0).
To make the passage of time visible, we'll have to reduce this value somehow.
Since we're trying to implement a blink effect (which can be described as a periodicically dimming and brightening light), we need a node that implements some kind of periodic function.
The functions implemented by the engine (Sine, Cosine, Frac (Sawtooth), Rectangle (Square), TriangleWave nodes) can be summarized in this image:
We can see that except for sine and its buddy cosine, all waveforms look "artificial", so we'll use Sine for this tutorial.
(Feel free to experiment with the others though!)
Thus a simple blink effect can be achieved by chaining a Sine and Time node together, and feeding its output to the Diffuse input like this:
After this, the material will periodically brighten and dim, however it'll stay completely black for a long period of time.
This is because the range of output values of the Sine wave is [-1, 1] by default, and every color below 0 is black.
To change this, select the Sine node and change its Minimum property to 0 instead of -1.
So far we've created a Sine wave illuminates the whole object. To make it only illuminate certain parts we'll need to add a texture that masks out certain parts and defines color values for others; in D:OS these are called glow maps (with _GM at the end of their names) - I'm going to use the HUM_Waypointshrine_Symbol_Earth_A_GM texture in this tutorial.
The desired effect can be achieved by multiplying the output of the Sine wave with the Texture color like this:
The result:
Now that the blinking part is done we can also connect the usual textures for the material:
Texture node (HUM_Waypointshrine_Symbol_Earth_A_DM) connects to the Diffuse input
Texture node (HUM_Waypointshrine_Symbol_Earth_A_SM) connects to the Specular input
Texture node (HUM_Waypointshrine_Symbol_Earth_A_NM) connects to the Normal input
We're already using HUM_Waypointshrine_Symbol_Earth_A_GM in the blinking part of the material, so let's connect the output of the blinking Multiply node to the Emissive input.
Note: Just like in the previous tutorial, you can select the HUM_Waypointshrine_Symbol_Earth_A mesh as a Custom mesh for the preview pane for extra immersion!
The end result should look like this:
While the blink effect looks nice, the timing is completely predictable, so let's make it a bit more random.
The current expression we're multiplying the glow texture with is a simple
sin(time) function.
To give it the illusion of randomness we'll combine multiple sine/cosine expressions.
There are lots of sine/cosine/multiply/add/clamp/etc. node combinations that'll yield good results, for this tutorial I've just added some sine waves with different periods and tweaked the numbers until it seemed OK.
(Making stuff "look right" is not exactly straightforward, you'll often have to experiment with different values and expressions to get the result you want.)
Google can be very helpful for this, as it'll do a 2D/3D plot for any function you input.
The one we're using is this:
sin(time*0.07) * sin(time*0.25) + sin(time*0.5)Larger multipliers for the Sine function will increase the flickering speed, smaller multipliers will reduce it.
Changing the Min/Max value for the Sine function will affect the intensity of the emitted light; with the default (-1 to 1) range it'll stay completely bright or dark most of the time, while with eg. (-0.1 to 0.4) it'll use intermediate intensity values more frequently.
The resulting material and preview: