Wire material lookup textures into Renderer
This commit is contained in:
parent
a1e164454d
commit
f5b04f08c6
2 changed files with 39 additions and 0 deletions
|
|
@ -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() {
|
||||
|
|
|
|||
11
src/materials/index.ts
Normal file
11
src/materials/index.ts
Normal file
|
|
@ -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";
|
||||
Loading…
Reference in a new issue