轻量封装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();
	}
}
相关推荐
昨日之日20067 小时前
WanGP V54:极致低显存再突破,更快生成与智能制作全面升级!低显存玩转一站式AI创作神器,视频图像3D世界音乐全搞定
人工智能·3d·音视频
I Am a robert girl13 小时前
Scaffold3D:当神经网络开始“请教”传统几何学家
人工智能·深度学习·神经网络·计算机视觉·3d·3d重建·几何约束
豪气的程序猿14 小时前
Win11播HEVC视频报0x80040265排查与D3D11硬解管线配置
3d·电脑·音视频
中科米堆1 天前
航空航天自动化 3D 尺寸检测方案|精密零部件三维扫描形位公差检测-CASAIM
运维·3d·自动化
全速向光1 天前
用 Three.js 从零打造一棵会发光的 3D 圣诞树
开发语言·javascript·3d
共享笔记1 天前
白膜数据生成 3D Tiles 并在 Cesium 加载:从建筑轮廓到三维城市的完整流程
3d·智慧城市·白膜数据·城市建筑
DTAS尺寸公差分析软件2 天前
DTAS3D 公差分析软件:尺寸链计算不用手算,百级零件 10–30 分钟建模
3d·尺寸公差分析·三维公差分析·公差计算软件·尺寸链分析软件
m0_743106462 天前
SAD-GS:从梯度邻域到频率驱动表达3D空间
人工智能·算法·计算机视觉·3d·几何学
工业机器人视觉检测设备2 天前
液压活塞帽三维视觉采图 工业机器人搭载3D相机的视觉检测实践
数码相机·3d·机器人
Jmyd01232 天前
数字博物馆技术方案:三层展示架构与素材阈值
3d·架构·系统架构·渲染·虚拟展厅·博物馆