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

轻量封装WebGPU渲染系统示例<39>- emissive和arm纹理支持(源码)

当前示例源码github地址:

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

当前示例运行效果:

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

export class DynamicShaderBuilding2 {private mRscene = new RendererScene();initialize(): void {this.mRscene.initialize({ canvasWith: 512, canvasHeight: 512, rpassparam: { multisampleEnabled: true } });this.initScene();this.initEvent();}private hdrEnvtex = new SpecularEnvBrnTexture();private createTextures(ns: string): WGTextureDataDescriptor[] {const albedoTex = { albedo: { url: `static/assets/pbr/${ns}/albedo.jpg` } };const normalTex = { normal: { url: `static/assets/pbr/${ns}/normal.jpg` } };const aoTex = { ao: { url: `static/assets/pbr/${ns}/ao.jpg` } };const roughnessTex = { roughness: { url: `static/assets/pbr/${ns}/roughness.jpg` } };const metallicTex = { metallic: { url: `static/assets/pbr/${ns}/metallic.jpg` } };const emissiveTex = { emissive: { url: `static/assets/color_07.jpg` } };let textures = [this.hdrEnvtex,albedoTex,normalTex,aoTex,roughnessTex,metallicTex,emissiveTex] as WGTextureDataDescriptor[];return textures;}private createArmTextures(): WGTextureDataDescriptor[] {const albedoTex = { albedo: { url: `static/assets/pbrtex/rough_plaster_broken_diff_1k.jpg` } };const normalTex = { normal: { url: `static/assets/pbrtex/rough_plaster_broken_nor_1k.jpg` } };const armTex = { arm: { url: `static/assets/pbrtex/rough_plaster_broken_arm_1k.jpg` } };let textures = [this.hdrEnvtex,albedoTex,normalTex,armTex] as WGTextureDataDescriptor[];return textures;}private initScene(): void {this.initEntities();}private mMonkeySrc: ModelEntity;private initEntities(): void {let callback = (): void => {this.initARMTexDisp();this.initEmissiveTexDisp();};this.mMonkeySrc = new ModelEntity({callback,modelUrl: "static/assets/draco/monkey.drc"});}private initARMTexDisp(): void {let textures = this.createArmTextures();let material = this.createModelEntity(this.mMonkeySrc, new Vector3(0, 0, -150), textures);this.applyMaterialPPt(material);}private initEmissiveTexDisp(): void {let textures = this.createTextures("plastic");let material = this.createModelEntity(this.mMonkeySrc, new Vector3(0, 0, 150), textures);this.applyMaterialPPt(material);}private applyMaterialPPt(material: BasePBRMaterial): void {let property = material.property;property.ambient.value = [0.0, 0.2, 0.2];property.albedo.value = [0.7, 0.7, 0.3];property.arms.roughness = 0.8;property.armsBase.value = [0, 0, 0];property.uvParam.value = [2, 2];property.param.scatterIntensity = 32;}private mLightParams: LightShaderDataParam[] = [];private createModelEntity(srcEntity: ModelEntity, position: Vector3DataType, textures: WGTextureDataDescriptor[]): BasePBRMaterial {let rc = this.mRscene;let lightParam = this.createLightData(position);let material = new BasePBRMaterial();material.setLightParam(lightParam);material.addTextures(textures);let monkey = new ModelEntity({materials: [material],geometry: srcEntity.geometry,transform: { position, scale: [100, 100, 100], rotation: [0, 90, 0] }});rc.addEntity(monkey);return material;}private createLightData(position: Vector3DataType): LightShaderDataParam {let pos = new Vector3().setVector4(position);let pv0 = pos.clone().addBy(new Vector3(0, 200, 0));let pv1 = pos.clone().addBy(new Vector3(200, 0, 0));let pv2 = pos.clone().addBy(new Vector3(0, 0, 200));let pv3 = pos.clone().addBy(new Vector3(-200, 0, 0));let pv4 = pos.clone().addBy(new Vector3(0, 0, -200));let posList = [pv0, pv1, pv2, pv3, pv4];let c0 = new Color4(0.1 + Math.random() * 13, 0.1 + Math.random() * 13, 0.0, 0.00002);let c1 = new Color4(0.0, 0.1 + Math.random() * 13, 1.0, 0.00002);let c2 = new Color4(0.0, 0.1 + Math.random() * 13, 0.1 + Math.random() * 13, 0.00002);let c3 = new Color4(0.1 + Math.random() * 13, 1.0, 0.1 + Math.random() * 13, 0.00002);let c4 = new Color4(0.5, 1.0, 0.1 + Math.random() * 13, 0.00002);let colorList = [c0, c1, c2, c3, c4];let pointLightsTotal = posList.length;let j = 0;let lightsData = new Float32Array(4 * pointLightsTotal);let lightColorsData = new Float32Array(4 * pointLightsTotal);for (let i = 0; i < lightsData.length;) {const pv = posList[j];pv.w = 0.00002;pv.toArray4(lightsData, i);const c = colorList[j];c.toArray4(lightColorsData, i);j++;i += 4;}let param = { lights: lightsData, colors: lightColorsData, pointLightsTotal };this.mLightParams.push(param);return param;}private initEvent(): void {const rc = this.mRscene;rc.addEventListener(MouseEvent.MOUSE_DOWN, this.mouseDown);new MouseInteraction().initialize(rc, 0, false).setAutoRunning(true);}private mouseDown = (evt: MouseEvent): void => { };run(): void {this.mRscene.run();}
}

相关文章:

  • 智能优化算法应用:基于水循环算法无线传感器网络(WSN)覆盖优化 - 附代码
  • 编译器设计02-前端概述
  • Android JNI 异常定位(2)—— addr2line
  • springboot 使用脚本进行启动部署
  • 7-2 输出大写英文字母
  • 园区智能配电系统(电力智能监控系统)
  • 算法基础之KMP算法
  • Jmeter 压测保姆级入门教程
  • Linux常用命令——rm 命令
  • python实现自动刷平台学时
  • 怎么给数据库某个字段建立一个前缀索引
  • 如何在Ubuntu系统上安装Redis
  • 97.STL-查找算法 find
  • 什么是计算机病毒?
  • axios 请求合集
  • 分享的文章《人生如棋》
  • 10个确保微服务与容器安全的最佳实践
  • 2019.2.20 c++ 知识梳理
  • CNN 在图像分割中的简史:从 R-CNN 到 Mask R-CNN
  • express.js的介绍及使用
  • Invalidate和postInvalidate的区别
  • JS正则表达式精简教程(JavaScript RegExp 对象)
  • Mysql优化
  • React系列之 Redux 架构模式
  • session共享问题解决方案
  • TypeScript实现数据结构(一)栈,队列,链表
  • 阿里云前端周刊 - 第 26 期
  • 百度小程序遇到的问题
  • -- 查询加强-- 使用如何where子句进行筛选,% _ like的使用
  • 初探 Vue 生命周期和钩子函数
  • 动手做个聊天室,前端工程师百无聊赖的人生
  • 理解 C# 泛型接口中的协变与逆变(抗变)
  • 算法之不定期更新(一)(2018-04-12)
  • 微信小程序设置上一页数据
  • 微信支付JSAPI,实测!终极方案
  • 正则表达式小结
  • AI算硅基生命吗,为什么?
  • NLPIR智能语义技术让大数据挖掘更简单
  • 宾利慕尚创始人典藏版国内首秀,2025年前实现全系车型电动化 | 2019上海车展 ...
  • (10)STL算法之搜索(二) 二分查找
  • (4)STL算法之比较
  • (C++)栈的链式存储结构(出栈、入栈、判空、遍历、销毁)(数据结构与算法)
  • (Forward) Music Player: From UI Proposal to Code
  • (JS基础)String 类型
  • (力扣题库)跳跃游戏II(c++)
  • (算法)求1到1亿间的质数或素数
  • (五)Python 垃圾回收机制
  • (转) 深度模型优化性能 调参
  • ****Linux下Mysql的安装和配置
  • .NET/C# 判断某个类是否是泛型类型或泛型接口的子类型
  • .net之微信企业号开发(一) 所使用的环境与工具以及准备工作
  • [ 隧道技术 ] cpolar 工具详解之将内网端口映射到公网
  • [【JSON2WEB】 13 基于REST2SQL 和 Amis 的 SQL 查询分析器
  • [<事务专题>]
  • [BT]BUUCTF刷题第8天(3.26)