Write Your First 360 Shader
A complete native GLSL shader, a parameter, content-time animation and focused Shader Workshop troubleshooting
Last updated: 2026-11-13
This companion starts with complete native direction_360 source. Shader Workshop is labelled ALPHA on the landing. The colours below are what this code computes, not a claim of observed GPU output. See the Workshop guide for opening, saving and importing a Shader, the .hexshader format reference for implementers, and the 360 Shaders feature overview.
For hiding controls while keeping your place in the editor, see Shader Workshop shortcuts. Editor Tab still indents and F types normally.
These original examples and this tutorial are dedicated to the public domain under CC0 1.0. Your own shader files and imported resources can carry other terms.
Download complete reference packages
The minimal shader, composite shader and coordinate shader are format-1 packages. The composite carries all ten control types, one helper, a still PNG and a Look. The coordinate package checks axes and pixel centres.
reader.mjs read admits a format-1 package. The version-1 inventory records their exact bytes and package digests. Verify the SHA-256 before using them as fixtures. The format reference separates a malformed package, a feature the host does not run, and a host-budget refusal.
For a still PNG in these packages, sample with hxSampleInputN, nearest or linear, and clamp or repeat. linear interpolates encoded sRGB and straight alpha before it decodes RGB. Alpha stays straight. Image sequences, Grad, cube and mipmap are outside that subset.
First source: a directional sky
In Create → Shader → Enter Workshop, create a native shader. Parameters live in shader.json, not in the GLSL. Set space to direction_360 and add one float. Then replace source.glsl with the program below. It has no header. The host supplies HxFrag, hxParam_gain and main().
{
"hexshader": 1,
"meta": { "title": "First Shader", "tags": [] },
"space": "direction_360",
"parameters": {
"gain": {
"type": "float", "default": 0.8, "min": 0, "max": 1, "step": 0.01,
"control": "slider", "label": "Brightness"
}
},
"values": { "gain": 0.8 }
}
vec4 hxMain(in HxFrag hx) {
float up = clamp(0.5 + 0.5 * hx.direction.y, 0.0, 1.0);
vec3 horizon = vec3(0.08, 0.18, 0.32);
vec3 zenith = vec3(0.35, 0.55, 0.90);
vec3 sky = mix(horizon, zenith, up) * hxParam_gain;
return vec4(sky, 1.0);
}
Use Compile. The button tooltip is "Compile (Ctrl+Enter)". On macOS the key is Cmd+Enter while the code editor has focus. The picture is a darker lower hemisphere and a brighter blue toward +Y. Moving around the sphere changes which direction is sampled. Adjust Brightness. Save a Look if you want to keep that value. The parameter's type and default live in shader.json. The current value is separate. Native output is linear sRGB with straight alpha. Hextile's PNG output composites its background and writes opaque sRGB.
hx.direction is a unit direction with +Y up and +Z forward. hx.uv rises from south to north. hx.mapUv descends from north to south. hx.fragCoord and hx.resolution describe the full output, not a tile. The entry is vec4 hxMain(in HxFrag hx). A Shadertoy mainImage belongs to a different space.
Animate with content time
Keep the same gain parameter. Replace source.glsl with this timed variant. hx.time is the sampled content time.
vec4 hxMain(in HxFrag hx) {
float up = clamp(0.5 + 0.5 * hx.direction.y, 0.0, 1.0);
float pulse = 0.7 + 0.3 * sin(hx.time * 2.0);
vec3 horizon = vec3(0.08, 0.18, 0.32);
vec3 zenith = vec3(0.35, 0.55, 0.90);
vec3 sky = mix(horizon, zenith, up) * hxParam_gain * pulse;
return vec4(sky, 1.0);
}
Compile, then use the Workshop Timeline to Play, Pause or Reset. Set Start, End and FPS. Preview Loop repeats that range. A Shader with no timeline starts at 0–60 seconds with Loop on. A sequence samples once at Start + n/FPS with End exclusive. Preview looping does not make a sequence repeat. hx.timeDelta, hx.frame and hx.frameRate come from the host. Read Timeline and value modes and Render Sequence and Dome output before you export motion.
Open Render Shader → Sequence for output. Its setup image is a labeled Workshop sample, not a preview of the requested interval. Watch in viewer follows verified frames. Hold, or closing the dialog, leaves rendering active while the app runs. Return to editing becomes available after rendering and cleanup settle. Use the existing job's Resume or Retry rather than starting over after a read or image failure.
An orbiting dot with a one-frame trail
A spherical trail reads one prior full frame. Add a float parameter trail_decay (default 0.97) and set passes to accumulate on that parameter:
"passes": { "mode": "accumulate", "decay": "trail_decay" }
Place a cyan mark on a great circle and combine it with the prior:
vec3 a = vec3(1.0, 0.0, 0.0);
vec3 b = vec3(0.0, 1.0, 0.0);
float theta = hx.time * 1.7 + float(hx.seed) * 0.001;
vec3 p = normalize(a * cos(theta) + b * sin(theta));
float mark = smoothstep(0.6, 0.0, hxAngularDistance(hx.direction, p));
vec3 markRgb = vec3(0.0, 0.8, 0.9) * mark;
return vec4(max(markRgb, hxParam_trail_decay * hxPriorColor(hx.mapUv).rgb), 1.0);
Frame 0 sees black. The next frame reads the frame you just committed. Seeking replays from the start of the range. The Workshop stops at 2048×1024 and at 240 frames. Use 1× sequence sampling. Higher supersampling is refused before work starts. This trail also refuses held image inputs. The host limits are on Shader Output.
A scene-linear ribbon for EXR compositing
The luminous_ribbon source below returns linear sRGB/Rec.709 colour and straight coverage. Its core exceeds display white. The outer colour has finite negative components. Leave those values intact. The host's linear EXR still export clamps coverage and associates RGB exactly once. The ordinary PNG path composites a background and encodes opaque sRGB. The source has no header. shader.json still needs "hexshader": 1, meta, space, parameters and values.
// Scene-linear Rec.709 emission, straight coverage, and an open 360-degree seam.
vec4 hxMain(in HxFrag hx) {
float longitude = hx.uv.x * 6.28318530718;
float latitude = hx.uv.y;
float spine = 0.46 + 0.12 * sin(longitude * 2.0 + hx.time * 0.25);
float distanceToSpine = abs(latitude - spine);
float coverage = 0.82 * (1.0 - smoothstep(0.015, 0.16, distanceToSpine));
float core = 1.0 - smoothstep(0.0, 0.075, distanceToSpine);
float northLight = 1.0 - 0.45 * latitude;
vec3 linearRgb = northLight * vec3(-0.08 + 4.8 * core,
0.12 + 1.7 * core,
-0.04 + 0.92 * core);
return vec4(linearRgb, coverage);
}
Save and Compile, then use the Workshop's Linear EXR still flow. The demonstrated size is 2048 × 1024. For a composite, read FLOAT RGBA as scene-linear associated colour. Apply an exposure multiplier to both the foreground RGB and a scene-linear 360 background before foreground.rgb + background.rgb * (1 - foreground.a). Then use your display transform. Do not multiply foreground RGB by alpha again, and do not clip signed or above-1 values before exposure. The software-render proof does not certify a receiving application or a physical GPU.
Inputs and controls
This first shader needs no image input, include or keyboard mapping. A helper lives at modules/… and is included by that path. An image slot is input1, input2, and so on, in shader.json. Sampling converts PNG RGB from sRGB to linear and keeps straight alpha. Playable channels and an optional camera live on controls. Live input and a seek differ from a frozen sequence sample. Check the format's time, image and pass rules before you depend on them. This tutorial does not assume a MIDI, OSC or gamepad bridge.
Troubleshooting
| Symptom | Check |
|---|---|
| Compile refusal | source.glsl is plain GLSL with hxMain and no header. Omit a user main(). Read the diagnostic's file and line. |
| A control is missing or has the wrong type | The parameter's id, type, default, min, max and step are in shader.json. GLSL reads hxParam_<id>. The value matches the type. |
| Include or resource refusal | The helper is under modules/. Every frame is a resources/<sha256>.png named in that slot. The hash matches the bytes. |
| Pass or feature refusal | passes is one mode: accumulate, feedback or buffers. Feedback and buffer passes cannot carry a clock, modulators or controls. Remove the family the mode excludes. |
| Preview works but sequence refuses | Compile again and preflight the interval you chose. Look for an expression cycle, a bad sample, or a missing frame. |
| Saved output differs from a loop | End is exclusive, and a sequence samples once. Use the Workshop sequence guide. |
Export Shader Bundle… zips the saved package. It does not zip an unsaved edit. Add Hexshader loads a package into a library. Import renders a panorama. The Workshop guide covers the journey, and the format reference covers host admission. The three sample zips linked above are format-1 packages.