Help, how can i put useSharedValue on uniform? #3521
Replies: 1 comment
-
|
i've just solved my self.. use useDerivedValue to make uniforms and pass it to shader(don't use uniforms.value just use uniforms) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello. I'm beginner of react native.
I'm just learning skia from youtube and tutorial says use useValue but it doesn't exist more.
Docs says use useSharedValue directly and it work, but when i try it, useSharedValue cannot be set to uniform variables.
How could i solve it? plz help me...
`import { Canvas, Fill, Shader, Skia, vec } from "@shopify/react-native-skia";
import { useWindowDimensions, View } from "react-native";
import { Gesture, GestureDetector } from "react-native-gesture-handler";
import { useSharedValue } from "react-native-reanimated";
const source = Skia.RuntimeEffect.Make(`
uniform vec4 colors[4];
uniform vec2 center;
uniform vec2 pointer;
export default function Index() {
const { width, height } = useWindowDimensions();
const center = vec(width / 2, height / 2);
const colors = ["#dafb61", "#61DAFB", "#fb61da", "#61fbcf"].map(color => Skia.Color(color));
const pointer = useSharedValue(vec(0,0));
const onTouch = Gesture.Pan().onChange((event) => {
pointer.value = vec(pointer.value.x + event.changeX, pointer.value.y + event.changeY);
});
if (!source) {
throw new Error("Couldn't compile the shader")
}
return (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<Canvas style={{ width, height }}>
<Shader source={source} uniforms={{ center, colors, pointer }} />
);
}
`
Beta Was this translation helpful? Give feedback.
All reactions