Game Development Reference
In-Depth Information
How to do it...
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:
1. First of all, we need to create a new
FilterPostProcessor
instance called
processor
.
2. Add this to the main view port, by calling
viewPort.addProcessor(processor)
from within the application.
3. Then, we create a new bloom filter called
bloomFilter
. The default settings
will produce a decent result, but it might be worth playing around a bit with the
settings.
4. Add the
bloomFilter
to
processor.addFilter(bloomFilter)
and
try it again.
5. Then, we create a new
LightScatteringFilter
instance called
lightSc-
atteringFilter
and add it again to
pro-
cessor.addFilter(lightScatteringFilter)
.
6. This is dependent on a position for the light to scatter, so we need to make it aware
of the sun's location. We can achieve this by adding a new field for the filter in the
SunControl
class from the last recipe along with a setter.
7. Then in the
controlUpdate
method, once we have updated
position
, we
add the following code:
lightScatteringFilter.setLightPosition(position.mult(1000));
8. We still have some tweaking to do as it will now also apply the effect when the sun
is below the ground. To mitigate this, we can disable the filter during nighttime:
if(y > -2f){
if(!lightScatteringFilter.isEnabled()){
lightScatteringFilter.setEnabled(true);
}
lightScatteringFilter.setLightDensity(1.4f);
} else if(lightScatteringFilter.isEnabled()){
lightScatteringFilter.setEnabled(false);
}