PostEffect class
A custom, user-authored post-processing effect: a fragment shader that reads the current color and writes a new one.
This is the post-processing counterpart of ShaderMaterial. Author a
fragment shader, compile it through the flutter_gpu_shaders build hook
into a .shaderbundle, load it, wrap it in a PostEffect, and add it
to Scene.postProcess.customEffects.
Engine-bound resources
The engine binds the current color to a sampler2D input_color, which
the shader samples at the v_uv varying:
uniform sampler2D input_color;
in vec2 v_uv;
out vec4 frag_color;
void main() { frag_color = texture(input_color, v_uv); }
Set useFrameInfo to also receive a PostFrameInfo block with the
target resolution, texel size, and a seconds time value:
uniform PostFrameInfo {
vec2 resolution;
vec2 texel_size;
float time;
float _pad;
} frame;
Declare your own uniform blocks and textures and set them by name with
setUniformBlock / setTexture, exactly like ShaderMaterial; the
std140 packing rules are the same (see MATERIALS.md).
A PostInsertion.beforeTonemap effect should output linear HDR premultiplied by alpha; a PostInsertion.afterTonemap effect works on the display-referred image.
Constructors
- PostEffect({Shader? fragmentShader, PostInsertion insertion = PostInsertion.beforeTonemap, bool enabled = true, bool useFrameInfo = false})
Properties
- enabled ↔ bool
-
Whether this effect runs. Disabled effects are skipped.
getter/setter pair
- fragmentShader → Shader
-
The fragment shader run for this effect. Set it via the constructor or
setFragmentShader; reading it throws until one is set.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- insertion ↔ PostInsertion
-
Where in the chain this effect runs.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
textureNames
→ Iterable<
String> -
All currently-bound sampler names.
no setter
-
uniformBlockNames
→ Iterable<
String> -
All currently-bound uniform block names.
no setter
- useFrameInfo ↔ bool
-
Whether the engine binds the
PostFrameInfoblock. Set this when the shader declares and uses it.getter/setter pair
Methods
-
bindUniforms(
RenderPass pass, HostBuffer transientsBuffer) → void - Binds this effect's own uniform blocks and textures. Engine-internal.
-
getTexture(
String name) → Texture? -
Reads back a previously-set texture binding, or
null. -
getUniformBlock(
String name) → ByteData? -
Reads back a previously-set uniform block, or
null. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
setFragmentShader(
Shader shader) → void - Assigns the fragment shader run for this effect.
-
setTexture(
String name, Texture? texture, {SamplerOptions? sampler}) → void - Assigns a texture to a sampler uniform by name.
-
setUniformBlock(
String name, ByteData? bytes) → void - Assigns the byte contents of a uniform block by name (std140 layout).
-
setUniformBlockFromFloats(
String name, List< double> floats) → void - Convenience wrapper around setUniformBlock that packs floats.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited