-
Notifications
You must be signed in to change notification settings - Fork 3
/
MultiMaterialPass.ts
74 lines (59 loc) · 2.21 KB
/
MultiMaterialPass.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { GeomDataBuilder } from "../geometry/GeomDataBuilder";
import vertWGSL from "./shaders/defaultEntity.vert.wgsl";
import fragWGSL from "./shaders/sampleTextureMixColor.frag.wgsl";
import { WGMaterial } from "../material/WGMaterial";
import { WGGeometry } from "../geometry/WGGeometry";
import { Entity3D } from "../entity/Entity3D";
import { WGRenderer } from "../rscene/WGRenderer";
import { WGImage2DTextureData } from "../texture/WGTextureWrapper";
import { WGRShderSrcType } from "../material/WGMaterialDescripter";
export class MultiMaterialPass {
private mEntity: Entity3D;
geomData = new GeomDataBuilder();
renderer = new WGRenderer();
initialize(): void {
console.log("MultiMaterialPass::initialize() ...");
const shdSrc = {
vert: { code: vertWGSL },
frag: { code: fragWGSL }
};
const tds = [new WGImage2DTextureData("static/assets/blueTransparent.png")];
let material0 = this.createMaterial(shdSrc, tds, ["transparent"], "front");
let material1 = this.createMaterial(shdSrc, tds, ["transparent"], "back");
this.mEntity = this.createEntity([material0, material1]);
}
private createMaterial(shaderSrc: WGRShderSrcType, texDatas?: WGImage2DTextureData[], blendModes: string[] = [], faceCullMode = "back"): WGMaterial {
let pipelineDefParam = {
depthWriteEnabled: true,
faceCullMode: faceCullMode,
blendModes: [] as string[]
};
pipelineDefParam.blendModes = blendModes;
const texTotal = texDatas ? texDatas.length : 0;
const material = new WGMaterial({
shadinguuid: "base-material-tex" + texTotal + faceCullMode,
shaderSrc,
pipelineDefParam
});
material.addTextureWithDatas(texDatas);
return material;
}
private createEntity(materials: WGMaterial[]): Entity3D {
const renderer = this.renderer;
const rgd = this.geomData.createSphere(150, 30, 30);
const geometry = new WGGeometry()
.addAttribute({ position: rgd.vs })
.addAttribute({ uv: rgd.uvs })
.setIndices( rgd.ivs );
const entity = new Entity3D({geometry, materials});
renderer.addEntity( entity );
return entity;
}
private mRotY = 0.0;
run(): void {
this.mRotY += 0.5;
this.mEntity.transform.setRotationXYZ(0, this.mRotY, this.mRotY + 0.5);
this.mEntity.update();
this.renderer.run();
}
}