vgpu/scene14 symbolsView source ↗

Symbols in this topic

unlitMaterial

Creates a flat-color material descriptor; renders without lights.

Import

TypeScript
1
import { unlitMaterial } from "vgpu/scene";

Signature

TypeScript
1
declare function unlitMaterial(options?: import("vgpu/scene").ColorMaterialOptions): import("vgpu/scene").UnlitMaterial;

Examples

TypeScript
1
2
3
4
import { srgb, unlitMaterial } from "vgpu/scene";
 
const material = unlitMaterial({ color: srgb("#3b82f6") });
material.set({ opacity: 0.5 });

Notes


lambertMaterial

Creates an N·L diffuse material descriptor lit by scene lights (uses @vgpu/wgsl-std/light lambert).

Import

TypeScript
1
import { lambertMaterial } from "vgpu/scene";

Signature

TypeScript
1
declare function lambertMaterial(options?: import("vgpu/scene").ColorMaterialOptions): import("vgpu/scene").LambertMaterial;

Examples

TypeScript
1
2
3
4
5
6
7
8
9
import { directionalLight, lambertMaterial, mesh, scene, sphere } from "vgpu/scene";
 
const root = scene({
  children: [
    mesh(sphere({ radius: 0.5 }), lambertMaterial({ color: [0.4, 0.6, 1] })),
    directionalLight({ direction: [-1, -2, -1], intensity: 1.2 }),
  ],
});
void root;

Notes


normalMaterial

Creates a debug material that shades world-space normals; needs no lights or parameters. It is the default material of mesh().

Import

TypeScript
1
import { normalMaterial } from "vgpu/scene";

Signature

TypeScript
1
declare function normalMaterial(): import("vgpu/scene").NormalMaterial;

Examples

TypeScript
1
2
3
4
import { mesh, normalMaterial, torus } from "vgpu/scene";
 
const donut = mesh(torus(), normalMaterial());
void donut;

Notes


shaderMaterial

Creates a custom material from a WGSL fragment stage compiled against the scene renderer's vertex contract. Scene globals live in @group(0) (renderer-owned); material bindings start at @group(1).

Import

TypeScript
1
import { shaderMaterial } from "vgpu/scene";

Signature

TypeScript
1
2
3
4
declare function shaderMaterial(
  source: string,
  options?: import("vgpu/scene").ShaderMaterialOptions,
): import("vgpu/scene").ShaderMaterial;

Parameters

ParamTypeRequiredDefaultNotes
sourcestringWGSL fragment stage. May import from @vgpu/wgsl-std/*.
options.setRecord<string, unknown>{}Initial binding values keyed by WGSL variable name, like draw.set().
options.blendMaterialBlend"alpha", "additive", or "premultiplied".
options.labelstringUsed in error where strings.

Returns: ShaderMaterial descriptor with source, values, and set(). Throws: None at construction; WGSL errors surface when the renderer compiles the material.

Examples

TypeScript
1
2
3
4
5
6
import { shaderMaterial } from "vgpu/scene";
 
const glow = shaderMaterial(GLOW_WGSL, { set: { params: { color: [0.2, 0.5, 1], intensity: 2 } } });
glow.set({ params: { intensity: 4 } }); // merges per binding, like draw.set()
 
declare const GLOW_WGSL: string;

Notes


SceneMaterial

Abstract base of every material descriptor. Discriminate concrete materials by kind.

Import

TypeScript
1
import { SceneMaterial } from "vgpu/scene";

Signature

TypeScript
1
2
3
4
5
declare abstract class SceneMaterial {
  abstract readonly kind: import("vgpu/scene").SceneMaterialKind;
  label: string | undefined;
  blend: import("vgpu/scene").MaterialBlend | undefined;
}

Examples

TypeScript
1
2
3
4
import { UnlitMaterial, unlitMaterial, type SceneMaterial } from "vgpu/scene";
 
const material: SceneMaterial = unlitMaterial();
if (material instanceof UnlitMaterial) void material.color;

Notes


UnlitMaterial

Class returned by unlitMaterial(). kind: "unlit" with color, opacity, and set().

Import

TypeScript
1
import type { UnlitMaterial } from "vgpu/scene";

Signature

TypeScript
1
2
3
4
5
6
declare class UnlitMaterial {
  readonly kind: "unlit";
  set(values: import("vgpu/scene").ColorMaterialValues): this;
  readonly color: Float32Array;
  readonly opacity: number;
}

Examples

TypeScript
1
2
3
import { unlitMaterial } from "vgpu/scene";
 
unlitMaterial().set({ color: [1, 0, 0] });

Notes


LambertMaterial

Class returned by lambertMaterial(). kind: "lambert" with color, opacity, and set().

Import

TypeScript
1
import type { LambertMaterial } from "vgpu/scene";

Signature

TypeScript
1
2
3
4
5
6
declare class LambertMaterial {
  readonly kind: "lambert";
  set(values: import("vgpu/scene").ColorMaterialValues): this;
  readonly color: Float32Array;
  readonly opacity: number;
}

Examples

TypeScript
1
2
3
import { lambertMaterial } from "vgpu/scene";
 
lambertMaterial({ color: [0.4, 0.6, 1] }).set({ opacity: 0.8 });

Notes


NormalMaterial

Class returned by normalMaterial(). kind: "normal", no parameters.

Import

TypeScript
1
import type { NormalMaterial } from "vgpu/scene";

Signature

TypeScript
1
2
3
declare class NormalMaterial {
  readonly kind: "normal";
}

Examples

TypeScript
1
2
3
4
import { normalMaterial, type NormalMaterial } from "vgpu/scene";
 
const material: NormalMaterial = normalMaterial();
void material;

Notes


ShaderMaterial

Class returned by shaderMaterial(). Holds the WGSL source plus binding values merged by set().

Import

TypeScript
1
import type { ShaderMaterial } from "vgpu/scene";

Signature

TypeScript
1
2
3
4
5
6
declare class ShaderMaterial {
  readonly kind: "shader";
  readonly source: string;
  readonly values: Readonly<Record<string, unknown>>;
  set(values: Record<string, unknown>): this;
}

Examples

TypeScript
1
2
3
4
import { shaderMaterial } from "vgpu/scene";
 
const material = shaderMaterial("@fragment fn fs_main() {}", { set: { params: { t: 0 } } });
material.set({ params: { t: 1 } });

Notes


ColorMaterialOptions

Options shared by unlitMaterial() and lambertMaterial().

Import

TypeScript
1
import type { ColorMaterialOptions } from "vgpu/scene";

Signature

TypeScript
1
2
3
4
5
6
interface ColorMaterialOptions {
  readonly color?: import("vgpu/scene").Vec3Like;
  readonly opacity?: number;
  readonly blend?: import("vgpu/scene").MaterialBlend;
  readonly label?: string;
}

Parameters

FieldTypeRequiredDefaultNotes
colorVec3Like[1, 1, 1]Linear RGB; pass srgb("#…") for hex input.
opacitynumber1In [0, 1]. Values below 1 need a blend mode to show.
blendMaterialBlendBlend preset shared with DrawOptions.blend.
labelstringUsed in error where strings.

Examples

TypeScript
1
2
3
import { srgb, unlitMaterial } from "vgpu/scene";
 
unlitMaterial({ color: srgb("#ff8800"), opacity: 0.75, blend: "alpha" });

Notes


ColorMaterialValues

Values accepted by set() on color materials.

Import

TypeScript
1
import type { ColorMaterialValues } from "vgpu/scene";

Signature

TypeScript
1
2
3
4
interface ColorMaterialValues {
  readonly color?: import("vgpu/scene").Vec3Like;
  readonly opacity?: number;
}

Examples

TypeScript
1
2
3
import { unlitMaterial } from "vgpu/scene";
 
unlitMaterial().set({ color: [0, 1, 0], opacity: 0.9 });

Notes


MaterialBlend

Blend preset accepted by materials; the same presets as DrawOptions.blend.

Import

TypeScript
1
import type { MaterialBlend } from "vgpu/scene";

Signature

TypeScript
1
type MaterialBlend = "alpha" | "additive" | "premultiplied";

Examples

TypeScript
1
2
3
4
import { unlitMaterial, type MaterialBlend } from "vgpu/scene";
 
const blend: MaterialBlend = "additive";
unlitMaterial({ blend });

Notes


SceneMaterialKind

Discriminator for material descriptors.

Import

TypeScript
1
import type { SceneMaterialKind } from "vgpu/scene";

Signature

TypeScript
1
type SceneMaterialKind = "unlit" | "normal" | "lambert" | "shader";

Examples

TypeScript
1
2
3
4
import { normalMaterial, type SceneMaterialKind } from "vgpu/scene";
 
const kind: SceneMaterialKind = normalMaterial().kind;
void kind;

Notes


ShaderMaterialOptions

Options accepted by shaderMaterial().

Import

TypeScript
1
import type { ShaderMaterialOptions } from "vgpu/scene";

Signature

TypeScript
1
2
3
4
5
interface ShaderMaterialOptions {
  readonly set?: Record<string, unknown>;
  readonly blend?: import("vgpu/scene").MaterialBlend;
  readonly label?: string;
}

Examples

TypeScript
1
2
3
import { shaderMaterial } from "vgpu/scene";
 
shaderMaterial("@fragment fn fs_main() {}", { label: "glow", blend: "additive" });

Notes