Custom shader material
Soft pearl shading with a gold, lavender and teal palette. Evaluate the JavaScript cell once before evaluating the example below. The upper-left studio light is built into the shader, so the finish stays consistent while rotating the scene.
.js
// Raster shader and physical path-tracing backend. Material maps are generated locally.
const pearlPalette = Object.freeze({
Gold: '#d8ae70', Lavender: '#ad9bd5', Teal: '#62a6b8',
Ice: '#cee6ef', Bond: '#b1a6cb', GoldBond: '#d6b17c', Glass: '#c8e4ed'
});
function createPearlMaterial(THREE, options = {}) {
if (options.pathTracing || options.renderer === 'PathTracing') return createPearlPhysicalMaterial(THREE, options);
const preset = options.preset ?? 'Lavender';
const color = new THREE.Color(options.color ?? pearlPalette[preset] ?? preset);
const roughness = Math.min(1, Math.max(0, options.roughness ?? 0.42));
const grain = Math.min(0.1, Math.max(0, options.grain ?? 0.014));
const isBond = options.bond ?? (preset === 'Bond' || preset === 'GoldBond');
const opacity = Math.min(1, Math.max(0, options.opacity ?? (preset === 'Glass' ? 0.16 : 1)));
const outputChunk = THREE.ShaderChunk.colorspace_fragment
? 'colorspace_fragment' : 'encodings_fragment';
const material = new THREE.ShaderMaterial({
name: `Pearl / ${preset}`,
uniforms: {
baseColor: { value: color },
pearlRoughness: { value: roughness },
pearlGrain: { value: grain },
pearlOpacity: { value: opacity },
pearlHighlight: { value: options.highlight ?? (preset === 'Glass' ? 0.0 : 1.0) },
pearlWash: { value: options.wash ?? (isBond ? 0.22 : 0.10) },
pearlGlass: { value: preset === 'Glass' ? 1.0 : 0.0 },
pearlBond: { value: isBond ? 1.0 : 0.0 },
pearlBleed: { value: options.bleed ?? (isBond ? 0.30 : 0.0) },
startColor: { value: new THREE.Color(options.startColor ?? color) },
endColor: { value: new THREE.Color(options.endColor ?? color) },
keyDirection: { value: new THREE.Vector3(-0.65, 0.85, 1.25).normalize() },
fillDirection: { value: new THREE.Vector3(0.8, -0.2, 0.6).normalize() }
},
vertexShader: `
varying vec3 pearlNormal;
varying vec3 pearlViewPosition;
varying vec3 pearlLocalPosition;
varying vec2 pearlUv;
void main() {
#include
#include
pearlNormal = normalize(transformedNormal);
pearlLocalPosition = position;
pearlUv = uv;
#include
#include
pearlViewPosition = -mvPosition.xyz;
}
`,
fragmentShader: `
uniform vec3 baseColor;
uniform vec3 keyDirection;
uniform vec3 fillDirection;
uniform float pearlRoughness;
uniform float pearlGrain;
uniform float pearlOpacity;
uniform float pearlHighlight;
uniform float pearlWash;
uniform float pearlGlass;
uniform float pearlBond;
uniform float pearlBleed;
uniform vec3 startColor;
uniform vec3 endColor;
varying vec3 pearlNormal;
varying vec3 pearlViewPosition;
varying vec3 pearlLocalPosition;
varying vec2 pearlUv;
float grainHash(vec3 p) {
p = fract(p * 0.1031);
p += dot(p, p.yzx + 33.33);
return fract((p.x + p.y) * p.z);
}
float grainNoise(vec3 p) {
vec3 cell = floor(p);
vec3 f = fract(p);
f = f * f * (3.0 - 2.0 * f);
return mix(
mix(mix(grainHash(cell), grainHash(cell + vec3(1,0,0)), f.x),
mix(grainHash(cell + vec3(0,1,0)), grainHash(cell + vec3(1,1,0)), f.x), f.y),
mix(mix(grainHash(cell + vec3(0,0,1)), grainHash(cell + vec3(1,0,1)), f.x),
mix(grainHash(cell + vec3(0,1,1)), grainHash(cell + vec3(1,1,1)), f.x), f.y), f.z);
}
void main() {
vec3 N = normalize(pearlNormal) * (gl_FrontFacing ? 1.0 : -1.0);
vec3 V = isOrthographic ? vec3(0.0, 0.0, 1.0) : normalize(pearlViewPosition);
vec3 H = normalize(keyDirection + V);
float key = pow(clamp(dot(N, keyDirection) * 0.5 + 0.5, 0.0, 1.0), 1.3);
float fill = max(dot(N, fillDirection), 0.0);
float facing = max(dot(N, V), 0.0);
float edge = pow(1.0 - facing, 2.0);
float wash = grainNoise(pearlLocalPosition * 2.8 + vec3(11.7, 4.2, 8.1));
float broad = pow(max(dot(N, H), 0.0), mix(16.0, 4.0, pearlRoughness));
float tight = pow(max(dot(N, H), 0.0), mix(130.0, 30.0, pearlRoughness));
vec3 pigment = baseColor;
float startWeight = 1.0 - smoothstep(0.0, 0.48, pearlUv.y);
float endWeight = smoothstep(0.52, 1.0, pearlUv.y);
pigment = mix(pigment, startColor, startWeight * pearlBond * pearlBleed);
pigment = mix(pigment, endColor, endWeight * pearlBond * pearlBleed);
pigment *= mix(vec3(0.93, 0.96, 1.06), vec3(1.06, 1.01, 0.96), wash) *
(1.0 + pearlWash * (wash - 0.5));
float shade = (0.34 + 0.66 * key + 0.07 * fill) * (1.0 - 0.18 * edge);
vec3 rgb = pigment * shade;
// Keep grain visible as atoms get smaller: blend to coarser surface noise.
float footprint = max(length(dFdx(pearlLocalPosition)), length(dFdy(pearlLocalPosition)));
float fineWeight = 1.0 - smoothstep(0.35, 1.2, footprint * 64.0);
float mediumWeight = 1.0 - smoothstep(0.35, 1.2, footprint * 16.0);
float coarseWeight = 1.0 - smoothstep(0.35, 1.2, footprint * 4.0);
float coarse = grainNoise(pearlLocalPosition * 4.0);
float medium = grainNoise(pearlLocalPosition * 16.0);
float fine = grainNoise(pearlLocalPosition * 64.0);
float surfaceGrain = mix(coarse, medium, mediumWeight);
surfaceGrain = mix(surfaceGrain, fine, fineWeight);
// Value noise is smoothed; restore useful contrast for the strength control.
rgb *= 1.0 + 3.5 * pearlGrain * coarseWeight * (2.0 * surfaceGrain - 1.0);
rgb = mix(rgb, baseColor * (0.92 + 0.08 * key), pearlGlass);
// Broad pearl sheen plus a brighter softbox core, added in linear light.
float highlight = (0.40 * broad + 0.22 * tight) * pearlHighlight;
highlight *= 1.0 + 0.20 * (wash - 0.5);
rgb += vec3(1.0, 0.975, 0.94) * highlight;
rgb += mix(pigment, vec3(0.7, 0.8, 0.94), 0.5) * edge * 0.075;
gl_FragColor = vec4(max(rgb, vec3(0.0)), pearlOpacity);
#include <${outputChunk}>
}
`,
// Deliberately self-lit: a portable illustration look under any scene lights.
lights: false,
toneMapped: false,
transparent: opacity < 1,
depthWrite: opacity >= 1,
side: opacity < 1 ? THREE.DoubleSide : THREE.FrontSide
});
// Also works with older Three.js WebGL1 builds used by some WLJS versions.
material.extensions.derivatives = true;
return material;
}
// Baked material maps are shared between matching presets, including repeated bonds.
const pearlPhysicalCaches = new WeakMap();
function pearlNoise2(x, y) {
const hash = (a, b) => {
let n = Math.imul(a, 374761393) ^ Math.imul(b, 668265263);
n = Math.imul(n ^ (n >>> 13), 1274126177);
return ((n ^ (n >>> 16)) >>> 0) / 4294967295;
};
const ix = Math.floor(x), iy = Math.floor(y);
let fx = x - ix, fy = y - iy;
fx *= fx * (3 - 2 * fx); fy *= fy * (3 - 2 * fy);
const a = hash(ix, iy), b = hash(ix + 1, iy);
const c = hash(ix, iy + 1), d = hash(ix + 1, iy + 1);
return (a + (b - a) * fx) * (1 - fy) + (c + (d - c) * fx) * fy;
}
function pearlPhysicalMaps(THREE, options, color) {
let cache = pearlPhysicalCaches.get(THREE);
if (!cache) { cache = new Map(); pearlPhysicalCaches.set(THREE, cache); }
const bond = options.bond ?? ['Bond', 'GoldBond'].includes(options.preset);
const grain = Math.min(0.1, Math.max(0, options.grain ?? 0.014));
const wash = options.wash ?? (bond ? 0.22 : 0.10);
const start = new THREE.Color(options.startColor ?? color);
const end = new THREE.Color(options.endColor ?? color);
const bleed = Math.min(1, Math.max(0, options.bleed ?? (bond ? 0.30 : 0)));
const key = JSON.stringify([color.getHex(), bond, grain, wash, start.getHex(), end.getHex(), bleed]);
if (cache.has(key)) return cache.get(key);
const size = 256;
const canvas = document.createElement('canvas');
canvas.width = canvas.height = size;
const ctx = canvas.getContext('2d');
const pixels = ctx.createImageData(size, size);
const rgb = new THREE.Color();
const smooth = (a, b, x) => { const t = Math.min(1, Math.max(0, (x-a)/(b-a))); return t*t*(3-2*t); };
for (let y = 0; y < size; y++) {
const v = 1 - (y + 0.5) / size;
for (let x = 0; x < size; x++) {
const u = (x + 0.5) / size;
const broad = pearlNoise2(u * 7, v * 9);
const fine = pearlNoise2(u * 93, v * 93);
rgb.copy(color);
if (bond) {
rgb.lerp(start, (1 - smooth(0, 0.48, v)) * bleed);
rgb.lerp(end, smooth(0.52, 1, v) * bleed);
}
const gain = 1 + wash * (broad - 0.5) + 3.5 * grain * (2 * fine - 1);
rgb.multiplyScalar(gain).convertLinearToSRGB();
const i = 4 * (y * size + x);
pixels.data[i] = Math.min(255, Math.max(0, Math.round(rgb.r * 255)));
pixels.data[i+1] = Math.min(255, Math.max(0, Math.round(rgb.g * 255)));
pixels.data[i+2] = Math.min(255, Math.max(0, Math.round(rgb.b * 255)));
pixels.data[i+3] = 255;
}
}
ctx.putImageData(pixels, 0, 0);
const map = new THREE.CanvasTexture(canvas);
map.colorSpace = THREE.SRGBColorSpace;
map.wrapS = map.wrapT = THREE.RepeatWrapping;
map.minFilter = THREE.LinearMipmapLinearFilter;
map.magFilter = THREE.LinearFilter;
// Roughness and normal maps are shared by all materials.
if (!cache.has('microstructure')) {
const roughData = new Uint8Array(size * size * 4);
const normalData = new Uint8Array(size * size * 4);
for (let y = 0; y < size; y++) for (let x = 0; x < size; x++) {
const u = (x+0.5)/size, v = (y+0.5)/size;
const h = pearlNoise2(u*93, v*93);
const dx = pearlNoise2((u+1/size)*93, v*93) - pearlNoise2((u-1/size)*93, v*93);
const dy = pearlNoise2(u*93, (v+1/size)*93) - pearlNoise2(u*93, (v-1/size)*93);
const n = new THREE.Vector3(-dx, -dy, 1).normalize();
const i = 4 * (y*size+x), r = Math.round(205 + 45*h);
roughData.set([r,r,r,255], i);
normalData.set([Math.round(127.5*(n.x+1)),Math.round(127.5*(n.y+1)),Math.round(127.5*(n.z+1)),255], i);
}
const roughnessMap = new THREE.DataTexture(roughData,size,size);
const normalMap = new THREE.DataTexture(normalData,size,size);
for (const texture of [roughnessMap,normalMap]) {
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.minFilter = texture.magFilter = THREE.LinearFilter;
texture.needsUpdate = true;
}
cache.set('microstructure',{roughnessMap,normalMap});
}
const maps = {map,...cache.get('microstructure')};
cache.set(key,maps);
return maps;
}
function createPearlPhysicalMaterial(THREE, options = {}) {
const preset = options.preset ?? 'Lavender';
const color = new THREE.Color(options.color ?? pearlPalette[preset] ?? preset);
const grain = Math.min(0.1, Math.max(0, options.grain ?? 0.014));
const roughness = Math.min(1, Math.max(0.08, options.roughness ?? 0.42));
const opacity = Math.min(1, Math.max(0, options.opacity ?? (preset === 'Glass' ? 0.16 : 1)));
const highlight = Math.max(0, options.highlight ?? 1);
if (preset === 'Glass') {
return new THREE.MeshPhysicalMaterial({name:'Pearl physical / Glass',color,
roughness:0.65,metalness:0,opacity,transparent:true,depthWrite:false,
side:THREE.DoubleSide,transmission:0,ior:1.1,clearcoat:0});
}
const maps = pearlPhysicalMaps(THREE,options,color);
return new THREE.MeshPhysicalMaterial({
name:`Pearl physical / ${preset}`,color:0xffffff,...maps,
roughness:Math.min(1,roughness*0.90),
metalness:['Gold','GoldBond'].includes(preset) ? 0.18 : 0.025,
normalScale:new THREE.Vector2(grain*2,grain*2),
clearcoat:Math.min(1,0.45*highlight),clearcoatRoughness:0.18,
sheen:0.12,sheenColor:color.clone().lerp(new THREE.Color('white'),0.35),
sheenRoughness:0.55,specularIntensity:Math.min(2,highlight),ior:1.48,
opacity,transparent:opacity<1,depthWrite:opacity>=1,
side:opacity<1 ? THREE.DoubleSide : THREE.FrontSide
});
}
function addPearlStudioLighting(THREE, scene, camera, target = new THREE.Vector3(0,1,0)) {
if (scene.userData.pearlStudio) return scene.userData.pearlStudio;
const forward = camera.getWorldDirection(new THREE.Vector3()).normalize();
const right = new THREE.Vector3().crossVectors(forward,camera.up).normalize();
const up = new THREE.Vector3().crossVectors(right,forward).normalize();
const make = (x,y,z,intensity,width,height) => {
const light = new THREE.RectAreaLight(0xffffff,intensity,width,height);
light.position.copy(target).addScaledVector(right,x).addScaledVector(up,y).addScaledVector(forward,-z);
light.lookAt(target); scene.add(light); return light;
};
const lights = [make(-4,5,7,12,4,5), make(4,1,5,1.5,5,5)];
scene.userData.pearlStudio = lights;
return lights;
}
// WLJS adapter. Evaluate this cell before using PearlMaterial in Graphics3D.
const ready = interpretate.shared.THREE.load().then(() => interpretate.shared.THREE.THREE);
core.PearlMaterial = async (args, env) => {
const THREE = await ready;
const values = await Promise.all(args.map(arg => interpretate(arg, env)));
const [preset = "Lavender", roughness = 0.42, grain = 0.014, opacity, highlight, wash = 0.10] = values;
if (!(preset in pearlPalette)) throw new Error("Unknown PearlMaterial preset: " + preset);
const pathTracing = env.PathRendering === true;
if (pathTracing) addPearlStudioLighting(THREE, env.global.scene, env.camera, env.controlObject?.o?.target);
return function PearlMaterialFactory() {
return createPearlMaterial(THREE, {preset, roughness, grain, opacity, highlight, wash, pathTracing});
};
};
core.PearlBondMaterial = async (args, env) => {
const THREE = await ready;
const [preset = "Bond", start = "Lavender", end = "Lavender", bleed = 0.30,
roughness = 0.35, grain = 0.012] = await Promise.all(args.map(arg => interpretate(arg, env)));
for (const name of [preset, start, end]) {
if (!(name in pearlPalette)) throw new Error("Unknown pearl preset: " + name);
}
const pathTracing = env.PathRendering === true;
if (pathTracing) addPearlStudioLighting(THREE, env.global.scene, env.camera, env.controlObject?.o?.target);
return function PearlBondMaterialFactory() {
return createPearlMaterial(THREE, {preset, roughness, grain, bond:true,
startColor:pearlPalette[start], endColor:pearlPalette[end], bleed, pathTracing});
};
};
// Static atom and bond swatches, rendered once with the raster shader.
const panel = document.createElement('div');
panel.style.cssText = 'background:white;border:1px solid #e1e5ea;border-radius:12px;padding:18px;max-width:720px;color:#17263d;font:14px system-ui';
const status = document.createElement('div');
status.textContent = 'Loading pearl materials…';
panel.append(status);
const swatches = document.createElement('div');
swatches.style.cssText = 'position:relative;width:100%';
panel.append(swatches);
let renderer;
const geometries = [];
const materials = [];
let destroyed = false;
this.ondestroy = () => {
destroyed = true;
geometries.forEach(geometry => geometry.dispose());
materials.forEach(material => material.dispose());
renderer?.dispose();
};
ready.then(THREE => {
if (destroyed) return;
renderer = new THREE.WebGLRenderer({antialias:true, alpha:false});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(640, 350);
if ('outputColorSpace' in renderer) renderer.outputColorSpace = THREE.SRGBColorSpace;
else renderer.outputEncoding = THREE.sRGBEncoding;
renderer.domElement.style.cssText = 'width:100%;height:auto;display:block';
swatches.append(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color('white');
const camera = new THREE.OrthographicCamera(-3.6,3.6,1.96875,-1.96875,0.1,20);
camera.position.z = 6;
const sphere = new THREE.SphereGeometry(0.65,64,48);
const cylinder = new THREE.CylinderGeometry(0.115,0.115,1.75,48,16);
const endpoint = new THREE.SphereGeometry(0.19,32,24);
geometries.push(sphere,cylinder,endpoint);
const materialFor = options => {
const material = createPearlMaterial(THREE,options);
materials.push(material); return material;
};
['Gold','Lavender','Teal'].forEach((preset,i) => {
const mesh = new THREE.Mesh(sphere,materialFor({preset,grain:0.014}));
mesh.position.set((i-1)*2.4,1.0,0);
scene.add(mesh);
});
const bonds = [
{preset:'Bond',start:'Lavender',end:'Lavender'},
{preset:'Bond',start:'Ice',end:'Lavender'},
{preset:'GoldBond',start:'Lavender',end:'Gold'}
];
bonds.forEach(({preset,start,end},i) => {
const group = new THREE.Group();
group.position.set((i-1)*2.4,-0.95,0);
group.rotation.z = 0.12;
const rod = new THREE.Mesh(cylinder,materialFor({
preset,bond:true,roughness:0.35,grain:0.012,bleed:0.30,
startColor:pearlPalette[start],endColor:pearlPalette[end]
}));
// Cylinder v=0 is the bottom end; rotating it puts that end on the left.
rod.rotation.z = -Math.PI/2;
group.add(rod);
[start,end].forEach((atom,j) => {
const mesh = new THREE.Mesh(endpoint,materialFor({preset:atom,grain:0.014}));
mesh.position.x = (j-0.5)*1.75;
group.add(mesh);
});
scene.add(group);
});
const labels = (top,items) => {
const row = document.createElement('div');
row.style.cssText = 'position:absolute;left:0;right:0;top:'+top+'%;display:grid;grid-template-columns:repeat(3,1fr);text-align:center;gap:8px;line-height:1.4;font-size:13px;pointer-events:none';
items.forEach(([title,detail]) => {
const label = document.createElement('div');
const name = document.createElement('strong'); name.textContent=title;
label.append(name);
if(detail) {
const sub=document.createElement('div'); sub.textContent=detail;
sub.style.cssText='color:#627087;font-size:11px';
label.append(sub);
}
row.append(label);
});
swatches.append(row);
};
labels(44,[['Gold','Atoms'],['Lavender','Atoms'],['Teal','Atoms']]);
labels(84,[['Bond','Lavender → Lavender'],['Bond · carbon end','Ice → Lavender'],['GoldBond','Lavender → Gold']]);
const errors = [];
renderer.debug.onShaderError = (gl,program,vertex,fragment) => {
errors.push(gl.getProgramInfoLog(program),gl.getShaderInfoLog(vertex),gl.getShaderInfoLog(fragment));
};
renderer.render(scene,camera);
if(errors.some(Boolean)) throw new Error(errors.filter(Boolean).join('\n'));
status.textContent='Pearl materials · atoms and bonds · raster preview · Three.js r'+THREE.REVISION;
}).catch(error => {status.textContent='Shader error: '+error.message;console.error(error);});
return panel;
%2F%2F%20Raster%20shader%20and%20physical%20path-tracing%20backend.%20Material%20maps%20are%20generated%20locally.%0Aconst%20pearlPalette%20%3D%20Object.freeze%28%7B%0A%20%20Gold%3A%20%27%23d8ae70%27%2C%20Lavender%3A%20%27%23ad9bd5%27%2C%20Teal%3A%20%27%2362a6b8%27%2C%0A%20%20Ice%3A%20%27%23cee6ef%27%2C%20Bond%3A%20%27%23b1a6cb%27%2C%20GoldBond%3A%20%27%23d6b17c%27%2C%20Glass%3A%20%27%23c8e4ed%27%0A%7D%29%3B%0A%0Afunction%20createPearlMaterial%28THREE%2C%20options%20%3D%20%7B%7D%29%20%7B%0A%20%20if%20%28options.pathTracing%20%7C%7C%20options.renderer%20%3D%3D%3D%20%27PathTracing%27%29%20return%20createPearlPhysicalMaterial%28THREE%2C%20options%29%3B%0A%20%20const%20preset%20%3D%20options.preset%20%3F%3F%20%27Lavender%27%3B%0A%20%20const%20color%20%3D%20new%20THREE.Color%28options.color%20%3F%3F%20pearlPalette%5Bpreset%5D%20%3F%3F%20preset%29%3B%0A%20%20const%20roughness%20%3D%20Math.min%281%2C%20Math.max%280%2C%20options.roughness%20%3F%3F%200.42%29%29%3B%0A%20%20const%20grain%20%3D%20Math.min%280.1%2C%20Math.max%280%2C%20options.grain%20%3F%3F%200.014%29%29%3B%0A%20%20const%20isBond%20%3D%20options.bond%20%3F%3F%20%28preset%20%3D%3D%3D%20%27Bond%27%20%7C%7C%20preset%20%3D%3D%3D%20%27GoldBond%27%29%3B%0A%20%20const%20opacity%20%3D%20Math.min%281%2C%20Math.max%280%2C%20options.opacity%20%3F%3F%20%28preset%20%3D%3D%3D%20%27Glass%27%20%3F%200.16%20%3A%201%29%29%29%3B%0A%20%20const%20outputChunk%20%3D%20THREE.ShaderChunk.colorspace_fragment%0A%20%20%20%20%3F%20%27colorspace_fragment%27%20%3A%20%27encodings_fragment%27%3B%0A%20%20const%20material%20%3D%20new%20THREE.ShaderMaterial%28%7B%0A%20%20%20%20name%3A%20%60Pearl%20%2F%20%24%7Bpreset%7D%60%2C%0A%20%20%20%20uniforms%3A%20%7B%0A%20%20%20%20%20%20baseColor%3A%20%7B%20value%3A%20color%20%7D%2C%0A%20%20%20%20%20%20pearlRoughness%3A%20%7B%20value%3A%20roughness%20%7D%2C%0A%20%20%20%20%20%20pearlGrain%3A%20%7B%20value%3A%20grain%20%7D%2C%0A%20%20%20%20%20%20pearlOpacity%3A%20%7B%20value%3A%20opacity%20%7D%2C%0A%20%20%20%20%20%20pearlHighlight%3A%20%7B%20value%3A%20options.highlight%20%3F%3F%20%28preset%20%3D%3D%3D%20%27Glass%27%20%3F%200.0%20%3A%201.0%29%20%7D%2C%0A%20%20%20%20%20%20pearlWash%3A%20%7B%20value%3A%20options.wash%20%3F%3F%20%28isBond%20%3F%200.22%20%3A%200.10%29%20%7D%2C%0A%20%20%20%20%20%20pearlGlass%3A%20%7B%20value%3A%20preset%20%3D%3D%3D%20%27Glass%27%20%3F%201.0%20%3A%200.0%20%7D%2C%0A%20%20%20%20%20%20pearlBond%3A%20%7B%20value%3A%20isBond%20%3F%201.0%20%3A%200.0%20%7D%2C%0A%20%20%20%20%20%20pearlBleed%3A%20%7B%20value%3A%20options.bleed%20%3F%3F%20%28isBond%20%3F%200.30%20%3A%200.0%29%20%7D%2C%0A%20%20%20%20%20%20startColor%3A%20%7B%20value%3A%20new%20THREE.Color%28options.startColor%20%3F%3F%20color%29%20%7D%2C%0A%20%20%20%20%20%20endColor%3A%20%7B%20value%3A%20new%20THREE.Color%28options.endColor%20%3F%3F%20color%29%20%7D%2C%0A%20%20%20%20%20%20keyDirection%3A%20%7B%20value%3A%20new%20THREE.Vector3%28-0.65%2C%200.85%2C%201.25%29.normalize%28%29%20%7D%2C%0A%20%20%20%20%20%20fillDirection%3A%20%7B%20value%3A%20new%20THREE.Vector3%280.8%2C%20-0.2%2C%200.6%29.normalize%28%29%20%7D%0A%20%20%20%20%7D%2C%0A%20%20%20%20vertexShader%3A%20%60%0A%20%20%20%20%20%20varying%20vec3%20pearlNormal%3B%0A%20%20%20%20%20%20varying%20vec3%20pearlViewPosition%3B%0A%20%20%20%20%20%20varying%20vec3%20pearlLocalPosition%3B%0A%20%20%20%20%20%20varying%20vec2%20pearlUv%3B%0A%20%20%20%20%20%20void%20main%28%29%20%7B%0A%20%20%20%20%20%20%20%20%23include%20%3Cbeginnormal_vertex%3E%0A%20%20%20%20%20%20%20%20%23include%20%3Cdefaultnormal_vertex%3E%0A%20%20%20%20%20%20%20%20pearlNormal%20%3D%20normalize%28transformedNormal%29%3B%0A%20%20%20%20%20%20%20%20pearlLocalPosition%20%3D%20position%3B%0A%20%20%20%20%20%20%20%20pearlUv%20%3D%20uv%3B%0A%20%20%20%20%20%20%20%20%23include%20%3Cbegin_vertex%3E%0A%20%20%20%20%20%20%20%20%23include%20%3Cproject_vertex%3E%0A%20%20%20%20%20%20%20%20pearlViewPosition%20%3D%20-mvPosition.xyz%3B%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%60%2C%0A%20%20%20%20fragmentShader%3A%20%60%0A%20%20%20%20%20%20uniform%20vec3%20baseColor%3B%0A%20%20%20%20%20%20uniform%20vec3%20keyDirection%3B%0A%20%20%20%20%20%20uniform%20vec3%20fillDirection%3B%0A%20%20%20%20%20%20uniform%20float%20pearlRoughness%3B%0A%20%20%20%20%20%20uniform%20float%20pearlGrain%3B%0A%20%20%20%20%20%20uniform%20float%20pearlOpacity%3B%0A%20%20%20%20%20%20uniform%20float%20pearlHighlight%3B%0A%20%20%20%20%20%20uniform%20float%20pearlWash%3B%0A%20%20%20%20%20%20uniform%20float%20pearlGlass%3B%0A%20%20%20%20%20%20uniform%20float%20pearlBond%3B%0A%20%20%20%20%20%20uniform%20float%20pearlBleed%3B%0A%20%20%20%20%20%20uniform%20vec3%20startColor%3B%0A%20%20%20%20%20%20uniform%20vec3%20endColor%3B%0A%20%20%20%20%20%20varying%20vec3%20pearlNormal%3B%0A%20%20%20%20%20%20varying%20vec3%20pearlViewPosition%3B%0A%20%20%20%20%20%20varying%20vec3%20pearlLocalPosition%3B%0A%20%20%20%20%20%20varying%20vec2%20pearlUv%3B%0A%20%20%20%20%20%20float%20grainHash%28vec3%20p%29%20%7B%0A%20%20%20%20%20%20%20%20p%20%3D%20fract%28p%20%2A%200.1031%29%3B%0A%20%20%20%20%20%20%20%20p%20%2B%3D%20dot%28p%2C%20p.yzx%20%2B%2033.33%29%3B%0A%20%20%20%20%20%20%20%20return%20fract%28%28p.x%20%2B%20p.y%29%20%2A%20p.z%29%3B%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20float%20grainNoise%28vec3%20p%29%20%7B%0A%20%20%20%20%20%20%20%20vec3%20cell%20%3D%20floor%28p%29%3B%0A%20%20%20%20%20%20%20%20vec3%20f%20%3D%20fract%28p%29%3B%0A%20%20%20%20%20%20%20%20f%20%3D%20f%20%2A%20f%20%2A%20%283.0%20-%202.0%20%2A%20f%29%3B%0A%20%20%20%20%20%20%20%20return%20mix%28%0A%20%20%20%20%20%20%20%20%20%20mix%28mix%28grainHash%28cell%29%2C%20grainHash%28cell%20%2B%20vec3%281%2C0%2C0%29%29%2C%20f.x%29%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20mix%28grainHash%28cell%20%2B%20vec3%280%2C1%2C0%29%29%2C%20grainHash%28cell%20%2B%20vec3%281%2C1%2C0%29%29%2C%20f.x%29%2C%20f.y%29%2C%0A%20%20%20%20%20%20%20%20%20%20mix%28mix%28grainHash%28cell%20%2B%20vec3%280%2C0%2C1%29%29%2C%20grainHash%28cell%20%2B%20vec3%281%2C0%2C1%29%29%2C%20f.x%29%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20mix%28grainHash%28cell%20%2B%20vec3%280%2C1%2C1%29%29%2C%20grainHash%28cell%20%2B%20vec3%281%2C1%2C1%29%29%2C%20f.x%29%2C%20f.y%29%2C%20f.z%29%3B%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20void%20main%28%29%20%7B%0A%20%20%20%20%20%20%20%20vec3%20N%20%3D%20normalize%28pearlNormal%29%20%2A%20%28gl_FrontFacing%20%3F%201.0%20%3A%20-1.0%29%3B%0A%20%20%20%20%20%20%20%20vec3%20V%20%3D%20isOrthographic%20%3F%20vec3%280.0%2C%200.0%2C%201.0%29%20%3A%20normalize%28pearlViewPosition%29%3B%0A%20%20%20%20%20%20%20%20vec3%20H%20%3D%20normalize%28keyDirection%20%2B%20V%29%3B%0A%20%20%20%20%20%20%20%20float%20key%20%3D%20pow%28clamp%28dot%28N%2C%20keyDirection%29%20%2A%200.5%20%2B%200.5%2C%200.0%2C%201.0%29%2C%201.3%29%3B%0A%20%20%20%20%20%20%20%20float%20fill%20%3D%20max%28dot%28N%2C%20fillDirection%29%2C%200.0%29%3B%0A%20%20%20%20%20%20%20%20float%20facing%20%3D%20max%28dot%28N%2C%20V%29%2C%200.0%29%3B%0A%20%20%20%20%20%20%20%20float%20edge%20%3D%20pow%281.0%20-%20facing%2C%202.0%29%3B%0A%20%20%20%20%20%20%20%20float%20wash%20%3D%20grainNoise%28pearlLocalPosition%20%2A%202.8%20%2B%20vec3%2811.7%2C%204.2%2C%208.1%29%29%3B%0A%20%20%20%20%20%20%20%20float%20broad%20%3D%20pow%28max%28dot%28N%2C%20H%29%2C%200.0%29%2C%20mix%2816.0%2C%204.0%2C%20pearlRoughness%29%29%3B%0A%20%20%20%20%20%20%20%20float%20tight%20%3D%20pow%28max%28dot%28N%2C%20H%29%2C%200.0%29%2C%20mix%28130.0%2C%2030.0%2C%20pearlRoughness%29%29%3B%0A%20%20%20%20%20%20%20%20vec3%20pigment%20%3D%20baseColor%3B%0A%20%20%20%20%20%20%20%20float%20startWeight%20%3D%201.0%20-%20smoothstep%280.0%2C%200.48%2C%20pearlUv.y%29%3B%0A%20%20%20%20%20%20%20%20float%20endWeight%20%3D%20smoothstep%280.52%2C%201.0%2C%20pearlUv.y%29%3B%0A%20%20%20%20%20%20%20%20pigment%20%3D%20mix%28pigment%2C%20startColor%2C%20startWeight%20%2A%20pearlBond%20%2A%20pearlBleed%29%3B%0A%20%20%20%20%20%20%20%20pigment%20%3D%20mix%28pigment%2C%20endColor%2C%20endWeight%20%2A%20pearlBond%20%2A%20pearlBleed%29%3B%0A%20%20%20%20%20%20%20%20pigment%20%2A%3D%20mix%28vec3%280.93%2C%200.96%2C%201.06%29%2C%20vec3%281.06%2C%201.01%2C%200.96%29%2C%20wash%29%20%2A%0A%20%20%20%20%20%20%20%20%20%20%281.0%20%2B%20pearlWash%20%2A%20%28wash%20-%200.5%29%29%3B%0A%20%20%20%20%20%20%20%20float%20shade%20%3D%20%280.34%20%2B%200.66%20%2A%20key%20%2B%200.07%20%2A%20fill%29%20%2A%20%281.0%20-%200.18%20%2A%20edge%29%3B%0A%20%20%20%20%20%20%20%20vec3%20rgb%20%3D%20pigment%20%2A%20shade%3B%0A%20%20%20%20%20%20%20%20%2F%2F%20Keep%20grain%20visible%20as%20atoms%20get%20smaller%3A%20blend%20to%20coarser%20surface%20noise.%0A%20%20%20%20%20%20%20%20float%20footprint%20%3D%20max%28length%28dFdx%28pearlLocalPosition%29%29%2C%20length%28dFdy%28pearlLocalPosition%29%29%29%3B%0A%20%20%20%20%20%20%20%20float%20fineWeight%20%3D%201.0%20-%20smoothstep%280.35%2C%201.2%2C%20footprint%20%2A%2064.0%29%3B%0A%20%20%20%20%20%20%20%20float%20mediumWeight%20%3D%201.0%20-%20smoothstep%280.35%2C%201.2%2C%20footprint%20%2A%2016.0%29%3B%0A%20%20%20%20%20%20%20%20float%20coarseWeight%20%3D%201.0%20-%20smoothstep%280.35%2C%201.2%2C%20footprint%20%2A%204.0%29%3B%0A%20%20%20%20%20%20%20%20float%20coarse%20%3D%20grainNoise%28pearlLocalPosition%20%2A%204.0%29%3B%0A%20%20%20%20%20%20%20%20float%20medium%20%3D%20grainNoise%28pearlLocalPosition%20%2A%2016.0%29%3B%0A%20%20%20%20%20%20%20%20float%20fine%20%3D%20grainNoise%28pearlLocalPosition%20%2A%2064.0%29%3B%0A%20%20%20%20%20%20%20%20float%20surfaceGrain%20%3D%20mix%28coarse%2C%20medium%2C%20mediumWeight%29%3B%0A%20%20%20%20%20%20%20%20surfaceGrain%20%3D%20mix%28surfaceGrain%2C%20fine%2C%20fineWeight%29%3B%0A%20%20%20%20%20%20%20%20%2F%2F%20Value%20noise%20is%20smoothed%3B%20restore%20useful%20contrast%20for%20the%20strength%20control.%0A%20%20%20%20%20%20%20%20rgb%20%2A%3D%201.0%20%2B%203.5%20%2A%20pearlGrain%20%2A%20coarseWeight%20%2A%20%282.0%20%2A%20surfaceGrain%20-%201.0%29%3B%0A%20%20%20%20%20%20%20%20rgb%20%3D%20mix%28rgb%2C%20baseColor%20%2A%20%280.92%20%2B%200.08%20%2A%20key%29%2C%20pearlGlass%29%3B%0A%20%20%20%20%20%20%20%20%2F%2F%20Broad%20pearl%20sheen%20plus%20a%20brighter%20softbox%20core%2C%20added%20in%20linear%20light.%0A%20%20%20%20%20%20%20%20float%20highlight%20%3D%20%280.40%20%2A%20broad%20%2B%200.22%20%2A%20tight%29%20%2A%20pearlHighlight%3B%0A%20%20%20%20%20%20%20%20highlight%20%2A%3D%201.0%20%2B%200.20%20%2A%20%28wash%20-%200.5%29%3B%0A%20%20%20%20%20%20%20%20rgb%20%2B%3D%20vec3%281.0%2C%200.975%2C%200.94%29%20%2A%20highlight%3B%0A%20%20%20%20%20%20%20%20rgb%20%2B%3D%20mix%28pigment%2C%20vec3%280.7%2C%200.8%2C%200.94%29%2C%200.5%29%20%2A%20edge%20%2A%200.075%3B%0A%20%20%20%20%20%20%20%20gl_FragColor%20%3D%20vec4%28max%28rgb%2C%20vec3%280.0%29%29%2C%20pearlOpacity%29%3B%0A%20%20%20%20%20%20%20%20%23include%20%3C%24%7BoutputChunk%7D%3E%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%60%2C%0A%20%20%20%20%2F%2F%20Deliberately%20self-lit%3A%20a%20portable%20illustration%20look%20under%20any%20scene%20lights.%0A%20%20%20%20lights%3A%20false%2C%0A%20%20%20%20toneMapped%3A%20false%2C%0A%20%20%20%20transparent%3A%20opacity%20%3C%201%2C%0A%20%20%20%20depthWrite%3A%20opacity%20%3E%3D%201%2C%0A%20%20%20%20side%3A%20opacity%20%3C%201%20%3F%20THREE.DoubleSide%20%3A%20THREE.FrontSide%0A%20%20%7D%29%3B%0A%20%20%2F%2F%20Also%20works%20with%20older%20Three.js%20WebGL1%20builds%20used%20by%20some%20WLJS%20versions.%0A%20%20material.extensions.derivatives%20%3D%20true%3B%0A%20%20return%20material%3B%0A%7D%0A%0A%2F%2F%20Baked%20material%20maps%20are%20shared%20between%20matching%20presets%2C%20including%20repeated%20bonds.%0Aconst%20pearlPhysicalCaches%20%3D%20new%20WeakMap%28%29%3B%0A%0Afunction%20pearlNoise2%28x%2C%20y%29%20%7B%0A%20%20const%20hash%20%3D%20%28a%2C%20b%29%20%3D%3E%20%7B%0A%20%20%20%20let%20n%20%3D%20Math.imul%28a%2C%20374761393%29%20%5E%20Math.imul%28b%2C%20668265263%29%3B%0A%20%20%20%20n%20%3D%20Math.imul%28n%20%5E%20%28n%20%3E%3E%3E%2013%29%2C%201274126177%29%3B%0A%20%20%20%20return%20%28%28n%20%5E%20%28n%20%3E%3E%3E%2016%29%29%20%3E%3E%3E%200%29%20%2F%204294967295%3B%0A%20%20%7D%3B%0A%20%20const%20ix%20%3D%20Math.floor%28x%29%2C%20iy%20%3D%20Math.floor%28y%29%3B%0A%20%20let%20fx%20%3D%20x%20-%20ix%2C%20fy%20%3D%20y%20-%20iy%3B%0A%20%20fx%20%2A%3D%20fx%20%2A%20%283%20-%202%20%2A%20fx%29%3B%20fy%20%2A%3D%20fy%20%2A%20%283%20-%202%20%2A%20fy%29%3B%0A%20%20const%20a%20%3D%20hash%28ix%2C%20iy%29%2C%20b%20%3D%20hash%28ix%20%2B%201%2C%20iy%29%3B%0A%20%20const%20c%20%3D%20hash%28ix%2C%20iy%20%2B%201%29%2C%20d%20%3D%20hash%28ix%20%2B%201%2C%20iy%20%2B%201%29%3B%0A%20%20return%20%28a%20%2B%20%28b%20-%20a%29%20%2A%20fx%29%20%2A%20%281%20-%20fy%29%20%2B%20%28c%20%2B%20%28d%20-%20c%29%20%2A%20fx%29%20%2A%20fy%3B%0A%7D%0A%0Afunction%20pearlPhysicalMaps%28THREE%2C%20options%2C%20color%29%20%7B%0A%20%20let%20cache%20%3D%20pearlPhysicalCaches.get%28THREE%29%3B%0A%20%20if%20%28%21cache%29%20%7B%20cache%20%3D%20new%20Map%28%29%3B%20pearlPhysicalCaches.set%28THREE%2C%20cache%29%3B%20%7D%0A%20%20const%20bond%20%3D%20options.bond%20%3F%3F%20%5B%27Bond%27%2C%20%27GoldBond%27%5D.includes%28options.preset%29%3B%0A%20%20const%20grain%20%3D%20Math.min%280.1%2C%20Math.max%280%2C%20options.grain%20%3F%3F%200.014%29%29%3B%0A%20%20const%20wash%20%3D%20options.wash%20%3F%3F%20%28bond%20%3F%200.22%20%3A%200.10%29%3B%0A%20%20const%20start%20%3D%20new%20THREE.Color%28options.startColor%20%3F%3F%20color%29%3B%0A%20%20const%20end%20%3D%20new%20THREE.Color%28options.endColor%20%3F%3F%20color%29%3B%0A%20%20const%20bleed%20%3D%20Math.min%281%2C%20Math.max%280%2C%20options.bleed%20%3F%3F%20%28bond%20%3F%200.30%20%3A%200%29%29%29%3B%0A%20%20const%20key%20%3D%20JSON.stringify%28%5Bcolor.getHex%28%29%2C%20bond%2C%20grain%2C%20wash%2C%20start.getHex%28%29%2C%20end.getHex%28%29%2C%20bleed%5D%29%3B%0A%20%20if%20%28cache.has%28key%29%29%20return%20cache.get%28key%29%3B%0A%20%20const%20size%20%3D%20256%3B%0A%20%20const%20canvas%20%3D%20document.createElement%28%27canvas%27%29%3B%0A%20%20canvas.width%20%3D%20canvas.height%20%3D%20size%3B%0A%20%20const%20ctx%20%3D%20canvas.getContext%28%272d%27%29%3B%0A%20%20const%20pixels%20%3D%20ctx.createImageData%28size%2C%20size%29%3B%0A%20%20const%20rgb%20%3D%20new%20THREE.Color%28%29%3B%0A%20%20const%20smooth%20%3D%20%28a%2C%20b%2C%20x%29%20%3D%3E%20%7B%20const%20t%20%3D%20Math.min%281%2C%20Math.max%280%2C%20%28x-a%29%2F%28b-a%29%29%29%3B%20return%20t%2At%2A%283-2%2At%29%3B%20%7D%3B%0A%20%20for%20%28let%20y%20%3D%200%3B%20y%20%3C%20size%3B%20y%2B%2B%29%20%7B%0A%20%20%20%20const%20v%20%3D%201%20-%20%28y%20%2B%200.5%29%20%2F%20size%3B%0A%20%20%20%20for%20%28let%20x%20%3D%200%3B%20x%20%3C%20size%3B%20x%2B%2B%29%20%7B%0A%20%20%20%20%20%20const%20u%20%3D%20%28x%20%2B%200.5%29%20%2F%20size%3B%0A%20%20%20%20%20%20const%20broad%20%3D%20pearlNoise2%28u%20%2A%207%2C%20v%20%2A%209%29%3B%0A%20%20%20%20%20%20const%20fine%20%3D%20pearlNoise2%28u%20%2A%2093%2C%20v%20%2A%2093%29%3B%0A%20%20%20%20%20%20rgb.copy%28color%29%3B%0A%20%20%20%20%20%20if%20%28bond%29%20%7B%0A%20%20%20%20%20%20%20%20rgb.lerp%28start%2C%20%281%20-%20smooth%280%2C%200.48%2C%20v%29%29%20%2A%20bleed%29%3B%0A%20%20%20%20%20%20%20%20rgb.lerp%28end%2C%20smooth%280.52%2C%201%2C%20v%29%20%2A%20bleed%29%3B%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20const%20gain%20%3D%201%20%2B%20wash%20%2A%20%28broad%20-%200.5%29%20%2B%203.5%20%2A%20grain%20%2A%20%282%20%2A%20fine%20-%201%29%3B%0A%20%20%20%20%20%20rgb.multiplyScalar%28gain%29.convertLinearToSRGB%28%29%3B%0A%20%20%20%20%20%20const%20i%20%3D%204%20%2A%20%28y%20%2A%20size%20%2B%20x%29%3B%0A%20%20%20%20%20%20pixels.data%5Bi%5D%20%3D%20Math.min%28255%2C%20Math.max%280%2C%20Math.round%28rgb.r%20%2A%20255%29%29%29%3B%0A%20%20%20%20%20%20pixels.data%5Bi%2B1%5D%20%3D%20Math.min%28255%2C%20Math.max%280%2C%20Math.round%28rgb.g%20%2A%20255%29%29%29%3B%0A%20%20%20%20%20%20pixels.data%5Bi%2B2%5D%20%3D%20Math.min%28255%2C%20Math.max%280%2C%20Math.round%28rgb.b%20%2A%20255%29%29%29%3B%0A%20%20%20%20%20%20pixels.data%5Bi%2B3%5D%20%3D%20255%3B%0A%20%20%20%20%7D%0A%20%20%7D%0A%20%20ctx.putImageData%28pixels%2C%200%2C%200%29%3B%0A%20%20const%20map%20%3D%20new%20THREE.CanvasTexture%28canvas%29%3B%0A%20%20map.colorSpace%20%3D%20THREE.SRGBColorSpace%3B%0A%20%20map.wrapS%20%3D%20map.wrapT%20%3D%20THREE.RepeatWrapping%3B%0A%20%20map.minFilter%20%3D%20THREE.LinearMipmapLinearFilter%3B%0A%20%20map.magFilter%20%3D%20THREE.LinearFilter%3B%0A%20%20%2F%2F%20Roughness%20and%20normal%20maps%20are%20shared%20by%20all%20materials.%0A%20%20if%20%28%21cache.has%28%27microstructure%27%29%29%20%7B%0A%20%20%20%20const%20roughData%20%3D%20new%20Uint8Array%28size%20%2A%20size%20%2A%204%29%3B%0A%20%20%20%20const%20normalData%20%3D%20new%20Uint8Array%28size%20%2A%20size%20%2A%204%29%3B%0A%20%20%20%20for%20%28let%20y%20%3D%200%3B%20y%20%3C%20size%3B%20y%2B%2B%29%20for%20%28let%20x%20%3D%200%3B%20x%20%3C%20size%3B%20x%2B%2B%29%20%7B%0A%20%20%20%20%20%20const%20u%20%3D%20%28x%2B0.5%29%2Fsize%2C%20v%20%3D%20%28y%2B0.5%29%2Fsize%3B%0A%20%20%20%20%20%20const%20h%20%3D%20pearlNoise2%28u%2A93%2C%20v%2A93%29%3B%0A%20%20%20%20%20%20const%20dx%20%3D%20pearlNoise2%28%28u%2B1%2Fsize%29%2A93%2C%20v%2A93%29%20-%20pearlNoise2%28%28u-1%2Fsize%29%2A93%2C%20v%2A93%29%3B%0A%20%20%20%20%20%20const%20dy%20%3D%20pearlNoise2%28u%2A93%2C%20%28v%2B1%2Fsize%29%2A93%29%20-%20pearlNoise2%28u%2A93%2C%20%28v-1%2Fsize%29%2A93%29%3B%0A%20%20%20%20%20%20const%20n%20%3D%20new%20THREE.Vector3%28-dx%2C%20-dy%2C%201%29.normalize%28%29%3B%0A%20%20%20%20%20%20const%20i%20%3D%204%20%2A%20%28y%2Asize%2Bx%29%2C%20r%20%3D%20Math.round%28205%20%2B%2045%2Ah%29%3B%0A%20%20%20%20%20%20roughData.set%28%5Br%2Cr%2Cr%2C255%5D%2C%20i%29%3B%0A%20%20%20%20%20%20normalData.set%28%5BMath.round%28127.5%2A%28n.x%2B1%29%29%2CMath.round%28127.5%2A%28n.y%2B1%29%29%2CMath.round%28127.5%2A%28n.z%2B1%29%29%2C255%5D%2C%20i%29%3B%0A%20%20%20%20%7D%0A%20%20%20%20const%20roughnessMap%20%3D%20new%20THREE.DataTexture%28roughData%2Csize%2Csize%29%3B%0A%20%20%20%20const%20normalMap%20%3D%20new%20THREE.DataTexture%28normalData%2Csize%2Csize%29%3B%0A%20%20%20%20for%20%28const%20texture%20of%20%5BroughnessMap%2CnormalMap%5D%29%20%7B%0A%20%20%20%20%20%20texture.wrapS%20%3D%20texture.wrapT%20%3D%20THREE.RepeatWrapping%3B%0A%20%20%20%20%20%20texture.minFilter%20%3D%20texture.magFilter%20%3D%20THREE.LinearFilter%3B%0A%20%20%20%20%20%20texture.needsUpdate%20%3D%20true%3B%0A%20%20%20%20%7D%0A%20%20%20%20cache.set%28%27microstructure%27%2C%7BroughnessMap%2CnormalMap%7D%29%3B%0A%20%20%7D%0A%20%20const%20maps%20%3D%20%7Bmap%2C...cache.get%28%27microstructure%27%29%7D%3B%0A%20%20cache.set%28key%2Cmaps%29%3B%0A%20%20return%20maps%3B%0A%7D%0A%0Afunction%20createPearlPhysicalMaterial%28THREE%2C%20options%20%3D%20%7B%7D%29%20%7B%0A%20%20const%20preset%20%3D%20options.preset%20%3F%3F%20%27Lavender%27%3B%0A%20%20const%20color%20%3D%20new%20THREE.Color%28options.color%20%3F%3F%20pearlPalette%5Bpreset%5D%20%3F%3F%20preset%29%3B%0A%20%20const%20grain%20%3D%20Math.min%280.1%2C%20Math.max%280%2C%20options.grain%20%3F%3F%200.014%29%29%3B%0A%20%20const%20roughness%20%3D%20Math.min%281%2C%20Math.max%280.08%2C%20options.roughness%20%3F%3F%200.42%29%29%3B%0A%20%20const%20opacity%20%3D%20Math.min%281%2C%20Math.max%280%2C%20options.opacity%20%3F%3F%20%28preset%20%3D%3D%3D%20%27Glass%27%20%3F%200.16%20%3A%201%29%29%29%3B%0A%20%20const%20highlight%20%3D%20Math.max%280%2C%20options.highlight%20%3F%3F%201%29%3B%0A%20%20if%20%28preset%20%3D%3D%3D%20%27Glass%27%29%20%7B%0A%20%20%20%20return%20new%20THREE.MeshPhysicalMaterial%28%7Bname%3A%27Pearl%20physical%20%2F%20Glass%27%2Ccolor%2C%0A%20%20%20%20%20%20roughness%3A0.65%2Cmetalness%3A0%2Copacity%2Ctransparent%3Atrue%2CdepthWrite%3Afalse%2C%0A%20%20%20%20%20%20side%3ATHREE.DoubleSide%2Ctransmission%3A0%2Cior%3A1.1%2Cclearcoat%3A0%7D%29%3B%0A%20%20%7D%0A%20%20const%20maps%20%3D%20pearlPhysicalMaps%28THREE%2Coptions%2Ccolor%29%3B%0A%20%20return%20new%20THREE.MeshPhysicalMaterial%28%7B%0A%20%20%20%20name%3A%60Pearl%20physical%20%2F%20%24%7Bpreset%7D%60%2Ccolor%3A0xffffff%2C...maps%2C%0A%20%20%20%20roughness%3AMath.min%281%2Croughness%2A0.90%29%2C%0A%20%20%20%20metalness%3A%5B%27Gold%27%2C%27GoldBond%27%5D.includes%28preset%29%20%3F%200.18%20%3A%200.025%2C%0A%20%20%20%20normalScale%3Anew%20THREE.Vector2%28grain%2A2%2Cgrain%2A2%29%2C%0A%20%20%20%20clearcoat%3AMath.min%281%2C0.45%2Ahighlight%29%2CclearcoatRoughness%3A0.18%2C%0A%20%20%20%20sheen%3A0.12%2CsheenColor%3Acolor.clone%28%29.lerp%28new%20THREE.Color%28%27white%27%29%2C0.35%29%2C%0A%20%20%20%20sheenRoughness%3A0.55%2CspecularIntensity%3AMath.min%282%2Chighlight%29%2Cior%3A1.48%2C%0A%20%20%20%20opacity%2Ctransparent%3Aopacity%3C1%2CdepthWrite%3Aopacity%3E%3D1%2C%0A%20%20%20%20side%3Aopacity%3C1%20%3F%20THREE.DoubleSide%20%3A%20THREE.FrontSide%0A%20%20%7D%29%3B%0A%7D%0A%0Afunction%20addPearlStudioLighting%28THREE%2C%20scene%2C%20camera%2C%20target%20%3D%20new%20THREE.Vector3%280%2C1%2C0%29%29%20%7B%0A%20%20if%20%28scene.userData.pearlStudio%29%20return%20scene.userData.pearlStudio%3B%0A%20%20const%20forward%20%3D%20camera.getWorldDirection%28new%20THREE.Vector3%28%29%29.normalize%28%29%3B%0A%20%20const%20right%20%3D%20new%20THREE.Vector3%28%29.crossVectors%28forward%2Ccamera.up%29.normalize%28%29%3B%0A%20%20const%20up%20%3D%20new%20THREE.Vector3%28%29.crossVectors%28right%2Cforward%29.normalize%28%29%3B%0A%20%20const%20make%20%3D%20%28x%2Cy%2Cz%2Cintensity%2Cwidth%2Cheight%29%20%3D%3E%20%7B%0A%20%20%20%20const%20light%20%3D%20new%20THREE.RectAreaLight%280xffffff%2Cintensity%2Cwidth%2Cheight%29%3B%0A%20%20%20%20light.position.copy%28target%29.addScaledVector%28right%2Cx%29.addScaledVector%28up%2Cy%29.addScaledVector%28forward%2C-z%29%3B%0A%20%20%20%20light.lookAt%28target%29%3B%20scene.add%28light%29%3B%20return%20light%3B%0A%20%20%7D%3B%0A%20%20const%20lights%20%3D%20%5Bmake%28-4%2C5%2C7%2C12%2C4%2C5%29%2C%20make%284%2C1%2C5%2C1.5%2C5%2C5%29%5D%3B%0A%20%20scene.userData.pearlStudio%20%3D%20lights%3B%0A%20%20return%20lights%3B%0A%7D%0A%0A%2F%2F%20WLJS%20adapter.%20Evaluate%20this%20cell%20before%20using%20PearlMaterial%20in%20Graphics3D.%0Aconst%20ready%20%3D%20interpretate.shared.THREE.load%28%29.then%28%28%29%20%3D%3E%20interpretate.shared.THREE.THREE%29%3B%0Acore.PearlMaterial%20%3D%20async%20%28args%2C%20env%29%20%3D%3E%20%7B%0A%20%20const%20THREE%20%3D%20await%20ready%3B%0A%20%20const%20values%20%3D%20await%20Promise.all%28args.map%28arg%20%3D%3E%20interpretate%28arg%2C%20env%29%29%29%3B%0A%20%20const%20%5Bpreset%20%3D%20%22Lavender%22%2C%20roughness%20%3D%200.42%2C%20grain%20%3D%200.014%2C%20opacity%2C%20highlight%2C%20wash%20%3D%200.10%5D%20%3D%20values%3B%0A%20%20if%20%28%21%28preset%20in%20pearlPalette%29%29%20throw%20new%20Error%28%22Unknown%20PearlMaterial%20preset%3A%20%22%20%2B%20preset%29%3B%0A%20%20const%20pathTracing%20%3D%20env.PathRendering%20%3D%3D%3D%20true%3B%0A%20%20if%20%28pathTracing%29%20addPearlStudioLighting%28THREE%2C%20env.global.scene%2C%20env.camera%2C%20env.controlObject%3F.o%3F.target%29%3B%0A%20%20return%20function%20PearlMaterialFactory%28%29%20%7B%0A%20%20%20%20return%20createPearlMaterial%28THREE%2C%20%7Bpreset%2C%20roughness%2C%20grain%2C%20opacity%2C%20highlight%2C%20wash%2C%20pathTracing%7D%29%3B%0A%20%20%7D%3B%0A%7D%3B%0Acore.PearlBondMaterial%20%3D%20async%20%28args%2C%20env%29%20%3D%3E%20%7B%0A%20%20const%20THREE%20%3D%20await%20ready%3B%0A%20%20const%20%5Bpreset%20%3D%20%22Bond%22%2C%20start%20%3D%20%22Lavender%22%2C%20end%20%3D%20%22Lavender%22%2C%20bleed%20%3D%200.30%2C%0A%20%20%20%20roughness%20%3D%200.35%2C%20grain%20%3D%200.012%5D%20%3D%20await%20Promise.all%28args.map%28arg%20%3D%3E%20interpretate%28arg%2C%20env%29%29%29%3B%0A%20%20for%20%28const%20name%20of%20%5Bpreset%2C%20start%2C%20end%5D%29%20%7B%0A%20%20%20%20if%20%28%21%28name%20in%20pearlPalette%29%29%20throw%20new%20Error%28%22Unknown%20pearl%20preset%3A%20%22%20%2B%20name%29%3B%0A%20%20%7D%0A%20%20const%20pathTracing%20%3D%20env.PathRendering%20%3D%3D%3D%20true%3B%0A%20%20if%20%28pathTracing%29%20addPearlStudioLighting%28THREE%2C%20env.global.scene%2C%20env.camera%2C%20env.controlObject%3F.o%3F.target%29%3B%0A%20%20return%20function%20PearlBondMaterialFactory%28%29%20%7B%0A%20%20%20%20return%20createPearlMaterial%28THREE%2C%20%7Bpreset%2C%20roughness%2C%20grain%2C%20bond%3Atrue%2C%0A%20%20%20%20%20%20startColor%3ApearlPalette%5Bstart%5D%2C%20endColor%3ApearlPalette%5Bend%5D%2C%20bleed%2C%20pathTracing%7D%29%3B%0A%20%20%7D%3B%0A%7D%3B%0A%2F%2F%20Static%20atom%20and%20bond%20swatches%2C%20rendered%20once%20with%20the%20raster%20shader.%0Aconst%20panel%20%3D%20document.createElement%28%27div%27%29%3B%0Apanel.style.cssText%20%3D%20%27background%3Awhite%3Bborder%3A1px%20solid%20%23e1e5ea%3Bborder-radius%3A12px%3Bpadding%3A18px%3Bmax-width%3A720px%3Bcolor%3A%2317263d%3Bfont%3A14px%20system-ui%27%3B%0Aconst%20status%20%3D%20document.createElement%28%27div%27%29%3B%0Astatus.textContent%20%3D%20%27Loading%20pearl%20materials%E2%80%A6%27%3B%0Apanel.append%28status%29%3B%0Aconst%20swatches%20%3D%20document.createElement%28%27div%27%29%3B%0Aswatches.style.cssText%20%3D%20%27position%3Arelative%3Bwidth%3A100%25%27%3B%0Apanel.append%28swatches%29%3B%0Alet%20renderer%3B%0Aconst%20geometries%20%3D%20%5B%5D%3B%0Aconst%20materials%20%3D%20%5B%5D%3B%0Alet%20destroyed%20%3D%20false%3B%0Athis.ondestroy%20%3D%20%28%29%20%3D%3E%20%7B%0A%20%20destroyed%20%3D%20true%3B%0A%20%20geometries.forEach%28geometry%20%3D%3E%20geometry.dispose%28%29%29%3B%0A%20%20materials.forEach%28material%20%3D%3E%20material.dispose%28%29%29%3B%0A%20%20renderer%3F.dispose%28%29%3B%0A%7D%3B%0Aready.then%28THREE%20%3D%3E%20%7B%0A%20%20if%20%28destroyed%29%20return%3B%0A%20%20renderer%20%3D%20new%20THREE.WebGLRenderer%28%7Bantialias%3Atrue%2C%20alpha%3Afalse%7D%29%3B%0A%20%20renderer.setPixelRatio%28Math.min%28window.devicePixelRatio%20%7C%7C%201%2C%202%29%29%3B%0A%20%20renderer.setSize%28640%2C%20350%29%3B%0A%20%20if%20%28%27outputColorSpace%27%20in%20renderer%29%20renderer.outputColorSpace%20%3D%20THREE.SRGBColorSpace%3B%0A%20%20else%20renderer.outputEncoding%20%3D%20THREE.sRGBEncoding%3B%0A%20%20renderer.domElement.style.cssText%20%3D%20%27width%3A100%25%3Bheight%3Aauto%3Bdisplay%3Ablock%27%3B%0A%20%20swatches.append%28renderer.domElement%29%3B%0A%20%20const%20scene%20%3D%20new%20THREE.Scene%28%29%3B%0A%20%20scene.background%20%3D%20new%20THREE.Color%28%27white%27%29%3B%0A%20%20const%20camera%20%3D%20new%20THREE.OrthographicCamera%28-3.6%2C3.6%2C1.96875%2C-1.96875%2C0.1%2C20%29%3B%0A%20%20camera.position.z%20%3D%206%3B%0A%20%20const%20sphere%20%3D%20new%20THREE.SphereGeometry%280.65%2C64%2C48%29%3B%0A%20%20const%20cylinder%20%3D%20new%20THREE.CylinderGeometry%280.115%2C0.115%2C1.75%2C48%2C16%29%3B%0A%20%20const%20endpoint%20%3D%20new%20THREE.SphereGeometry%280.19%2C32%2C24%29%3B%0A%20%20geometries.push%28sphere%2Ccylinder%2Cendpoint%29%3B%0A%20%20const%20materialFor%20%3D%20options%20%3D%3E%20%7B%0A%20%20%20%20const%20material%20%3D%20createPearlMaterial%28THREE%2Coptions%29%3B%0A%20%20%20%20materials.push%28material%29%3B%20return%20material%3B%0A%20%20%7D%3B%0A%20%20%5B%27Gold%27%2C%27Lavender%27%2C%27Teal%27%5D.forEach%28%28preset%2Ci%29%20%3D%3E%20%7B%0A%20%20%20%20const%20mesh%20%3D%20new%20THREE.Mesh%28sphere%2CmaterialFor%28%7Bpreset%2Cgrain%3A0.014%7D%29%29%3B%0A%20%20%20%20mesh.position.set%28%28i-1%29%2A2.4%2C1.0%2C0%29%3B%0A%20%20%20%20scene.add%28mesh%29%3B%0A%20%20%7D%29%3B%0A%20%20const%20bonds%20%3D%20%5B%0A%20%20%20%20%7Bpreset%3A%27Bond%27%2Cstart%3A%27Lavender%27%2Cend%3A%27Lavender%27%7D%2C%0A%20%20%20%20%7Bpreset%3A%27Bond%27%2Cstart%3A%27Ice%27%2Cend%3A%27Lavender%27%7D%2C%0A%20%20%20%20%7Bpreset%3A%27GoldBond%27%2Cstart%3A%27Lavender%27%2Cend%3A%27Gold%27%7D%0A%20%20%5D%3B%0A%20%20bonds.forEach%28%28%7Bpreset%2Cstart%2Cend%7D%2Ci%29%20%3D%3E%20%7B%0A%20%20%20%20const%20group%20%3D%20new%20THREE.Group%28%29%3B%0A%20%20%20%20group.position.set%28%28i-1%29%2A2.4%2C-0.95%2C0%29%3B%0A%20%20%20%20group.rotation.z%20%3D%200.12%3B%0A%20%20%20%20const%20rod%20%3D%20new%20THREE.Mesh%28cylinder%2CmaterialFor%28%7B%0A%20%20%20%20%20%20preset%2Cbond%3Atrue%2Croughness%3A0.35%2Cgrain%3A0.012%2Cbleed%3A0.30%2C%0A%20%20%20%20%20%20startColor%3ApearlPalette%5Bstart%5D%2CendColor%3ApearlPalette%5Bend%5D%0A%20%20%20%20%7D%29%29%3B%0A%20%20%20%20%2F%2F%20Cylinder%20v%3D0%20is%20the%20bottom%20end%3B%20rotating%20it%20puts%20that%20end%20on%20the%20left.%0A%20%20%20%20rod.rotation.z%20%3D%20-Math.PI%2F2%3B%0A%20%20%20%20group.add%28rod%29%3B%0A%20%20%20%20%5Bstart%2Cend%5D.forEach%28%28atom%2Cj%29%20%3D%3E%20%7B%0A%20%20%20%20%20%20const%20mesh%20%3D%20new%20THREE.Mesh%28endpoint%2CmaterialFor%28%7Bpreset%3Aatom%2Cgrain%3A0.014%7D%29%29%3B%0A%20%20%20%20%20%20mesh.position.x%20%3D%20%28j-0.5%29%2A1.75%3B%0A%20%20%20%20%20%20group.add%28mesh%29%3B%0A%20%20%20%20%7D%29%3B%0A%20%20%20%20scene.add%28group%29%3B%0A%20%20%7D%29%3B%0A%20%20const%20labels%20%3D%20%28top%2Citems%29%20%3D%3E%20%7B%0A%20%20%20%20const%20row%20%3D%20document.createElement%28%27div%27%29%3B%0A%20%20%20%20row.style.cssText%20%3D%20%27position%3Aabsolute%3Bleft%3A0%3Bright%3A0%3Btop%3A%27%2Btop%2B%27%25%3Bdisplay%3Agrid%3Bgrid-template-columns%3Arepeat%283%2C1fr%29%3Btext-align%3Acenter%3Bgap%3A8px%3Bline-height%3A1.4%3Bfont-size%3A13px%3Bpointer-events%3Anone%27%3B%0A%20%20%20%20items.forEach%28%28%5Btitle%2Cdetail%5D%29%20%3D%3E%20%7B%0A%20%20%20%20%20%20const%20label%20%3D%20document.createElement%28%27div%27%29%3B%0A%20%20%20%20%20%20const%20name%20%3D%20document.createElement%28%27strong%27%29%3B%20name.textContent%3Dtitle%3B%0A%20%20%20%20%20%20label.append%28name%29%3B%0A%20%20%20%20%20%20if%28detail%29%20%7B%0A%20%20%20%20%20%20%20%20const%20sub%3Ddocument.createElement%28%27div%27%29%3B%20sub.textContent%3Ddetail%3B%0A%20%20%20%20%20%20%20%20sub.style.cssText%3D%27color%3A%23627087%3Bfont-size%3A11px%27%3B%0A%20%20%20%20%20%20%20%20label.append%28sub%29%3B%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20row.append%28label%29%3B%0A%20%20%20%20%7D%29%3B%0A%20%20%20%20swatches.append%28row%29%3B%0A%20%20%7D%3B%0A%20%20labels%2844%2C%5B%5B%27Gold%27%2C%27Atoms%27%5D%2C%5B%27Lavender%27%2C%27Atoms%27%5D%2C%5B%27Teal%27%2C%27Atoms%27%5D%5D%29%3B%0A%20%20labels%2884%2C%5B%5B%27Bond%27%2C%27Lavender%20%E2%86%92%20Lavender%27%5D%2C%5B%27Bond%20%C2%B7%20carbon%20end%27%2C%27Ice%20%E2%86%92%20Lavender%27%5D%2C%5B%27GoldBond%27%2C%27Lavender%20%E2%86%92%20Gold%27%5D%5D%29%3B%0A%20%20const%20errors%20%3D%20%5B%5D%3B%0A%20%20renderer.debug.onShaderError%20%3D%20%28gl%2Cprogram%2Cvertex%2Cfragment%29%20%3D%3E%20%7B%0A%20%20%20%20errors.push%28gl.getProgramInfoLog%28program%29%2Cgl.getShaderInfoLog%28vertex%29%2Cgl.getShaderInfoLog%28fragment%29%29%3B%0A%20%20%7D%3B%0A%20%20renderer.render%28scene%2Ccamera%29%3B%0A%20%20if%28errors.some%28Boolean%29%29%20throw%20new%20Error%28errors.filter%28Boolean%29.join%28%27%5Cn%27%29%29%3B%0A%20%20status.textContent%3D%27Pearl%20materials%20%C2%B7%20atoms%20and%20bonds%20%C2%B7%20raster%20preview%20%C2%B7%20Three.js%20r%27%2BTHREE.REVISION%3B%0A%7D%29.catch%28error%20%3D%3E%20%7Bstatus.textContent%3D%27Shader%20error%3A%20%27%2Berror.message%3Bconsole.error%28error%29%3B%7D%29%3B%0Areturn%20panel%3B
Atoms and faces: MeshMaterial[PearlMaterial["Gold"]]. Other presets: "Lavender", "Teal", "Ice" and "Glass".
Optional controls: PearlMaterial[preset, roughness, grain, opacity, highlight, wash]. Increase grain for texture, highlight for shine, or wash for colour variation.
Bonds: MeshMaterial[PearlBondMaterial["Bond", "Ice", "Lavender"]]. The last two colours tint the bond ends. Use "GoldBond" for gold bonds. Optional controls: PearlBondMaterial[base, start, end, bleed, roughness, grain]; set bleed to 0 to remove the end tints.
Path tracing: add "Renderer" -> "PathTracing" and "MultipleImportanceSampling" -> True. For a five-second preview, use "SleepAfter" -> 5 1000 and Rasterize[..., "ExposureTime" -> 5]. Increase both times for a cleaner image.
Minimal example
Two atoms joined by a bond, using both material functions.
Graphics3D[{
{MeshMaterial[PearlMaterial["Ice"]],
Sphere[{-1, 0, 0}, .35]},
{MeshMaterial[PearlMaterial["Lavender"]],
Sphere[{1, 0, 0}, .35]},
{MeshMaterial[PearlBondMaterial["Bond", "Ice", "Lavender"]],
Cylinder[{{-1, 0, 0}, {1, 0, 0}}, .09]}
}, Background -> White,
ImageSize -> 450, ViewPoint -> {0, -3, 1}]
(*VB[*)(Graphics3D[{{MeshMaterial[PearlMaterial["Ice"]], Sphere[{-1, 0, 0}, 0.35]}, {MeshMaterial[PearlMaterial["Lavender"]], Sphere[{1, 0, 0}, 0.35]}, {MeshMaterial[PearlBondMaterial["Bond", "Ice", "Lavender"]], Cylinder[{{-1, 0, 0}, {1, 0, 0}}, 0.09]}}, Background -> GrayLevel[1], ImageSize -> 450, ViewPoint -> {0, -3, 1}])(*,*)(*"1:eJy1ksFKAzEQhndVRBc8+Ai+geBZhFbRwhZKFzxvuvunOxiTNdmt1tfxIbz7EPo0okmWtLaUemoOP5lh5p9vQs4maszjKIrMgZU7JUruLiaxcqtZXVFhLq75fqhIyTR8byXy3edW+opzIKWnFq3Ob14aSENKmnxplA9hqiFroImJrvPEyghMi5DO3LBBgW7MoZWsrqCxCkE/9pANIi+a+/N5tWu4I+fMZpAl9D+EcYDbEaGfdhoIe0qWC0rn7hLhLTdgu0x/LmiZWSBte+jtOyZfb/Vl8v5nx3Er4H9TjxUPU61aWXYrH3c/bJ5iBuF91ppcweCRTZHRK+gj3lhwT3geKZLr0B7p25E751/1Zr5+"*)(*]VB*)
Cage
The cosahedral cage, camera, atom sizes and bond connectivity, rendered with the pearl materials
PearlCageFigure = Module[
{phi, cageSites, edgePairs, view, carbonIndices, boronIndices,
hSites, cageBonds, terminalBonds, faces, sitePreset},
phi = GoldenRatio;
cageSites = N@Join[
Flatten[Table[{0, s, t phi}, {s, {-1, 1}}, {t, {-1, 1}}], 1],
Flatten[Table[{s, t phi, 0}, {s, {-1, 1}}, {t, {-1, 1}}], 1],
Flatten[Table[{t phi, 0, s}, {s, {-1, 1}}, {t, {-1, 1}}], 1]];
edgePairs = Select[Subsets[Range[Length[cageSites]], {2}],
Abs[EuclideanDistance @@ cageSites[[#]] - 2] < 10^-6 &];
view = Normalize[{2.4, -2.8, 2.1}];
carbonIndices = First@MaximalBy[edgePairs, Dot[Mean[cageSites[[#]]], view] &];
boronIndices = Complement[Range[12], carbonIndices];
hSites = (# + .78 Normalize[#]) & /@ cageSites;
sitePreset[i_] := If[MemberQ[carbonIndices, i], "Ice", "Lavender"];
cageBonds = ({MeshMaterial[PearlBondMaterial["Bond",
sitePreset[#[[1]]], sitePreset[#[[2]]], .30, .35, 3 .012]],
Cylinder[cageSites[[#]], .055]} &) /@ edgePairs;
terminalBonds = Table[{
MeshMaterial[PearlBondMaterial["GoldBond", sitePreset[i], "Gold", .25, .32, .012]],
Cylinder[{cageSites[[i]], hSites[[i]]}, .045]}, {i, 12}];
faces = MeshPrimitives[ConvexHullMesh[cageSites], 2];
Graphics3D[{
{MeshMaterial[PearlMaterial["Glass", .60, 0., .12, 0.]], faces},
cageBonds,
terminalBonds,
{MeshMaterial[PearlMaterial["Lavender", .36, 2 .014]], Sphere[cageSites[[boronIndices]], .23]},
{MeshMaterial[PearlMaterial["Ice", .34, 2 .008]], Sphere[cageSites[[carbonIndices]], .27]},
{MeshMaterial[PearlMaterial["Gold", .32, 2 .012]], Sphere[hSites, .13]},
{Black, Directive[FontSize -> 18],
(Text[Style["C", Bold], # + .4 {1,0,-1}] &)@
First@MaximalBy[cageSites[[carbonIndices]], Dot[#, view] &],
(Text[Style["B", Bold], # + {0.4,-0.2,-1.8}] &)@
First@MaximalBy[cageSites[[boronIndices]], Dot[#, view] &],
(Text[Style["H", Bold], # + .45 Normalize[#]] &)@
First@MaximalBy[hSites, Dot[#, view] &]}
}, Boxed -> False, Background -> White, SphericalRegion -> True,
ViewPoint -> {2.4, -2.8, 2.1}, ViewVertical -> {0,0,1},
PlotRange -> All, ImageSize -> Large, "AcesToneMapping" -> False, "OrthographicCameraZoom" -> .72]
]
(*VB[*)(FrontEndRef["F160fc7f8-e1ac-4965-b016-d462954a1fb0"])(*,*)(*"1:eJxTTMoPSmNkYGAoZgESHvk5KRCeEJBwK8rPK3HNS3GtSE0uLUlMykkNVgUJG5oZpCWbp1nophomJuuaWJqZ6iYZGJrpppiYGVmamiQapiUZAACZUhW2"*)(*]VB*)
Path-traced pearl cage
The same geometry and material calls with "Renderer" -> "PathTracing". The material factories automatically use physical materials and locally generated pigment, roughness and normal textures, with two soft studio lights. Rasterization continues to use the custom shader.
Show[PearlCageFigure,
"Renderer" -> "PathTracing", "MultipleImportanceSampling" -> True,
"EnvironmentIntensity" -> .50, "BackgroundAlpha" -> 0,
"Bounces" -> 5,
"SleepAfter" -> 30 1000]