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

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

(便捷)易用性,灵活性,正确性,在用户直接接触的层面,比性能或者专业性要重要得多。如何才能做到使用丝滑的感觉呢?书到用时方恨少,来来去去很烧脑。

当前示例源码github地址:

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

当前示例运行效果:

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

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

	initialize(): void {
		console.log("RTTTest::initialize() ...");

		this.applyRTT();
		this.initScene();
	}
	private applyRTT(): void {

		let rc = this.mRscene;

		// rtt texture proxy descriptor
		let rttTex = { uuid: "rtt0", rttTexture: {} };
		// define a rtt pass color colorAttachment0
		let colorAttachments = [
			{
				texture: rttTex,
				// green clear background color
				clearValue: { r: 0.1, g: 0.9, b: 0.1, a: 1.0 },
				loadOp: "clear",
				storeOp: "store"
			}
		];
		// create a separate rtt rendering pass
		let rPass = rc.createRTTPass({ colorAttachments });

		const diffuseTex = { diffuse: { url: "static/assets/default.jpg", flipY: true } };
		let extent = [-0.5, -0.5, 0.8, 0.8];
		let rttEntity = new FixScreenPlaneEntity({ extent, textures: [diffuseTex] }).setColor([1.0, 0.0, 0.0]);
		// 往pass中添加可渲染对象
		rPass.addEntity(rttEntity);

		// 使用rtt纹理
		extent = [0.3, 0.3, 0.6, 0.6];
		let entity = new FixScreenPlaneEntity({ extent, flipY: true, textures: [{ diffuse: rttTex }] });
		rc.addEntity(entity);
	}
	private initScene(): void {
		const rc = this.mRscene;

		const diffuseTex = { diffuse: { url: "static/assets/default.jpg", flipY: true } };
		let extent = [-0.9, 0.0, 0.5, 0.5];
		let entity = new FixScreenPlaneEntity({ extent }).setColor([0.2, 0.5, 0.7]);
		rc.addEntity(entity);

		extent = [-0.8, -0.8, 0.8, 0.8];
		entity = new FixScreenPlaneEntity({ extent, textures: [diffuseTex] }).setColor([0.1, 0.3, 0.9]);
		rc.addEntity(entity);
	}

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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值