-
-
Notifications
You must be signed in to change notification settings - Fork 22
Open
Description
This hook should accept two parameters:
schema: TSchema
: The schema that will be used to allocate a GPU buffer, and serialize values to VRAM.initialValue?: TValue
: The value that the buffer will hold initially. Changes to this value after the initial component render are ignored.
Signature:
useUniformValue<TSchema extends d.AnyWgslData, TValue extends d.Infer<TSchema>>(schema: TSchema, initialValue?: TValue | undefined): UniformValue<TSchema, TValue>;
Usage:
const Component = () => {
const time = useUniformValue(d.f32, 0);
// Runs every frame on the CPU
useFrame(() => {
// The .value property allows mutable access on the CPU
time.value = performance.now() / 1000;
});
const { ref } = useRender({
fragment: () => {
'kernel';
// The .$ property allows readonly access on the GPU
const t = time.$;
return d.vec4f(sin(t) * 0.5 + 0.5, 0, 0, 1);
},
});
return <canvas ref={ref}></canvas>;
};
Metadata
Metadata
Assignees
Labels
No labels