/** Captures Three-expanded sources only. No WebGL context, browser, or GPU execution. */ import fs from 'node:fs'; import * as THREE from 'three'; import {WebGLProgram} from 'three/src/renderers/webgl/WebGLProgram.js'; import {loadTypescript} from './load-typescript.mjs'; const {attachMeshRefraction}=await loadTypescript(new URL('../../src/rendering/MeshRefraction.ts',import.meta.url)); const material=new THREE.MeshPhysicalMaterial({transmission:1});attachMeshRefraction(material,new THREE.Mesh());const shader={vertexShader:THREE.ShaderLib.physical.vertexShader,fragmentShader:THREE.ShaderLib.physical.fragmentShader,uniforms:{}};material.onBeforeCompile(shader,{}); for(const area of [0,1]){ const params={...shader,defines:material.defines,precision:'highp',shaderType:'MeshPhysicalMaterial',shaderName:'OfflineReview',transmission:true,thicknessMap:true,thicknessMapUv:'uv',envMap:true,envMapMode:THREE.CubeUVReflectionMapping,combine:THREE.MultiplyOperation,envMapCubeUVHeight:128,toneMapping:THREE.NoToneMapping,outputColorSpace:THREE.LinearSRGBColorSpace,numDirLights:0,numPointLights:0,numSpotLights:0,numSpotLightMaps:0,numRectAreaLights:area,numHemiLights:0,numDirLightShadows:0,numSpotLightShadows:0,numSpotLightShadowsWithMaps:0,numPointLightShadows:0,numClippingPlanes:1,numClipIntersection:0}; const gl={VERTEX_SHADER:0,FRAGMENT_SHADER:1,createProgram:()=>({}),createShader:type=>({type}),shaderSource:(shader,source)=>fs.writeFileSync(`/tmp/b-review-${area}.${shader.type===0?'vert':'frag'}`,source),compileShader:shader=>{if(shader.type===1)throw new Error('Captured both sources; deliberately no GL compiler or driver used');}}; try{new WebGLProgram({getContext:()=>gl},'offline-review',params,{});}catch(e){if(!e.message.startsWith('Captured'))throw e;console.log('Captured r169 shader sources for '+area+' area lights')} }