software-mansion / software-mansion/TypeGPU

feat(@typegpu/react): useUniformValue

Open
#1,689 0 comments 0 reactions 1 assignee View on GitHub

@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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.