• 轻量封装WebGPU渲染系统示例<35>- HDR环境数据应用到PBR渲染材质


    当前示例源码github地址:

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

    当前示例运行效果:

    微调参数之后的效果:

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

    1. export class BasePbrMaterialTest {
    2. private mRscene = new RendererScene();
    3. initialize(): void {
    4. this.mRscene.initialize({ canvasWith: 1024, canvasHeight: 1024, rpassparam: { multisampleEnabled: true } });
    5. this.initScene();
    6. this.initEvent();
    7. }
    8. private hdrEnvtex = new SpecularEnvBrnTexture();
    9. private createTextures(ns: string): WGTextureDataDescriptor[] {
    10. const albedoTex = { albedo: { url: `static/assets/pbr/${ns}/albedo.jpg` } };
    11. const normalTex = { normal: { url: `static/assets/pbr/${ns}/normal.jpg` } };
    12. const aoTex = { ao: { url: `static/assets/pbr/${ns}/ao.jpg` } };
    13. const roughnessTex = { roughness: { url: `static/assets/pbr/${ns}/roughness.jpg` } };
    14. const metallicTex = { metallic: { url: `static/assets/pbr/${ns}/metallic.jpg` } };
    15. let textures = [this.hdrEnvtex, albedoTex, normalTex, aoTex, roughnessTex, metallicTex];
    16. return textures;
    17. }
    18. private initScene(): void {
    19. this.initEntities();
    20. }
    21. private initEntities(): void {
    22. let rc = this.mRscene;
    23. let monkeySrc = new ModelEntity({
    24. modelUrl: "static/assets/draco/monkey.drc"
    25. });
    26. let sphSrc = new SphereEntity({
    27. radius: 100,
    28. latitudeNumSegments: 30,
    29. longitudeNumSegments: 30
    30. });
    31. let lightData = this.createLightData();
    32. let startV = new Vector3(-500, 0, -500);
    33. for (let i = 0; i < 3; ++i) {
    34. for (let j = 0; j < 5; ++j) {
    35. let pos = new Vector3(j * 300 + startV.x, 0, i * 600 + startV.z);
    36. let roughness = 1.0 - (0.05 + 0.95 * j/(5-1));
    37. let roughnessBase = i/(3-1);
    38. let material = new BasePBRMaterial();
    39. let property = material.property;
    40. property.setLightData(lightData.lightsData, lightData.lightColorsData);
    41. property.ambient.value = new Color4().randomRGB(0.3, 0.1);
    42. property.albedo.value = new Color4().randomRGB(1.0, 0.2);
    43. property.arms.value = [1, roughness, 1];
    44. property.armsBase.value = [0, roughnessBase ,0];
    45. material.addTextures(this.createTextures("gold"));
    46. let sph = new SphereEntity({
    47. materials: [material],
    48. geometry: sphSrc.geometry
    49. });
    50. sph.transform.setPosition(pos);
    51. rc.addEntity(sph);
    52. material = new BasePBRMaterial();
    53. property = material.property;
    54. property.setLightData(lightData.lightsData, lightData.lightColorsData);
    55. property.ambient.value = new Color4().randomRGB(0.3, 0.1).ceil();
    56. property.albedo.value = new Color4().randomRGB(1.0, 0.2);
    57. property.arms.value = [1, roughness, 1];
    58. property.armsBase.value = [0, roughnessBase ,0];
    59. property.uvParam.value = [2,2];
    60. material.addTextures(this.createTextures("rusted_iron"));
    61. let monkey = new ModelEntity({
    62. materials: [material],
    63. geometry: monkeySrc.geometry,
    64. transform: { position: pos.clone().subtractBy(new Vector3(0, 0, 270)), scale: [100, 100, 100], rotation: [0, 90, 0] }
    65. });
    66. rc.addEntity(monkey);
    67. }
    68. }
    69. }
    70. private createLightData(): { lightsData: Float32Array; lightColorsData: Float32Array } {
    71. let lightsData = new Float32Array([0.0, 300.0, 0, 0.000001]);
    72. let lightColorsData = new Float32Array([5.0, 5.0, 5.0, 0.000005]);
    73. return { lightsData, lightColorsData };
    74. }
    75. private initEvent(): void {
    76. const rc = this.mRscene;
    77. rc.addEventListener(MouseEvent.MOUSE_DOWN, this.mouseDown);
    78. new MouseInteraction().initialize(rc, 0, false).setAutoRunning(true);
    79. }
    80. private mouseDown = (evt: MouseEvent): void => {};
    81. run(): void {
    82. this.mRscene.run();
    83. }
    84. }

  • 相关阅读:
    ElasticSearch使用_1_基本语法
    非零基础自学Java (老师:韩顺平) 第10章 面向对象编程(高级部分) 10.3 代码块
    对称二叉树(C++)
    部署LVS-NAT群集实验
    CTF-sql注入(X-Forwarded-For)【简单易懂】
    如何使用C++图形界面开发框架Qt创建一个应用程序?(Part 2)
    buuctf_练[CSCCTF 2019 Qual]FlaskLight
    《网络安全笔记》第十章:数据的封装和解封装
    十九章总结
    为什么软件可以操作硬件
  • 原文地址:https://blog.csdn.net/vily_lei/article/details/134518980