# `Labs.shading.graph`

> Contract 2.0.0 · package sha256 `a857eca95b35921109faf997094bb4192f12527d9d0fcd4be7e97f06425bad6e` · generated from `configurator-runtime.d.ts` by `services/onsite-scripter/scripts/build-contract-docs.mjs`; edit the source, not this file.

Method of [`Labs.shading`](Labs.shading.md) · labs · since 2.0.0 · called as `session.labs.shading.graph`

```ts
graph<U extends Record<string, ShadingUniformType>>(uniforms: U, build: (n: ShadingNodes<U>) => ShadingOutputs, options: {
  owner: Collection;
}): Shading<U>;
```

Builds a graph from typed nodes; `uniforms` names its inputs and their types. Immediate;
owned by `owner`: its dispose disposes the graph. `build` runs at the call; a node, input or
output outside [`ShadingNodes`](ShadingNodes.md)' set records 'unsupported-spec' naming it, and materials
wearing the graph draw their base fields. The shader code loads on demand: the graph draws
from the first frame after it arrives (spec section 6.3).

**Default:** each uniform 0 (a 'texture' none) until [`Shading.set`](Shading.set.md)

## Options

Through [`Session`](Session.md):

| Option | Type | Default | What it does |
| --- | --- | --- | --- |
| `owner` | `Collection` | — |  |

Through [`Tx`](Tx.md):

| Option | Type | Default | What it does |
| --- | --- | --- | --- |
| `owner` | `Collection` | — |  |

## Example

Imports: values (`has`, `validate`, the `Holo*Error` classes, the pure helpers) from `@holostep-configurators/runtime-client`, types from `@holostep-configurators/runtime-client/contract`, `/math` and `/testing` names from those entries; `boot` from the runtime module the root's `loadRuntimeAtFloor` resolves to. A type your page defines is your app's: declare it there, never import it from the package.

Compiled under the contract's strict settings (`examples/declaration/20-Labs.shading.graph.ts`):

```ts
import type { Session } from '@holostep-configurators/runtime-client/contract';
declare const session: Session;
declare const signal: AbortSignal;
// a fabric grade over the mapped base colour: saturation, then gamma
const owner = session.collection('fabrics', { role: 'scenery', signal });
const luma709 = { x: 0.2126, y: 0.7152, z: 0.0722 };
const grade = session.labs.shading.graph(
  { gamma: 'float', saturation: 'float' },
  (n) => {
    const albedo = n.base('baseColor');
    const luma = n.node<'float'>('dotproduct', { in1: albedo, in2: luma709 });
    const grey = n.node<'color3'>('combine3', { in1: luma, in2: luma, in3: luma });
    const sat = n.node<'color3'>('mix', { bg: grey, fg: albedo, mix: n.uniform('saturation') });
    return { baseColor: n.node<'color3'>('power', { in1: sat, in2: n.uniform('gamma') }) };
  },
  { owner },
);
grade.set('gamma', 1.12);
grade.set('saturation', 1.12);
await session.find({ slot: 'fabric' }).set({ material: { labs: { shading: grade } } });
```

## Generic-API test (spec 3.1)

| Rule | Result |
| --- | --- |
| 1. Neutral name | pass: `graph` names no product |
| 2. A precedent | pass (through its owner [`Labs.shading`](Labs.shading.md)): [Babylon.js NodeMaterial](https://github.com/BabylonJS/Babylon.js/blob/master/packages/dev/core/src/Materials/Node/nodeMaterial.ts) (row `K21`); [Blender shader nodes](https://docs.blender.org/manual/en/latest/render/shader_nodes/index.html) (row `K21`) |
| 3. Two apps, or labs | labs: it graduates when a second app uses it; apps today: app-510d750508, app-59c5b5751e |
| 4. The cheaper fix first | decided per need in Appendix B: rows `K21` (through its owner [`Labs.shading`](Labs.shading.md)) at tier labs (a member only where no rule, data, asset or app code serves the need) |
