Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public final class PostProcess

  1. Object
  2. PostProcess

Full screen effects applied to a rendered frame: bloom, a colour grade, vignette and film grain. It is what turns a correctly lit scene into one that looks shot through a lens.

The scene is drawn into an offscreen image, the effects are applied, and the result is drawn to the screen. Touch controls are drawn afterwards and are never graded. A device that cannot render offscreen (GpuCapabilities.isPostProcessSupported is false) draws the scene directly and ignores this.

GameView view = new GameView() {
    protected void update(double deltaSeconds) {
    }
};
view.setPostProcess(new PostProcess()
        .setBloom(0.75f, 0.6f)
        .setGrade(1.08f, 0.9f, 0xff0e1a24, 0xfffff1dc)
        .setVignette(0.35f)
        .setGrain(0.04f));

All effects start off, so new PostProcess() changes nothing but the cost of the extra pass.

Fields

public static final String SCENE_COLOR = "cn1SceneColor"The texture name a custom pass reads the frame from.

Constructors

public PostProcess()

Methods

public PostProcess setBloom(float threshold, float intensity)Makes bright parts of the frame glow into their surroundings.
public PostProcess setGrade(float contrast, float saturation, int shadowTint, int highlightTint)Grades the colour of the frame.
public PostProcess setVignette(float amount)Darkens the corners of the frame.
public PostProcess setGrain(float amount)Adds moving film grain.
public float getBloomThreshold()Returns the bloom brightness threshold.
public float getBloomIntensity()Returns the bloom intensity, 0 when bloom is off.
public boolean isBloom()Returns true if bloom is on.
public float getContrast()Returns the contrast multiplier.
public float getSaturation()Returns the saturation multiplier.
public int getShadowTint()Returns the shadow tint as ARGB.
public int getHighlightTint()Returns the highlight tint as ARGB.
public float getVignette()Returns the vignette amount.
public float getGrain()Returns the grain amount.
public PostProcess setChromaticAberration(float amount)Splits the colour channels toward the edges of the frame, the fringe of a cheap lens.
public float getChromaticAberration()Returns the chromatic aberration amount.
public PostProcess setFxaa(boolean on)Smooths jagged edges with FXAA, a single full screen pass that finds edges by contrast and blends along them.
public boolean isFxaa()Returns true when FXAA is on.
public PostProcess setGodRays(float strength)Light shafts from the sun: bright parts of the frame (sky, a sunlit wall) are smeared radially from where the sun sits on screen, so they stream past whatever stands in front of it.
public float getGodRays()Returns the god ray strength.
public PostProcess setAmbientOcclusion(float strength, float radiusPixels)Darkens creases and contact points from the depth of the frame (screen space ambient occlusion), so objects sit on the ground instead of floating over it.
public float getAmbientOcclusion()Returns the ambient occlusion strength.
public float getAmbientOcclusionRadius()Returns the ambient occlusion radius in pixels.
public PostProcess setDepthOfField(float focusDistance, float blurPixels)Blurs what is nearer or farther than the focus distance, as a camera lens with a wide aperture does.
public float getFocusDistance()Returns the focus distance.
public float getDepthOfFieldBlur()Returns the widest depth of field blur in pixels.
public PostProcess setOutline(float strength, int argb)Draws a line where the depth of the frame jumps, around silhouettes and creases, for a toon or ink look.
public float getOutline()Returns the outline strength.
public int getOutlineColor()Returns the outline colour.
public PostProcess setColorLut(Texture table, float strength)Maps every colour through a lookup table after the grade, the way a film look is applied in a colour grading tool.
public Texture getColorLut()Returns the lookup table, or null.
public float getColorLutStrength()Returns the lookup table strength, 0 when there is no table.
public boolean isDepthEffects()True when an effect reads the depth of the frame: ambient occlusion, depth of field or outline.
public PostProcess addPass(ShaderMaterial pass)Adds a full screen effect of your own, written with the same com.codename1.gpu.shader.ShaderNode graphs as a material.
public PostProcess clearPasses()Removes every pass addPass added.
public int getPassCount()Returns how many custom passes there are.
public ShaderMaterial getPass(int index)Returns a custom pass.

Inherited methods

Field details

SCENE_COLOR

public static final String SCENE_COLOR = "cn1SceneColor"
The texture name a custom pass reads the frame from. addPass declares it on the pass; read it with com.codename1.gpu.shader.ShaderNode.sceneColor.

Constructor details

PostProcess

public PostProcess()

Method details

setBloom

public PostProcess setBloom(float threshold, float intensity)
Makes bright parts of the frame glow into their surroundings.

Parameters

threshold float
how bright a pixel must be to glow, from 0 to 1 of its brightest channel; lower glows more of the frame
intensity float
how strong the glow is; 0 turns bloom off

Returns

this post process for chaining

setGrade

public PostProcess setGrade(float contrast, float saturation, int shadowTint, int highlightTint)
Grades the colour of the frame.

Parameters

contrast float
1 leaves it, above 1 deepens shadows and brightens highlights
saturation float
1 leaves it, 0 is greyscale
shadowTint int
the colour the darkest tones are lifted toward, as ARGB; black leaves them
highlightTint int
the colour the brightest tones are multiplied by, as ARGB; white leaves them

Returns

this post process for chaining

setVignette

public PostProcess setVignette(float amount)
Darkens the corners of the frame.

Parameters

amount float
0 for none, 1 for black corners

Returns

this post process for chaining

setGrain

public PostProcess setGrain(float amount)
Adds moving film grain.

Parameters

amount float
0 for none; 0.03 to 0.06 reads as film

Returns

this post process for chaining

getBloomThreshold

public float getBloomThreshold()
Returns the bloom brightness threshold.

getBloomIntensity

public float getBloomIntensity()
Returns the bloom intensity, 0 when bloom is off.

isBloom

public boolean isBloom()
Returns true if bloom is on.

getContrast

public float getContrast()
Returns the contrast multiplier.

getSaturation

public float getSaturation()
Returns the saturation multiplier.

getShadowTint

public int getShadowTint()
Returns the shadow tint as ARGB.

getHighlightTint

public int getHighlightTint()
Returns the highlight tint as ARGB.

getVignette

public float getVignette()
Returns the vignette amount.

getGrain

public float getGrain()
Returns the grain amount.

setChromaticAberration

public PostProcess setChromaticAberration(float amount)
Splits the colour channels toward the edges of the frame, the fringe of a cheap lens. Subtle values sell an action camera; strong ones a hit or a glitch.

Parameters

amount float
0 for none; 0.004 to 0.01 is subtle

Returns

this post process for chaining

getChromaticAberration

public float getChromaticAberration()
Returns the chromatic aberration amount.

setFxaa

public PostProcess setFxaa(boolean on)
Smooths jagged edges with FXAA, a single full screen pass that finds edges by contrast and blends along them. Cheaper than multisampling and it also smooths edges inside textures and shaders.

Parameters

on boolean
true to smooth

Returns

this post process for chaining

isFxaa

public boolean isFxaa()
Returns true when FXAA is on.

setGodRays

public PostProcess setGodRays(float strength)
Light shafts from the sun: bright parts of the frame (sky, a sunlit wall) are smeared radially from where the sun sits on screen, so they stream past whatever stands in front of it. The sun’s position comes from the scene’s light and camera each frame; the shafts fade out as the sun leaves the screen or drops behind the camera.

Parameters

strength float
0 for none; 0.3 to 0.8 for visible shafts

Returns

this post process for chaining

getGodRays

public float getGodRays()
Returns the god ray strength.

setAmbientOcclusion

public PostProcess setAmbientOcclusion(float strength, float radiusPixels)
Darkens creases and contact points from the depth of the frame (screen space ambient occlusion), so objects sit on the ground instead of floating over it.

Parameters

strength float
0 for none; 0.5 to 1 for visible contact shadows
radiusPixels float
how far around each pixel to look, in pixels

Returns

this post process for chaining

getAmbientOcclusion

public float getAmbientOcclusion()
Returns the ambient occlusion strength.

getAmbientOcclusionRadius

public float getAmbientOcclusionRadius()
Returns the ambient occlusion radius in pixels.

setDepthOfField

public PostProcess setDepthOfField(float focusDistance, float blurPixels)
Blurs what is nearer or farther than the focus distance, as a camera lens with a wide aperture does.

Parameters

focusDistance float
the distance from the camera that stays sharp, in world units
blurPixels float
the widest blur, in pixels; 0 turns depth of field off

Returns

this post process for chaining

getFocusDistance

public float getFocusDistance()
Returns the focus distance.

getDepthOfFieldBlur

public float getDepthOfFieldBlur()
Returns the widest depth of field blur in pixels.

setOutline

public PostProcess setOutline(float strength, int argb)
Draws a line where the depth of the frame jumps, around silhouettes and creases, for a toon or ink look.

Parameters

strength float
0 for none, 1 for solid lines
argb int
the line colour

Returns

this post process for chaining

getOutline

public float getOutline()
Returns the outline strength.

getOutlineColor

public int getOutlineColor()
Returns the outline colour.

setColorLut

public PostProcess setColorLut(Texture table, float strength)
Maps every colour through a lookup table after the grade, the way a film look is applied in a colour grading tool. The table is a 256 by 16 strip of 16 squares: square b holds blue b / 15, and inside it the column is red and the row (from the top) green, both 0 to 15. ColorLuts builds such strips.

Parameters

table Texture
the lookup strip, or null for none
strength float
0 keeps the graded colour, 1 uses the table’s

Returns

this post process for chaining

getColorLut

public Texture getColorLut()
Returns the lookup table, or null.

getColorLutStrength

public float getColorLutStrength()
Returns the lookup table strength, 0 when there is no table.

isDepthEffects

public boolean isDepthEffects()
True when an effect reads the depth of the frame: ambient occlusion, depth of field or outline.

addPass

public PostProcess addPass(ShaderMaterial pass)

Adds a full screen effect of your own, written with the same com.codename1.gpu.shader.ShaderNode graphs as a material. The pass’s ShaderMaterial.Hook.BASE_COLOR graph is evaluated for every pixel of the frame: ShaderNode.screenUv() is the pixel’s place on screen (0,0 top left) and ShaderNode.sceneColor(uv) reads the frame as it stands so far. Its own uniforms, textures and ShaderNode.time() work as on any material.

import com.codename1.gpu.PostProcess;
import com.codename1.gpu.shader.ShaderMaterial;
import com.codename1.gpu.shader.ShaderNode;

PostProcess post = new PostProcess();
ShaderNode uv = ShaderNode.screenUv();
ShaderNode wobble = ShaderNode.sin(uv.y().mul(ShaderNode.f(40f)).add(ShaderNode.time()))
        .mul(ShaderNode.f(0.004f));
post.addPass(new ShaderMaterial().set(ShaderMaterial.Hook.BASE_COLOR,
        ShaderNode.sceneColor(uv.add(ShaderNode.vec(wobble, ShaderNode.f(0f))))));

Passes run in the order they were added, each reading the one before, and the built-in effects run on the result. The depth based effects (isDepthEffects) read the depth of the scene, which a pass does not have, so they are left out of a frame with passes. A device that cannot draw offscreen draws the scene without the passes.

Parameters

pass ShaderMaterial
a shader material with a BASE_COLOR graph

Returns

this post process for chaining

clearPasses

public PostProcess clearPasses()
Removes every pass addPass added.

Returns

this post process for chaining

getPassCount

public int getPassCount()
Returns how many custom passes there are.

getPass

public ShaderMaterial getPass(int index)
Returns a custom pass.

Parameters

index int
0 for the first pass added

Returns

the pass