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

threejs-galaxy-shader

v1.0.2

Published

A performant Three.js galaxy shader with customizable colors, spiral patterns, and black hole effects

Readme

Galaxy Shader

A Three.js custom shader for rendering spiral galaxy point clouds with black hole effects.

Features

  • Spiral galaxy geometry
  • Black hole distortion
  • Customizable Parameters
    • Colors
    • Spiral Args, Twists
    • Start Count
    • Some more, not documented yet

Getting Started

React | Node

Step 1. Install library with

npm install --save threejs-galaxy-shader

Note: Make sure you have threejs installed

npm install --save three

Step 2. Code Sample

import { useEffect, useRef } from "react";
import * as THREE from "three";
import { GalaxyGeometry, GalaxyShader } from "threejs-galaxy-shader";
let isFirst = true;
const ThreeScene = () => {
  const mountRef = useRef(null);
  const sceneRef = useRef(null);
  const rendererRef = useRef(null);
  const frameRef = useRef(null);

  useEffect(() => {
    if (isFirst) {
      isFirst = false;
      return;
    }
    if (!mountRef.current) return;

    // Scene setup
    const scene = new THREE.Scene();
    scene.background = new THREE.Color(0x000011);

    // Camera setup
    const camera = new THREE.PerspectiveCamera(
      75,
      window.innerWidth / window.innerHeight,
      0.1,
      1000
    );
    camera.position.z = 3; // Closer view for galaxy

    // Renderer setup
    const renderer = new THREE.WebGLRenderer({ antialias: true });
    renderer.setSize(window.innerWidth, window.innerHeight);
    renderer.setPixelRatio(window.devicePixelRatio);
    mountRef.current.appendChild(renderer.domElement);

    // Create a simple galaxy using the GalaxyShaderLibrary
    const galaxyConfig = {
      spiralCount: 3,
      turnsPerSpiral: 1.0,
      totalStars: 15000,
      pointSize: 2.0,
      blackHoleRadius: 0.1,
      colorMode: 2, // Single color mode
      color: new THREE.Color(0x00ff88), // Fixed green color
      colorIntensity: 1.0,
    };

    // Create galaxy geometry and shader material
    const geometry = new GalaxyGeometry(galaxyConfig.totalStars);
    const material = new GalaxyShader({
      resolution: new THREE.Vector2(window.innerWidth, window.innerHeight),
      color: galaxyConfig.color,
      pointSize: galaxyConfig.pointSize,
      totalStars: galaxyConfig.totalStars,
      time: 0,
      blackHoleRadius: galaxyConfig.blackHoleRadius,
      blackHolePosition: new THREE.Vector3(0, 0, 0),
      spiralCount: galaxyConfig.spiralCount,
      turnsPerSpiral: galaxyConfig.turnsPerSpiral,
      colorMode: galaxyConfig.colorMode,
      colorIntensity: galaxyConfig.colorIntensity,
      fadeNear: 5.0,
      fadeFar: 100.0,
    });

    const points = new THREE.Points(geometry, material);

    // Add a simple black hole visualization
    const blackHoleGeometry = new THREE.SphereGeometry(
      galaxyConfig.blackHoleRadius,
      16,
      16
    );
    const blackHoleMaterial = new THREE.MeshBasicMaterial({ color: 0x000000 });
    const blackHole = new THREE.Mesh(blackHoleGeometry, blackHoleMaterial);

    scene.add(points);
    scene.add(blackHole);

    // Store references
    sceneRef.current = scene;
    rendererRef.current = renderer;

    // Animation loop
    const animate = () => {
      frameRef.current = requestAnimationFrame(animate);

      // Update time uniform for galaxy animation
      const time = performance.now() / 10000 / 5;
      material.uniforms.u_time.value = time;
      renderer.render(scene, camera);
      // console.log(material.uniforms.u_time.value);
    };

    animate();

    // Handle window resize
    const handleResize = () => {
      camera.aspect = window.innerWidth / window.innerHeight;
      camera.updateProjectionMatrix();
      renderer.setSize(window.innerWidth, window.innerHeight);

      // Update resolution uniform
      material.uniforms.u_resolution.value.set(
        window.innerWidth,
        window.innerHeight
      );
    };

    window.addEventListener("resize", handleResize);

    // Cleanup
    return () => {
      window.removeEventListener("resize", handleResize);
      if (frameRef.current) {
        cancelAnimationFrame(frameRef.current);
      }
      if (mountRef.current && renderer.domElement) {
        mountRef.current.removeChild(renderer.domElement);
      }
      renderer.dispose();
      geometry.dispose();
      material.dispose();
    };
  }, []);

  return <div ref={mountRef} style={{ width: "100%", height: "100vh" }} />;
};

export default ThreeScene;

CommonJs

Example is under exmaples/index.html.

Please modify the import paths based on your setup.

License

MIT License

Copyright 2025 AMIT DIGGA

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.