轻量封装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();}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/182902.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

python操作Mysql学习

文章目录 版权声明准备&#xff1a;MYSQL数据库数据库简介数据库分类数据库管理系统SQL语句关系型数据库中核心元素MySQL环境搭建Mysql数据类型数据完整性和约束MYSql基本操作登录和退出数据库命令数据库基本操作命令数据表基本操作命令数据表结构修改命令表数据操作命令Mysql查…

PCIe学习必读——《PCI Express System Architecture》

PCI Express (peripheral component interconnect express) 简称 PCIe&#xff0c;是一种高速串行计算机扩展总线标准。是一种全双工总线&#xff0c;使用高速串行传送方式&#xff0c;能够支持更高的频率&#xff0c;连接的设备不再像 PCI 总线那样共享总线带宽。PCIe目前发布…

数据结构-二叉树(2)

3.4堆的应用 3.4.1 堆排序 堆排序即利用堆的思想来进行排序&#xff0c;总共分为两个步骤&#xff1a; 1. 建堆 1.升序&#xff1a;建大堆&#xff1b; 2.降序&#xff1a;建小堆。 2. 利用堆删除思想来进行排序 这种写法有两个缺点&#xff1a; 1、先有一个堆的数据结构 …

微信小程序 老年人心血管健康知识科普系统

本系统的功能有管理员&#xff1a;个人中心&#xff0c;用户管理&#xff0c;热点信息管理&#xff0c;疾病管理&#xff0c;疾病类型管理&#xff0c;治疗管理&#xff0c;治疗类型管理&#xff0c;护理管理&#xff0c;护理类型管理&#xff0c;科普管理&#xff0c;科普类型…

如何利用轮廓系数(Silhouette Coefficient)来判断模糊c均值聚类FCM的聚类簇数量

文章目录 前言一、轮廓系数的计算方法二、具体流程 前言 轮廓系数&#xff08;Silhouette Coefficient&#xff09;是一种评价聚类效果的指标&#xff0c;它可以用于判断模糊C均值聚类的聚类簇数量。 一、轮廓系数的计算方法 对于每个数据点i&#xff0c;计算它属于每个聚类…

lightdb-ignore_row_on_dupkey_index

LightDB 支持 ignore_row_on_dupkey_index hint LightDB 从23.4 开始支持oracle的 ignore_row_on_dupkey_index hint&#xff0c; 这个hint是用来忽略唯一键冲突的。类似与mysql的 insert ignore。 语法如下&#xff1a; 在LightDB中ignore_row_on_dupkey_index的效果等同于o…

深入了解HMAC加密技术:原理、应用与实践

一、引言 在网络安全领域&#xff0c;消息认证码&#xff08;MAC&#xff09;是一种重要的技术手段。Hash-based Message Authentication Code&#xff08;HMAC&#xff09;作为其中的一种&#xff0c;凭借其简单、高效、安全的特性&#xff0c;广泛应用于各种网络通信场景。本…

k8s中批量处理Pod应用的Job和CronJob控制器介绍

目录 一.Job控制器 1.简介 2.Jobs较完整解释 3.示例演示 4.注意&#xff1a;如上例的话&#xff0c;执行“kubectl delete -f myJob.yaml”就可以将job删掉 二.CronJob&#xff08;简写为cj&#xff09; 1.简介 2.CronJob较完整解释 3.案例演示 4.如上例的话&#xf…

工艺系统所管理数字化实践

摘要 本文介绍了上海核工程设计研究院在数字化转型方面的实践&#xff0c;包括业务数字化和管理数字化两个方面。业务数字化方面&#xff0c;该院通过开发小工具改进工作流程。管理数字化方面&#xff0c;该院采用零代码平台集中管理管道力学信息相关模型和数据&#xff0c;并…

JeeSpringCloud uploadFile.jsp 文件上传漏洞复现

0x01 产品简介 JeeSpringCloud是一款免费开源的JAVA互联网云快速开发平台&#xff0c;微服务分布式代码生成的敏捷开发系统架构&#xff0c;项目代码简洁、注释丰富、上手容易、还同时集中分布式、分布式事务、微服务,同时包含许多基础模块和监控、服务模块&#xff0c;JeeSpri…

RabbitMQ消息模型之Work Queues

Work Queues Work Queues&#xff0c;也被称为&#xff08;Task Queues&#xff09;&#xff0c;任务模型&#xff0c;也是官网给出的第二个模型&#xff0c;使用的交换机类型是直连direct&#xff0c;也是默认的交换机类型。当消息处理比较耗时的时候&#xff0c;可能生产消息…

供应链 | “利刃出鞘”——顶刊POMS论文解读:制造商借助电子商务部门入侵

论文解读者&#xff1a;肖善&#xff0c;温梓曦&#xff0c;张怡雯&#xff0c;杨子豪 编者按&#xff1a; 解密品牌商在线电商平台&#xff1a;组织结构、策略选择、三方共赢 Manufacturer encroachment with an e‐commerce division 原文作者信息 Shi, S., Wang, C., Ch…

微信小程序上传报错TypeError: Failed to fetch

上传之后报message&#xff1a;TypeError: Failed to fetch这个错误。 关掉项目 > 选择项目的ide界面右上有个齿轮设置 > 代理

嵌入式设备与PC上位机通信协议设计的几点原则

嵌入式设备在运行中需要设置参数&#xff0c;这个工作经常由PC机来实现&#xff0c;需要为双方通信设计协议&#xff0c;有代表性协议是如下三种&#xff1a; 从上表可以看到&#xff0c;一般嵌入式设备内存和运算性能都有限&#xff0c;因此固定二进制是首选通信协议。 一&am…

【智能算法】改进粒子群优化算法及对比分析

程序名称&#xff1a;改进粒子群优化算法及对比分析 实现平台&#xff1a;matlab 代码简介&#xff1a;基本粒子群算法(BPSO)中&#xff0c;每个优化问题的解都可以看作粒子在搜索空间中的位置&#xff0c;粒子通过飞行速度决定它们的搜索方向和搜索范围&#xff0c;粒子群通…

磁环电感参数计算

磁环电感参数计算 1.什么是电感磁饱和2.电感饱和的原因3.电感饱和带来的影响3.1 感应电动势变化3.2 电感值变化3.3 功率损耗增加3.4 系统稳定性受到影响4.饱和电流计算最近在做DC/DC电源,电感是用磁环绕制的,所以关注一下磁环绕制电感参数的计算,学习学习。 某款磁环参数。 …

【Java安全】Java反射机制-成员变量的赋值与取值

文章目录 前言利用反射机制获取类的成员变量利用反射机制获取类的成员方法总结前言 Java反射(Reflection)是Java非常重要的动态特性,通过使用反射我们不仅可以获取到任何类的成员方法(Methods)、成员变量(Fields)、构造方法(Constructors)等信息,还可以动态创建Java类实例、…

【Python】实现一个简单的区块链系统

本文章利用 Python 实现一个简单的功能较为完善的区块链系统&#xff08;包括区块链结构、账户、钱包、转账&#xff09;&#xff0c;采用的共识机制是 POW。 一、区块与区块链结构 Block.py import hashlib from datetime import datetimeclass Block:"""区…

Linux常用命令——ls 命令详解

文章目录 在Linux操作系统中&#xff0c;ls 命令是最常用且基础的命令之一。它用于列出目录内容&#xff0c;展示文件和目录的信息。本文将详细介绍ls 命令的各个参数及其含义&#xff0c;并通过实例演示它们的用法。 ls命令概述 ls 命令的基本格式为 ls [选项] [文件或目录]…

VirtualBox 7.0.8(虚拟机软件)

VirtualBox是一款开源的虚拟机软件&#xff0c;它是使用Qt编写&#xff0c;在Sun被Oracle收购后正式更名成Oracle VM VirtualBox。它可以在VirtualBox上安装并且执行Solaris、Windows、DOS、Linux、OS/2 Warp、BSD等系统作为客户端操作系统。使用者可以在VirtualBox上安装并且运…