The base Effect base class that should be extended when making an effect.

The typical example:

import moderngl
from demosys.effects import Effect
from demosys import geometry

class MyEffect(Effect):
    def __init__(self):
        # Initalization happens after resources are loaded
        self.program = self.get_program("my_program_label")
        self.fullscreen_quad = geometry.quad_fs()

    def post_load(self):
        # Initialization after all effects are initialized

    def draw(self, time, frametime, target):
        # Render a colored fullscreen quad
        self.program["color"].value = (1.0, 1.0, 1.0, 1.0)


Effect.__init__(*args, **kwargs)

Implement the initialize when extending the class. This method is responsible for fetching or creating resources and doing genereal initalization of the effect.

The effect initializer is called when all resources are loaded (with the exception of resources you manually load in the the initializer).

If your effect requires arguments during initialiation you are free to add positional and keyword arguments.

You do not have to call the superclass initializer though super()


def __init__(self):
    # Fetch reference to resource by their label
    self.program = self.get_program('simple_textured')
    self.texture = self.get_texture('bricks')
    # .. create a cube etc ..

Called after all effects are initialized before drawing starts. Some initialization may be neccessary to do here such as interaction with other effects.

This method does nothing unless implemented.

Draw Methods

Effect.draw(time: float, frametime: float, target: moderngl.framebuffer.Framebuffer)

Draw function called by the system every frame when the effect is active. This method raises NotImplementedError unless implemented.

  • time (float) – The current time in seconds.
  • frametime (float) – The time the previous frame used to render in seconds.
  • target (moderngl.Framebuffer) – The target FBO for the effect.

Resource Methods

Effect.get_texture(label: str) → Union[moderngl.texture.Texture, moderngl.texture_array.TextureArray, moderngl.texture_3d.Texture3D, moderngl.texture_cube.TextureCube]

Get a texture by its label

Parameters:label (str) – The Label for the texture
Returns:The py:class:moderngl.Texture instance
Effect.get_program(label: str) → moderngl.program.Program

Get a program by its label

Parameters:label (str) – The label for the program

Returns: py:class:moderngl.Program instance

Effect.get_scene(label: str) → demosys.scene.scene.Scene

Get a scene by its label

Parameters:label (str) – The label for the scene

Returns: The Scene instance


Get a data instance by its label

Parameters:label (str) – Label for the data instance
Returns:Contents of the data file
Effect.get_effect(label: str) → demosys.effects.effect.Effect

Get an effect instance by label.

Parameters:label (str) – Label for the data file

Returns: The Effect instance

Effect.get_effect_class(effect_name: str, package_name: str = None) → Type[demosys.effects.effect.Effect]

Get an effect class by the class name

Parameters:effect_name (str) – Name of the effect class
Keyword Arguments:
 package_name (str) – The package the effect belongs to. This is optional and only needed when effect class names are not unique.
Returns:Effect class
Effect.get_track(name: str) → rocket.tracks.Track

Gets or creates a rocket track. Only avaiable when using a Rocket timer.

Parameters:name (str) – The rocket track name
Returns:The rocket.Track instance

Utility Methods

Effect.create_projection(fov: float = 75.0, near: float = 1.0, far: float = 100.0, aspect_ratio: float = None)

Create a projection matrix with the following parameters. When aspect_ratio is not provided the configured aspect ratio for the window will be used.

  • fov (float) – Field of view (float)
  • near (float) – Camera near value
  • far (float) – Camrea far value
Keyword Arguments:

aspect_ratio (float) – Aspect ratio of the viewport


The projection matrix as a float32 numpy.array

Effect.create_transformation(rotation=None, translation=None)

Creates a transformation matrix woth rotations and translation.

  • rotation – 3 component vector as a list, tuple, or pyrr.Vector3
  • translation – 3 component vector as a list, tuple, or pyrr.Vector3

A 4x4 matrix as a numpy.array


Creates a normal matrix from modelview matrix

Parameters:modelview – The modelview matrix
Returns:A 3x3 Normal matrix as a numpy.array


Effect.runnable = True

The runnable status of the effect instance. A runnable effect should be able to run with the runeffect command or run in a project


The ModernGL context


The Window


The system camera responding to input

Full python path to the effect


The label assigned to this effect instance