Skip to content

How to use Runtime Shader with Skia Image to achieve pixelated effects? #2302

Closed Answered by ponikar
ponikar asked this question in Q&A
Discussion options

You must be logged in to vote

For anyone is looking for a simplest implementation.
All I had to create a custom shader which transform each block of image into pixel with respective coordinates(xy) of color.

import {
  Canvas,
  Image,
  RuntimeShader,
  Skia,
  useImage,
} from "@shopify/react-native-skia";
import { useWindowDimensions } from "react-native";

// Shader that creates pixelation effect
const source = Skia.RuntimeEffect.Make(`
    uniform shader image;
    uniform float2 resolution;  // Screen resolution
    uniform float pixelSize;    // Size of each "pixel" block
    
    half4 main(float2 xy) {   
        // Convert xy to pixel coordinates
        float2 pixelCoord = floor(xy / pixelSize) * pixelSize;

Replies: 4 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@ponikar
Comment options

Comment options

You must be logged in to vote
1 reply
@ponikar
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by ponikar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants