software-mansion / software-mansion/TypeGPU
feat(@typegpu/react): useUniformValue
Open
@piaccho is already working on this.
Since Sep 11, 2025.
- Dominant language
- TypeScript
- Stars
- 3.2k
- Forks
- 122
- Avg merge
- 3d 5h
- Merged PRs (30d)
- 34
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>;
};
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.