轻量封装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();
	}
}
相关推荐
草莓奶忻9 小时前
Eigen 几何模块深拆:Isometry3d vs Affine3d + 变换矩阵本质详解
3d
Casia_Dominic9 小时前
【三维重建工具】NeRFStudio、3D GaussianSplatting、Colmap安装与使用指南
git·3d·github·点云
threelab9 小时前
threejs案例开发-中国3D国旗动画
3d
真的不想学习啦9 小时前
3D Surface Reconstruction with Enhanced High-Frequency Details
人工智能·3d
咔咔一顿操作19 小时前
Cesium实战:交互式多边形绘制与编辑功能完全指南(最终修复版)
前端·javascript·3d·vue
ykjhr_3d1 天前
3D 演示动画在汽车培训与教育领域中的应用
3d·汽车
三月的一天1 天前
React Three Fiber 实现 3D 模型点击高亮交互的核心技巧
3d·webgl·threejs·reactthreefiber
云空2 天前
《PyQt6-3D应用开发技术文档》
3d·pyqt
鹧鸪云光伏2 天前
光伏无人机3D建模:毫秒级精度设计
3d·无人机
杀生丸学AI2 天前
【三维生成】FlashDreamer:基于扩散模型的单目图像到3D场景
人工智能·3d·大模型·aigc·蒸馏与迁移学习·扩散模型与生成模型