npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-native-webgpu-worklets

v0.3.0

Published

ThreeJS + wgpu-matrix + TypeGPU for WebGPU on Reanimated Worklets

Readme

react-native-webgpu-worklets

WebGPU Worklets allow you to run react-native-wgpu, Three.js, wgpu-matrix, and TypeGPU libraries on Reanimated Worklets on the UI Thread. With that integration, you can run smooth 3D animations backed by WebGPU using the Reanimated API and enjoy seamless integration with the Gesture Handler.

Installation

yarn add react-native-webgpu-worklets

Add peer dependencies

yarn add react-native-reanimated react-native-worklets react-native-wgpu three typegpu wgpu-matrix

It required Reanimated 4.1.0 or newer and Worklets 0.5.0 or newer.

Usage

import { 
  enableGPUForWorklets, 
  requireUI,
} from 'react-native-webgpu-worklets';
import { runOnUI } from 'react-native-reanimated';

// ...

enableGPUForWorklets(); // <- initialize GPU on UI Thread

runOnUI(() => {
  const THREE = requireUI('threejs'); // <- import library on UI

  const scene = new THREE.Scene();
})();

Example

import { enableGPUForWorklets, requireUI, makeWebGPURenderer, useSharedContext } from 'react-native-webgpu-worklets';
import { runOnUI, useFrameCallback, useSharedValue } from 'react-native-reanimated';

import { Canvas, type RNCanvasContext, useCanvasEffect } from "react-native-wgpu";
import { PerspectiveCamera, Scene, Mesh } from 'three';
import { Gesture, GestureDetector, GestureHandlerRootView } from 'react-native-gesture-handler';
import type { WebGPURenderer } from 'three/webgpu';


type SharedContext = {
  context: RNCanvasContext,
  camera: PerspectiveCamera,
  scene: Scene,
  mesh: Mesh,
  renderer: WebGPURenderer,
};

export default function CubeExample() {
  const sharedContext = useSharedContext<SharedContext | {}>({});

  const ref = useCanvasEffect(async () => {
    enableGPUForWorklets(); 
    const context = ref.current!.getContext("webgpu")!;
    const adapter = await navigator.gpu.requestAdapter();
    const device = await adapter?.requestDevice();
    
    runOnUI(async () => {
      const THREE = requireUI('threejs');
      
      const { width, height } = context.canvas as unknown as { width: number, height: number };
      
      const camera = new THREE.PerspectiveCamera(70, width / height, 0.01, 10);
      camera.position.z = 1;
      
      const scene = new THREE.Scene();
      const geometry = new THREE.BoxGeometry(0.2, 0.2, 0.2);
      const material = new THREE.MeshNormalMaterial();
      const mesh = new THREE.Mesh(geometry, material);
      scene.add(mesh);
      const renderer = makeWebGPURenderer(context, device);
      await renderer.init();
      renderer.render(scene, camera);
      context.present();

      sharedContext.value = { context, camera, scene, mesh, renderer };
    })();
  });

  const isGestureActive = useSharedValue(false);

  useFrameCallback(() => {
    if (isGestureActive.value) {
      return;
    }
    const { context, camera, scene, mesh, renderer } = sharedContext.value as SharedContext;
    if (!renderer || !renderer._initialized) {
      return;
    }
    
    mesh.rotation.x += 0.01;
    mesh.rotation.y += 0.01;
    mesh.rotation.z += 0.01;

    renderer.render(scene, camera);
    context.present();
  });

  const panGesture = Gesture.Pan()
    .onUpdate((e) => {
      isGestureActive.value = true;
      const { context, camera, scene, mesh, renderer } = sharedContext.value as SharedContext;
      mesh.rotation.x += e.translationY * 0.001;
      mesh.rotation.y += e.translationX * 0.001;

      renderer.render(scene, camera);
      context.present();
    })
    .onEnd((_e) => {
      isGestureActive.value = false;
    });

  return (
    <GestureHandlerRootView style={{ flex: 1 }}>
      <GestureDetector gesture={panGesture}>
        <Canvas ref={ref} style={{ flex: 1 }} />
      </GestureDetector>
    </GestureHandlerRootView>
  );
}

https://github.com/user-attachments/assets/3f949aaf-36c0-4874-820b-cf53216591f4

Overview

enableGPUForWorklets(config?: ModulesConfig)

You need to call it on the JS thread to initialize GPU access on the UI thread and create instances of the libraries you want to use on the UI.

ModulesConfig allows you to enable or disable library instances on the UI. By default, all libraries are available, but for performance reasons, you may want to disable some libraries.

type ModulesConfig = {
  threeJSCore: boolean,
  threeJSTSL: boolean,
  threeJSAddonsMath: boolean,
  threeJSAddonsUtils: boolean,
  typeGPU: boolean,
  wgpuMatrix: boolean,
}

requireUI(moduleName: string): <ModuleType>

Use this function to load your library in a worklet.

Example:

runOnUI(() => {
  const THREE = requireUI('threejs');
})();

Possible imports include:

  • threejs
  • threejs/tsl
  • threejs/addson/math
  • threejs/addson/utils
  • wgpu-matrix
  • typegpu
  • typegpu/data
  • typegpu/std

runOnBackground(job: () => {})

Spawn a new thread with its own JavaScript runtime and schedule a job on it. This job doesn't block your JS or UI thread. You can render on a WebGPU canvas from the background thread.

Example:

runOnBackground(() => {
  'worklet'
  const THREE = requireUI('threejs');
})();

makeWebGPURenderer(context: GPUCanvasContext, device: GPUDevice)

Allows you to create a renderer that you can use across the UI thread.

useSharedContext<T>(initialValue: T): T

Allows you to create a container to share data between multiple worklets. For example, you can create a renderer in one worklet and then use it in a worklet invoked by useFrameCallback.

Example:

type SharedContext = {
  renderer?: WebGPURenderer,
};

const sharedContext = useSharedContext<SharedContext>({renderer: null});
runOnUI(async () => {
  const THREE = requireUI('threejs');
  // ...
  const renderer = makeWebGPURenderer(context, device);

  sharedContext.value = { renderer };
})();

useFrameCallback(() => {
  const { renderer } = sharedContext.value as SharedContext;
  renderer.render();
});

License

react-native-webgpu-worklets library is licensed under The MIT License.

This library contains transformed code from the following libraries:

I'm not the author of these libraries. You should use them according to their licenses.

Credits

swm

react-native-webgpu-worklets is created by Software Mansion

Since 2012 Software Mansion is a software agency with experience in building web and mobile apps. We are Core React Native Contributors and experts in dealing with all kinds of React Native issues. We can help you build your next dream product – Hire us.

Community Discord

Join the Software Mansion Community Discord to chat about Reanimated or other Software Mansion libraries.