hydra_define
Define a reusable GLSL transform for Hydra chains with custom parameters, then use it like a built-in function. Compiles before use to catch GLSL errors.
Instructions
Add a custom transform written in GLSL (Hydra's setFunction), usable in any chain afterwards like a built-in.
type and what the body receives / must return:
src _st (vec2 coords) -> vec4 colour
coord _st -> vec2 coords
color _c0 (vec4 incoming colour) -> vec4
combine _c0, _c1 (two colours) -> vec4
combineCoord _st, _c0 -> vec2
glsl is the function BODY only. inputs are its parameters, in order:
[{"name": "amount", "type": "float", "default": 0.5}] (types: float, vec4, sampler2D).
For combine types, declare the incoming chain first: {"name": "tex", "type": "vec4"}.
It is compiled inside a throwaway chain before anything goes live, so a GLSL mistake
comes back as the compiler's own error. On success it is stored as block fn_<name>
at the top of the document (so it is defined again before use when a page reloads) and
use shows a call to start from.
Example: hydra_define("stripes", "src", "return vec4(vec3(step(0.5, fract(_st.x * count))), 1.0);", inputs=[{"name": "count", "type": "float", "default": 10}]) then: stripes(20).rotate(0.3).out(o1)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| glsl | Yes | ||
| name | Yes | ||
| take | No | ||
| type | Yes | ||
| inputs | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |