frame_effect

class janim.items.effect.frame_effect.AppliedGroup(*items: Item, root_only: bool = False, **kwargs)

Bases: Item

The base class for classes such as FrameEffect

Provides apply() and discard() methods to mark applying or removing the effect for specified items

add(*objs, prepend=False, insert=None) Self

Warning

Calling add() is unlikely to work as expected.

If you want to apply additional items, use apply().

remove(*objs) Self

Warning

Calling remove() is unlikely to work as expected.

If you want to discard applied items, use discard().

apply(*items: Item, root_only: bool = False) Self

Apply the effect to more items.

discard(*items: Item, root_only: bool = False) Self

Remove the effect from the specified items.

class janim.items.effect.frame_effect.FrameEffect(*items: Item, fragment_shader: str, cache_key: str | None = None, root_only: bool = False, **kwargs)

Bases: AppliedGroup

Applies the passed shader fragment_shader to items

Basic shader format:

#version 330 core

in vec2 v_texcoord; // Input texture coordinates
out vec4 f_color;   // Output color

#[JA_FINISH_UP_UNIFORMS]

void main()
{
    // Perform processing, for example
    f_color = frame_texture(v_texcoord);    // Note: use frame_texture to read texture color (i.e. the rendering result of items)
    f_color.rgb = 1.0 - f_color.rgb;        // Invert colors

    #[JA_FINISH_UP]
}

#[JA_FINISH_UP] is a placeholder where JAnim performs additional operations, and the preceding #[JA_FINISH_UP_UNIFORMS] corresponds to it

The core of the above code is the “processing” part in main, the rest of the code can be copied as fixed patterns

If you don’t want to copy, you can use SimpleFrameEffect, which only requires writing the “processing” part, as it encapsulates the rest of the code

For complete examples, refer to the corresponding code in Basic Examples

renderer_cls

alias of FrameEffectRenderer

apply_uniforms(*, optional: bool = False, **kwargs) None
dynamic_uniforms() dict
class janim.items.effect.frame_effect.SimpleFrameEffect(*items: Item, shader: str, uniforms: Iterable[str] = [], cache_key: str | None = None, root_only: bool = False, **kwargs)

Bases: FrameEffect

Simplified wrapper for FrameEffect, for details refer to the description in FrameEffect

Note

If an error occurs in the shader code, it will be displayed as occurring in JA_SIMPLE_FRAMEEFFECT_SHADER.