Python: SPG Generating Node#

An SPG node with no input AOV at all. Every value it needs is a typed USD attribute, and it draws a checkerboard into its own output, which the scene publishes as Checker.

Running#

uv run main.py                                   # CUDA
uv run main.py --scene checker_scene_slang.usda  # Slang

The first step compiles the kernel and can take up to 5 minutes on a cold shader cache. A successful run writes _output/checker.png: 64-pixel squares in white and dark blue, the size and colours the scene authors.

The Node#

-- Launch script for a node with no resource-input.
--
-- There is no input descriptor to take a shape
-- from. The size comes from typed USD attributes instead, like every other
-- value the node uses.
function checker(inputs, outputs)
    local width  = inputs["width"].value
    local height = inputs["height"].value
    assert(width > 0 and height > 0, "width and height must be positive")
    assert(inputs["squareSize"].value > 0, "squareSize must be positive")

    outputs["Checker"] = cuda.image(width, height, cuda.uchar4)

    return cuda.kernel({
        args = {
            cuda.int(width),                        -- -> int width
            cuda.int(height),                       -- -> int height
            cuda.int(inputs["squareSize"]),         -- -> int squareSize
            cuda.array(inputs["colorA"]),           -- -> const float* colorA
            cuda.array(inputs["colorB"]),           -- -> const float* colorB
            cuda.SurfaceObject(outputs["Checker"]), -- -> cudaSurfaceObject_t output
        },
        block = { 16, 16 },
        grid  = { math.ceil(width / 16), math.ceil(height / 16) },
    })
end

Refer to Write a Node With No Input for what a node without an input can and cannot assume.