Python: SPG Stateful Node#
An SPG node that reads back its own previous output, so a moving object drags a fading comet
tail behind it. The feedback is one line, history[n] = current[n] + decay * history[n-1]:
fade what you kept last time, add what you were handed this time.
The frame it reads back is memory of the node, stated in the launch script as
self.memory["History"]: SPG keeps it across frames instead of handing out a fresh resource,
and zeroes it when it is created, so the node needs no special case for the first frame.
The run writes two images from the same render step, _output/live.png and
_output/trail.png, through the same node and the same tone map. Everything that differs
between them came from the previous frame.
Prerequisites#
Python 3.10-3.13
An NVIDIA RTX-capable GPU and a supported driver
Running#
uv run main.py # CUDA
uv run main.py --scene trail_scene_slang.usda # Slang
See Keep State Across Frames for what a node’s memory is and how it is stated.