Postprocessing
Postprocessing in NGE is anything that happens after the scene has been rendered but before it is displayed on the screen. This includes effects like bloom, depth of field, and more.
Postprocessing effects can be attached to a viewport with a component that implements MainViewPortFragment and overrides the loadMainViewPortFilterPostprocessor
method, from there you can add your desired postprocessing effects to the FilterPostProcessor instance that is passed preconfigured to the method.
Example
public class MyPostProcessingComponent implements Component<Object>, MainViewPortFragment {
@Override
public void loadMainViewPortFilterPostprocessor(AssetManager assetManager, FilterPostProcessor fpp){
// add your postprocessing effects here
// fpp.addFilter(new BloomFilter());
// ....
}
@Override
public void updateMainViewPort(ViewPort viewPort,float tpf) {}
}
Tip
The current version of NGE inherits its postprocessing capabilities from jMonkeyEngine (jME3), you can refer to the jME3 wiki for more info jME3 Postprocessing Documentation.
ToneMap¶
Tone mapping is a postprocessing effect that adjusts the brightness and contrast of a scene to simulate the way cameras capture light. It helps to create a more balanced and visually appealing image, especially in high dynamic range (HDR) scenes.
ToneMapFilter toneMap = new ToneMapFilter();
toneMap.setWhitePoint(1.0f);
fpp.addFilter(toneMap);
Bloom¶
Bloom is a postprocessing effect that simulates the way bright light sources bleed into surrounding areas, creating a glowing effect. It enhances the visual appeal of scenes with bright lights.
BloomFilter bloom=new BloomFilter();
bloom.setDownSamplingFactor(2);
bloom.setBlurScale(1.37f);
bloom.setExposurePower(3.30f);
bloom.setExposureCutOff(0.2f);
bloom.setBloomIntensity(2.45f);
fpp.addFilter(bloom);
Depth of Field¶
Depth of Field (DoF) is a postprocessing effect that simulates the way cameras focus on objects at different distances, blurring out-of-focus areas. It creates a more realistic and cinematic look.
DepthOfFieldFilter dof = new DepthOfFieldFilter();
dof.setFocusDistance(10f);
dof.setFocusRange(5f);
dof.setBlurScale(2f);
fpp.addFilter(dof);
Light Scattering¶
Light scattering simulates volumetric light at a given position
LightScatteringFilter filter = new LightScatteringFilter(lightPos);
fpp.addFilter(filter);
Screen Space Ambient Occlusion (SSAO)¶
Screen Space Ambient Occlusion (SSAO) is a postprocessing effect that simulates the way light interacts with surfaces, creating soft shadows in crevices and corners. It enhances depth perception and realism in scenes.
SSAOFilter ssaoFilter = new SSAOFilter(2.9299974f,32.920483f,5.8100376f,0.091000035f);
ssaoFilter.setApproximateNormals(true);
fpp.addFilter(ssaoFilter);
Fog¶
Fog is a postprocessing effect that adds a layer of fog to the scene, it can be used to create atmospheric effects or to hide distant objects. It can be configured to use different colors and densities.
FogFilter fog = new FogFilter();
fog.setFogColor(ColorRGBA.Gray);
fog.setFogDistance(100f);
fpp.addFilter(fog);
Shadows¶
Shadows in NGE are rendered as post pcrocessing effects. There is one Filter for each type of light source, that can be added to the FilterPostProcessor
instance to render its shadow
light source class | shadow filter class |
---|---|
PointLight | PointLightShadowFilter |
DirectionalLight | DirectionalLightShadowFilter |
SpotLight | SpotLightShadowFilter |
AmbientLight | (not applicable) |
Shadow calculations (cast and receive) have a performance impact, so use them sparingly. You can turn off shadow casting for individual geometries, for portions of the scene graph, or for the entire scene:
spatial.setShadowMode(ShadowMode.Inherit); // This is the default setting for new spatials.
rootNode.setShadowMode(ShadowMode.Off); // Disable shadows for the whole scene, except where overridden.
airplane.setShadowMode(ShadowMode.Cast); // There's nothing above the airplane to cast shadows on it.
ghost.setShadowMode(ShadowMode.Off); // The ghost is translucent: it neither casts nor receives shadows.
More¶
For more postprocessing effects, refer to the Javadoc or the jME3 wiki.
Tip
You can also create your own custom postprocessing effects by extending the Filter
class and implementing the necessary methods. They are screen-space shader effects, not dissimilar to the way materials work, but they are applied to a quad covering the entire screen rather than to individual geometries.