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

lumiere-gem

v0.1.0

Published

Real-time refractive + dispersive gem shader for three.js. Cubemap-baked ray tracing with per-channel dispersion, Beer-Lambert absorption and Fresnel. Works in the browser and in React Native via expo-gl.

Downloads

142

Readme

lumiere-gem

Real-time refractive + dispersive gem shader for three.js. Renders diamonds, moissanite, emerald, ruby and sapphire with true internal ray bouncing — not a transmission approximation.

Runs in the browser and on-device in React Native via expo-gl.

npm install lumiere-gem three

License: PolyForm Noncommercial 1.0.0. Free for personal, hobby, educational and research use. Commercial use requires a separate license — reach out at jeanrojas.com.


Why not MeshPhysicalMaterial?

transmission + ior gives you a glass ball. A cut gem's entire look comes from light entering a facet, bouncing several times off the internal facet walls under total internal reflection, and leaving through a different facet — with each wavelength taking a slightly different path.

This package models that directly:

  • Cubemap-baked surface representation. Each geometry is baked once into a 256²×6 half-float cubemap storing per-direction surface normal (RGB) and radial distance (alpha). The ray march then resolves real facet hits without a BVH.
  • Two-pass facet refinement. An ellipsoid intersection seeds the search, then two rounds of cubemap-lookup + plane-refine land the ray on the actual facet. The ellipsoid is fitted to the bounding box, so ovals and marquise cuts converge instead of clustering as round brilliants.
  • Per-channel dispersion. Three IORs (R/G/B, separated by rIndexDelta) traced independently — this is what produces "fire".
  • Beer-Lambert absorption for colored stones, plus a GGX environment specular and Fresnel term on the outer surface.

Geometry is CPU-flat-shaded before baking using the geometric face normal, oriented against the bounding-box center — so welded CAD exports with inconsistent winding render as crisp facets rather than smooth blobs.

Usage

import * as THREE from "three";
import { createGemMaterial, updateGemMatrix, clearGemCache } from "lumiere-gem";

// envMap is an equirectangular THREE.Texture (an HDR/EXR works well).
const material = createGemMaterial(
  mesh.geometry,
  envMap,
  renderer,
  {
    color: "#ffffff",
    refractiveIndex: 2.42,   // diamond
    rIndexDelta: 0.013,      // dispersion spread
    absorptionFactor: 0.6,
    environmentIntensity: 0.95,
    reflectivity: 0.55,
    bounces: 5,
  },
  mesh,
  "Gem 01", // bake key — see below
);

if (material) mesh.material = material;

The material refreshes its own model matrix in onBeforeRender, so animated or re-parented meshes need no extra work. Call updateGemMatrix(material, mesh) yourself only if you bypass that path.

The bake key matters

Baking is keyed, and choosing the key well is the difference between a correct render and a slow, inconsistent one:

createGemMaterial(geometry, envMap, renderer, opts, mesh, "Gem 01");

Every mesh passing the same key shares one cubemap bake. Use the material slot name from your GLB. If artists baked per-instance rotation into vertex positions — common in jewelry CAD exports — per-instance baking makes the left and right stones of a paired setting look visibly different. One bake per cut fixes that and costs one bake instead of N.

Omit the key and the bake falls back to a content-derived signature, which still dedupes geometries that happen to be identical.

Cleaning up

clearGemCache() disposes every baked cube texture. Call it when your scene tears down — otherwise bakes leak GPU textures across scene switches.

useEffect(() => () => clearGemCache(), []);

Options

| Option | Default | What it does | |---|---|---| | color | #ffffff | Base stone tint | | refractiveIndex | 2.4 | IOR. Diamond 2.42, moissanite 2.65, CZ 2.16, sapphire 1.77, ruby 1.76, emerald 1.58 | | rIndexDelta | 0.012 | R↔B IOR spread. Higher = more fire | | absorptionFactor | 1.0 | Beer-Lambert strength. ~0.6 for white stones, ~3.0 for colored | | environmentIntensity | 1.0 | Environment map contribution | | reflectivity | 0.5 | Outer-surface specular strength | | bounces | 5 | Internal ray bounces, clamped 1–7. Cost scales with this | | boostFactors | [1,1,1] | Per-channel output gain | | colorCorrection | [1,1,1] | Per-channel post-tint | | gammaFactor | 1.0 | Output gamma | | squashFactor | 1.0 | Per-cut vertical squash | | geometryFactor | 0.5 | Per-cut geometry blend | | centerOffset | [0,0,0] | Optical-center offset for non-centered cuts (pear, heart) |

Requirements

  • three ≥ 0.160 (peer dependency)
  • A WebGLRenderer — the bake needs render-to-cubemap
  • Half-float render target support (universal on modern targets; on WebGL1 it needs OES_texture_half_float)

Performance

The bake is the expensive part and it happens once per key, synchronously, on first material creation. Budget for a frame hitch when a new cut first appears, or warm the cache during a loading state.

Per-frame cost scales with bounces — 5 is the visual sweet spot; 3 is noticeably cheaper on older mobile GPUs.

License

PolyForm Noncommercial 1.0.0 — free for noncommercial use.

Commercial licenses available: jeanrojas.com

Required Notice: Copyright 2026 Jean Rojas (https://jeanrojas.com)