Skip to content

Commit 67c2815

Browse files
committed
Basic effect docs
1 parent 3b6944d commit 67c2815

File tree

4 files changed

+82
-4
lines changed

4 files changed

+82
-4
lines changed

demosys/effects/effect.py

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33

44

55
def bind_target(func):
6-
"""Decorator auto binding and releasing the incoming FBO"""
6+
"""
7+
Decorator auto binding and releasing the incoming FBO in ``draw()``.
8+
9+
literal blocks::
10+
11+
@bind_target
12+
def draw(...):
13+
# draw stuff
14+
"""
715
def func_wrapper(*args, **kwargs):
816
args[3].bind()
917
func(*args, **kwargs)
@@ -12,6 +20,15 @@ def func_wrapper(*args, **kwargs):
1220

1321

1422
class Effect:
23+
"""Effect base class.
24+
25+
The following attributes are injected by demosys before initialization:
26+
27+
* window_width (int): Window width in pixels
28+
* window_height (int): Window height in pixels
29+
* window_aspect (float): Aspect ratio of the resolution
30+
* sys_camera (demosys.scene.camera.Camera): The system camera responding to inputs
31+
"""
1532
# Window properties set by controller on initialization
1633
name = ""
1734
window_width = 0
@@ -21,22 +38,61 @@ class Effect:
2138

2239
# Methods to override
2340
def draw(self, time, frametime, target):
41+
"""Draw function called by the system every frame.
42+
43+
:param time: The current time in seconds (float)
44+
:param frametime: The number of milliseconds the frame is expected to take
45+
:param target: The target FBO for the effect
46+
"""
2447
raise NotImplemented
2548

2649
# Methods for getting resources
2750

2851
def get_shader(self, path):
52+
"""
53+
Get a shader or schedule the shader for loading.
54+
If the resource is not loaded yet, an empty shader object
55+
is returned that will be populated later.
56+
57+
:param path: Path to the shader in the virtual shader directory
58+
:return: Shader object
59+
"""
2960
return resources.shaders.get(path, create=True)
3061

3162
def get_texture(self, path):
63+
"""
64+
Get a shader or schedule the texture for loading.
65+
If the resource is not loaded yet, an empty texture object
66+
is returned that will be populated later.
67+
68+
:param path: Path to the texture in the virtual texture directory
69+
:return: Texture object
70+
"""
3271
return resources.textures.get(path, create=True)
3372

3473
def get_track(self, name):
74+
"""
75+
Get or create a rocket track. This only makes sense when using rocket timers.
76+
If the resource is not loaded yet, an empty track object
77+
is returned that will be populated later.
78+
79+
:param name: The rocket track name
80+
:return: Track object
81+
"""
3582
return resources.tracks.get(name)
3683

3784
# Utility methods for matrices
3885

3986
def create_projection(self, fov=75.0, near=1.0, far=100.0, ratio=None):
87+
"""
88+
Create a projection matrix with the following parameters.
89+
90+
:param fov: Field of view (float)
91+
:param near: Camera near value
92+
:param far: Camrea far value
93+
:param ratio: Aspect ratio of the window
94+
:return: The projection matrix
95+
"""
4096
return matrix44.create_perspective_projection_matrix(
4197
fov,
4298
ratio or self.window_aspect,
@@ -64,7 +120,13 @@ def create_transformation(self, rotation=None, translation=None):
64120
return mat
65121

66122
def create_normal_matrix(self, modelview):
67-
"""Convert to mat3 and return inverse transpose"""
123+
"""
124+
Convert to mat3 and return inverse transpose.
125+
These are normally needed when dealing with normals in shaders.
126+
127+
:param modelview: The modelview matrix
128+
:return: Normal matrix
129+
"""
68130
normal_m = Matrix33.from_matrix44(modelview)
69131
normal_m = normal_m.inverse
70132
normal_m = normal_m.transpose()

docs/source/conf.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,15 @@
2121
# import sys
2222
# sys.path.insert(0, os.path.abspath('.'))
2323

24+
import os
2425
import sphinx.environment
2526
from docutils.utils import get_source_line
2627

2728

29+
# Define a settings module
30+
os.environ['DEMOSYS_SETTINGS_MODULE'] = 'demosys.conf.default_settings'
31+
32+
2833
# Monkey patch sphinx to ignore: WARNING: nonlocal image URI
2934
def _warn_node(self, msg, node, **kwargs):
3035
if not msg.startswith('nonlocal image URI found:'):
@@ -65,9 +70,9 @@ def _warn_node(self, msg, node, **kwargs):
6570
# built documents.
6671
#
6772
# The short X.Y version.
68-
version = '0.3.5'
73+
version = '0.3.6'
6974
# The full version, including alpha/beta/rc tags.
70-
release = '0.3.5'
75+
release = '0.3.6'
7176

7277
# The language for content autogenerated by Sphinx. Refer to documentation
7378
# for a list of supported languages.

docs/source/effects.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
Effects
3+
=======
4+
5+
Effect documentation
6+
7+
.. autoclass:: demosys.effects.effect.Effect
8+
:members: draw, get_shader, get_texture, get_track, create_projection, create_transformation, create_normal_matrix
9+
10+
.. autofunction:: demosys.effects.effect.bind_target

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ time creating all the tooling to get things up and running.
3030
quickstart
3131
controls
3232
settings
33+
effects
3334
tempnotes
3435

3536
Indices and tables

0 commit comments

Comments
 (0)