Shader transitions on an Image (on press) with react-native-skia #2369
-
I'm pretty new to react-native-skia, I have a grayscale shader applied on an Image and I would like to apply this kind of transition animation on press to switch between grayscale and full colored picture. Here is the code that I'm using to apply a grayscale effect. const GRAYSCALE_SHADER = Skia.RuntimeEffect.Make(`
uniform shader image;
half4 main(in vec2 xy)
{
//Grabbing the texture color at the current pixel.
vec4 texColor = image.eval(xy).rgba;
vec3 gray_scale = vec3(dot(vec3(0.5, 0.2, 0.2), texColor.rgb));
// Output to screen
return vec4(gray_scale, texColor.a) ;
}
`)!;
const image = useImage('../path/to/image.png');
return (
<Canvas
style={{ flex: 1 }}
>
<Image
image={image}
fit="cover"
x={0}
y={0}
width={200}
height={200}
>
<RuntimeShader source={GRAYSCALE_SHADER} />
</Image>
</Canvas>
) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Please, if someone can take 30 sec to just redirect me to some documentation that could help me or any other link 🙏🏽 it will be very helpful. |
Beta Was this translation helpful? Give feedback.
-
My version of code,
Here's the documentation for learning about RN Skia, |
Beta Was this translation helpful? Give feedback.
We do support these gltransitions almost out of the box: https://github.com/Shopify/react-native-skia/tree/main/example/src/Examples/Transitions
Here is the tutorial: https://www.youtube.com/watch?v=PzKWpwmmRqM
I hope this helps