Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useClock does not update when passed as a uniform #2640

Open
ettnn opened this issue Sep 19, 2024 · 0 comments
Open

useClock does not update when passed as a uniform #2640

ettnn opened this issue Sep 19, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@ettnn
Copy link

ettnn commented Sep 19, 2024

Description

The clock value does not update when passed as a uniform to a shader. This is completely breaking for any time-based custom shaders. The useComputedValue hook from previous versions used to work, but that was removed. This version breaks it.

`const ShaderTest = () => {
  const { width, height } = Dimensions.get("window")

  const t = useClock()
  const uniforms = useDerivedValue(() => ({ iRotation: t.value }), [t])

  
  const source = Skia.RuntimeEffect.Make(`
    uniform float iRotation;

    vec4 main(vec2 FC) {
      vec4 o = vec4(0);
      vec2 p = vec2(0), c=p, u=FC.xy*2.-vec2(1080.0, 1920.0); // Hardcoded resolution
      float a;
      for (float i=0.; i<4e2; i++) {
        a = i/2e2-1.;
        p = cos(i*2.4+vec2(0,11)+iRotation)*sqrt(1.-a*a);
        c = u/1920.0+vec2(p.x,a)/(p.y+2.); // Using height (1920.0) for normalization
        o += (cos(i+vec4(0,2,4,0))+1.)/dot(c,c)*(1.-p.y)/3e4;
      }
      return o;
    }
  `)
  if (!source) {
    return null
  }

  return (
    <View
      style={{
        flex: 1,
        alignItems: "center",
        justifyContent: "center",
        backgroundColor: "black",
      }}
    >
      <Canvas style={{ width, height }}>
        <Fill>
          <Shader source={source} uniforms={uniforms} />
        </Fill>
      </Canvas>
    </View>
  )
}
`

Version

1.3.13

Steps to reproduce

Use useClock for a custom shader

Snack, code example, screenshot, or link to a repository

No repo

@ettnn ettnn added the bug Something isn't working label Sep 19, 2024
@ettnn ettnn changed the title useClock does not update useClock does not update when passed as a uniform Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant