Skip to content

Config File Format (.sha.json)

This page describes the raw JSON config format. Most users will find it easier to use the Config panel in the UI instead — this reference is for those who prefer editing the file directly.

Naming Convention

The config file must share the same base name as your shader:

  • Shader file: example.glsl
  • Config file: example.sha.json

Place them in the same directory. To generate a config automatically, run Shader Studio: Generate Config for GLSL File from the command palette.

Basic Example

A single-pass shader with no inputs:

{
  "version": "1.0",
  "passes": {
    "Image": {
      "inputs": {}
    }
  }
}

Multi-Pass Example

Image reads from an arbitrarily named Simulation pass, which reads keyboard input:

{
  "version": "1.0",
  "passes": {
    "Image": {
      "inputs": {
        "iChannel0": { "source": "Simulation", "type": "buffer" }
      }
    },
    "Simulation": {
      "path": "simulation.glsl",
      "inputs": {
        "iChannel1": { "type": "keyboard" }
      }
    }
  }
}

Native Stages and Shared Sources

WGSL and Slang passes select annotated functions with entryPoints. Several passes may use the same source file and select different functions:

{
  "version": "1.0",
  "webgpu": { "defaultRenderAuthoring": "native" },
  "passes": {
    "ComputeA": {
      "type": "compute",
      "path": "shared.wgsl",
      "entryPoints": { "compute": "advance" },
      "outputLayers": 2
    },
    "BufferA": {
      "path": "shared.wgsl",
      "entryPoints": { "fragment": "twoOutputs" },
      "outputFormat": "rgba16float"
    },
    "Image": {
      "inputs": {
        "iChannel0": { "type": "buffer", "source": "BufferA", "output": 1 },
        "iChannel1": { "type": "buffer", "source": "ComputeA", "layer": 1 }
      }
    }
  }
}

Image uses the main shader file. For vertex sources, omitted vertex and entryPoints.vertex use the generated stage; vertex equal to the pass source chooses Same file, while another path chooses Separate file. Native vertex selection uses entryPoints.vertex; a Built-in custom source provides mainVertex. Fragment and vertex choices are independent. Pure native fragments do not need mainImage.

Compute uses entryPoints.compute; legacy entryPoint still loads. Native render output slots and default names are inferred from the selected fragment return declaration in the pass source and Common code. Do not add an outputs array to allocate attachments: edit the shader declaration instead. Legacy outputs entries can override labels by slot. A channel's output selects a render attachment, and layer selects a compute output layer; both default to zero.

The config UI writes these paths and selections when you choose a file or function. Add function… also inserts source code in that stage's file. Output selection in Misc only changes the channel connection. See Native entry points and Multiple render targets.

For mesh passes, useViewerCamera: false disables the viewer transform in GLSL, WGSL, and Slang. Omitting it inherits the shader-wide webgpu.useViewerCamera setting, then the global preference. Use default removes the pass override.

Texture Input Example

Bind an image file to a channel:

{
  "version": "1.0",
  "passes": {
    "Image": {
      "inputs": {
        "iChannel0": { "path": "textures/noise.png", "type": "texture" }
      }
    }
  }
}

Video Input Example

Bind a video file:

{
  "version": "1.0",
  "passes": {
    "Image": {
      "inputs": {
        "iChannel0": { "path": "videos/timelapse.mp4", "type": "video" }
      }
    }
  }
}

Audio Input Example

Bind an audio file. The texture provides FFT frequency data (row 0) and waveform data (row 1), matching Shadertoy's audio format:

{
  "version": "1.0",
  "passes": {
    "Image": {
      "inputs": {
        "iChannel0": {
          "type": "audio",
          "path": "music/track.mp3",
          "startTime": 0,
          "endTime": 30
        }
      }
    }
  }
}

Access in GLSL:

float fft  = texture(iChannel0, vec2(uv.x, 0.25)).r; // FFT row
float wave = texture(iChannel0, vec2(uv.x, 0.75)).r;  // Waveform row

Cubemap Input Example

Bind a T-cross layout cubemap image. The channel is bound as a samplerCube:

{
  "version": "1.0",
  "passes": {
    "Image": {
      "inputs": {
        "iChannel0": {
          "type": "cubemap",
          "path": "textures/skybox.png",
          "filter": "mipmap"
        }
      }
    }
  }
}

Access in GLSL (channel must be declared as samplerCube):

vec4 col = texture(iChannel0, normalize(dir));

Script-Driven Uniforms

Add a script field to run a TypeScript or JavaScript file that computes custom uniform values. Export a uniforms(ctx) function returning named values; their types are inferred automatically:

{
  "version": "1.0",
  "script": "uniforms.ts",
  "scriptMaxPollingFps": 30,
  "passes": {
    "Image": { "inputs": {} }
  }
}

Example uniforms.ts:

export function uniforms(ctx) {
  return {
    uSpeed: ctx.iTime * 0.5,
    uColor: [Math.sin(ctx.iTime), 0.5, 1.0],
  };
}

Available context fields: iTime, iFrame, iResolution, iMouse, iDate, iChannelTime, iSampleRate. Read them from ctx; they are not globals. The script is polled at scriptMaxPollingFps (30 by default).

Supported uniform types: float, vec2, vec3, vec4, bool.

Resolution Settings

Pin a resolution to the config so it applies whenever the shader is opened:

{
  "version": "1.0",
  "passes": {
    "Image": {
      "resolution": {
        "scale": 1,
        "aspectRatio": "16:9"
      },
      "inputs": {}
    }
  }
}

Fixed pixel dimensions:

"resolution": {
  "width": 1920,
  "height": 1080
}

Fixed dimensions are the base size. scale still applies if you set both:

"resolution": {
  "scale": 2,
  "width": 320,
  "height": 180
}

This renders at 640 × 360.

Buffer passes use a simpler fixed-size resolution:

"Flow": {
  "path": "flow.glsl",
  "resolution": { "width": 512, "height": 512 },
  "outputFormat": "rgba32float"
}

GLSL, Slang, and WGSL buffer passes accept outputFormat, as do Slang and WGSL compute passes:

Value Meaning
auto (default) Prefer rgba32float storage
rgba16float Explicit four-component 16-bit float storage
rgba32float Explicit four-component 32-bit float storage

If your device cannot use the requested format, Shader Studio reports an error rather than silently changing precision. The exceptions are a blended pass on a GPU that cannot blend 32-bit floats and a pass with samples: 4: both store rgba16float and show a warning. The Image canvas format is not controlled by this field. In the Config panel, Output format appears at the bottom of buffer and compute pass settings. Leave it on Auto unless you want to trade precision for lower memory use with 16-bit storage.

Image and buffer passes also accept clear: [r, g, b, a]. Components range from 0 to 1; the default is opaque black, [0, 0, 0, 1]. A transparent clear such as [0, 0, 0, 0] is useful for buffer layers that will be alpha-composited later. Compute and Common passes do not accept clear.

Passes

Pass Description
Image Main output pass (required, always present)
Any identifier An intermediate fragment pass. Names and pass counts are unrestricted; each renders to a texture other passes can read.
Compute* A Slang or WGSL WebGPU compute pass. See Compute Passes.
Common Shared GLSL, Slang, or WGSL code included in all passes. Useful for shared functions, types, and constants.

Each non-Image pass needs a path field pointing to its .glsl, .slang, or .wgsl file. If the file doesn't exist, the visual editor offers a button to create it.

Channel Types

Each pass can bind input channels with configuration keys such as iChannel0 and iChannel1. In GLSL, those same names and matching metadata accessors (iCh0, iCh1, and so on) are available in the shader. In Slang, the configured names are direct channel globals such as iChannel0 and iChannel1.

Type Fields Description
buffer source, optional layer, filter, wrap Read from an arbitrary fragment buffer pass or a compute pass (write its pixels with writeOutput); common and Image are not sources, and layer selects a compute texture-array layer
texture path, filter, wrap, vflip, grayscale Image file
video path, filter, wrap, vflip, muted Video file
audio path, startTime, endTime, muted Audio file with FFT/waveform texture
cubemap path, filter, wrap, vflip T-cross cubemap image
keyboard — Key state input texture

Channel bindings remain under each pass's inputs field in .sha.json. Shader access uses the configured channel name. See Channels for GLSL, Slang, and WGSL metadata and sampling examples.

Buffer input filter accepts linear (default) or nearest; wrap accepts clamp (default) or repeat. These settings belong to the input, so two channels can read one source with different samplers. Buffer mipmaps and vflip are not supported. On WebGPU without 32-bit float filtering, a linear request falls back to nearest without reducing the source's 32-bit storage precision. See Buffer Precision and Exact Reads for exact-load helpers and coordinate conventions.

Texture / Video / Cubemap Options

Field Values Description
filter mipmap (default), linear, nearest Texture filtering
wrap clamp (default), repeat Edge wrap mode
vflip true / false Flip vertically
grayscale true / false Texture only: convert to greyscale
muted true / false Video and audio only: start the channel muted (default false)

Buffer Self-Read

A buffer can read its own previous frame's output by binding itself as an input:

{
  "Feedback": {
    "path": "feedback.glsl",
    "inputs": {
      "iChannel0": { "source": "Feedback", "type": "buffer" }
    }
  }
}

This is how Shadertoy-style feedback effects work (trails, fluid simulations, game of life). For reads from other passes, an earlier source supplies its current frame and a later source supplies its previous frame. Declaration order determines buffer order; WebGPU runs compute passes first, and Image always runs last. See Pass Execution Order for examples.

File Paths

Paths in the config are relative to the config file's directory. Keep all referenced files (buffer .glsl files, textures, videos, audio) in the same directory or subdirectories.

Storage Declarations

Declare WebGPU storage at the top level of the config, alongside passes. The visual Storage workspace edits these declarations.

{
  "version": "1.0",
  "storage": {
    "particles": {
      "count": 1024,
      "elementType": "ParticleData",
      "fields": [
        { "name": "position", "type": "float4" },
        { "name": "velocity", "type": "float4" }
      ],
      "resetOnRestart": false
    },
    "counter": {
      "count": 1,
      "elementType": "u32",
      "initialDataFiles": [{ "path": "data/counter.bin", "byteOffset": 0 }]
    }
  },
  "passes": { "Image": {} }
}
Field Meaning
count Positive integer element count.
elementType Numeric Slang/WGSL type or struct name.
fields Optional 1-64 named numeric fields. When supplied, generates the named struct; omit for a type defined in shader source. Field names must be unique shader identifiers.
initialDataFiles Optional ordered list of { path, byteOffset }. Each path points to raw binary data and resolves relative to the shader, @/ workspace-relative, or absolute. Offsets are destination bytes from the buffer's start and default to zero. Offset plus file length must fit in the buffer. Later files overwrite overlaps; unfilled bytes are zero.
clearEachFrame Optional boolean, default false. Zeros storage before each normal simulation frame.
resetOnRestart Optional boolean, default true. Set false to preserve compatible existing storage during a shader restart.

The example initializes counter[0] to 1u when data/counter.bin holds the four bytes 01 00 00 00. Binary data must match the actual GPU element stride and field offsets, including padding. Changing a declaration's layout, size or initial data can recreate its buffer. Capture settings and the selected inspector field are UI choices, not storage declaration fields.