轻量封装WebGPU渲染系统示例<6>-混合模式(源码)

当前示例源码github地址:

https://github.com/vilyLei/voxwebgpu/blob/version-1.01/src/voxgpu/sample/BlendTest.ts

此示例渲染系统实现的特性:

  1. 用户态与系统态隔离。

  2. 高频调用与低频调用隔离。

  3. 面向用户的易用性封装。

  4. 渲染数据和渲染机制分离。

  5. 用户操作和渲染系统调度并行机制。

当前示例运行效果:

此示例基于此渲染系统实现,当前示例TypeScript源码如下

javascript 复制代码
export class BlendTest {

	geomData = new GeomDataBuilder();
	renderer = new WGRenderer();

	initialize(): void {
		console.log("BlendTest::initialize() ...");

		const shdSrc = {
			vertShaderSrc: { code: vertWGSL, uuid: "vtxShdCode" },
			fragShaderSrc: { code: fragWGSL, uuid: "fragShdCode" }
		};
		let materials = [
			this.createMaterial(shdSrc, [new WGImage2DTextureData("static/assets/box.jpg")]),
			this.createMaterial(shdSrc, [new WGImage2DTextureData("static/assets/default.jpg")], ["add"]),
			this.createMaterial(shdSrc, [new WGImage2DTextureData("static/assets/xulie_08_61.png")], ["alpha_add"]),
			this.createMaterial(shdSrc, [new WGImage2DTextureData("static/assets/blueTransparent.png")], ["add"])
		]
		for(let i = 0; i < materials.length; ++i) {
			this.createEntity([materials[i]], new Vector3(0, 0, -50 + i * 50));
		}
	}

	private createMaterial(
		shdSrc: WGRShderSrcType,
		texDatas?: WGImage2DTextureData[],
		blendModes: string[] = []
	): WGMaterial {

		let pipelineDefParam = {
			faceCullMode: "back",
			blendModes: [] as string[]
		};
		pipelineDefParam.blendModes = blendModes;
		const texTotal = texDatas ? texDatas.length : 0;

		const material = new WGMaterial({
			shadinguuid: "base-material-tex" + texTotal,
			shaderCodeSrc: shdSrc,
			pipelineDefParam
		});
		if (texTotal > 0) {
			const texWrappers: WGTextureWrapper[] = new Array(texTotal);
			for (let i = 0; i < texTotal; ++i) {
				texWrappers[i] = new WGTextureWrapper({ texture: { data: texDatas[i], shdVarName: "texture" + i } });
			}
			material.textures = texWrappers;
		}
		return material;
	}
	private createEntity(materials: WGMaterial[], pv: Vector3): Entity3D {

		const renderer = this.renderer;
		const rgd = this.geomData.createSquare(600);

		const geometry = new WGGeometry()
			.addAttribute({ shdVarName: "position", data: rgd.vs, strides: [3] })
			.addAttribute({ shdVarName: "uv", data: rgd.uvs, strides: [2] })
			.setIndexBuffer({ name: "geomIndex", data: rgd.ivs });

		const entity = new Entity3D();
		entity.materials = materials;
		entity.geometry = geometry;
		entity.transform.setPosition(pv);

		renderer.addEntity(entity);
		return entity;
	}

	run(): void {
		this.renderer.run();
	}
}
相关推荐
GIS数据转换器16 小时前
空天地一体化边坡监测及安全预警系统
大数据·人工智能·安全·机器学习·3d·无人机
野区捕龙为宠20 小时前
unity 实现3D空间音效特性
3d·unity·游戏引擎
CreasyChan21 小时前
unity射线与几何检测 - “与世界的交互”
算法·游戏·3d·unity·数学基础
"YOUDIG"2 天前
从算法到3D美学——一站式生成个性化手办风格照片
算法·3d
sbjdhjd2 天前
开源分享 | 超浪漫 3D 圣诞树立体动画(附零基础使用教程)
3d·青少年编程·开源·html·节日
lrh30253 天前
Custom SRP - 16 Render Scale
3d·unity·srp·render pipeline·render scale
毕安格 - BimAngle3 天前
Revit 模型一键输出 3D Tiles (for Cesium) 和 glTF/glb
3d·cesium·gltf·glb·3d tiles
map_vis_3d3 天前
JSAPIThree 加载 3D Tiles 学习笔记:大规模三维场景渲染
笔记·学习·3d
da_vinci_x3 天前
Substance 3D Painter 进阶:手绘“掉漆”太累?用 Anchor Point 让材质“活”过来
游戏·3d·aigc·材质·设计师·技术美术·游戏美术
攻城狮7号3 天前
微软开源 TRELLIS.2:单图 3 秒变 3D?
人工智能·3d·trellis.2·o-voxel·sc-vae·微软开源模型