22Effects
33=======
44
5- In order to draw something to the screen using this framework you need to make one or
6- multiple effects. what these effects are doing is entirely up to you. Some like to
5+ In order to actually draw something to the screen you need to make one or
6+ multiple effects. What these effects are doing is entirely up to you. Some like to
77put everything into one effect and switch what they draw by flipping some internal
88states, but this is probably not practical for more complex things.
99
10- An effect is a class with references to resources and a method for drawing.
11- An effect is an independent python package of specific format.
10+ An effect is a class with references to resources such as shaders, geometry, fbos and textures
11+ and a method for drawing. An effect is an independent python package of specific format.
1212
1313The Effect Package
1414^^^^^^^^^^^^^^^^^^
1515
16- The effect package should have the following structure (assuming our effect is named "cube".
16+ The effect package should have the following structure (assuming our effect is named "cube") .
1717
1818.. code-block :: bash
1919
@@ -26,20 +26,29 @@ The effect package should have the following structure (assuming our effect is n
2626 └── cube
2727 └── ...
2828
29- The ``effect.py `` module is where the draw logic for the effect resides. Directories at the
30- same level are for resources for the effect. Notice that the resource directories contains
31- another directory with the name of the effect. This is because these folders are added to
32- a virtual directory (for each resource type) so we should place it in a directory to
33- reduce the change of name collisions. Two effects with the texture ``texture.png `` in
34- the root of their local ``textures/ `` directory will cause the first effect to
29+ The ``effect.py `` module is the actual code for the effect. Directories at the
30+ same level are for local resources for the effect.
31+
32+ .. Note :: Notice that the resource directories contains another sub-directory with
33+ the same name as the effect. This is because these folders are added to
34+ a **virtual directory ** (for each resource type), so we should place it in a directory to
35+ reduce the chance of a name collisions.
36+
37+ .. Note :: Two effects with the texture name ``texture.png`` in
38+ the root of their local ``textures/ `` directory will cause a name collision were
39+ the texture from the first registered effect will be used in both effects.
40+ This can be used to override resources intentionally.
41+
42+ We can also decide not to have any effect-local resources and configure
43+ a project-global resource directory. More about this in :doc: `settings `.
3544
3645Registry
3746^^^^^^^^
3847
39- For an effect to be recognised by the system it has to be registered
48+ For an effect to be recognised by the system, it has to be registered
4049in the ``EFFECTS `` tuple/list in your settings module.
4150Simply add the full python path to the package. If our cube example
42- above resides inside a ``myproject `` project package we need to add
51+ above is located inside a ``myproject `` project package we need to add
4352the string ``myproject.cube ``. See :doc: `settings `.
4453
4554You can always run a single effect by using the ``runeffect `` command.
@@ -48,7 +57,7 @@ You can always run a single effect by using the ``runeffect`` command.
4857
4958 ./manage.py runeffect myproject.cube
5059
51- If you have multiple effects you need to crate or use an existing :doc: `effectmanagers `
60+ If you have multiple effects, you need to crate or use an existing :doc: `effectmanagers `
5261that will decide what effect would be active at what time or state.
5362
5463Resources
@@ -64,24 +73,24 @@ resource finders in :doc:`settings`.
6473The Effect Module
6574^^^^^^^^^^^^^^^^^
6675
67- The effect module in an effect package needs to be named ``effect.py `` and
68- reside in the root of the package. It can only contain a single effect
76+ The effect module needs to be named ``effect.py `` and
77+ located in the root of the effect package. It can only contain a single effect
6978class. The name of the class doesn't matter right now, but we are
7079considering allowing multiple effects in the future, so giving it
71- at least a descriptive name of that it represents is a good idea.
80+ at least a descriptive name is a good idea.
7281
7382There are two important methods in an effect:
83+
7484- ``__init__() ``
75- - draw()
85+ - `` draw() ``
7686
77- The **initializer ** is called before resources are loaded. This is so the
78- effects can register the what resources they need. The resource
87+ The **initializer ** is called before resources are loaded. This way the
88+ effects can register the resources they need. The resource
7989managers will return an empty object that will be populated when
8090loading starts.
8191
82- The **draw ** method is called by the framework or from a your custom
83- :doc: `effectmanagers ` ever frame, or at least every frame the manager
84- decides the effect should be active at least.
92+ The ``draw `` method is called by the configured `EffectManager`` (see :doc: `effectmanagers `)
93+ ever frame, or at least every frame the manager decides the effect should be active.
8594
8695The standard effect example:
8796
@@ -121,20 +130,24 @@ The standard effect example:
121130
122131 The parameters in the draw effect is:
123132
124- - ``time ``: The current time reported by our configured Timer in seconds.
133+ - ``time ``: The current time reported by our configured `` Timer `` in seconds.
125134- ``frametime ``: The time a frame is expected to take in seconds.
126- This is useful when you cannot use `` time `` . Should be avoided.
135+ This is useful when you cannot use time. Should be avoided.
127136- ``target `` is the target FBO of the effect
128137
129- Time can potentially move at any speed or direction so it's good practice
138+ Time can potentially move at any speed or direction, so it's good practice
130139to make sure the effect can run when time is moving in any direction.
131140
132141The ``bind_target `` decorator is useful when you want to ensure
133142that an FBO passed to the effect is bound on entry and released on exit.
134- By default a fake FBO is passed in representing the window framebuffer .
143+ By default a fake FBO is passed in representing the window frame buffer .
135144EffectManagers can be used to pass in your own FBOs or another effect
136145can call ``draw(..) `` requesting the result to end up in the FBO it passes in
137- and then use this FBO as a texture on a cube.
146+ and then use this FBO as a texture on a cube or do post processing.
147+
148+ As we can see in the example, the ``Effect `` base class have a couple
149+ of convenient methods for doing basic matrix math, but generally you
150+ are expected do to these calculations yourself.
138151
139152Effect Base Class
140153^^^^^^^^^^^^^^^^^
0 commit comments