轻量封装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();
	}
}
相关推荐
old_power5 小时前
【PCL】Segmentation 模块—— 基于图割算法的点云分割(Min-Cut Based Segmentation)
c++·算法·计算机视觉·3d
Thomas_YXQ5 小时前
Unity3D项目开发中的资源加密详解
游戏·3d·unity·unity3d·游戏开发
jimumeta8 小时前
不建模,无代码,如何构建一个3D虚拟展厅?
3d·虚拟展厅·3d展厅
菩提树下的凡夫10 小时前
Halcon 3D基础知识及常用函数
3d
CASAIM20 小时前
手持式三维激光扫描仪-3D扫描产品尺寸
3d·信息可视化
old_power2 天前
【PCL】Segmentation 模块—— 欧几里得聚类提取(Euclidean Cluster Extraction)
c++·计算机视觉·3d
3D小将2 天前
3D 模型格式转换之 STP 转 STL 深度解析
3d·建造者模式
Σίσυφος19002 天前
SLAM 6 3Dto2D 的Pnp 和光束平移法
3d
jndingxin2 天前
OpenCV相机标定与3D重建(62)根据两个投影矩阵和对应的图像点来计算3D空间中点的坐标函数triangulatePoints()的使用
opencv·3d
jndingxin2 天前
OpenCV相机标定与3D重建(61)处理未校准的立体图像对函数stereoRectifyUncalibrated()的使用
opencv·3d