Paints a material's base color from a WGSL fragment you write yourself — the
most general color-source, the escape hatch for any spatial → color rule the
built-in sources cannot express.
Declarative element:
<sk-custom-wgsl-color-source>
Not on the sk.* global — construct via the declarative element or a module import.
This is the author-WGSL member of the ColorSource family: like every
color-source it gives a material a base color that varies across the surface,
but here you supply the evaluator itself as WGSL rather than composing built-in
pieces. It is the color-source analogue of the wider custom-WGSL family (see
AbstractComputeNode).
The contract. The body must define an evaluateColorSourceRaw entry
function returning straight-alpha RGBA in LINEAR space (you may declare
additional helper functions alongside it):
``wgsl
fn evaluateColorSourceRaw(worldPos: vec3<f32>, uv: vec2<f32>, strokeCoord: vec2<f32>, strokeLength: f32, fragCoord: vec2<f32>) -> vec4<f32>
`
Each input is explicitly named for what it carries: worldPos and
fragCoord are always meaningful; uv is the mesh texture coordinate
(surface and edge paints); strokeCoord/strokeLength are the stroke
parametrization — arc-length progress in .x, cross position in .y,
total arc length in strokeLength (stroke paints). The framework declares
a module-scope constant SK_EVAL_SURFACE: bool — true when the shader is
generated for a surface/edge pipeline, false for a stroke pipeline — so
one body serving both topologies can branch on its context (never on
coordinate values, which cannot discriminate).
Masking is not your concern — the applicability field and the
mix(baseColor, source, weight) blend are applied outside the raw evaluator by
the shared wrapper. You declare no bind groups; instead you read your own
parameters through generated skUniform_<name>()` accessors, one per named
sk-wgsl-uniform child, so a uniform can be animated to drive the shader
without hand-packing a buffer.
This element's own world matrix. The kernel can read this element's own
transform: skWorldMatrix() -> mat4x4<f32> (parent chain included) and
skWorldMatrixInverse(). Author a spatial uniform (a position, a direction) in
the element's LOCAL frame and lift it with
(skWorldMatrix() * vec4<f32>(localPos, 1.0)).xyz (a direction uses w = 0),
or map worldPos back to source-local with the inverse — so the effect moves
WITH the geometry when the source (or an ancestor) is transformed. It is this
ELEMENT's transform, not the painted mesh's, so one source painting several
meshes exposes one consistent frame; place the source under the node whose
motion it should follow. Resolves in every pass — surface, edge, stroke,
stacked paint, and the shadow pipelines.
Key attributes. wgsl supplies the body inline; src loads it from an
external URL (src wins over inline, with no fallback on failure), and the
source is inert — the flat base-color shows through — until it resolves.
alpha-mode declares how the returned alpha is classified for compositing.
Related. A material selects it with base-color-source="#id" (see
sk-plain-material); its parameters are sk-wgsl-uniform,
sk-wgsl-vec2-uniform, sk-wgsl-vec3-uniform,
sk-wgsl-vec4-uniform, sk-wgsl-color-uniform (a colour authored
as a string), and sk-wgsl-f32-array-uniform children. For
a precomputed color array from a compute shader instead of a per-fragment
formula, use sk-compute-buffer-color-source; to layer it, use
sk-composite-color-source.
constructor(config?: VisualizableSceneNodeConfig)
Inherited from VisualizableSceneNode.
Inherited from: ColorSource, VisualizableSceneNode, SceneNode, SkenraAnimatable
— see those pages for inherited members.
| Property | Type | Default | Description | Declared by |
|---|---|---|---|---|
wgsl |
string |
"" |
Inline WGSL shader body. Ignored while src is set. |
CustomWGSLColorSource |
src |
string | null |
— | External WGSL source URL (src), or null. Assigning starts a load. |
CustomWGSLColorSource |
hasEffectiveWGSLread-only |
boolean |
— | Whether usable effective WGSL is available. false while a src is set |
CustomWGSLColorSource |
alphaMode |
CustomWGSLAlphaMode |
"auto" |
Author-declared fragment classification (alpha-mode). Drives |
CustomWGSLColorSource |
fieldanimatable |
Field | null |
— | Gets the optional applicability field that masks where this source | ColorSource |
visualize |
boolean |
false |
Whether the visualization is visible (wireframe splines + center marker). | VisualizableSceneNode |
xanimatable |
number |
0 |
Gets the X position component. | SceneNode |
yanimatable |
number |
0 |
Gets the Y position component. | SceneNode |
zanimatable |
number |
0 |
Gets the Z position component. | SceneNode |
hanimatable |
number |
0 |
Gets the heading (Y-axis) rotation in radians. | SceneNode |
panimatable |
number |
0 |
Gets the pitch (X-axis) rotation in radians. | SceneNode |
banimatable |
number |
0 |
Gets the bank (Z-axis) rotation in radians. | SceneNode |
quaternionanimatable |
Quaternion |
— | Gets the rotation as a quaternion. | SceneNode |
sxanimatable |
number |
1 |
Gets the X-axis scale factor. | SceneNode |
syanimatable |
number |
1 |
Gets the Y-axis scale factor. | SceneNode |
szanimatable |
number |
1 |
Gets the Z-axis scale factor. | SceneNode |
hRad |
number |
0 |
Gets the heading (Y-axis) rotation in radians. | SceneNode |
pRad |
number |
0 |
Gets the pitch (X-axis) rotation in radians. | SceneNode |
bRad |
number |
0 |
Gets the bank (Z-axis) rotation in radians. | SceneNode |
hDeg |
number |
0 |
Gets the heading (Y-axis) rotation in degrees. | SceneNode |
pDeg |
number |
0 |
Gets the pitch (X-axis) rotation in degrees. | SceneNode |
bDeg |
number |
0 |
Gets the bank (Z-axis) rotation in degrees. | SceneNode |
xBasebase value |
number |
— | Gets the base (non-animated) value of X position. | SceneNode |
yBasebase value |
number |
— | Gets the base (non-animated) value of Y position. | SceneNode |
zBasebase value |
number |
— | Gets the base (non-animated) value of Z position. | SceneNode |
hBasebase value |
number |
0 |
Gets the base (non-animated) value of heading (Y-axis rotation). | SceneNode |
pBasebase value |
number |
0 |
Gets the base (non-animated) value of pitch (X-axis rotation). | SceneNode |
bBasebase value |
number |
0 |
Gets the base (non-animated) value of bank (Z-axis rotation). | SceneNode |
quaternionBasebase value |
Quaternion |
— | Gets the base (non-animated) quaternion rotation. | SceneNode |
sxBasebase value |
number |
— | Gets the base (non-animated) value of X-axis scale. | SceneNode |
syBasebase value |
number |
— | Gets the base (non-animated) value of Y-axis scale. | SceneNode |
szBasebase value |
number |
— | Gets the base (non-animated) value of Z-axis scale. | SceneNode |
draggable |
boolean |
false |
Gets whether this node can be dragged. | SceneNode |
parentread-only |
SceneNode | null |
— | The parent node in the scene graph, or null at the root. |
SceneNode |
sceneread-only |
any |
— | Gets the Scene this node belongs to, if any. | SceneNode |
posread-only |
Point3D |
— | Gets the world-space position of this node. | SceneNode |
matrixread-only |
Float32Array<ArrayBufferLike> |
— | Gets the computed 4x4 transformation matrix. | SceneNode |
animationsread-only |
SkenraAnimation[] |
— | Public getter for the animations affecting this target. | SkenraAnimatable |
| Method | Description | Declared by |
|---|---|---|
addUniform(name: string, value: number): WGSLUniform |
Imperative twin of authoring a <sk-wgsl-uniform> child. |
CustomWGSLColorSource |
addF32ArrayUniform(name: string, values: readonly number[]): WGSLF32ArrayUniform |
Imperative twin of authoring a <sk-wgsl-f32-array-uniform> child. |
CustomWGSLColorSource |
addVec2Uniform(name: string, x: number, y: number): WGSLVec2Uniform |
Imperative twin of authoring a <sk-wgsl-vec2-uniform> child. |
CustomWGSLColorSource |
addVec3Uniform(name: string, x: number, y: number, z: number): WGSLVec3Uniform |
Imperative twin of authoring a <sk-wgsl-vec3-uniform> child. |
CustomWGSLColorSource |
addVec4Uniform(name: string, x: number, y: number, z: number, w: number): WGSLVec4Uniform |
Imperative twin of authoring a <sk-wgsl-vec4-uniform> child. |
CustomWGSLColorSource |
addColorUniform(name: string, color: ColorInput): WGSLColorUniform |
Imperative twin of authoring a <sk-wgsl-color-uniform> child. |
CustomWGSLColorSource |
addMaterialPaint(material: Material, paintTarget: PaintTarget, options?: any): Paint |
Applies a material to this node for a specific paint target. | SceneNode |
getPaints(): ReadonlyMap<PaintTarget, Paint> |
— | SceneNode |
getOwnPaints(): readonly Paint[] |
Gets only the paints directly applied to this node (not inherited). | SceneNode |
removePaint(paint: Paint): void |
Removes a paint from this node. | SceneNode |
getWorldPosition(): number[] |
Returns this node’s origin in world space. | SceneNode |
getWorldMatrix(): Float32Array<ArrayBufferLike> |
Returns this node’s world transform — its local transform composed with all ancestor transforms. | SceneNode |
setViewportPosition(camera: AbstractCamera, x: number, y: number, z: number = 0.5): boolean |
Sets the node's local translation so that it appears at the specified viewport position. | SceneNode |
getViewportPosition(camera?: AbstractCamera): [number, number, number] | null |
Returns the node's current world position projected to viewport CSS pixel coordinates. | SceneNode |
setNDCPosition(camera: AbstractCamera, ndcX: number, ndcY: number, ndcZ: number = 0.5): boolean |
Sets the node's local translation so that it appears at the specified NDC position in the viewport. | SceneNode |
getBoundsInSpace(targetSpaceMatrix: Float32Array): { minX: number; maxX: number; minY: number; maxY: number; minZ: number; maxZ: number; } | null |
Computes the axis-aligned bounding box (AABB) of this node and its descendants | SceneNode |
animate(firstArg: TypedKeyframe<this>[] | TypedPropertyIndexedKeyframes<this> | Record<string, any> | globalThis.Keyframe[] | globalThis.PropertyIndexedKeyframes | null, secondArg?: number | KeyframeAnimationOptions | globalThis.KeyframeAnimationOptions): SkenraAnimation & Animation |
Creates a new SkenraAnimation for this target per Web Animations API. | SkenraAnimatable |
removeAnimation(animation: SkenraAnimation): boolean |
Removes a specific animation from this object. | SkenraAnimatable |
constrain(type: K, config: ConstraintConfigMap[K]): ConstraintReturnMap[K] |
Creates a constraint on this Animatable using a fluent API. | SkenraAnimatable |