Python: SPG Grayscale#
The “hello world” of Sensor Processing Graphs. A custom CUDA kernel converts the renderer’s
LdrColor AOV to grayscale entirely on the GPU and publishes the result as a new
LdrGrayscale AOV. This is the minimal three-file SPG shader (.cu kernel, .cu.lua
launch script, .usda shader definition) wired into a RenderProduct.
“Create the smallest useful SPG example: a CUDA kernel that converts the LdrColor render output to grayscale, wired into a RenderProduct and read back from Python as a new AOV.”
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 grayscale_scene_slang.usda # Slang
The first step compiles the kernel and can block for up to 5 minutes on a fresh
shader cache. A successful run writes _output/input.png and _output/grayscale.png, which
is the same image with the colour taken out.
See the SPG reference for every Lua function and USD attribute you can author.