当前位置: 首页 > news >正文

轻量封装WebGPU渲染系统示例<25>- 颜色附件数据更新替换(源码)

当前示例源码github地址:

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

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

const rttTex0 = { diffuse: { uuid: 'rtt0', rttTexture: {} } };
const rttTex1 = { diffuse: { uuid: 'rtt1', rttTexture: {} } };
const attachment0 = {texture: rttTex0,clearValue: [] as ColorDataType,loadOp: "clear",storeOp: "store"
} as WGRPassColorAttachment;
const attachment1 = {texture: rttTex1,clearValue: [] as ColorDataType,
} as WGRPassColorAttachment;
const colorAttachments: WGRPassColorAttachment[] = [attachment0];class PassGraph extends WGRPassNodeGraph {private mTimes = 0;constructor() { super(); }runBegin(): void {super.runBegin();}run(): void {this.mTimes++;if (this.mTimes == 50) {const replaceColorAttachment = true;if (replaceColorAttachment) {// replace color attachmentattachment1.clearValue = [0.2, 0.5, 0.2];colorAttachments[0] = attachment1;} else {// replace texturecolorAttachments[0].texture = rttTex1;}}let pass = this.passes[0];for (let i = 0; i < 1; ++i) {pass.colorAttachments[0].clearEnabled = i < 1;pass.render();}}
}export class ColorAttachmentReplace {private mRscene = new RendererScene();initialize(): void {console.log("ColorAttachmentReplace::initialize() ...");let multisampleEnabled = true;let depthTestEnabled = false;let rpassparam = { multisampleEnabled, depthTestEnabled };this.mRscene.initialize({ rpassparam });this.initEvent();this.initScene();}private mGraph = new PassGraph();private applyRTTPass(clearColor: ColorDataType, extent = [0.4, 0.3, 0.5, 0.5]): void {let rs = this.mRscene;const graph = this.mGraph;attachment0.clearValue = clearColor;attachment1.clearValue = clearColor;let rPass = rs.renderer.appendRenderPass({ separate: true, colorAttachments });const diffuseTex = { diffuse: { url: "static/assets/huluwa.jpg", flipY: true } };let rttEntity = new FixScreenPlaneEntity({ extent: [-0.8, -0.8, 1.6, 1.6], textures: [diffuseTex] });rPass.addEntity(rttEntity);graph.passes = [rPass];rs.setPassNodeGraph(graph);let entity = new FixScreenPlaneEntity({ extent, flipY: true, textures: [rttTex0] });rs.addEntity(entity);extent = [-0.9, -0.9, 1.2, 1.2];entity = new FixScreenPlaneEntity({ extent, flipY: true, textures: [rttTex1] });rs.addEntity(entity);}private initEvent(): void {const rs = this.mRscene;new MouseInteraction().initialize(rs, 0, false).setAutoRunning(true);}private initScene(): void {this.applyRTTPass([0.1, 0.1, 0.1, 1.0], [-0.8, -0.8, 1.6, 1.6]);}run(): void {this.mRscene.run();}
}

http://www.lryc.cn/news/227823.html

相关文章:

  • c语言练习第11周(1~5)
  • 阿里云国际站服务器如何升级内存容量?
  • 神经网络(第二周)
  • 《网络协议》04. 应用层(DNS DHCP HTTP)
  • springboot自己添加的配置文件没有绿色叶子问题
  • 【Java】定时任务 - Timer/TimerTask 源码原理解析
  • SAP ABAP基础语法-Excel上传(十)
  • 记录一次某某虚拟机的逆向
  • upload-labs关卡7(基于黑名单的空格绕过)通关思路
  • CnosDB 在最近新发布的 2.4.0 版本中增加对时空函数的支持。
  • python实现炒股自动化,个人账户无门槛量化交易的开始
  • 推荐系统笔记--Swing模型的原理
  • 联想小新Pro14默认设置的问题
  • 【洛谷 P5019】[NOIP2018 提高组] 铺设道路 题解(分治算法+双指针)
  • 牛客刷题记录11.12
  • NextJS开发:使用IconPark、Lucide图标库
  • 11.12总结
  • Gogs安装和部署教程-centos上
  • Unity中Shader雾效的实现方法一
  • Mac安装配置Tomcat,以及使用(详解)
  • Smart Link 和 Monitor Link应用
  • 【debug】解决Kali虚拟机开机黑屏,左上角光标一直闪动无法开机问题
  • 目标检测YOLO实战应用案例100讲-基于改进YOLO算法的道路交通目标检测(续)
  • 爬虫怎么伪装才更安全
  • openssl+sha256开发实例(C++)
  • 【Bug】当用opencv库的imread()函数读取图像,用matplotlib库的plt.imshow()函数显示图像时,图像色彩出现偏差问题的解决方法
  • 通过顶顶通呼叫中心中间件玩转FreeSWITCH媒体流
  • Maven内网开发使用离线仓库
  • CSS特效007:绘制3D文字,类似PS效果
  • LLM 面试总结