Code Nodes
Write your own image node in WGSL with the Shader node, and your own 3D surface with the Surface Shader node, in DASCA's Node mode.
These docs cover Dasca 2.3.
Two nodes let you write code: Shader draws or changes images, and Surface Shader paints the surface of 3D objects. Both use WGSL, the shading language of WebGPU. Open the card with Show all settings to see the code.
Editing the code:
- Click into the code and type.
Ctrl+Enterapplies the code, and so does clicking outside it. Tabinserts two spaces.- Errors appear under the code, with their line number where it is known, and the card shows a red dot. While its code has an error, a Shader keeps showing its last working result, and a Surface Shader paints with its plain Color, Roughness and Metal.
Shader
The Shader node has four image inputs, A, B, C and D, and one image output. Your code needs a shade function that returns the color of one pixel:
param speed = 0.25 (0, 2)
param width = 0.5 (0, 1)
color tint = #ff7a1a
fn shade(uv: vec2f) -> vec4f {
let base = a(uv);
let stripes = smoothstep(width - 0.1, width + 0.1, fract(uv.x * 12.0 + uv.y * 4.0 - time * speed));
let glow = mix(base.rgb, tint.rgb, stripes * 0.6);
return vec4f(glow, max(base.a, stripes * 0.6));
}
This is the code a new Shader starts with: it lays moving stripes over input A.
Settings from code
Lines that start with param or color become settings on the card:
| Line | Setting |
|---|---|
param speed = 0.25 (0, 2) | A number setting named speed, starting at 0.25, with a range from 0 to 2. Without the range, it runs from 0 to 1, or wider to include the starting value. |
color tint = #ff7a1a | A color setting named tint. |
A Shader can have up to 8 number settings and up to 4 color settings. Like other settings, they can be dragged, keyframed and driven by wires. When you edit the code, settings that keep their name keep their value.
What the code can use
| Name | What it is |
|---|---|
uv | The argument of shade: the position of the pixel, from 0 to 1 across the image, with 0,0 at the top left. You can give it another name. |
a(uv), b(uv), c(uv), d(uv) | The color of input A, B, C or D at a position. An empty input gives transparent black. |
time | The time on the timeline, in seconds. |
size | The size of the result in pixels. |
px | The position of the pixel in pixels (uv * size). |
| Your settings | Each param is an f32 and each color a vec4f, under the name you gave it. |
shade returns the color with its alpha, not premultiplied. Colors sets how the colors in the code are read and written: Display (the default) works with colors as you see them, and Linear light works with light values, which suits blending and math.
Names that WGSL or the node already uses, such as time or fn, cannot be used for settings.
Surface Shader
The Surface Shader node is a material you write in code. Wire its output into the Material input of a Shape 3D, Model 3D, Tube 3D or Relief 3D. Your code needs a paint function:
fn paint(p: Point, base: Paint) -> Paint {
var look = base;
let bands = 0.5 + 0.5 * sin(p.world.y * 10.0 - p.time * 2.0 + noise(p.world * 3.0) * 4.0);
let rim = pow(1.0 - max(dot(p.normal, p.view), 0.0), 3.0);
look.color = mix(base.color, vec3f(1.0, 0.32, 0.18), bands * p.a);
look.glow = vec3f(0.25, 0.55, 1.0) * rim * p.b * 4.0;
return look;
}
paint receives the point being drawn and the base paint, and returns the paint to use:
Point field | What it is |
|---|---|
uv | The texture position on the surface. |
local | The position on the object, before it is moved. |
world | The position in the scene. |
normal | The direction the surface faces. |
view | The direction from the surface toward the camera. |
time | The time on the timeline, in seconds. |
a, b, c, d | The A, B, C and D settings of the node, from 0 to 1. |
Paint field | What it is |
|---|---|
color | The surface color. |
roughness | Low values are glossy, 1 is matte. |
metal | 0 is non-metal, 1 is metal. |
glow | Light the surface gives off. |
alpha | Opacity. |
The base paint comes from the node's Color, Roughness and Metal settings. noise(p) gives smooth noise for a 3D position. Both sides draws the back faces of the surface too.