# CustomShader Reference Exhaustive struct/enum tables and built-in uniform catalog for the `cesiumjs-custom-shader` skill. Updated for the CesiumJS 1.144 public API. --- ## Attributes struct Auto-generated per primitive from glTF attributes. Access via `vsInput.attributes.` or `fsInput.attributes.`. | glTF attribute | Shader field | GLSL type | Vertex | Fragment | Notes | |---|---|---|---|---|---| | `POSITION` | `positionMC` | `vec3` | Yes | Yes | Model coordinates | | `POSITION` | `positionWC` | `vec3` | — | Yes | World (ECEF) coordinates, low precision | | `POSITION` | `positionEC` | `vec3` | — | Yes | Eye coordinates | | `NORMAL` | `normalMC` | `vec3` | Yes | — | Unit normal, model coordinates | | `NORMAL` | `normalEC` | `vec3` | — | Yes | Unit normal, eye coordinates | | `TANGENT` | `tangentMC` | `vec3` | Yes | — | `w` stripped after bitangent computation | | `TANGENT` | `tangentEC` | `vec3` | — | Yes | Same as above, eye space | | `NORMAL` + `TANGENT` | `bitangentMC` | `vec3` | Yes | — | Only when both N + T present | | `NORMAL` + `TANGENT` | `bitangentEC` | `vec3` | — | Yes | Same | | `TEXCOORD_N` | `texCoord_N` | `vec2` | Yes | Yes | N = 0, 1, 2, … | | `COLOR_N` | `color_N` | `vec4` | Yes | Yes | Alpha defaults to 1 when absent | | `JOINTS_N` | `joints_N` | `ivec4` | Yes | Yes | Skin joint indices | | `WEIGHTS_N` | `weights_N` | `vec4` | Yes | Yes | Skin weights | **Custom underscore-prefixed attributes.** glTF attributes starting with `_` are lowercased and un-prefixed: `_SURFACE_TEMPERATURE` → `fsInput.attributes.surface_temperature`. **Fallback when missing.** If a primitive lacks a requested attribute (e.g. no `TEXCOORD_0`), the runtime either synthesizes a default or, when no sensible default exists, disables the custom shader stage *just for that primitive*. Other primitives in the same model/tile continue to use the shader. --- ## Coordinate-space validation errors The `CustomShader` constructor scans shader text and throws `DeveloperError` for ambiguous or wrong-stage attribute names. Error format: > ` () is not available in the shader. Did you mean () instead?` Suffix expansion: `MC` → "(model coordinates)", `WC` → "(Cartesian world coordinates)", `EC` → "(eye coordinates)". Bare names are not expanded. | Name | Rejected in | Suggested alternative | |---|---|---| | `position` | vertex | `positionMC` | | `position` | fragment | `positionEC` | | `normal` | vertex | `normalMC` | | `normal` | fragment | `normalEC` | | `tangent` | vertex | `tangentMC` | | `tangent` | fragment | `tangentEC` | | `bitangent` | vertex | `bitangentMC` | | `bitangent` | fragment | `bitangentEC` | | `positionWC` | vertex | `positionMC` | | `positionEC` | vertex | `positionMC` | | `normalEC` | vertex | `normalMC` | | `tangentEC` | vertex | `tangentMC` | | `bitangentEC` | vertex | `bitangentMC` | | `normalMC` | fragment | `normalEC` | | `tangentMC` | fragment | `tangentEC` | | `bitangentMC` | fragment | `bitangentEC` | **Note:** `positionMC` is **not** rejected in the fragment shader — it is valid in both stages. --- ## Enums ### CustomShaderMode Frozen string enum. String value is used directly in the `CUSTOM_SHADER_` GLSL define. | JS constant | String value | Pipeline | |---|---|---| | `MODIFY_MATERIAL` (default) | `"MODIFY_MATERIAL"` | material → custom shader → lighting | | `REPLACE_MATERIAL` | `"REPLACE_MATERIAL"` | custom shader → lighting (skips material stage) | ### LightingModel Frozen numeric enum. When omitted from the constructor, the model's default lighting is preserved. | JS constant | Value | Behavior | |---|---|---| | `UNLIT` | `0` | Skip lighting; `material.diffuse` used directly as output (alpha still applied) | | `PBR` | `1` | Physically-based with IBL when available | ### CustomShaderTranslucencyMode Frozen numeric enum. Default `INHERIT`. | JS constant | Value | Effect | |---|---|---| | `INHERIT` | `0` | Honor the source material's translucency | | `OPAQUE` | `1` | Force opaque render pass | | `TRANSLUCENT` | `2` | Force translucent render pass | ### UniformType Frozen string enum. String values are GLSL type names. | JS constant | GLSL type | JS value type | |---|---|---| | `FLOAT` | `float` | `Number` | | `VEC2` | `vec2` | `Cartesian2` | | `VEC3` | `vec3` | `Cartesian3` | | `VEC4` | `vec4` | `Cartesian4` | | `INT` | `int` | `Number` | | `INT_VEC2` | `ivec2` | `Cartesian2` | | `INT_VEC3` | `ivec3` | `Cartesian3` | | `INT_VEC4` | `ivec4` | `Cartesian4` | | `BOOL` | `bool` | `Boolean` | | `BOOL_VEC2` | `bvec2` | `Cartesian2` | | `BOOL_VEC3` | `bvec3` | `Cartesian3` | | `BOOL_VEC4` | `bvec4` | `Cartesian4` | | `MAT2` | `mat2` | `Matrix2` | | `MAT3` | `mat3` | `Matrix3` | | `MAT4` | `mat4` | `Matrix4` | | `SAMPLER_2D` | `sampler2D` | `TextureUniform` | | `SAMPLER_CUBE` | `samplerCube` | **Rejected** — throws `DeveloperError("CustomShader does not support samplerCube uniforms")` at construction | ### VaryingType Frozen string enum. Floating-point types only. | JS constant | GLSL type | |---|---| | `FLOAT` | `float` | | `VEC2` | `vec2` | | `VEC3` | `vec3` | | `VEC4` | `vec4` | | `MAT2` | `mat2` | | `MAT3` | `mat3` | | `MAT4` | `mat4` | --- ## TextureUniform options ```js new TextureUniform({ url, // string | Resource — mutually exclusive with typedArray typedArray, // Uint8Array — mutually exclusive with url width, height, // required when typedArray is used pixelFormat, // default PixelFormat.RGBA pixelDatatype, // default PixelDatatype.UNSIGNED_BYTE repeat, // default true → REPEAT; false → CLAMP_TO_EDGE (both axes) minificationFilter, // default LINEAR magnificationFilter, // default LINEAR maximumAnisotropy, // default 1.0 }); ``` **Construction errors:** - `"exactly one of options.typedArray, options.url must be defined"` - `"options.width and options.height are required when options.typedArray is defined"` Texture memory uses row-major storage with WebGL's bottom-up Y convention. --- ## FeatureIds struct Auto-generated from the primitive's `featureIds` array. All values are GLSL `int` (not `uint`). | Access | Source | Notes | |---|---|---| | `featureId_N` | `EXT_mesh_features` attribute or implicit | `N` is position in `featureIds` array | | `featureId_N` | `EXT_mesh_features` feature ID texture | **Fragment shader only** | | `