Sprint 4 FlickerLightComponent - UQdeco2800/2021-studio-6 GitHub Wiki

Overview

In order to attempt to recreate a realistic light source in-game, time had gone in to develop a specific component to emulate this effect as best as possible. The general reasoning behind this is to add 'juiciness' to the game in the form of an immersive visual feature. This also helps to make the game more dynamic and the environment more engaging and interactive. Before work began on the component, a brief amount of research was conducted into similar ideas, the most noteworthy piece being an article about '“Reverse engineering” a real candle' (https://cpldcpu.wordpress.com/2016/01/05/reverse-engineering-a-real-candle/) that proved the main inspiration. With an added insight into the pattern and behaviour of realistic lighting,

The Component

It was devised that the component would consist of multiple PointLights of set colours with randomly oscillating light ranges would best achieve the look of realistic lighting. As such, FlickerLightComponent features 4 PointLights that are set are varying distances radiating outwards. Due to the limitations of the lighting engine, distance and colour are really the only two variables of a light source that can be effected. Each one is given a different colour and a distance so that while some of them (namely, the large lights) might overlap, all of the borders remain clear between the lights. With the lights created, the main part comes in the update() function where the distances of the lights are changed. Here, Rand() is used to calculate a small float value to either incremenet or decrement the light distance by. By increasing and decreasing it by this small and random values, the transition of the sizes feels smoother and more natural than just setting distances to different values. To improve the realism of the flicker, Rand() is also used to set the time between changes of the light. This way, the time between each distance change is different and unpredictable. This helps to replicate the randomly oscillating pattern of realistic lighting. Once all of the four different coloured lights start randomly changing their values by a random distance at randomly calculated time intervals, the full flicker light comes together.

How to use it

Using it is relatively simple, as it functions much in the same way that a normal PointLightComponent works. The only difference is in the constructor, where FlickerLightComponent(Color colorOut, Color colorBase, Color colorMid, Color colorInner, float distance, float offsetx, float offsety) requrires additional colours. Here, distance, offsetx and offsety function identical to PointLightComponent, with distance representing the largest of the light distances. Differing are the colours, where colorOut is the furtherest light, colorBase the second furtherest, colorMid being closer to the entity and colorInner being the closest light source. To get the most realistic effect, all these colours should be very close in the colour wheel and similar for the purpose at hand. For flame flicker, a mixture of orange and red tones normally works best.

image