In the Creating dynamic skybox with moving sun recipe, we created a dynamic skybox that has many applications. It's possible to improve the appearance of this (and any other) scene significantly with postprocessing filters. They are called postprocessing filters because they are applied after the scene has already been rendered. This also makes them affect everything in the scene.
We also covered how to create an advanced postfilter in Chapter 1, SDK Game Development Hub.
The sun we have is now moving across the sky. It has very sharp edges and we can use a bloom filter to smooth it out a bit. Perform the following steps to improve a scene with the help of postprocessing filters:
FilterPostProcessor
instance called processor
.viewPort.addProcessor(processor)
from within the application.bloomFilter
. The default settings will produce a decent result, but it might be worth playing around a bit with the settings.bloomFilter
to processor.addFilter(bloomFilter)
and try it again.LightScatteringFilter
instance called lightScatteringFilter
and add it again to processor.addFilter(lightScatteringFilter)
.SunControl
class from the last recipe along with a setter.controlUpdate
method, once we have updated position
, we add the following code:lightScatteringFilter.setLightPosition(position.mult(1000));
if(y > -2f){ if(!lightScatteringFilter.isEnabled()){ lightScatteringFilter.setEnabled(true); } lightScatteringFilter.setLightDensity(1.4f); } else if(lightScatteringFilter.isEnabled()){ lightScatteringFilter.setEnabled(false); }
The FilterPostProcessor
acts as a container for the filters and applies them to the rendered result. Several filters can be added to the same processor and the order matters. If we add LightScatteringFilter
before bloomFilter
, we will get bloom applied to the light scattering and vice versa.
The bloomFilter
works by blurring the image slightly and intensifying colors, making the result appear a bit softer. Bloom filters work best with tweaking and shouldn't just be slapped on to the scene. It's easy to be impressed by the initial effect and leave it at that but it should always be adapted to the art style of the game. A fantasy game in an enchanted forest might get away with more bloom than a hard-boiled cyberpunk shooter.
The LightScatteringFilter
instance does two things. Firstly, it creates a halo of rays emanating from the direction of the light source. Secondly, if the camera is pointing towards the light source, it will whiteout the image increasingly, simulating glare.
In a normal skybox, the sun would be static but in this example the sun keeps moving. By supplying the filter to SunControl
, we could keep the logic to update the position within that class. We will also get some weird effects as the glare will still show. The easy way out is to simply turn off the effect as the sun gets below the horizon.
3.145.191.134