Skip to content

Conversation

piaccho
Copy link
Collaborator

@piaccho piaccho commented Sep 12, 2025

Changes

  • Added an implementation of the useUniformValue hook
  • Updated the triangle example

Closes #1689

Copy link

github-actions bot commented Sep 12, 2025

pkg.pr.new

packages
Ready to be installed by your favorite package manager ⬇️

https://pkg.pr.new/software-mansion/TypeGPU/typegpu@b8069548cdb78735790e6ea64950cf13265cb89a
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/noise@b8069548cdb78735790e6ea64950cf13265cb89a
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@b8069548cdb78735790e6ea64950cf13265cb89a

benchmark
view benchmark

commit
view commit

@piaccho piaccho requested a review from iwoplaza September 12, 2025 11:41
@piaccho piaccho marked this pull request as ready for review September 12, 2025 11:59
@piaccho piaccho requested a review from iwoplaza September 15, 2025 13:26
@piaccho piaccho requested a review from reczkok September 15, 2025 14:33

// biome-ignore lint/correctness/useExhaustiveDependencies: This value needs to be stable
const uniformValue = useMemo(() => {
let currentValue = initialValue;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Schemas should generally be callable, in which case they return an initial value that matches that schema.

Suggested change
let currentValue = initialValue;
let currentValue = initialValue ?? schema();

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing that out! However, with current implementation:

export function useUniformValue<
  TSchema extends d.AnyWgslData,
  TValue extends d.Infer<TSchema>,
>(
  schema: ValidateUniformSchema<TSchema>,
  initialValue?: TValue | undefined,
): UniformValue<TSchema, TValue> {

schema is not callable:

This expression is not callable.
  Not all constituents of type 'AnyWgslData | `(Error) ${string}`' are callable.
    Type 'U16' has no call signatures.ts(2349)

I'm wondering how can I alter this to simplify the logic.

Comment on lines +39 to +47
get value() {
return currentValue;
},
set value(newValue: TValue | undefined) {
currentValue = newValue;
if (newValue !== undefined) {
uniformBuffer.write(newValue);
}
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of the previous comment, we don't have to worry about undefined.

Suggested change
get value() {
return currentValue;
},
set value(newValue: TValue | undefined) {
currentValue = newValue;
if (newValue !== undefined) {
uniformBuffer.write(newValue);
}
},
get value() {
return currentValue;
},
set value(newValue: TValue) {
currentValue = newValue;
uniformBuffer.write(newValue);
},

Copy link
Collaborator

@iwoplaza iwoplaza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this 🙏
As for the comments, I'll sort it out in the original branch

@iwoplaza iwoplaza merged commit 7fb73e6 into feat/typegpu-react Sep 16, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants