Skip to content

feat(@typegpu/react): useMirroredUniform #1714

@iwoplaza

Description

@iwoplaza

The useMirroredUniform hook is used to "synchronise"/"mirror" a JS value from React onto the GPU.

useUniformValue useMirroredUniform
mutable .value
reacts to change in parameters (schema, value)
function Component(props: { color: d.v3f }) {
  // The uniform will be updated with the latest value of `props.color`
  // on every React render.
  const color = useMirroredUniform(d.vec3f, props.color);

  const { ref } = useRender({
    fragment: () => {
      'kernel';
      return d.vec4f(color.$, 1);
    },
  });

  return <canvas ref={ref}></canvas>
}

Doing the same with useUniformValue would require manually syncing the value either in a useEffect, or on every frame.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions