轻量封装WebGPU渲染系统示例<28>- MRT纹理(源码)

当前示例源码github地址:

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

当前示例运行效果:

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

javascript 复制代码
export class MRT {

	private mRscene = new RendererScene();

	initialize(): void {

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

		this.initEvent();
		this.initScene();
	}
	private initEvent(): void {
		const rc = this.mRscene;
		rc.addEventListener(MouseEvent.MOUSE_DOWN, this.mouseDown);
		new MouseInteraction().initialize(rc, 0, false).setAutoRunning(true);
	}
	private mFlag = 6;
	private mouseDown = (evt: MouseEvent): void => {
		this.mFlag = 1;
	}

	private applyMRTPass(extent: number[]): void {
		let rs = this.mRscene;

		const attachment0 = {
			texture: colorRTTTex,
			clearValue: [0.15, 0.15, 0.15, 1.0]
		};
		const attachment1 = {
			texture: albedoRTTTex,
			clearValue: [0.15, 0.25, 0.25, 1.0]
		};
		const attachment2 = {
			texture: floatRTTTex,
			clearValue: [0.2, 0.25, 0.2, 1.0]
		};

		const colorAttachments = [attachment0, attachment1, attachment2];

		let rPass = rs.createRenderPass({ separate: true, colorAttachments });

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

		let shaderSrc = {
			vert: { code: vertMRT, uuid: "vertMRT" },
			frag: { code: fragMRT, uuid: "fragMRT" }
		};

		let uniformValues = [{ data: new Float32Array([1,1,1,1]) }];
		let torus = new TorusEntity({shaderSrc, textures: [diffuseTex], uniformValues});
		rPass.addEntity(torus);

		// display rendering result
		extent = [-0.8, -0.8, 1.6, 1.6];
		let entity = new FixScreenPlaneEntity({ extent, textures: [colorRTTTex] });
		rs.addEntity(entity);

		shaderSrc = {
			vert: { code: vertWGSL, uuid: "vert" },
			frag: { code: fragReadNormal, uuid: "readNromal" }
		};
		// display normal drawing result
		extent = [-0.7, -0.95, 0.6, 0.6];
		entity = new FixScreenPlaneEntity({ extent, textures: [floatRTTTex], shaderSrc, shadinguuid: "readNromal" });
		rs.addEntity(entity);

		// display albedo drawing result
		extent = [0.1, -0.95, 0.6, 0.6];
		entity = new FixScreenPlaneEntity({ extent, textures: [albedoRTTTex] });
		rs.addEntity(entity);
	}
	private initScene(): void {
		this.applyMRTPass( [-1, -1, 2, 2] );
	}
	run(): void {
		this.mRscene.run();
	}
}
相关推荐
CHOTEST中图仪器1 天前
3d光学轮廓仪如何局部测量标准台阶?
3d·光学轮廓仪·三维形貌·微观尺寸
前端_Danny2 天前
使用 ECharts + ECharts-GL 生成 3D 环形图
3d·信息可视化·echarts
学無芷境2 天前
Large-Scale 3D Medical Image Pre-training with Geometric Context Priors
人工智能·3d
暴风鱼划水2 天前
三维重建【4-A】3D Gaussian Splatting:代码解读
python·深度学习·3d·3dgs
老黄编程2 天前
pcl 3DSC特征描述符、对应关系可视化以及ICP配准
3d·pcl·3dsc·icp
猿来是你_L2 天前
UGUI笔记——3D坐标转换成UGUI坐标
笔记·3d
渲吧云渲染3 天前
3D 技术赋能制造企业精准高效装配生产
3d·数字化装配·制造业转型
不会学习的小白O^O4 天前
基于色彩融合和3D功能的自动苹果识别
3d
上海蓝色星球4 天前
基于3DGIS+BIM的智慧园区运维平台价值分享
运维·人工智能·3d
alphacoder1234 天前
【2025最新】AutoCAD Plant3D下载与安装完整教程(附安装包)
其他·3d