惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

AWS News Blog
AWS News Blog
Engineering at Meta
Engineering at Meta
T
Tailwind CSS Blog
博客园 - 【当耐特】
F
Fortinet All Blogs
博客园 - 司徒正美
Stack Overflow Blog
Stack Overflow Blog
罗磊的独立博客
Google DeepMind News
Google DeepMind News
博客园_首页
A
About on SuperTechFans
博客园 - 聂微东
N
Netflix TechBlog - Medium
MongoDB | Blog
MongoDB | Blog
H
Help Net Security
GbyAI
GbyAI
O
OpenAI News
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
C
Check Point Blog
S
Schneier on Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Apple Machine Learning Research
Apple Machine Learning Research
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Martin Fowler
Martin Fowler
J
Java Code Geeks
T
Tor Project blog
T
Threatpost
G
GRAHAM CLULEY
P
Privacy & Cybersecurity Law Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Y
Y Combinator Blog
The Register - Security
The Register - Security
阮一峰的网络日志
阮一峰的网络日志
D
Docker
Vercel News
Vercel News
I
Intezer
Microsoft Security Blog
Microsoft Security Blog
爱范儿
爱范儿
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
P
Privacy International News Feed
Cyberwarzone
Cyberwarzone
Spread Privacy
Spread Privacy
N
News and Events Feed by Topic
N
News | PayPal Newsroom
The GitHub Blog
The GitHub Blog
U
Unit 42
WordPress大学
WordPress大学
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Simon Willison's Weblog
Simon Willison's Weblog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
Procedurally generating marble dice textures with simplex noise
Matías Denda · 2026-05-16 · via DEV Community

I built a 3D dice roller as a Chrome extension and wanted dice that look like the marbled Chessex ones — those rich, swirling, Old-World-stone dice every tabletop player covets. The catch: the renderer (@3d-dice/dice-box) lets the user pick a color per die kind (d4 red, d6 blue, d20 gold, etc.), so the texture can't just be a flat painted bitmap. The marble pattern has to stay, but the color underneath has to follow whatever the user picked.

This post is the recipe for generating those textures from scratch with simplex noise — no Photoshop, no marble photo, just code that produces something like this for every die:

Marble dice in different colors, generated procedurally

The pipeline is three layers stacked on top of plain noise, plus one trick about the alpha channel that took me a while to spot. Let's walk through it.

Layer 1: Multi-octave simplex noise

Start with the basic noise field. One sample of simplex noise gives you smooth, organic blobs that look more like cloud cover than rock. To get the multi-scale detail real marble has — broad slabs of color and fine hairline streaks — you sum several octaves of noise at doubling frequencies, halving the amplitude each time:

import { createNoise2D } from 'simplex-noise';
const baseNoise = createNoise2D(/* seeded PRNG */);

function sample(x, y) {
  let amp = 1;
  let freqX = BASE_FREQ * 0.7;  // mild horizontal stretch
  let freqY = BASE_FREQ * 1.3;
  let acc = 0;
  let totalAmp = 0;
  for (let o = 0; o < OCTAVES; o++) {
    acc += amp * baseNoise(x * freqX, y * freqY);
    totalAmp += amp;
    amp *= 0.5;
    freqX *= 2;
    freqY *= 2;
  }
  return acc / totalAmp;   // in roughly [-1, 1]
}

Enter fullscreen mode Exit fullscreen mode

The slight asymmetry between freqX and freqY gives the streaks a hint of horizontal flow, like the grain in cut stone. Here's what that looks like as a grayscale field:

Stage 1: multi-octave simplex noise, grayscale

It's already organic-looking, but it's also too uniform — straight parallel-ish bands like wood grain, not the curling whorls of marble. Real marble veins bend, swirl, and double back on themselves. That's the next layer.

Layer 2: Domain warping

Domain warping is one of those tricks that feels like cheating because it's so simple and the result is so dramatic. Instead of sampling the noise on a straight (x, y) grid, you offset every (x, y) by another noise field before sampling:

const warpA = createNoise2D(/* different seed */);
const warpB = createNoise2D(/* yet another seed */);

const WARP_FREQ = 0.003;    // broad, slow swirls
const WARP_AMOUNT = 90;     // pixels of displacement at peak

for (let y = 0; y < H; y++) {
  for (let x = 0; x < W; x++) {
    const wx = warpA(x * WARP_FREQ, y * WARP_FREQ) * WARP_AMOUNT;
    const wy = warpB(x * WARP_FREQ, y * WARP_FREQ) * WARP_AMOUNT;
    const v = sample(x + wx, y + wy);
    // ...
  }
}

Enter fullscreen mode Exit fullscreen mode

You're literally bending the input space before reading the noise. Two independent low-frequency noise fields (one per axis) push each pixel up to 90 pixels in some random direction, so the patterns above get twisted into curls. Same noise, same algorithm, different coords:

Stage 2: noise with domain warping applied to the coordinates

Now we're getting marble whorls. But the field is still soft — gradual gradients everywhere. Marble has veins: sharp edges where dark meets light. That's the third layer.

Layer 3: Ridged transform

The ridged transform is a one-line operation: 1 - |n|. It folds the noise field around zero and inverts it, so what used to be a smooth roll between -1 and +1 becomes a series of sharp peaks at every zero-crossing of the original noise. Mathematically, the zero-crossings of a smooth random field form a set of curves — and 1 - |n| lights those curves up.

function sample(x, y, ridged) {
  // ... octave summing as before ...
  const n = acc / totalAmp;
  return ridged ? 1 - Math.abs(n) : (n + 1) / 2;
}

Enter fullscreen mode Exit fullscreen mode

Apply that and the soft swirls turn into something with backbone:

Stage 3: same field, now with the ridged transform applied

That's the geometry of marble veins — long, curving ridges with a clear edge between "vein" and "background". Now we have a usable pattern.

Composition: dual fields + thresholds

The actual marble texture uses two of these fields with different seeds — one for dark veins, one for light highlights — and per pixel picks whichever signal is stronger. Threshold each field at around 0.86 so only the sharpest ridge crests become streaks:

const darkStrength = Math.pow(
  Math.max(0, dn - DARK_THRESHOLD),
  STREAK_CONTRAST,
);
const lightStrength = Math.pow(
  Math.max(0, ln - LIGHT_THRESHOLD),
  STREAK_CONTRAST,
);

const darkAlpha = Math.min(MAX_DARK_ALPHA, darkStrength * DARK_GAIN);
const lightAlpha = Math.min(MAX_LIGHT_ALPHA, lightStrength * LIGHT_GAIN);

if (lightAlpha > darkAlpha) {
  // light streak wins
  r = g = b = 255;
  a = lightAlpha;
} else if (darkAlpha > 0) {
  // dark vein wins
  r = g = b = 0;
  a = darkAlpha;
} else {
  // nothing — see "the trick" below
  a = 0;
}

Enter fullscreen mode Exit fullscreen mode

MAX_DARK_ALPHA is higher than MAX_LIGHT_ALPHA (215 vs 160) so the dark veins read as proper marbling and the light streaks stay subtle highlights — flip those and the dice look chalky.

The trick: alpha as the actual lever

Here's the part that bit me for half an evening. @3d-dice/dice-box's color shader is essentially this line of GLSL:

finalColor = mix(themeColor.rgb, textureColor.rgb, textureColor.a);

Enter fullscreen mode Exit fullscreen mode

If the texture's alpha is 1.0 (opaque), the result is 100% texture, 0% themeColor. Which means: if you generate a normal RGB marble texture — black veins on a white background, fully opaque — the user's color choice (the themeColor) is completely invisible. Every die comes out the same washed-out gray, no matter what color is selected.

The fix isn't in the colors — it's the alpha channel.

Write the marble pattern into alpha, not RGB. Where you want a dark vein, the RGB is black and the alpha is high (the texture covers the themeColor). Where you want a light streak, RGB is white with moderate alpha. Where you want pure themeColor, alpha is zero and RGB doesn't matter. The texture is essentially a black-and-white-and-transparent stencil through which the themeColor shows.

That's why the snippet above sets r = g = b = 0 (or 255) and modulates the alpha. The alpha channel is doing the actual work; the RGB just decides whether visible pixels are "darker than themeColor" or "lighter than themeColor".

One more wrinkle: the original dice texture has numbers on the faces, and those need to stay readable. The fix is a simple override — wherever the source atlas has a high-alpha pixel (a number glyph), force the output to opaque black:

if (numbersAlpha[i] > 200) {
  r = g = b = 0;
  a = numbersAlpha[i];   // preserve anti-aliasing
  continue;
}

Enter fullscreen mode Exit fullscreen mode

Numbers always win.

The result

Stack all of that — two warped, ridged, thresholded noise fields composed into a single texture with the alpha trick — and the renderer produces dice that share a consistent marble pattern but pick up whatever per-die color you've configured:

Final marble dice rendered in the extension, in their per-kind colors

The whole texture-generation pass runs offline as a build step (one Node script with simplex-noise and sharp), so there's zero runtime cost — the extension just ships the resulting 1024×1024 PNG.

Try it / read the code

If you want to see this running in a real Chrome extension, I published the dice roller it's a part of here:

🎲 Dice Roller on the Chrome Web Store: https://chromewebstore.google.com/detail/dice-roller/oiknfbfchalpjggppamjfchhlplaieol