轻量封装WebGPU渲染系统示例<23>- 可渲染对象添加到多个渲染Pass节点(源码)

82 篇文章 3 订阅
73 篇文章 3 订阅

渲染和计算混合系统, 可以看做基于算力驱动设计理念的一种实现。

此系统中,可渲染(rendering)/计算(computing)实体可以任意添加到一个渲染器pass节点。若干个这样的节点相关联,就能构成对应的pass node graph,也就实现了整个3D渲染及GPU计算的应用场景。Pass node graph也许会复杂,实际上一般的3D场景只需要一个默认的rendering pass node graph节点即可,最多在加上一个computing pass node graph来利用GPU计算。

当前示例源码github地址:

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

当前示例运行效果:

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

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

	initialize(): void {

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

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

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

		let entity = new FixScreenPlaneEntity({ extent, flipY: true, textures: [rttTex] });
		entity.setColor([0.7, 0.5, 0.5]);
		entity.uuid = 'apply-rtt-entity';
		rc.addEntity(entity);
	}
	private initEvent(): void {
		const rc = this.mRscene;
		new MouseInteraction().initialize(rc, 0, false).setAutoRunning(true);
	}
	private initScene(): void {

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

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

		let entities: FixScreenPlaneEntity[] = [];
		entity = new FixScreenPlaneEntity({ extent: [-0.8, -0.8, 0.8, 0.8], textures: [diffuseTex] });
		entity.setColor([0.9, 0.3, 0.9]);
		entity.uuid = "pl-0";
		rc.addEntity(entity);
		entities.push(entity);

		entity = new FixScreenPlaneEntity({ extent: [-0.2, -0.2, 0.4, 0.4], textures: [diffuseTex] });
		entity.setColor([0.2, 0.9, 0.9]);
		entity.uuid = "pl-1";
		rc.addEntity(entity);
		entities.push(entity);

		this.applyNewRPass( 'rtt0', entities, [0.1, 0.5, 0.9, 1.0] );
		this.applyNewRPass( 'rtt1', entities, [0.3, 0.5, 0.1, 1.0], [-0.2, 0.3, 0.5, 0.5] );
		this.applyNewRPass( 'rtt2', entities, [0.3, 0.5, 0.7, 1.0], [-0.8, 0.3, 0.5, 0.5] );
	}

	run(): void {
		this.mRscene.run();
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值