From f5b04f08c624192dc9db3900abc6e1a66514b91b Mon Sep 17 00:00:00 2001 From: Jared Miller Date: Wed, 11 Mar 2026 13:25:10 -0400 Subject: [PATCH] Wire material lookup textures into Renderer --- src/Renderer.ts | 28 ++++++++++++++++++++++++++++ src/materials/index.ts | 11 +++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/materials/index.ts diff --git a/src/Renderer.ts b/src/Renderer.ts index d471fba..b3d198b 100644 --- a/src/Renderer.ts +++ b/src/Renderer.ts @@ -9,6 +9,11 @@ import { TERRAIN_TYPE_MASK, TERRAIN_TYPE_SHIFT, } from "./constants"; +import { + generateColorData, + generateLookupData, + MaterialRegistry, +} from "./materials"; interface Resources { worldRenderTarget: THREE.WebGLRenderTarget; @@ -24,11 +29,34 @@ export default class Renderer { private renderer: THREE.WebGLRenderer; public resources!: Resources; private colonyStats = new ColonyStats(); + public readonly materialRegistry = new MaterialRegistry(); + public readonly materialPropsTexture!: THREE.DataTexture; + public readonly materialColorTexture!: THREE.DataTexture; constructor(public canvas: HTMLCanvasElement) { this.renderer = new THREE.WebGLRenderer({ canvas }); this.initResources(); + + const propsData = generateLookupData(this.materialRegistry); + this.materialPropsTexture = new THREE.DataTexture( + propsData, + 256, + 1, + THREE.RGBAFormat, + THREE.FloatType, + ); + this.materialPropsTexture.needsUpdate = true; + + const colorData = generateColorData(this.materialRegistry); + this.materialColorTexture = new THREE.DataTexture( + colorData, + 256, + 1, + THREE.RGBAFormat, + THREE.FloatType, + ); + this.materialColorTexture.needsUpdate = true; } private initResources() { diff --git a/src/materials/index.ts b/src/materials/index.ts new file mode 100644 index 0000000..5d98eb2 --- /dev/null +++ b/src/materials/index.ts @@ -0,0 +1,11 @@ +export { generateColorData, generateLookupData } from "./lookupTexture"; +export { MaterialRegistry } from "./registry"; +export { + BEHAVIOR_GAS, + BEHAVIOR_LIQUID, + BEHAVIOR_POWDER, + BEHAVIOR_SOLID, + type BehaviorType, + type Color4, + type Material, +} from "./types";