# Mapshroom shader specification

Generated from the workspace's canonical shader contract. Available without MCP.
Product/input workflow: https://mapshroom.dev/mcp/context.md
Canvas preview and Open on Mapshroom button without MCP: https://mapshroom.dev/mcp/canvas.md
Fallback: https://mapshroom.dev/mcp/fallback.md

## Contract

The formatting rules below apply only to the shader code block or tool code argument, not the whole assistant response. Without MCP, create and render a Canvas with this exact shader and an Open on Mapshroom button using the canvas guide. Do not stop at a GLSL code block when HTML/WebGL rendering is available.

Return one complete replacement fragment shader.
The first non-empty line must be: // NAME: <Short Name>
The second non-empty line must be: // MAPSHROOM PROMPT: "<the exact user request as a JSON string>"
All visual logic must live inside: vec4 processColor(sampler2D tex, vec2 uv, float time, vec2 resolution)
Expose 3 to 6 meaningful effect controls as custom uniforms so Mapshroom automatically creates controls. Convert adjustable concepts in the request into uniforms instead of hardcoded constants: numbers become float/int sliders, colors become vec3 color controls, and switches become bool controls
If the user does not name adjustable parameters, infer the 3 to 6 most useful creative controls for the requested effect
Use only supported custom uniform types: float, int, vec3, bool
Put every uniform on its own line and keep its UI metadata on that same line after //
Every float or int must include: @min <number> @max <number> @default <number>
Every vec3 must include: @default <r>,<g>,<b>; every bool must include: @default true|false
The shader is invalid if it has fewer than 3 correctly annotated custom uniforms. Before returning, count the declarations and verify their metadata
Preserve useful uniforms from the current shader unless the user explicitly asks to remove them
Use GLSL ES 3.00 syntax for WebGL 2 and sample textures with texture()
Do not include #version 300 es because Mapshroom injects the version and program wrapper
Do not declare void main()
Do not write to gl_FragColor in the generated body
Do not include explanations outside the GLSL response
Semantic input ABI v1:
After NAME and MAPSHROOM PROMPT, include // MAPSHROOM CONTRACT: <single-line JSON>.
Preserve the current contract and named slots when editing unless the request changes the actual input requirements. Declare every input the code really reads. Metadata never starts generation. No inference or normal fitting inside GLSL.
The first input is the processColor tex argument. Additional slots use uniform sampler2D u_input_<slot>, declared in GLSL. All source inputs share UV and crop.
Canonical codec formats (copy exactly, including profiles and normal conventions): {"color":{"encoding":"rgba-color","version":1,"colorSpace":"srgb","filtering":"linear","alpha":"coverage"},"regionPieces":{"encoding":"mapshroom.regions.r8-rgb24-table","version":1,"colorSpace":"data","filtering":"nearest","alpha":"coverage","generationProfile":"segmentation-rigid-anchors-v1"},"depth":{"encoding":"mapshroom.depth.gray-rgb-alpha-a","version":1,"colorSpace":"data","filtering":"linear","alpha":"coverage"},"normal":{"encoding":"mapshroom.normal.xyz-rgb-alpha-a","version":1,"colorSpace":"data","filtering":"linear","alpha":"coverage","normalConvention":"mapshroom-normal-xyz-v1","generationProfile":"depth-smoothed-central-difference-v1"},"combinedDepth":{"encoding":"mapshroom.surface.oct-rg-depth-b-alpha-a","version":1,"colorSpace":"data","filtering":"linear","alpha":"coverage","normalConvention":"mapshroom-tiles-v1","generationProfile":"tiles-plane-fit-v1"},"normalAtlas":{"encoding":"mapshroom.surface.depth-normal-atlas-2x2","version":1,"colorSpace":"data","filtering":"linear","alpha":"coverage","normalConvention":"mapshroom-normal-xyz-v1","generationProfile":"depth-smoothed-central-difference-v1"},"sourceEdges":{"encoding":"mapshroom.edges.gray-rgb-alpha-a","version":1,"colorSpace":"data","filtering":"linear","alpha":"coverage","generationProfile":"source-luminance-nms-v1"}}
Packed surface RG encodes upper-hemisphere oct normal, B depth, A coverage. Decode f=rg*2-1, n=normalize(vec3(f,1-abs(f.x)-abs(f.y))), then flip normal Y for geometry. XYZ normal and 2x2 atlas are different codecs. Region Pieces R stores exact 8-bit IDs with nearest filtering and an appended RGB24 anchor/bounds table. Never interpret colored segmentation palettes as IDs.
Use surface-render for a complete 3D effect. Shared material/geometry modules are unsupported in V1. With scene-final lighting, declare vec3 u_scene_lightDirection, float u_scene_ambient, float u_scene_softness and use the same light in shading and shadows. No local moving light. These managed uniforms have no UI annotations and do not count as creative controls. X right, Y up in geometry, Z toward viewer. Preserve photographic shadows without inverse compensation.
Chain-compatible pointwise filters declare post-color, one required screen-space color input with rgba-color format, output color, lighting none, photoShadows preserve. Implement vec4 processPostColor(vec4 source, vec2 uv, float time, vec2 resolution) using that incoming color, without texture reads or lighting. Standalone entry must be exactly vec4 processColor(sampler2D tex, vec2 uv, float time, vec2 resolution) { return processPostColor(texture(tex, uv), uv, time, resolution); }. Neighborhood filters need intermediate render targets and are unsupported in Color chain; keep them legacy-render for standalone/Mix.
For legacy behavior with local lighting or unverified composability declare legacy-render honestly.
Default single-photo contract: {"version":1,"role":"legacy-render","inputs":[{"slot":"color","semantic":"color","required":true,"space":"source-uv","accepted":[{"encoding":"rgba-color","version":1,"colorSpace":"srgb","filtering":"linear","alpha":"coverage"}],"defaultVariant":"original"}],"output":"color","lighting":"legacy-owned","photoShadows":"not-applicable"}

## Complete procedural example

This example works with the default neutral white input. Adapt the effect and record the actual user request in the second comment. Compilation must be checked in the user's WebGL 2 browser.

```glsl
// NAME: Chromatic Waves
// MAPSHROOM PROMPT: "Create slow chromatic waves with speed, scale and intensity controls."
// MAPSHROOM CONTRACT: {"version":1,"role":"legacy-render","inputs":[{"slot":"color","semantic":"color","required":true,"space":"source-uv","accepted":[{"encoding":"rgba-color","version":1,"colorSpace":"srgb","filtering":"linear","alpha":"coverage"}],"defaultVariant":"original"}],"output":"color","lighting":"legacy-owned","photoShadows":"not-applicable"}
uniform float speed; // @min 0 @max 3 @default 0.6
uniform float scale; // @min 1 @max 12 @default 4
uniform float intensity; // @min 0.1 @max 1 @default 0.8
vec4 processColor(sampler2D tex, vec2 uv, float time, vec2 resolution) {
  vec2 p = (uv - 0.5) * vec2(resolution.x / resolution.y, 1.0);
  float wave = sin(p.x * scale + time * speed) + cos(p.y * scale - time * speed);
  vec3 col = 0.5 + 0.5 * cos(wave + vec3(0.0, 2.0, 4.0));
  return vec4(col * intensity, 1.0);
}
```

## Semantic input metadata

The canonical schema is [effect-contract.schema.json](https://mapshroom.dev/mcp/effect-contract.schema.json). The workspace supports multiple declared inputs, shared scene lighting and a pointwise color chain. Existing bodies without declarations remain legacy. MCP/Canvas previews support one local image; effects needing prepared packed maps, several samplers or scene lighting show an explicit compatibility message and can be transferred to the workspace for preparation. Metadata does not implement the future shared geometry ABI. Contract validation is not a rendering review.
