轻量封装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();
	}
}
相关推荐
应用市场1 小时前
基于上下文感知分层深度修复的3D照片生成技术详解
3d
你好!蒋韦杰-(烟雨平生)2 小时前
OpenGL
c++·数学·游戏·3d
星幻元宇VR4 小时前
消防安全教育展厅设备|消防器材装备3D展示系统
安全·3d·虚拟现实
山楂树の4 小时前
3D渲染分层机制 Layers 的原理分析(Threejs)
数据结构·3d·相机
应用市场5 小时前
【自动驾驶感知】基于3D部件引导的图像编辑:细粒度车辆状态理解技术详解
人工智能·3d·自动驾驶
EliseL1 天前
SuperMap iObjects Java 如何将3DTiles数据转换为S3M三维瓦片
java·3d·三维
qq_532453531 天前
使用 GaussianSplats3D 在 Vue 3 中构建交互式 3D 高斯点云查看器
前端·vue.js·3d
CoLiuRs1 天前
Image-to-3D — 让 2D 图片跃然立体*
python·3d·flask
新启航光学频率梳1 天前
特种爆破装置传爆深孔孔深光学3D轮廓测量-激光频率梳3D轮廓技术
科技·3d·制造
应用市场1 天前
基于稠密对应关系的3D人体网格回归技术详解
3d·数据挖掘·回归