# Inputs, parameters and constants

> The nodes every shader starts from: where the pixel is, the time, the mouse, your own variables and fixed values.

Source: https://albakore.github.io/pyzed/shading/nodes/inputs/

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

```python
from pyzed import shading

g = shading.Graph("demo")
```

## Input

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

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

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

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` |

```python title="Example"
uv = g.uv()
g.output(g.gradient(uv["x"]))
```

### Pixel

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

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

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` |

```python title="Example"
px = g.pixel()
lines = g.fract(px["y"] / 4.0)
g.output(g.rgba(g.step(0.5, lines), 1.0))
```

### Size

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

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

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` |

```python title="Example"
s = g.size()
g.output(g.rgba(g.fract(s["aspect"]), 1.0))
```

### Time

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

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

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` |

```python title="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

`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.

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` |

```python title="Example"
m = g.mouse()
light = g.radial_gradient(center=m["position"], radius=0.3)
g.output(g.rgba(light, 1.0))
```

### Centered UV

`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 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` |

```python title="Example"
c = g.centered_uv()
d = g.length(c["centered"])
g.output(g.rgba(g.smoothstep(0.4, 0.0, d), 1.0))
```

## Parameters

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

### Parameter

`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.

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`.

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

## Constants

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

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

A fixed number.

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` |

```python title="Example"
half = g.float(0.5)
g.output(g.rgba(g.compose(half, half, 1.0), 1.0))
```

### Int

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

A fixed whole number.

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

| Output | Type |
| --- | --- |
| `value` | `int` |

| Setting | Values | Default |
| --- | --- | --- |
| `value` | `int` | `1` |

```python title="Example"
octaves = g.int(3)
n = g.fbm(octaves=octaves)
g.output(g.rgba(n, 1.0))
```

### Bool

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

A fixed true or false.

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

| Output | Type |
| --- | --- |
| `value` | `bool` |

| Setting | Values | Default |
| --- | --- | --- |
| `value` | `bool` | `true` |

```python title="Example"
on = g.bool(True)
g.output(g.rgba(g.select(on, 1.0, 0.2), 1.0))
```

### Vector2

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

Two fixed numbers.

Two fixed numbers: a point or a size.

| Output | Type |
| --- | --- |
| `value` | `vec2` |

| Setting | Values | Default |
| --- | --- | --- |
| `value` | `vec2` | `(0.5, 0.5)` |

```python title="Example"
center = g.vec2([0.3, 0.5])
g.output(g.rgba(g.radial_gradient(center=center, radius=0.3), 1.0))
```

### Vector3

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

Three fixed numbers.

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)` |

```python title="Example"
orange = g.vec3([1.0, 0.5, 0.0])
g.output(g.rgba(orange, 1.0))
```

### Vector4

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

Four fixed numbers.

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

| Output | Type |
| --- | --- |
| `value` | `vec4` |

| Setting | Values | Default |
| --- | --- | --- |
| `value` | `vec4` | `(1, 1, 1, 1)` |

```python title="Example"
g.output(g.vec4([0.1, 0.2, 0.4, 1.0]))
```

### Color

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

A fixed color.

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` |

```python title="Example"
g.output(g.color("#7c3aed"))
```

### Math constants

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

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

π, τ (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` |

```python title="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))
```

**Always up to date:**

This page is generated from the node catalog of `pyzed.shading`, so the ports, types and defaults are always those of this version. Each example is compiled when the docs are built.

**See also:** [Getting started](https://albakore.github.io/pyzed/shading/getting-started/) · [The Shader view](https://albakore.github.io/pyzed/shading/shader-designer/) · [Recipes](https://albakore.github.io/pyzed/shading/recipes/) · [Shader graphs in Python](https://albakore.github.io/pyzed/shading/shader-graphs/)
