轻量封装WebGPU渲染系统示例<24>- Rendering Pass Graph基本用法(源码)

当前示例源码github地址:

https://github.com/vilyLei/voxwebgpu/blob/feature/rendering/src/voxgpu/sample/PassNodeGraphTest.ts

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

javascript 复制代码
class PassGraph extends WGRPassNodeGraph {
	constructor() { super(); }
	runBegin(): void {
		super.runBegin();
	}
	run(): void {
		let pass = this.passes[0];
		for (let i = 0; i < 16; ++i) {
			pass.colorAttachments[0].clearEnabled = i < 1;
			pass.render();
		}
	}
}

export class PassNodeGraphTest {
	private mRscene = new RendererScene();

	initialize(): void {

		let multisampleEnabled = true;
		let depthTestEnabled = false;
		let rpassparam = { multisampleEnabled, depthTestEnabled };
		this.mRscene.initialize({ rpassparam });
		this.initEvent();
		this.initScene();
	}

	private applyNewRPass(texUUID: string, entities: FixScreenPlaneEntity[], clearColor: ColorDataType, extent = [0.4, 0.3, 0.5, 0.5]): void {

		let rs = this.mRscene;
		let rttTex = { diffuse: { uuid: texUUID, rttTexture: {} } };
		let colorAttachments = [
			{
				texture: rttTex,
				clearValue: clearColor,
				loadOp: "clear",
				storeOp: "store"
			}
		];
		let rPass = rs.renderer.appendRenderPass({ separate: true, colorAttachments });
		for (let i = 0; i < entities.length; ++i) {
			rPass.addEntity(entities[i]);
		}

		let graph = new PassGraph();
		graph.passes = [rPass];
		rs.setPassNodeGraph(graph);

		let entity = new FixScreenPlaneEntity({ extent, flipY: true, textures: [rttTex] });
		rs.addEntity(entity);
	}
	private initEvent(): void {
		const rs = this.mRscene;
		new MouseInteraction().initialize(rs, 0, false).setAutoRunning(true);
	}
	private initScene(): void {

		const rs = this.mRscene;
		let entity: FixScreenPlaneEntity;

		const diffuseTex = { diffuse: { url: "static/assets/guangyun_40.png", flipY: true } };

		let blendModes = ['add'];
		let entities: FixScreenPlaneEntity[] = [];
		entity = new FixScreenPlaneEntity({ extent: [-0.8, -0.8, 0.8, 0.8], textures: [diffuseTex], blendModes });
		entity.setColor([0.9, 0.3, 0.9]);
		rs.addEntity(entity);
		entities.push(entity);

		this.applyNewRPass('rtt0', entities, [0.2, 0.2, 0.2, 1.0], [-0.2, 0.1, 0.8, 0.8]);
	}

	run(): void {
		this.mRscene.run();
	}
}
相关推荐
CG_MAGIC1 小时前
Blender《废弃房屋》的制作过程
3d·blender·贴图·效果图·建模教程
码农三叔5 小时前
(10-2)大模型时代的人形机器人感知:3D大模型与场景理解
人工智能·机器学习·计算机视觉·3d·机器人·人形机器人
yeflx5 小时前
从3D到2D:相机投影的完整解析
数码相机·3d
新启航光学频率梳5 小时前
航空航天支架孔深光学3D轮廓测量-激光频率梳3D轮廓技术
科技·3d·制造
七77.5 小时前
【世界模型】UrbanWorld: An Urban World Model for 3D City Generation
3d·世界模型
给算法爸爸上香20 小时前
web网页显示点云
前端·3d·web·点云
V搜xhliang024620 小时前
3D 点云处理(PCL)
人工智能·目标检测·计算机视觉·3d·分类·知识图谱
weixin_5051544620 小时前
博维数孪创新引领,3D作业指导助力制造业升级
大数据·人工智能·3d·数字孪生·数据可视化·产品交互展示
twe775825820 小时前
“揭开3D IC封装的神秘面纱:动画演绎芯片堆叠的艺术“
科技·3d·制造·动画
CHENJIAMIAN PRO21 小时前
3D Tiles 2.0 技术审查整理笔记
笔记·3d