Skip to content

Inputs, parameters and constants

Every example on this page runs after these two lines, and ends by sending a color to the Output node:

from pyzed import shading
g = shading.Graph("demo")

Where the pixel being painted is, how big the area is, the time and the mouse. Almost every graph starts with one of these.

uv · Input · g.uv(...)

Where the pixel is, from (0, 0) at the top left to (1, 1) at the bottom right.

The UV node as it looks in the Shader view, with its preview

The most used node. x goes from 0 at the left to 1 at the right and y from 0 at the top to 1 at the bottom, whatever the size of the widget. Wire x into a Gradient to get a horizontal ramp.

Output Type
uv vec2
x float
y float
Example
uv = g.uv()
g.output(g.gradient(uv["x"]))

pixel · Input · g.pixel(...)

Where the pixel is, in pixels from the top left.

The Pixel node as it looks in the Shader view, with its preview

The same as UV but in pixels: use it for things that must keep their size in pixels when the widget grows, such as scanlines every 3 pixels.

Output Type
px · pixel vec2
x float
y float
Example
px = g.pixel()
lines = g.fract(px["y"] / 4.0)
g.output(g.rgba(g.step(0.5, lines), 1.0))

size · Input · g.size(...)

The size of the shaded area in pixels, and its aspect ratio (width / height).

The Size node as it looks in the Shader view, with its preview

The width and height of the area in pixels. aspect (width ÷ height) keeps circles round on wide widgets; Centered UV already uses it for you.

Output Type
size vec2
width float
height float
aspect float
Example
s = g.size()
g.output(g.rgba(g.fract(s["aspect"]), 1.0))

time · Input · g.time(...)

Seconds since the app started (times scale), and their sine and cosine.

The Time node as it looks in the Shader view, with its preview

Seconds since the app started: anything wired to it moves. sin and cos swing smoothly between −1 and 1, perfect for pulses. scale speeds it up or slows it down.

Input Type Default
scale float 1
Output Type
time float
sin float
cos float
Example
t = g.time(scale=2.0)
pulse = t["sin"] * 0.5 + 0.5
g.output(g.rgba(g.hsv_to_rgb(0.6, 0.8, pulse), 1.0))

mouse · Input · g.mouse(...)

Where the pointer is from 0 to 1 (the center while it is outside), and whether it is over the shader.

The Mouse node as it looks in the Shader view, with its preview

Where the pointer is, in UV (0 to 1). While it is outside the shader, position is the center and inside is false. Great for spotlights and hover effects.

Output Type
position vec2
inside bool
Example
m = g.mouse()
light = g.radial_gradient(center=m["position"], radius=0.3)
g.output(g.rgba(light, 1.0))

centered_uv · Input · g.centered_uv(...)

UV with (0, 0) in the middle and circles kept round: the place to draw shapes. Aspect UV goes from 0 to the aspect ratio across, so noise and cells stay square.

The Centered UV node as it looks in the Shader view, with its preview

The coordinates to draw shapes with: (0, 0) is the middle and one unit is the height, so a circle stays round on any widget. aspect_uv keeps noise and cells square.

Input Type Default
uv vec2 UV (context)
Output Type
centered vec2
aspect_uv · aspect uv vec2
Example
c = g.centered_uv()
d = g.length(c["centered"])
g.output(g.rgba(g.smoothstep(0.4, 0.0, d), 1.0))

A Parameter node reads one of the shader’s variables: the values your Python code (or a slider in the Preview tab) changes.

parameter · Parameters · g.parameter(...)

Reads a variable of the shader (see the Variables list): a mutable one changes without recompiling, a constant is built into the code.

The Parameter node as it looks in the Shader view, with its preview

Your shader’s knobs. g.uniform(...) adds a mutable variable and a Parameter node at once; in the designer, drag a variable from the Outline onto the graph. A color variable gives color, rgb and alpha outputs.

Output Type
value float
Setting Values Default
name variable —

The output takes the variable’s type; a color variable gives color, rgb and alpha.

Example
tint = g.uniform("tint", "color", "#22d3ee")
glow = g.radial_gradient(radius=0.6)
g.output(g.rgba(tint["rgb"] * glow, 1.0))

Fixed values written into the shader. When a value never changes, a constant is the simplest choice; when you want to change it from code, use a variable instead.

float · Constants · g.float(...)

A fixed number.

The Float node as it looks in the Shader view, with its preview

One fixed number. Most inputs already take a typed value directly, so you only need this node to feed the same number into several places.

Output Type
value float
Setting Values Default
value float 0.5
Example
half = g.float(0.5)
g.output(g.rgba(g.compose(half, half, 1.0), 1.0))

int · Constants · g.int(...)

A fixed whole number.

The Int node as it looks in the Shader view, with its preview

A fixed whole number, for inputs such as the octaves of Fractal noise.

Output Type
value int
Setting Values Default
value int 1
Example
octaves = g.int(3)
n = g.fbm(octaves=octaves)
g.output(g.rgba(n, 1.0))

bool · Constants · g.bool(...)

A fixed true or false.

The Bool node as it looks in the Shader view, with its preview

A fixed true or false, for Select and Logic nodes.

Output Type
value bool
Setting Values Default
value bool true
Example
on = g.bool(True)
g.output(g.rgba(g.select(on, 1.0, 0.2), 1.0))

vec2 · Constants · g.vec2(...)

Two fixed numbers.

The Vector2 node as it looks in the Shader view, with its preview

Two fixed numbers: a point or a size.

Output Type
value vec2
Setting Values Default
value vec2 (0.5, 0.5)
Example
center = g.vec2([0.3, 0.5])
g.output(g.rgba(g.radial_gradient(center=center, radius=0.3), 1.0))

vec3 · Constants · g.vec3(...)

Three fixed numbers.

The Vector3 node as it looks in the Shader view, with its preview

Three fixed numbers: often an RGB color written as numbers from 0 to 1.

Output Type
value vec3
Setting Values Default
value vec3 (1, 1, 1)
Example
orange = g.vec3([1.0, 0.5, 0.0])
g.output(g.rgba(orange, 1.0))

vec4 · Constants · g.vec4(...)

Four fixed numbers.

The Vector4 node as it looks in the Shader view, with its preview

Four fixed numbers: a color with alpha, as numbers.

Output Type
value vec4
Setting Values Default
value vec4 (1, 1, 1, 1)
Example
g.output(g.vec4([0.1, 0.2, 0.4, 1.0]))

color · Constants · g.color(...)

A fixed color.

The Color node as it looks in the Shader view, with its preview

A fixed color picked with the color picker (or written as #rrggbb).

Output Type
color vec4
rgb vec3
alpha float
Setting Values Default
value color #7c3aed
Example
g.output(g.color("#7c3aed"))

math_constants · Constants · g.math_constants(...)

π, τ (2π), e and the golden ratio.

The Math constants node as it looks in the Shader view, with its preview

π, τ (2π), e and φ, so you don’t have to type 3.14159. Multiply a 0..1 value by τ to get a full turn in radians.

Output Type
pi · π float
tau · τ float
e float
phi · φ float
Example
k = g.math_constants()
wave = g.sin(g.uv()["x"] * k["tau"] * 3.0) * 0.5 + 0.5
g.output(g.rgba(wave, 1.0))

See also: Getting started · The Shader view · Recipes · Shader graphs in Python