Shader#
A shader definition shared by materials: surface model, exposed parameter declarations and defaults. Create one through plupy.data.shaders; assign it using material.props["material.shader"] = shader. Edit defaults through shader.props["shader.default.<name>"]; materials with their own values keep those overrides. Node editing is available in the editor's Nodes workspace, not through this handle.
class Shader(DataBlock)Inherits DataBlock: its members are documented there.
Usage and examples
Members: surface_model · render_mode · source · parameters · set_code
surface_model#
surface_model -> str # read-onlyThe engine surface model's stable identifier, such as lit or unlit. Custom Slang shaders support lit, unlit and liquid.
render_mode#
render_mode -> str | None # read-onlyCustom surface coverage: opaque, cutout or transparent; None for a built-in model's own policy. Edit props["shader.renderMode"] or supply render_mode to set_code with matching source.
source#
source -> str | None # read-onlyAuthored Slang text, or None for a built-in shader or graph. Replace code and declarations together with set_code.
parameters#
parameters -> tuple[dict, ...] # read-onlyA snapshot of the exposed declarations, with stable name, display label and value kind. Declaration defaults are distinct from overrides in shader.props; reading material props gives effective values. Editing this snapshot changes nothing until it is passed to set_code on a Slang shader.
set_code#
set_code(*, source: str, parameters: list[dict], surface_model: str | None=None, render_mode: str | None=None, wind: bool | None=None) -> NoneReplaces a Slang shader's code and declarations together in one undoable edit, keeping its ID and material values. Omit surface_model and render_mode to keep them, or supply lit/unlit/liquid/volume and opaque/cutout/transparent together with matching source. Alpha and cutout threshold are editable material values only when declared as parameters and used by the source. Liquid requires opaque, its shared simulation declarations, LiquidShape Shape() and LiquidSurface Surface(LiquidPoint p); see the material manual. Volume requires opaque, a Number parameter named extinction, and VolumeSurface Surface(VolumePoint p). Built-in shaders and graphs are refused. Invalid declarations raise PlupyError and roll back; valid declarations with invalid Slang are saved for correction and reported by compilation diagnostics.
Each declaration has name (stable Slang identifier), optional label (display text), and kind: Number, Color, Vector2, Vector3, Vector4 or Texture2D. Numbers accept a finite default and optional min/max and angle=True for degrees converted to radians in Slang; colors use six-digit sRGB hex; vector defaults are lists/tuples of finite components. Texture2D takes interpretation="Color" (sRGB decoding, the default) or "Data" (linear). Assign default images through props["shader.default.<name>"] using an image handle, not inside the declaration. Declare 1–64 parameters. Liquid also accepts Environment declarations; assign their defaults through shader props using environment handles. Renaming a label preserves values; changing a name creates a different parameter. Removed values stay stored.
shader = plupy.data.shaders.new_slang("Tint", source="float3 SurfaceColor(SurfacePoint p) { return material.tint.rgb; }",
parameters=[{"name": "tint", "label": "Tint", "kind": "Color", "default": "#FFFFFF"}])Related types#
Data · DataBlock · Node · PlupyError · edit
Source#
- _live.py:759