@luma.gl/shadertools 9.1.0-alpha.16 → 9.1.0-alpha.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/dist/dist.dev.js +277 -344
  2. package/dist/dist.min.js +215 -314
  3. package/dist/index.cjs +276 -346
  4. package/dist/index.cjs.map +4 -4
  5. package/dist/index.d.ts +4 -2
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +0 -1
  8. package/dist/lib/shader-module/shader-module.d.ts +24 -14
  9. package/dist/lib/shader-module/shader-module.d.ts.map +1 -1
  10. package/dist/lib/shader-module/shader-module.js +11 -15
  11. package/dist/lib/shader-module/shader-pass.d.ts +4 -2
  12. package/dist/lib/shader-module/shader-pass.d.ts.map +1 -1
  13. package/dist/lib/utils/uniform-types.d.ts +11 -0
  14. package/dist/lib/utils/uniform-types.d.ts.map +1 -0
  15. package/dist/lib/utils/uniform-types.js +1 -0
  16. package/dist/modules/engine/picking/picking.d.ts +7 -7
  17. package/dist/modules/engine/picking/picking.d.ts.map +1 -1
  18. package/dist/modules/engine/picking/picking.js +2 -2
  19. package/dist/modules/engine/project/project.d.ts +9 -8
  20. package/dist/modules/engine/project/project.d.ts.map +1 -1
  21. package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts +3 -57
  22. package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts.map +1 -1
  23. package/dist/modules/lighting/gouraud-material/gouraud-material.js +9 -6
  24. package/dist/modules/lighting/lights/lighting-uniforms-glsl.d.ts +1 -1
  25. package/dist/modules/lighting/lights/lighting-uniforms-glsl.d.ts.map +1 -1
  26. package/dist/modules/lighting/lights/lighting-uniforms-glsl.js +35 -12
  27. package/dist/modules/lighting/lights/lighting.d.ts +55 -29
  28. package/dist/modules/lighting/lights/lighting.d.ts.map +1 -1
  29. package/dist/modules/lighting/lights/lighting.js +46 -35
  30. package/dist/modules/lighting/no-material/dirlight.d.ts +3 -3
  31. package/dist/modules/lighting/no-material/dirlight.d.ts.map +1 -1
  32. package/dist/modules/lighting/no-material/dirlight.js +1 -1
  33. package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.d.ts +1 -1
  34. package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.d.ts.map +1 -1
  35. package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.js +56 -60
  36. package/dist/modules/lighting/pbr-material/pbr-material.d.ts +56 -98
  37. package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
  38. package/dist/modules/lighting/pbr-material/pbr-material.js +14 -22
  39. package/dist/modules/lighting/pbr-material/pbr-projection.d.ts +10 -0
  40. package/dist/modules/lighting/pbr-material/pbr-projection.d.ts.map +1 -0
  41. package/dist/modules/lighting/pbr-material/pbr-projection.js +24 -0
  42. package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.d.ts +1 -1
  43. package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.d.ts.map +1 -1
  44. package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.js +8 -16
  45. package/dist/modules/lighting/phong-material/phong-material.d.ts +5 -59
  46. package/dist/modules/lighting/phong-material/phong-material.d.ts.map +1 -1
  47. package/dist/modules/lighting/phong-material/phong-material.js +6 -4
  48. package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts +1 -40
  49. package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
  50. package/dist/modules/lighting/phong-material/phong-shaders-glsl.js +8 -87
  51. package/dist/modules-webgl1/project/project.d.ts +6 -4
  52. package/dist/modules-webgl1/project/project.d.ts.map +1 -1
  53. package/dist/passes/postprocessing/fxaa/fxaa.d.ts +1 -1
  54. package/dist/passes/postprocessing/fxaa/fxaa.d.ts.map +1 -1
  55. package/dist/passes/postprocessing/fxaa/fxaa.js +1 -1
  56. package/dist/passes/postprocessing/image-adjust-filters/brightnesscontrast.d.ts +0 -1
  57. package/dist/passes/postprocessing/image-adjust-filters/brightnesscontrast.d.ts.map +1 -1
  58. package/dist/passes/postprocessing/image-adjust-filters/brightnesscontrast.js +0 -1
  59. package/dist/passes/postprocessing/image-adjust-filters/huesaturation.d.ts +0 -1
  60. package/dist/passes/postprocessing/image-adjust-filters/huesaturation.d.ts.map +1 -1
  61. package/dist/passes/postprocessing/image-adjust-filters/huesaturation.js +0 -1
  62. package/dist/passes/postprocessing/image-adjust-filters/vibrance.d.ts +3 -0
  63. package/dist/passes/postprocessing/image-adjust-filters/vibrance.d.ts.map +1 -1
  64. package/dist/passes/postprocessing/image-adjust-filters/vibrance.js +3 -0
  65. package/dist/passes/postprocessing/image-blur-filters/tiltshift.d.ts +2 -2
  66. package/dist/passes/postprocessing/image-blur-filters/tiltshift.d.ts.map +1 -1
  67. package/dist/passes/postprocessing/image-blur-filters/triangleblur.d.ts +1 -1
  68. package/dist/passes/postprocessing/image-blur-filters/triangleblur.d.ts.map +1 -1
  69. package/dist/passes/postprocessing/image-blur-filters/zoomblur.d.ts +1 -1
  70. package/dist/passes/postprocessing/image-blur-filters/zoomblur.d.ts.map +1 -1
  71. package/dist/passes/postprocessing/image-fun-filters/colorhalftone.d.ts +1 -1
  72. package/dist/passes/postprocessing/image-fun-filters/colorhalftone.d.ts.map +1 -1
  73. package/dist/passes/postprocessing/image-fun-filters/dotscreen.d.ts +1 -1
  74. package/dist/passes/postprocessing/image-fun-filters/dotscreen.d.ts.map +1 -1
  75. package/dist/passes/postprocessing/image-fun-filters/edgework.d.ts +15 -11
  76. package/dist/passes/postprocessing/image-fun-filters/edgework.d.ts.map +1 -1
  77. package/dist/passes/postprocessing/image-fun-filters/edgework.js +24 -12
  78. package/dist/passes/postprocessing/image-fun-filters/hexagonalpixelate.d.ts +1 -1
  79. package/dist/passes/postprocessing/image-fun-filters/hexagonalpixelate.d.ts.map +1 -1
  80. package/dist/passes/postprocessing/image-fun-filters/magnify.d.ts +2 -2
  81. package/dist/passes/postprocessing/image-fun-filters/magnify.d.ts.map +1 -1
  82. package/dist/passes/postprocessing/image-warp-filters/bulgepinch.d.ts +1 -1
  83. package/dist/passes/postprocessing/image-warp-filters/bulgepinch.d.ts.map +1 -1
  84. package/package.json +3 -3
  85. package/src/index.ts +9 -3
  86. package/src/lib/shader-module/shader-module.ts +31 -20
  87. package/src/lib/shader-module/shader-pass.ts +7 -4
  88. package/src/lib/utils/uniform-types.ts +66 -0
  89. package/src/modules/engine/picking/picking.ts +9 -9
  90. package/src/modules/engine/project/project.ts +10 -9
  91. package/src/modules/lighting/gouraud-material/gouraud-material.ts +14 -12
  92. package/src/modules/lighting/lights/lighting-uniforms-glsl.ts +35 -12
  93. package/src/modules/lighting/lights/lighting.ts +83 -54
  94. package/src/modules/lighting/no-material/dirlight.ts +3 -3
  95. package/src/modules/lighting/pbr-material/pbr-fragment-glsl.ts +56 -60
  96. package/src/modules/lighting/pbr-material/pbr-material.ts +40 -74
  97. package/src/modules/lighting/pbr-material/pbr-projection.ts +39 -0
  98. package/src/modules/lighting/pbr-material/pbr-vertex-glsl.ts +8 -16
  99. package/src/modules/lighting/phong-material/phong-material.ts +12 -12
  100. package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +8 -88
  101. package/src/modules-webgl1/project/project.ts +8 -7
  102. package/src/passes/postprocessing/fxaa/fxaa.ts +2 -2
  103. package/src/passes/postprocessing/image-adjust-filters/brightnesscontrast.ts +0 -1
  104. package/src/passes/postprocessing/image-adjust-filters/huesaturation.ts +0 -1
  105. package/src/passes/postprocessing/image-adjust-filters/vibrance.ts +3 -0
  106. package/src/passes/postprocessing/image-blur-filters/tiltshift.ts +2 -2
  107. package/src/passes/postprocessing/image-blur-filters/triangleblur.ts +1 -1
  108. package/src/passes/postprocessing/image-blur-filters/zoomblur.ts +1 -1
  109. package/src/passes/postprocessing/image-fun-filters/colorhalftone.ts +1 -1
  110. package/src/passes/postprocessing/image-fun-filters/dotscreen.ts +1 -1
  111. package/src/passes/postprocessing/image-fun-filters/edgework.ts +26 -15
  112. package/src/passes/postprocessing/image-fun-filters/hexagonalpixelate.ts +1 -1
  113. package/src/passes/postprocessing/image-fun-filters/magnify.ts +2 -2
  114. package/src/passes/postprocessing/image-warp-filters/bulgepinch.ts +1 -1
  115. package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.d.ts +0 -42
  116. package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.d.ts.map +0 -1
  117. package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.js +0 -134
  118. package/src/modules/lighting/gouraud-material/gouraud-shaders-glsl.ts +0 -137
@@ -1,4 +1,4 @@
1
- import type { NumberArray } from '@math.gl/types';
1
+ import type { NumberArray3 } from '@math.gl/core';
2
2
  /** Shader type field for lights */
3
3
  export declare enum LIGHT_TYPE {
4
4
  POINT = 0,
@@ -8,21 +8,20 @@ export declare enum LIGHT_TYPE {
8
8
  export type Light = AmbientLight | PointLight | DirectionalLight;
9
9
  export type AmbientLight = {
10
10
  type: 'ambient';
11
- color?: Readonly<NumberArray>;
11
+ color?: Readonly<NumberArray3>;
12
12
  intensity?: number;
13
13
  };
14
14
  export type PointLight = {
15
15
  type: 'point';
16
- position: Readonly<NumberArray>;
17
- color?: Readonly<NumberArray>;
16
+ position: Readonly<NumberArray3>;
17
+ color?: Readonly<NumberArray3>;
18
18
  intensity?: number;
19
- attenuation?: number;
19
+ attenuation?: Readonly<NumberArray3>;
20
20
  };
21
21
  export type DirectionalLight = {
22
22
  type: 'directional';
23
- position: Readonly<NumberArray>;
24
- direction: Readonly<NumberArray>;
25
- color?: Readonly<NumberArray>;
23
+ direction: Readonly<NumberArray3>;
24
+ color?: Readonly<NumberArray3>;
26
25
  intensity?: number;
27
26
  };
28
27
  export type LightingProps = {
@@ -37,13 +36,22 @@ export type LightingProps = {
37
36
  };
38
37
  export type LightingUniforms = {
39
38
  enabled: number;
40
- ambientLightColor: Readonly<NumberArray>;
41
- numberOfLights: number;
39
+ ambientLightColor: Readonly<NumberArray3>;
40
+ directionalLightCount: number;
41
+ pointLightCount: number;
42
42
  lightType: number;
43
- lightColor: Readonly<NumberArray>;
44
- lightPosition: Readonly<NumberArray>;
45
- lightDirection: Readonly<NumberArray>;
46
- lightAttenuation: Readonly<NumberArray>;
43
+ lightColor0: Readonly<NumberArray3>;
44
+ lightPosition0: Readonly<NumberArray3>;
45
+ lightDirection0: Readonly<NumberArray3>;
46
+ lightAttenuation0: Readonly<NumberArray3>;
47
+ lightColor1: Readonly<NumberArray3>;
48
+ lightPosition1: Readonly<NumberArray3>;
49
+ lightDirection1: Readonly<NumberArray3>;
50
+ lightAttenuation1: Readonly<NumberArray3>;
51
+ lightColor2: Readonly<NumberArray3>;
52
+ lightPosition2: Readonly<NumberArray3>;
53
+ lightDirection2: Readonly<NumberArray3>;
54
+ lightAttenuation2: Readonly<NumberArray3>;
47
55
  };
48
56
  /** UBO ready lighting module */
49
57
  export declare const lighting: {
@@ -51,31 +59,49 @@ export declare const lighting: {
51
59
  readonly uniforms: LightingUniforms;
52
60
  readonly name: "lighting";
53
61
  readonly defines: {
54
- readonly MAX_LIGHTS: 5;
62
+ readonly MAX_LIGHTS: 3;
55
63
  };
56
64
  readonly uniformTypes: {
57
65
  readonly enabled: "i32";
58
- readonly ambientLightColor: "vec3<f32>";
59
- readonly numberOfLights: "i32";
60
66
  readonly lightType: "i32";
61
- readonly lightColor: "vec3<f32>";
62
- readonly lightPosition: "vec3<f32>";
63
- readonly lightDirection: "vec3<f32>";
64
- readonly lightAttenuation: "vec3<f32>";
67
+ readonly directionalLightCount: "i32";
68
+ readonly pointLightCount: "i32";
69
+ readonly ambientLightColor: "vec3<f32>";
70
+ readonly lightColor0: "vec3<f32>";
71
+ readonly lightPosition0: "vec3<f32>";
72
+ readonly lightDirection0: "vec3<f32>";
73
+ readonly lightAttenuation0: "vec3<f32>";
74
+ readonly lightColor1: "vec3<f32>";
75
+ readonly lightPosition1: "vec3<f32>";
76
+ readonly lightDirection1: "vec3<f32>";
77
+ readonly lightAttenuation1: "vec3<f32>";
78
+ readonly lightColor2: "vec3<f32>";
79
+ readonly lightPosition2: "vec3<f32>";
80
+ readonly lightDirection2: "vec3<f32>";
81
+ readonly lightAttenuation2: "vec3<f32>";
65
82
  };
66
83
  readonly defaultUniforms: {
67
84
  readonly enabled: 1;
68
- readonly ambientLightColor: readonly [0.1, 0.1, 0.1];
69
- readonly numberOfLights: 0;
70
85
  readonly lightType: LIGHT_TYPE.POINT;
71
- readonly lightColor: readonly [1, 1, 1];
72
- readonly lightPosition: readonly [1, 1, 2];
73
- readonly lightDirection: readonly [1, 1, 1];
74
- readonly lightAttenuation: readonly [1, 1, 1];
86
+ readonly directionalLightCount: 0;
87
+ readonly pointLightCount: 0;
88
+ readonly ambientLightColor: readonly [0.1, 0.1, 0.1];
89
+ readonly lightColor0: readonly [1, 1, 1];
90
+ readonly lightPosition0: readonly [1, 1, 2];
91
+ readonly lightDirection0: readonly [1, 1, 1];
92
+ readonly lightAttenuation0: readonly [1, 0, 0];
93
+ readonly lightColor1: readonly [1, 1, 1];
94
+ readonly lightPosition1: readonly [1, 1, 2];
95
+ readonly lightDirection1: readonly [1, 1, 1];
96
+ readonly lightAttenuation1: readonly [1, 0, 0];
97
+ readonly lightColor2: readonly [1, 1, 1];
98
+ readonly lightPosition2: readonly [1, 1, 2];
99
+ readonly lightDirection2: readonly [1, 1, 1];
100
+ readonly lightAttenuation2: readonly [1, 0, 0];
75
101
  };
76
102
  readonly source: "// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nstruct AmbientLight {\n color: vec3<f32>,\n};\n\nstruct PointLight {\n color: vec3<f32>,\n position: vec3<f32>,\n attenuation: vec3<f32>, // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct DirectionalLight {\n color: vec3<f32>,\n direction: vec3<f32>,\n};\n\nstruct lightingUniforms {\n enabled: i32,\n poightCount: i32,\n directionalLightCount: i32,\n\n ambientColor: vec3<f32>,\n\n // TODO - support multiple lights by uncommenting arrays below\n lightType: i32,\n lightColor: vec3<f32>,\n lightDirection: vec3<f32>,\n lightPosition: vec3<f32>,\n lightAttenuation: vec3<f32>,\n\n // AmbientLight ambientLight;\n // PointLight pointLight[MAX_LIGHTS];\n // DirectionalLight directionalLight[MAX_LIGHTS];\n};\n\n// Binding 0:1 is reserved for lighting (Note: could go into separate bind group as it is stable across draw calls)\n@binding(1) @group(0) var<uniform> lighting : lightingUniforms;\n\nfn lighting_getPointLight(index: i32) -> PointLight {\n return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);\n}\n\nfn lighting_getDirectionalLight(index: i32) -> DirectionalLight {\n return DirectionalLight(lighting.lightColor, lighting.lightDirection);\n} \n\nfn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 {\n return pointLight.attenuation.x\n + pointLight.attenuation.y * distance\n + pointLight.attenuation.z * distance * distance;\n}\n";
77
- readonly vs: "precision highp int;\n\n// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nstruct AmbientLight {\n vec3 color;\n};\n\nstruct PointLight {\n vec3 color;\n vec3 position;\n vec3 attenuation; // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct DirectionalLight {\n vec3 color;\n vec3 direction;\n};\n\nuniform lightingUniforms {\n int enabled;\n int pointLightCount;\n int directionalLightCount;\n\n vec3 ambientColor;\n\n int lightType;\n vec3 lightColor;\n vec3 lightDirection;\n vec3 lightPosition;\n vec3 lightAttenuation;\n\n // AmbientLight ambientLight;\n // PointLight pointLight[MAX_LIGHTS];\n // DirectionalLight directionalLight[MAX_LIGHTS];\n} lighting;\n\nPointLight lighting_getPointLight(int index) {\n return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);\n}\n\nDirectionalLight lighting_getDirectionalLight(int index) {\n return DirectionalLight(lighting.lightColor, lighting.lightDirection);\n} \n\nfloat getPointLightAttenuation(PointLight pointLight, float distance) {\n return pointLight.attenuation.x\n + pointLight.attenuation.y * distance\n + pointLight.attenuation.z * distance * distance;\n}\n\n// #endif\n";
78
- readonly fs: "precision highp int;\n\n// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nstruct AmbientLight {\n vec3 color;\n};\n\nstruct PointLight {\n vec3 color;\n vec3 position;\n vec3 attenuation; // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct DirectionalLight {\n vec3 color;\n vec3 direction;\n};\n\nuniform lightingUniforms {\n int enabled;\n int pointLightCount;\n int directionalLightCount;\n\n vec3 ambientColor;\n\n int lightType;\n vec3 lightColor;\n vec3 lightDirection;\n vec3 lightPosition;\n vec3 lightAttenuation;\n\n // AmbientLight ambientLight;\n // PointLight pointLight[MAX_LIGHTS];\n // DirectionalLight directionalLight[MAX_LIGHTS];\n} lighting;\n\nPointLight lighting_getPointLight(int index) {\n return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);\n}\n\nDirectionalLight lighting_getDirectionalLight(int index) {\n return DirectionalLight(lighting.lightColor, lighting.lightDirection);\n} \n\nfloat getPointLightAttenuation(PointLight pointLight, float distance) {\n return pointLight.attenuation.x\n + pointLight.attenuation.y * distance\n + pointLight.attenuation.z * distance * distance;\n}\n\n// #endif\n";
103
+ readonly vs: "precision highp int;\n\n// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nstruct AmbientLight {\n vec3 color;\n};\n\nstruct PointLight {\n vec3 color;\n vec3 position;\n vec3 attenuation; // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct DirectionalLight {\n vec3 color;\n vec3 direction;\n};\n\nuniform lightingUniforms {\n int enabled;\n int lightType;\n\n int directionalLightCount;\n int pointLightCount;\n\n vec3 ambientColor;\n\n vec3 lightColor0;\n vec3 lightPosition0;\n vec3 lightDirection0;\n vec3 lightAttenuation0;\n\n vec3 lightColor1;\n vec3 lightPosition1;\n vec3 lightDirection1;\n vec3 lightAttenuation1;\n\n vec3 lightColor2;\n vec3 lightPosition2;\n vec3 lightDirection2;\n vec3 lightAttenuation2;\n} lighting;\n\nPointLight lighting_getPointLight(int index) {\n switch (index) {\n case 0:\n return PointLight(lighting.lightColor0, lighting.lightPosition0, lighting.lightAttenuation0);\n case 1:\n return PointLight(lighting.lightColor1, lighting.lightPosition1, lighting.lightAttenuation1);\n case 2:\n default: \n return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2);\n }\n}\n\nDirectionalLight lighting_getDirectionalLight(int index) {\n switch (index) {\n case 0:\n return DirectionalLight(lighting.lightColor0, lighting.lightDirection0);\n case 1:\n return DirectionalLight(lighting.lightColor1, lighting.lightDirection1);\n case 2:\n default: \n return DirectionalLight(lighting.lightColor2, lighting.lightDirection2);\n }\n} \n\nfloat getPointLightAttenuation(PointLight pointLight, float distance) {\n return pointLight.attenuation.x\n + pointLight.attenuation.y * distance\n + pointLight.attenuation.z * distance * distance;\n}\n\n// #endif\n";
104
+ readonly fs: "precision highp int;\n\n// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nstruct AmbientLight {\n vec3 color;\n};\n\nstruct PointLight {\n vec3 color;\n vec3 position;\n vec3 attenuation; // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct DirectionalLight {\n vec3 color;\n vec3 direction;\n};\n\nuniform lightingUniforms {\n int enabled;\n int lightType;\n\n int directionalLightCount;\n int pointLightCount;\n\n vec3 ambientColor;\n\n vec3 lightColor0;\n vec3 lightPosition0;\n vec3 lightDirection0;\n vec3 lightAttenuation0;\n\n vec3 lightColor1;\n vec3 lightPosition1;\n vec3 lightDirection1;\n vec3 lightAttenuation1;\n\n vec3 lightColor2;\n vec3 lightPosition2;\n vec3 lightDirection2;\n vec3 lightAttenuation2;\n} lighting;\n\nPointLight lighting_getPointLight(int index) {\n switch (index) {\n case 0:\n return PointLight(lighting.lightColor0, lighting.lightPosition0, lighting.lightAttenuation0);\n case 1:\n return PointLight(lighting.lightColor1, lighting.lightPosition1, lighting.lightAttenuation1);\n case 2:\n default: \n return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2);\n }\n}\n\nDirectionalLight lighting_getDirectionalLight(int index) {\n switch (index) {\n case 0:\n return DirectionalLight(lighting.lightColor0, lighting.lightDirection0);\n case 1:\n return DirectionalLight(lighting.lightColor1, lighting.lightDirection1);\n case 2:\n default: \n return DirectionalLight(lighting.lightColor2, lighting.lightDirection2);\n }\n} \n\nfloat getPointLightAttenuation(PointLight pointLight, float distance) {\n return pointLight.attenuation.x\n + pointLight.attenuation.y * distance\n + pointLight.attenuation.z * distance * distance;\n}\n\n// #endif\n";
79
105
  readonly getUniforms: typeof getUniforms;
80
106
  };
81
107
  declare function getUniforms(props?: LightingProps, prevUniforms?: Partial<LightingUniforms>): LightingUniforms;
@@ -1 +1 @@
1
- {"version":3,"file":"lighting.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/lights/lighting.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAWhD,mCAAmC;AAEnC,oBAAY,UAAU;IACpB,KAAK,IAAI;IACT,WAAW,IAAI;CAChB;AAED,4BAA4B;AAE5B,MAAM,MAAM,KAAK,GAAG,YAAY,GAAG,UAAU,GAAG,gBAAgB,CAAC;AAEjE,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IAChC,KAAK,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,aAAa,CAAC;IACpB,QAAQ,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IAChC,SAAS,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;IACjB,kBAAkB;IAClB,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,kBAAkB;IAClB,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IAC3B,kBAAkB;IAClB,iBAAiB,CAAC,EAAE,gBAAgB,EAAE,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IACzC,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IAClC,aAAa,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IACrC,cAAc,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IACtC,gBAAgB,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;CACzC,CAAC;AAEF,gCAAgC;AAChC,eAAO,MAAM,QAAQ;oBACN,aAAa;uBACV,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoCgC,CAAC;AAEnE,iBAAS,WAAW,CAClB,KAAK,CAAC,EAAE,aAAa,EACrB,YAAY,GAAE,OAAO,CAAC,gBAAgB,CAAM,GAC3C,gBAAgB,CAoClB"}
1
+ {"version":3,"file":"lighting.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/lights/lighting.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,eAAe,CAAC;AAQhD,mCAAmC;AAEnC,oBAAY,UAAU;IACpB,KAAK,IAAI;IACT,WAAW,IAAI;CAChB;AAED,4BAA4B;AAE5B,MAAM,MAAM,KAAK,GAAG,YAAY,GAAG,UAAU,GAAG,gBAAgB,CAAC;AAEjE,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,CAAC,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,aAAa,CAAC;IACpB,SAAS,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IAClC,KAAK,CAAC,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;IACjB,kBAAkB;IAClB,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,kBAAkB;IAClB,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IAC3B,kBAAkB;IAClB,iBAAiB,CAAC,EAAE,gBAAgB,EAAE,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IAC1C,qBAAqB,EAAE,MAAM,CAAC;IAC9B,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACpC,cAAc,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACvC,eAAe,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACxC,iBAAiB,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IAC1C,WAAW,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACpC,cAAc,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACvC,eAAe,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACxC,iBAAiB,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IAC1C,WAAW,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACpC,cAAc,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACvC,eAAe,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACxC,iBAAiB,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;CAC3C,CAAC;AAEF,gCAAgC;AAChC,eAAO,MAAM,QAAQ;oBACN,aAAa;uBACV,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8DoC,CAAC;AAEvE,iBAAS,WAAW,CAClB,KAAK,CAAC,EAAE,aAAa,EACrB,YAAY,GAAE,OAAO,CAAC,gBAAgB,CAAM,GAC3C,gBAAgB,CAoClB"}
@@ -1,10 +1,11 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
+ import { log } from '@luma.gl/core';
4
5
  import { lightingUniformsGLSL } from "./lighting-uniforms-glsl.js";
5
6
  import { lightingUniformsWGSL } from "./lighting-uniforms-wgsl.js";
6
7
  /** Max number of supported lights (in addition to ambient light */
7
- const MAX_LIGHTS = 5;
8
+ const MAX_LIGHTS = 3;
8
9
  /** Whether to divide */
9
10
  const COLOR_FACTOR = 255.0;
10
11
  /** Shader type field for lights */
@@ -24,25 +25,44 @@ export const lighting = {
24
25
  },
25
26
  uniformTypes: {
26
27
  enabled: 'i32',
28
+ lightType: 'i32',
29
+ directionalLightCount: 'i32',
30
+ pointLightCount: 'i32',
27
31
  ambientLightColor: 'vec3<f32>',
28
- numberOfLights: 'i32', // , array: MAX_LIGHTS,
29
- lightType: 'i32', // , array: MAX_LIGHTS,
30
- lightColor: 'vec3<f32>', // , array: MAX_LIGHTS,
31
- lightPosition: 'vec3<f32>', // , array: MAX_LIGHTS,
32
+ // TODO define as arrays once we have appropriate uniformTypes
33
+ lightColor0: 'vec3<f32>',
34
+ lightPosition0: 'vec3<f32>',
32
35
  // TODO - could combine direction and attenuation
33
- lightDirection: 'vec3<f32>', // , array: MAX_LIGHTS,
34
- lightAttenuation: 'vec3<f32>' // , array: MAX_LIGHTS},
36
+ lightDirection0: 'vec3<f32>',
37
+ lightAttenuation0: 'vec3<f32>',
38
+ lightColor1: 'vec3<f32>',
39
+ lightPosition1: 'vec3<f32>',
40
+ lightDirection1: 'vec3<f32>',
41
+ lightAttenuation1: 'vec3<f32>',
42
+ lightColor2: 'vec3<f32>',
43
+ lightPosition2: 'vec3<f32>',
44
+ lightDirection2: 'vec3<f32>',
45
+ lightAttenuation2: 'vec3<f32>'
35
46
  },
36
47
  defaultUniforms: {
37
48
  enabled: 1,
38
- ambientLightColor: [0.1, 0.1, 0.1],
39
- numberOfLights: 0,
40
49
  lightType: LIGHT_TYPE.POINT,
41
- lightColor: [1, 1, 1],
42
- lightPosition: [1, 1, 2],
50
+ directionalLightCount: 0,
51
+ pointLightCount: 0,
52
+ ambientLightColor: [0.1, 0.1, 0.1],
53
+ lightColor0: [1, 1, 1],
54
+ lightPosition0: [1, 1, 2],
43
55
  // TODO - could combine direction and attenuation
44
- lightDirection: [1, 1, 1],
45
- lightAttenuation: [1, 1, 1]
56
+ lightDirection0: [1, 1, 1],
57
+ lightAttenuation0: [1, 0, 0],
58
+ lightColor1: [1, 1, 1],
59
+ lightPosition1: [1, 1, 2],
60
+ lightDirection1: [1, 1, 1],
61
+ lightAttenuation1: [1, 0, 0],
62
+ lightColor2: [1, 1, 1],
63
+ lightPosition2: [1, 1, 2],
64
+ lightDirection2: [1, 1, 1],
65
+ lightAttenuation2: [1, 0, 0]
46
66
  },
47
67
  source: lightingUniformsWGSL,
48
68
  vs: lightingUniformsGLSL,
@@ -80,38 +100,29 @@ function getUniforms(props, prevUniforms = {}) {
80
100
  return uniforms;
81
101
  }
82
102
  function getLightSourceUniforms({ ambientLight, pointLights = [], directionalLights = [] }) {
83
- const lightSourceUniforms = {
84
- // lightType: new Array(MAX_LIGHTS).fill(0),
85
- // lightColor: new Array(MAX_LIGHTS).fill([0, 0, 0]),
86
- // lightPosition: new Array(MAX_LIGHTS).fill([0, 0, 0]),
87
- // lightDirection: new Array(MAX_LIGHTS).fill([0, 0, 0]),
88
- // lightAttenuation: new Array(MAX_LIGHTS).fill([0, 0, 0])
89
- };
103
+ const lightSourceUniforms = {};
90
104
  lightSourceUniforms.ambientLightColor = convertColor(ambientLight);
91
105
  let currentLight = 0;
92
106
  for (const pointLight of pointLights) {
93
- // lightSourceUniforms.lightType[currentLight] = LIGHT_TYPE.POINT;
94
- // lightSourceUniforms.lightColor[currentLight] = convertColor(pointLight);
95
- // lightSourceUniforms.lightPosition[currentLight] = pointLight.position;
96
- // lightSourceUniforms.lightAttenuation[currentLight] = [pointLight.attenuation || 1, 0, 0];
97
107
  lightSourceUniforms.lightType = LIGHT_TYPE.POINT;
98
- lightSourceUniforms.lightColor = convertColor(pointLight);
99
- lightSourceUniforms.lightPosition = pointLight.position;
100
- lightSourceUniforms.lightAttenuation = [pointLight.attenuation || 1, 0, 0];
108
+ const i = currentLight;
109
+ lightSourceUniforms[`lightColor${i}`] = convertColor(pointLight);
110
+ lightSourceUniforms[`lightPosition${i}`] = pointLight.position;
111
+ lightSourceUniforms[`lightAttenuation${i}`] = pointLight.attenuation || [1, 0, 0];
101
112
  currentLight++;
102
113
  }
103
114
  for (const directionalLight of directionalLights) {
104
- // lightSourceUniforms.lightType[currentLight] = LIGHT_TYPE.DIRECTIONAL;
105
- // lightSourceUniforms.lightColor[currentLight] = convertColor(directionalLight);
106
- // lightSourceUniforms.lightPosition[currentLight] = directionalLight.position;
107
- // lightSourceUniforms.lightDirection[currentLight] = directionalLight.direction;
108
115
  lightSourceUniforms.lightType = LIGHT_TYPE.DIRECTIONAL;
109
- lightSourceUniforms.lightColor = convertColor(directionalLight);
110
- lightSourceUniforms.lightPosition = directionalLight.position;
111
- lightSourceUniforms.lightDirection = directionalLight.direction;
116
+ const i = currentLight;
117
+ lightSourceUniforms[`lightColor${i}`] = convertColor(directionalLight);
118
+ lightSourceUniforms[`lightDirection${i}`] = directionalLight.direction;
112
119
  currentLight++;
113
120
  }
114
- lightSourceUniforms.numberOfLights = currentLight;
121
+ if (currentLight > MAX_LIGHTS) {
122
+ log.warn('MAX_LIGHTS exceeded')();
123
+ }
124
+ lightSourceUniforms.directionalLightCount = directionalLights.length;
125
+ lightSourceUniforms.pointLightCount = pointLights.length;
115
126
  return lightSourceUniforms;
116
127
  }
117
128
  function extractLightTypes(lights) {
@@ -1,6 +1,6 @@
1
- import type { Vector3Like, TypedArray } from '@math.gl/core';
1
+ import type { Vector3Like } from '@math.gl/core';
2
2
  export type DirlightProps = {
3
- lightDirection?: Vector3Like | TypedArray;
3
+ lightDirection?: Vector3Like;
4
4
  };
5
5
  export type DirlightUniforms = DirlightProps;
6
6
  export declare const SOURCE_WGSL = " \nstruct dirlightUniforms {\n lightDirection: vec3<f32>,\n};\n\nalias DirlightNormal = vec3<f32>;\n\nstruct DirlightInputs {\n normal: DirlightNormal,\n};\n\n@binding(1) @group(0) var<uniform> dirlight : dirlightUniforms;\n\n// For vertex\nfn dirlight_setNormal(normal: vec3<f32>) -> DirlightNormal {\n return normalize(normal);\n}\n\n// Returns color attenuated by angle from light source\nfn dirlight_filterColor(color: vec4<f32>, inputs: DirlightInputs) -> vec4<f32> {\n // TODO - fix default light direction\n // let lightDirection = dirlight.lightDirection;\n let lightDirection = vec3<f32>(1, 1, 1);\n let d: f32 = abs(dot(inputs.normal, normalize(lightDirection)));\n return vec4<f32>(color.rgb * d, color.a);\n}\n";
@@ -19,7 +19,7 @@ export declare const dirlight: {
19
19
  readonly lightDirection: "vec3<f32>";
20
20
  };
21
21
  readonly defaultUniforms: {
22
- readonly lightDirection: Float32Array;
22
+ readonly lightDirection: [1, 1, 2];
23
23
  };
24
24
  readonly getUniforms: typeof getUniforms;
25
25
  };
@@ -1 +1 @@
1
- {"version":3,"file":"dirlight.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/no-material/dirlight.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,WAAW,EAAE,UAAU,EAAC,MAAM,eAAe,CAAC;AAG3D,MAAM,MAAM,aAAa,GAAG;IAC1B,cAAc,CAAC,EAAE,WAAW,GAAG,UAAU,CAAC;CAC3C,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,aAAa,CAAC;AAG7C,eAAO,MAAM,WAAW,guBA0BvB,CAAC;AAwBF;;GAEG;AACH,eAAO,MAAM,QAAQ;oBACN,aAAa;uBACV,gBAAgB;;;;;;;;;;;;;CAqBgC,CAAC;AAEnE,iBAAS,WAAW,CAAC,IAAI,GAAE,aAAwC,GAAG,gBAAgB,CAOrF"}
1
+ {"version":3,"file":"dirlight.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/no-material/dirlight.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAG/C,MAAM,MAAM,aAAa,GAAG;IAC1B,cAAc,CAAC,EAAE,WAAW,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,aAAa,CAAC;AAG7C,eAAO,MAAM,WAAW,guBA0BvB,CAAC;AAwBF;;GAEG;AACH,eAAO,MAAM,QAAQ;oBACN,aAAa;uBACV,gBAAgB;;;;;;;;;;;;;CAqBgC,CAAC;AAEnE,iBAAS,WAAW,CAAC,IAAI,GAAE,aAAwC,GAAG,gBAAgB,CAOrF"}
@@ -70,7 +70,7 @@ export const dirlight = {
70
70
  lightDirection: 'vec3<f32>'
71
71
  },
72
72
  defaultUniforms: {
73
- lightDirection: new Float32Array([1, 1, 2])
73
+ lightDirection: [1, 1, 2]
74
74
  },
75
75
  getUniforms
76
76
  };
@@ -1,2 +1,2 @@
1
- export declare const fs = "precision highp float;\n\nuniform Projection {\n // Projection\n uniform vec3 u_Camera;\n};\n\nuniform pbrMaterial {\n // Material is unlit\n bool unlit;\n\n // Base color map\n bool baseColorMapEnabled;\n vec4 baseColorFactor;\n\n bool normalMapEnabled; \n float normalScale; // #ifdef HAS_NORMALMAP\n\n bool emissiveMapEnabled;\n vec3 emissiveFactor; // #ifdef HAS_EMISSIVEMAP\n\n vec2 metallicRoughnessValues;\n bool metallicRoughnessMapEnabled;\n\n bool occlusionMapEnabled;\n float occlusionStrength; // #ifdef HAS_OCCLUSIONMAP\n \n bool alphaCutoffEnabled;\n float alphaCutoff; // #ifdef ALPHA_CUTOFF\n \n // IBL\n bool IBLenabled;\n vec2 scaleIBLAmbient; // #ifdef USE_IBL\n \n // debugging flags used for shader output of intermediate PBR variables\n // #ifdef PBR_DEBUG\n vec4 scaleDiffBaseMR;\n vec4 scaleFGDSpec;\n // #endif\n} u_pbrMaterial;\n\n// Samplers\n#ifdef HAS_BASECOLORMAP\nuniform sampler2D u_BaseColorSampler;\n#endif\n#ifdef HAS_NORMALMAP\nuniform sampler2D u_NormalSampler;\n#endif\n#ifdef HAS_EMISSIVEMAP\nuniform sampler2D u_EmissiveSampler;\n#endif\n#ifdef HAS_METALROUGHNESSMAP\nuniform sampler2D u_MetallicRoughnessSampler;\n#endif\n#ifdef HAS_OCCLUSIONMAP\nuniform sampler2D u_OcclusionSampler;\n#endif\n#ifdef USE_IBL\nuniform samplerCube u_DiffuseEnvSampler;\nuniform samplerCube u_SpecularEnvSampler;\nuniform sampler2D u_brdfLUT;\n#endif\n\n// Inputs from vertex shader\n\nvarying vec3 pbr_vPosition;\nvarying vec2 pbr_vUV;\n\n#ifdef HAS_NORMALS\n#ifdef HAS_TANGENTS\nvarying mat3 pbr_vTBN;\n#else\nvarying vec3 pbr_vNormal;\n#endif\n#endif\n\n// Encapsulate the various inputs used by the various functions in the shading equation\n// We store values in this struct to simplify the integration of alternative implementations\n// of the shading terms, outlined in the Readme.MD Appendix.\nstruct PBRInfo {\n float NdotL; // cos angle between normal and light direction\n float NdotV; // cos angle between normal and view direction\n float NdotH; // cos angle between normal and half vector\n float LdotH; // cos angle between light direction and half vector\n float VdotH; // cos angle between view direction and half vector\n float perceptualRoughness; // roughness value, as authored by the model creator (input to shader)\n float metalness; // metallic value at the surface\n vec3 reflectance0; // full reflectance color (normal incidence angle)\n vec3 reflectance90; // reflectance color at grazing angle\n float alphaRoughness; // roughness mapped to a more linear change in the roughness (proposed by [2])\n vec3 diffuseColor; // color contribution from diffuse lighting\n vec3 specularColor; // color contribution from specular lighting\n vec3 n; // normal at surface point\n vec3 v; // vector from surface point to camera\n};\n\nconst float M_PI = 3.141592653589793;\nconst float c_MinRoughness = 0.04;\n\nvec4 SRGBtoLINEAR(vec4 srgbIn)\n{\n#ifdef MANUAL_SRGB\n#ifdef SRGB_FAST_APPROXIMATION\n vec3 linOut = pow(srgbIn.xyz,vec3(2.2));\n#else // SRGB_FAST_APPROXIMATION\n vec3 bLess = step(vec3(0.04045),srgbIn.xyz);\n vec3 linOut = mix( srgbIn.xyz/vec3(12.92), pow((srgbIn.xyz+vec3(0.055))/vec3(1.055),vec3(2.4)), bLess );\n#endif //SRGB_FAST_APPROXIMATION\n return vec4(linOut,srgbIn.w);;\n#else //MANUAL_SRGB\n return srgbIn;\n#endif //MANUAL_SRGB\n}\n\n// Find the normal for this fragment, pulling either from a predefined normal map\n// or from the interpolated mesh normal and tangent attributes.\nvec3 getNormal()\n{\n // Retrieve the tangent space matrix\n#ifndef HAS_TANGENTS\n vec3 pos_dx = dFdx(pbr_vPosition);\n vec3 pos_dy = dFdy(pbr_vPosition);\n vec3 tex_dx = dFdx(vec3(pbr_vUV, 0.0));\n vec3 tex_dy = dFdy(vec3(pbr_vUV, 0.0));\n vec3 t = (tex_dy.t * pos_dx - tex_dx.t * pos_dy) / (tex_dx.s * tex_dy.t - tex_dy.s * tex_dx.t);\n\n#ifdef HAS_NORMALS\n vec3 ng = normalize(pbr_vNormal);\n#else\n vec3 ng = cross(pos_dx, pos_dy);\n#endif\n\n t = normalize(t - ng * dot(ng, t));\n vec3 b = normalize(cross(ng, t));\n mat3 tbn = mat3(t, b, ng);\n#else // HAS_TANGENTS\n mat3 tbn = pbr_vTBN;\n#endif\n\n#ifdef HAS_NORMALMAP\n vec3 n = texture2D(u_NormalSampler, pbr_vUV).rgb;\n n = normalize(tbn * ((2.0 * n - 1.0) * vec3(u_pbrMaterial.normalScale, u_pbrMaterial.normalScale, 1.0)));\n#else\n // The tbn matrix is linearly interpolated, so we need to re-normalize\n vec3 n = normalize(tbn[2].xyz);\n#endif\n\n return n;\n}\n\n// Calculation of the lighting contribution from an optional Image Based Light source.\n// Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].\n// See our README.md on Environment Maps [3] for additional discussion.\n#ifdef USE_IBL\nvec3 getIBLContribution(PBRInfo pbrInfo, vec3 n, vec3 reflection)\n{\n float mipCount = 9.0; // resolution of 512x512\n float lod = (pbrInfo.perceptualRoughness * mipCount);\n // retrieve a scale and bias to F0. See [1], Figure 3\n vec3 brdf = SRGBtoLINEAR(texture2D(u_brdfLUT,\n vec2(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness))).rgb;\n vec3 diffuseLight = SRGBtoLINEAR(textureCube(u_DiffuseEnvSampler, n)).rgb;\n\n#ifdef USE_TEX_LOD\n vec3 specularLight = SRGBtoLINEAR(textureCubeLod(u_SpecularEnvSampler, reflection, lod)).rgb;\n#else\n vec3 specularLight = SRGBtoLINEAR(textureCube(u_SpecularEnvSampler, reflection)).rgb;\n#endif\n\n vec3 diffuse = diffuseLight * pbrInfo.diffuseColor;\n vec3 specular = specularLight * (pbrInfo.specularColor * brdf.x + brdf.y);\n\n // For presentation, this allows us to disable IBL terms\n diffuse *= u_pbrMaterial.scaleIBLAmbient.x;\n specular *= u_pbrMaterial.scaleIBLAmbient.y;\n\n return diffuse + specular;\n}\n#endif\n\n// Basic Lambertian diffuse\n// Implementation from Lambert's Photometria https://archive.org/details/lambertsphotome00lambgoog\n// See also [1], Equation 1\nvec3 diffuse(PBRInfo pbrInfo)\n{\n return pbrInfo.diffuseColor / M_PI;\n}\n\n// The following equation models the Fresnel reflectance term of the spec equation (aka F())\n// Implementation of fresnel from [4], Equation 15\nvec3 specularReflection(PBRInfo pbrInfo)\n{\n return pbrInfo.reflectance0 +\n (pbrInfo.reflectance90 - pbrInfo.reflectance0) *\n pow(clamp(1.0 - pbrInfo.VdotH, 0.0, 1.0), 5.0);\n}\n\n// This calculates the specular geometric attenuation (aka G()),\n// where rougher material will reflect less light back to the viewer.\n// This implementation is based on [1] Equation 4, and we adopt their modifications to\n// alphaRoughness as input as originally proposed in [2].\nfloat geometricOcclusion(PBRInfo pbrInfo)\n{\n float NdotL = pbrInfo.NdotL;\n float NdotV = pbrInfo.NdotV;\n float r = pbrInfo.alphaRoughness;\n\n float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));\n float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));\n return attenuationL * attenuationV;\n}\n\n// The following equation(s) model the distribution of microfacet normals across\n// the area being drawn (aka D())\n// Implementation from \"Average Irregularity Representation of a Roughened Surface\n// for Ray Reflection\" by T. S. Trowbridge, and K. P. Reitz\n// Follows the distribution function recommended in the SIGGRAPH 2013 course notes\n// from EPIC Games [1], Equation 3.\nfloat microfacetDistribution(PBRInfo pbrInfo)\n{\n float roughnessSq = pbrInfo.alphaRoughness * pbrInfo.alphaRoughness;\n float f = (pbrInfo.NdotH * roughnessSq - pbrInfo.NdotH) * pbrInfo.NdotH + 1.0;\n return roughnessSq / (M_PI * f * f);\n}\n\nvoid PBRInfo_setAmbientLight(inout PBRInfo pbrInfo) {\n pbrInfo.NdotL = 1.0;\n pbrInfo.NdotH = 0.0;\n pbrInfo.LdotH = 0.0;\n pbrInfo.VdotH = 1.0;\n}\n\nvoid PBRInfo_setDirectionalLight(inout PBRInfo pbrInfo, vec3 lightDirection) {\n vec3 n = pbrInfo.n;\n vec3 v = pbrInfo.v;\n vec3 l = normalize(lightDirection); // Vector from surface point to light\n vec3 h = normalize(l+v); // Half vector between both l and v\n\n pbrInfo.NdotL = clamp(dot(n, l), 0.001, 1.0);\n pbrInfo.NdotH = clamp(dot(n, h), 0.0, 1.0);\n pbrInfo.LdotH = clamp(dot(l, h), 0.0, 1.0);\n pbrInfo.VdotH = clamp(dot(v, h), 0.0, 1.0);\n}\n\nvoid PBRInfo_setPointLight(inout PBRInfo pbrInfo, PointLight pointLight) {\n vec3 light_direction = normalize(pointLight.position - pbr_vPosition);\n PBRInfo_setDirectionalLight(pbrInfo, light_direction);\n}\n\nvec3 calculateFinalColor(PBRInfo pbrInfo, vec3 lightColor) {\n // Calculate the shading terms for the microfacet specular shading model\n vec3 F = specularReflection(pbrInfo);\n float G = geometricOcclusion(pbrInfo);\n float D = microfacetDistribution(pbrInfo);\n\n // Calculation of analytical lighting contribution\n vec3 diffuseContrib = (1.0 - F) * diffuse(pbrInfo);\n vec3 specContrib = F * G * D / (4.0 * pbrInfo.NdotL * pbrInfo.NdotV);\n // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law)\n return pbrInfo.NdotL * lightColor * (diffuseContrib + specContrib);\n}\n\nvec4 pbr_filterColor(vec4 colorUnused)\n{\n // The albedo may be defined from a base texture or a flat color\n#ifdef HAS_BASECOLORMAP\n vec4 baseColor = SRGBtoLINEAR(texture2D(u_BaseColorSampler, pbr_vUV)) * u_pbrMaterial.baseColorFactor;\n#else\n vec4 baseColor = u_pbrMaterial.baseColorFactor;\n#endif\n\n#ifdef ALPHA_CUTOFF\n if (baseColor.a < u_pbrMaterial.alphaCutoff) {\n discard;\n }\n#endif\n\n vec3 color = vec3(0, 0, 0);\n\n if(u_pbrMaterial.unlit){\n color.rgb = baseColor.rgb;\n }\n else{\n // Metallic and Roughness material properties are packed together\n // In glTF, these factors can be specified by fixed scalar values\n // or from a metallic-roughness map\n float perceptualRoughness = u_pbrMaterial.metallicRoughnessValues.y;\n float metallic = u_pbrMaterial.metallicRoughnessValues.x;\n#ifdef HAS_METALROUGHNESSMAP\n // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.\n // This layout intentionally reserves the 'r' channel for (optional) occlusion map data\n vec4 mrSample = texture2D(u_MetallicRoughnessSampler, pbr_vUV);\n perceptualRoughness = mrSample.g * perceptualRoughness;\n metallic = mrSample.b * metallic;\n#endif\n perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);\n metallic = clamp(metallic, 0.0, 1.0);\n // Roughness is authored as perceptual roughness; as is convention,\n // convert to material roughness by squaring the perceptual roughness [2].\n float alphaRoughness = perceptualRoughness * perceptualRoughness;\n\n vec3 f0 = vec3(0.04);\n vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0);\n diffuseColor *= 1.0 - metallic;\n vec3 specularColor = mix(f0, baseColor.rgb, metallic);\n\n // Compute reflectance.\n float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);\n\n // For typical incident reflectance range (between 4% to 100%) set the grazing\n // reflectance to 100% for typical fresnel effect.\n // For very low reflectance range on highly diffuse objects (below 4%),\n // incrementally reduce grazing reflecance to 0%.\n float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);\n vec3 specularEnvironmentR0 = specularColor.rgb;\n vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;\n\n vec3 n = getNormal(); // normal at surface point\n vec3 v = normalize(u_Camera - pbr_vPosition); // Vector from surface point to camera\n\n float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);\n vec3 reflection = -normalize(reflect(v, n));\n\n PBRInfo pbrInfo = PBRInfo(\n 0.0, // NdotL\n NdotV,\n 0.0, // NdotH\n 0.0, // LdotH\n 0.0, // VdotH\n perceptualRoughness,\n metallic,\n specularEnvironmentR0,\n specularEnvironmentR90,\n alphaRoughness,\n diffuseColor,\n specularColor,\n n,\n v\n );\n\n#ifdef USE_LIGHTS\n // Apply ambient light\n PBRInfo_setAmbientLight(pbrInfo);\n color += calculateFinalColor(pbrInfo, lighting_uAmbientLight.color);\n\n // Apply directional light\n for(int i = 0; i < lighting_uDirectionalLightCount; i++) {\n if (i < lighting_uDirectionalLightCount) {\n PBRInfo_setDirectionalLight(pbrInfo, lighting_uDirectionalLight[i].direction);\n color += calculateFinalColor(pbrInfo, lighting_uDirectionalLight[i].color);\n }\n }\n\n // Apply point light\n for(int i = 0; i < lighting_uPointLightCount; i++) {\n if (i < lighting_uPointLightCount) {\n PBRInfo_setPointLight(pbrInfo, lighting_uPointLight[i]);\n float attenuation = getPointLightAttenuation(lighting_uPointLight[i], distance(lighting_uPointLight[i].position, pbr_vPosition));\n color += calculateFinalColor(pbrInfo, lighting_uPointLight[i].color / attenuation);\n }\n }\n#endif\n\n // Calculate lighting contribution from image based lighting source (IBL)\n#ifdef USE_IBL\n if (u_pbrMateral.IBLEnabled) {\n color += getIBLContribution(pbrInfo, n, reflection);\n }\n#endif\n\n // Apply optional PBR terms for additional (optional) shading\n#ifdef HAS_OCCLUSIONMAP\n if (u_pbrMaterial.occlusionMapEnabled) {\n float ao = texture2D(u_OcclusionSampler, pbr_vUV).r;\n color = mix(color, color * ao, u_pbrMaterial.occlusionStrength);\n }\n#endif\n\n#ifdef HAS_EMISSIVEMAP\n if (u_pbrMaterial.emmissiveMapEnabled) {\n vec3 emissive = SRGBtoLINEAR(texture2D(u_EmissiveSampler, pbr_vUV)).rgb * u_pbrMaterial.emissiveFactor;\n color += emissive;\n }\n#endif\n\n // This section uses mix to override final color for reference app visualization\n // of various parameters in the lighting equation.\n#ifdef PBR_DEBUG\n // TODO: Figure out how to debug multiple lights\n\n // color = mix(color, F, u_ScaleFGDSpec.x);\n // color = mix(color, vec3(G), u_ScaleFGDSpec.y);\n // color = mix(color, vec3(D), u_ScaleFGDSpec.z);\n // color = mix(color, specContrib, u_ScaleFGDSpec.w);\n\n // color = mix(color, diffuseContrib, u_ScaleDiffBaseMR.x);\n color = mix(color, baseColor.rgb, u_pbrMaterial.scaleDiffBaseMR.y);\n color = mix(color, vec3(metallic), u_pbrMaterial.scaleDiffBaseMR.z);\n color = mix(color, vec3(perceptualRoughness), u_pbrMaterial.scaleDiffBaseMR.w);\n#endif\n\n }\n\n return vec4(pow(color,vec3(1.0/2.2)), baseColor.a);\n}\n";
1
+ export declare const fs = "precision highp float;\n\nuniform pbrMaterialUniforms {\n // Material is unlit\n bool unlit;\n\n // Base color map\n bool baseColorMapEnabled;\n vec4 baseColorFactor;\n\n bool normalMapEnabled; \n float normalScale; // #ifdef HAS_NORMALMAP\n\n bool emissiveMapEnabled;\n vec3 emissiveFactor; // #ifdef HAS_EMISSIVEMAP\n\n vec2 metallicRoughnessValues;\n bool metallicRoughnessMapEnabled;\n\n bool occlusionMapEnabled;\n float occlusionStrength; // #ifdef HAS_OCCLUSIONMAP\n \n bool alphaCutoffEnabled;\n float alphaCutoff; // #ifdef ALPHA_CUTOFF\n \n // IBL\n bool IBLenabled;\n vec2 scaleIBLAmbient; // #ifdef USE_IBL\n \n // debugging flags used for shader output of intermediate PBR variables\n // #ifdef PBR_DEBUG\n vec4 scaleDiffBaseMR;\n vec4 scaleFGDSpec;\n // #endif\n} pbrMaterial;\n\n// Samplers\n#ifdef HAS_BASECOLORMAP\nuniform sampler2D pbr_baseColorSampler;\n#endif\n#ifdef HAS_NORMALMAP\nuniform sampler2D pbr_normalSampler;\n#endif\n#ifdef HAS_EMISSIVEMAP\nuniform sampler2D pbr_emissiveSampler;\n#endif\n#ifdef HAS_METALROUGHNESSMAP\nuniform sampler2D pbr_metallicRoughnessSampler;\n#endif\n#ifdef HAS_OCCLUSIONMAP\nuniform sampler2D pbr_occlusionSampler;\n#endif\n#ifdef USE_IBL\nuniform samplerCube pbr_diffuseEnvSampler;\nuniform samplerCube pbr_specularEnvSampler;\nuniform sampler2D pbr_brdfLUT;\n#endif\n\n// Inputs from vertex shader\n\nin vec3 pbr_vPosition;\nin vec2 pbr_vUV;\n\n#ifdef HAS_NORMALS\n#ifdef HAS_TANGENTS\nin mat3 pbr_vTBN;\n#else\nin vec3 pbr_vNormal;\n#endif\n#endif\n\n// Encapsulate the various inputs used by the various functions in the shading equation\n// We store values in this struct to simplify the integration of alternative implementations\n// of the shading terms, outlined in the Readme.MD Appendix.\nstruct PBRInfo {\n float NdotL; // cos angle between normal and light direction\n float NdotV; // cos angle between normal and view direction\n float NdotH; // cos angle between normal and half vector\n float LdotH; // cos angle between light direction and half vector\n float VdotH; // cos angle between view direction and half vector\n float perceptualRoughness; // roughness value, as authored by the model creator (input to shader)\n float metalness; // metallic value at the surface\n vec3 reflectance0; // full reflectance color (normal incidence angle)\n vec3 reflectance90; // reflectance color at grazing angle\n float alphaRoughness; // roughness mapped to a more linear change in the roughness (proposed by [2])\n vec3 diffuseColor; // color contribution from diffuse lighting\n vec3 specularColor; // color contribution from specular lighting\n vec3 n; // normal at surface point\n vec3 v; // vector from surface point to camera\n};\n\nconst float M_PI = 3.141592653589793;\nconst float c_MinRoughness = 0.04;\n\nvec4 SRGBtoLINEAR(vec4 srgbIn)\n{\n#ifdef MANUAL_SRGB\n#ifdef SRGB_FAST_APPROXIMATION\n vec3 linOut = pow(srgbIn.xyz,vec3(2.2));\n#else // SRGB_FAST_APPROXIMATION\n vec3 bLess = step(vec3(0.04045),srgbIn.xyz);\n vec3 linOut = mix( srgbIn.xyz/vec3(12.92), pow((srgbIn.xyz+vec3(0.055))/vec3(1.055),vec3(2.4)), bLess );\n#endif //SRGB_FAST_APPROXIMATION\n return vec4(linOut,srgbIn.w);;\n#else //MANUAL_SRGB\n return srgbIn;\n#endif //MANUAL_SRGB\n}\n\n// Find the normal for this fragment, pulling either from a predefined normal map\n// or from the interpolated mesh normal and tangent attributes.\nvec3 getNormal()\n{\n // Retrieve the tangent space matrix\n#ifndef HAS_TANGENTS\n vec3 pos_dx = dFdx(pbr_vPosition);\n vec3 pos_dy = dFdy(pbr_vPosition);\n vec3 tex_dx = dFdx(vec3(pbr_vUV, 0.0));\n vec3 tex_dy = dFdy(vec3(pbr_vUV, 0.0));\n vec3 t = (tex_dy.t * pos_dx - tex_dx.t * pos_dy) / (tex_dx.s * tex_dy.t - tex_dy.s * tex_dx.t);\n\n#ifdef HAS_NORMALS\n vec3 ng = normalize(pbr_vNormal);\n#else\n vec3 ng = cross(pos_dx, pos_dy);\n#endif\n\n t = normalize(t - ng * dot(ng, t));\n vec3 b = normalize(cross(ng, t));\n mat3 tbn = mat3(t, b, ng);\n#else // HAS_TANGENTS\n mat3 tbn = pbr_vTBN;\n#endif\n\n#ifdef HAS_NORMALMAP\n vec3 n = texture(pbr_normalSampler, pbr_vUV).rgb;\n n = normalize(tbn * ((2.0 * n - 1.0) * vec3(pbrMaterial.normalScale, pbrMaterial.normalScale, 1.0)));\n#else\n // The tbn matrix is linearly interpolated, so we need to re-normalize\n vec3 n = normalize(tbn[2].xyz);\n#endif\n\n return n;\n}\n\n// Calculation of the lighting contribution from an optional Image Based Light source.\n// Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].\n// See our README.md on Environment Maps [3] for additional discussion.\n#ifdef USE_IBL\nvec3 getIBLContribution(PBRInfo pbrInfo, vec3 n, vec3 reflection)\n{\n float mipCount = 9.0; // resolution of 512x512\n float lod = (pbrInfo.perceptualRoughness * mipCount);\n // retrieve a scale and bias to F0. See [1], Figure 3\n vec3 brdf = SRGBtoLINEAR(texture(pbr_brdfLUT,\n vec2(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness))).rgb;\n vec3 diffuseLight = SRGBtoLINEAR(texture(pbr_diffuseEnvSampler, n)).rgb;\n\n#ifdef USE_TEX_LOD\n vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection, lod)).rgb;\n#else\n vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection)).rgb;\n#endif\n\n vec3 diffuse = diffuseLight * pbrInfo.diffuseColor;\n vec3 specular = specularLight * (pbrInfo.specularColor * brdf.x + brdf.y);\n\n // For presentation, this allows us to disable IBL terms\n diffuse *= pbrMaterial.scaleIBLAmbient.x;\n specular *= pbrMaterial.scaleIBLAmbient.y;\n\n return diffuse + specular;\n}\n#endif\n\n// Basic Lambertian diffuse\n// Implementation from Lambert's Photometria https://archive.org/details/lambertsphotome00lambgoog\n// See also [1], Equation 1\nvec3 diffuse(PBRInfo pbrInfo)\n{\n return pbrInfo.diffuseColor / M_PI;\n}\n\n// The following equation models the Fresnel reflectance term of the spec equation (aka F())\n// Implementation of fresnel from [4], Equation 15\nvec3 specularReflection(PBRInfo pbrInfo)\n{\n return pbrInfo.reflectance0 +\n (pbrInfo.reflectance90 - pbrInfo.reflectance0) *\n pow(clamp(1.0 - pbrInfo.VdotH, 0.0, 1.0), 5.0);\n}\n\n// This calculates the specular geometric attenuation (aka G()),\n// where rougher material will reflect less light back to the viewer.\n// This implementation is based on [1] Equation 4, and we adopt their modifications to\n// alphaRoughness as input as originally proposed in [2].\nfloat geometricOcclusion(PBRInfo pbrInfo)\n{\n float NdotL = pbrInfo.NdotL;\n float NdotV = pbrInfo.NdotV;\n float r = pbrInfo.alphaRoughness;\n\n float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));\n float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));\n return attenuationL * attenuationV;\n}\n\n// The following equation(s) model the distribution of microfacet normals across\n// the area being drawn (aka D())\n// Implementation from \"Average Irregularity Representation of a Roughened Surface\n// for Ray Reflection\" by T. S. Trowbridge, and K. P. Reitz\n// Follows the distribution function recommended in the SIGGRAPH 2013 course notes\n// from EPIC Games [1], Equation 3.\nfloat microfacetDistribution(PBRInfo pbrInfo)\n{\n float roughnessSq = pbrInfo.alphaRoughness * pbrInfo.alphaRoughness;\n float f = (pbrInfo.NdotH * roughnessSq - pbrInfo.NdotH) * pbrInfo.NdotH + 1.0;\n return roughnessSq / (M_PI * f * f);\n}\n\nvoid PBRInfo_setAmbientLight(inout PBRInfo pbrInfo) {\n pbrInfo.NdotL = 1.0;\n pbrInfo.NdotH = 0.0;\n pbrInfo.LdotH = 0.0;\n pbrInfo.VdotH = 1.0;\n}\n\nvoid PBRInfo_setDirectionalLight(inout PBRInfo pbrInfo, vec3 lightDirection) {\n vec3 n = pbrInfo.n;\n vec3 v = pbrInfo.v;\n vec3 l = normalize(lightDirection); // Vector from surface point to light\n vec3 h = normalize(l+v); // Half vector between both l and v\n\n pbrInfo.NdotL = clamp(dot(n, l), 0.001, 1.0);\n pbrInfo.NdotH = clamp(dot(n, h), 0.0, 1.0);\n pbrInfo.LdotH = clamp(dot(l, h), 0.0, 1.0);\n pbrInfo.VdotH = clamp(dot(v, h), 0.0, 1.0);\n}\n\nvoid PBRInfo_setPointLight(inout PBRInfo pbrInfo, PointLight pointLight) {\n vec3 light_direction = normalize(pointLight.position - pbr_vPosition);\n PBRInfo_setDirectionalLight(pbrInfo, light_direction);\n}\n\nvec3 calculateFinalColor(PBRInfo pbrInfo, vec3 lightColor) {\n // Calculate the shading terms for the microfacet specular shading model\n vec3 F = specularReflection(pbrInfo);\n float G = geometricOcclusion(pbrInfo);\n float D = microfacetDistribution(pbrInfo);\n\n // Calculation of analytical lighting contribution\n vec3 diffuseContrib = (1.0 - F) * diffuse(pbrInfo);\n vec3 specContrib = F * G * D / (4.0 * pbrInfo.NdotL * pbrInfo.NdotV);\n // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law)\n return pbrInfo.NdotL * lightColor * (diffuseContrib + specContrib);\n}\n\nvec4 pbr_filterColor(vec4 colorUnused)\n{\n // The albedo may be defined from a base texture or a flat color\n#ifdef HAS_BASECOLORMAP\n vec4 baseColor = SRGBtoLINEAR(texture(pbr_baseColorSampler, pbr_vUV)) * pbrMaterial.baseColorFactor;\n#else\n vec4 baseColor = pbrMaterial.baseColorFactor;\n#endif\n\n#ifdef ALPHA_CUTOFF\n if (baseColor.a < pbrMaterial.alphaCutoff) {\n discard;\n }\n#endif\n\n vec3 color = vec3(0, 0, 0);\n\n if(pbrMaterial.unlit){\n color.rgb = baseColor.rgb;\n }\n else{\n // Metallic and Roughness material properties are packed together\n // In glTF, these factors can be specified by fixed scalar values\n // or from a metallic-roughness map\n float perceptualRoughness = pbrMaterial.metallicRoughnessValues.y;\n float metallic = pbrMaterial.metallicRoughnessValues.x;\n#ifdef HAS_METALROUGHNESSMAP\n // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.\n // This layout intentionally reserves the 'r' channel for (optional) occlusion map data\n vec4 mrSample = texture(pbr_metallicRoughnessSampler, pbr_vUV);\n perceptualRoughness = mrSample.g * perceptualRoughness;\n metallic = mrSample.b * metallic;\n#endif\n perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);\n metallic = clamp(metallic, 0.0, 1.0);\n // Roughness is authored as perceptual roughness; as is convention,\n // convert to material roughness by squaring the perceptual roughness [2].\n float alphaRoughness = perceptualRoughness * perceptualRoughness;\n\n vec3 f0 = vec3(0.04);\n vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0);\n diffuseColor *= 1.0 - metallic;\n vec3 specularColor = mix(f0, baseColor.rgb, metallic);\n\n // Compute reflectance.\n float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);\n\n // For typical incident reflectance range (between 4% to 100%) set the grazing\n // reflectance to 100% for typical fresnel effect.\n // For very low reflectance range on highly diffuse objects (below 4%),\n // incrementally reduce grazing reflecance to 0%.\n float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);\n vec3 specularEnvironmentR0 = specularColor.rgb;\n vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;\n\n vec3 n = getNormal(); // normal at surface point\n vec3 v = normalize(pbrProjection.camera - pbr_vPosition); // Vector from surface point to camera\n\n float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);\n vec3 reflection = -normalize(reflect(v, n));\n\n PBRInfo pbrInfo = PBRInfo(\n 0.0, // NdotL\n NdotV,\n 0.0, // NdotH\n 0.0, // LdotH\n 0.0, // VdotH\n perceptualRoughness,\n metallic,\n specularEnvironmentR0,\n specularEnvironmentR90,\n alphaRoughness,\n diffuseColor,\n specularColor,\n n,\n v\n );\n\n\n#ifdef USE_LIGHTS\n // Apply ambient light\n PBRInfo_setAmbientLight(pbrInfo);\n color += calculateFinalColor(pbrInfo, lighting.ambientColor);\n\n // Apply directional light\n for(int i = 0; i < lighting.directionalLightCount; i++) {\n if (i < lighting.directionalLightCount) {\n PBRInfo_setDirectionalLight(pbrInfo, lighting_getDirectionalLight(i).direction);\n color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);\n }\n }\n\n // Apply point light\n for(int i = 0; i < lighting.pointLightCount; i++) {\n if (i < lighting.pointLightCount) {\n PBRInfo_setPointLight(pbrInfo, lighting_getPointLight(i));\n float attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));\n color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);\n }\n }\n#endif\n\n // Calculate lighting contribution from image based lighting source (IBL)\n#ifdef USE_IBL\n if (pbrMaterial.IBLenabled) {\n color += getIBLContribution(pbrInfo, n, reflection);\n }\n#endif\n\n // Apply optional PBR terms for additional (optional) shading\n#ifdef HAS_OCCLUSIONMAP\n if (pbrMaterial.occlusionMapEnabled) {\n float ao = texture(pbr_occlusionSampler, pbr_vUV).r;\n color = mix(color, color * ao, pbrMaterial.occlusionStrength);\n }\n#endif\n\n#ifdef HAS_EMISSIVEMAP\n if (pbrMaterial.emissiveMapEnabled) {\n vec3 emissive = SRGBtoLINEAR(texture(pbr_emissiveSampler, pbr_vUV)).rgb * pbrMaterial.emissiveFactor;\n color += emissive;\n }\n#endif\n\n // This section uses mix to override final color for reference app visualization\n // of various parameters in the lighting equation.\n#ifdef PBR_DEBUG\n // TODO: Figure out how to debug multiple lights\n\n // color = mix(color, F, pbr_scaleFGDSpec.x);\n // color = mix(color, vec3(G), pbr_scaleFGDSpec.y);\n // color = mix(color, vec3(D), pbr_scaleFGDSpec.z);\n // color = mix(color, specContrib, pbr_scaleFGDSpec.w);\n\n // color = mix(color, diffuseContrib, pbr_scaleDiffBaseMR.x);\n color = mix(color, baseColor.rgb, pbrMaterial.scaleDiffBaseMR.y);\n color = mix(color, vec3(metallic), pbrMaterial.scaleDiffBaseMR.z);\n color = mix(color, vec3(perceptualRoughness), pbrMaterial.scaleDiffBaseMR.w);\n#endif\n\n }\n\n return vec4(pow(color,vec3(1.0/2.2)), baseColor.a);\n}\n";
2
2
  //# sourceMappingURL=pbr-fragment-glsl.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pbr-fragment-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/pbr-material/pbr-fragment-glsl.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,EAAE,o2cAsZd,CAAC"}
1
+ {"version":3,"file":"pbr-fragment-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/pbr-material/pbr-fragment-glsl.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,EAAE,wwcAkZd,CAAC"}
@@ -9,12 +9,7 @@
9
9
  export const fs = /* glsl */ `\
10
10
  precision highp float;
11
11
 
12
- uniform Projection {
13
- // Projection
14
- uniform vec3 u_Camera;
15
- };
16
-
17
- uniform pbrMaterial {
12
+ uniform pbrMaterialUniforms {
18
13
  // Material is unlit
19
14
  bool unlit;
20
15
 
@@ -46,40 +41,40 @@ uniform pbrMaterial {
46
41
  vec4 scaleDiffBaseMR;
47
42
  vec4 scaleFGDSpec;
48
43
  // #endif
49
- } u_pbrMaterial;
44
+ } pbrMaterial;
50
45
 
51
46
  // Samplers
52
47
  #ifdef HAS_BASECOLORMAP
53
- uniform sampler2D u_BaseColorSampler;
48
+ uniform sampler2D pbr_baseColorSampler;
54
49
  #endif
55
50
  #ifdef HAS_NORMALMAP
56
- uniform sampler2D u_NormalSampler;
51
+ uniform sampler2D pbr_normalSampler;
57
52
  #endif
58
53
  #ifdef HAS_EMISSIVEMAP
59
- uniform sampler2D u_EmissiveSampler;
54
+ uniform sampler2D pbr_emissiveSampler;
60
55
  #endif
61
56
  #ifdef HAS_METALROUGHNESSMAP
62
- uniform sampler2D u_MetallicRoughnessSampler;
57
+ uniform sampler2D pbr_metallicRoughnessSampler;
63
58
  #endif
64
59
  #ifdef HAS_OCCLUSIONMAP
65
- uniform sampler2D u_OcclusionSampler;
60
+ uniform sampler2D pbr_occlusionSampler;
66
61
  #endif
67
62
  #ifdef USE_IBL
68
- uniform samplerCube u_DiffuseEnvSampler;
69
- uniform samplerCube u_SpecularEnvSampler;
70
- uniform sampler2D u_brdfLUT;
63
+ uniform samplerCube pbr_diffuseEnvSampler;
64
+ uniform samplerCube pbr_specularEnvSampler;
65
+ uniform sampler2D pbr_brdfLUT;
71
66
  #endif
72
67
 
73
68
  // Inputs from vertex shader
74
69
 
75
- varying vec3 pbr_vPosition;
76
- varying vec2 pbr_vUV;
70
+ in vec3 pbr_vPosition;
71
+ in vec2 pbr_vUV;
77
72
 
78
73
  #ifdef HAS_NORMALS
79
74
  #ifdef HAS_TANGENTS
80
- varying mat3 pbr_vTBN;
75
+ in mat3 pbr_vTBN;
81
76
  #else
82
- varying vec3 pbr_vNormal;
77
+ in vec3 pbr_vNormal;
83
78
  #endif
84
79
  #endif
85
80
 
@@ -147,8 +142,8 @@ vec3 getNormal()
147
142
  #endif
148
143
 
149
144
  #ifdef HAS_NORMALMAP
150
- vec3 n = texture2D(u_NormalSampler, pbr_vUV).rgb;
151
- n = normalize(tbn * ((2.0 * n - 1.0) * vec3(u_pbrMaterial.normalScale, u_pbrMaterial.normalScale, 1.0)));
145
+ vec3 n = texture(pbr_normalSampler, pbr_vUV).rgb;
146
+ n = normalize(tbn * ((2.0 * n - 1.0) * vec3(pbrMaterial.normalScale, pbrMaterial.normalScale, 1.0)));
152
147
  #else
153
148
  // The tbn matrix is linearly interpolated, so we need to re-normalize
154
149
  vec3 n = normalize(tbn[2].xyz);
@@ -166,22 +161,22 @@ vec3 getIBLContribution(PBRInfo pbrInfo, vec3 n, vec3 reflection)
166
161
  float mipCount = 9.0; // resolution of 512x512
167
162
  float lod = (pbrInfo.perceptualRoughness * mipCount);
168
163
  // retrieve a scale and bias to F0. See [1], Figure 3
169
- vec3 brdf = SRGBtoLINEAR(texture2D(u_brdfLUT,
164
+ vec3 brdf = SRGBtoLINEAR(texture(pbr_brdfLUT,
170
165
  vec2(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness))).rgb;
171
- vec3 diffuseLight = SRGBtoLINEAR(textureCube(u_DiffuseEnvSampler, n)).rgb;
166
+ vec3 diffuseLight = SRGBtoLINEAR(texture(pbr_diffuseEnvSampler, n)).rgb;
172
167
 
173
168
  #ifdef USE_TEX_LOD
174
- vec3 specularLight = SRGBtoLINEAR(textureCubeLod(u_SpecularEnvSampler, reflection, lod)).rgb;
169
+ vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection, lod)).rgb;
175
170
  #else
176
- vec3 specularLight = SRGBtoLINEAR(textureCube(u_SpecularEnvSampler, reflection)).rgb;
171
+ vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection)).rgb;
177
172
  #endif
178
173
 
179
174
  vec3 diffuse = diffuseLight * pbrInfo.diffuseColor;
180
175
  vec3 specular = specularLight * (pbrInfo.specularColor * brdf.x + brdf.y);
181
176
 
182
177
  // For presentation, this allows us to disable IBL terms
183
- diffuse *= u_pbrMaterial.scaleIBLAmbient.x;
184
- specular *= u_pbrMaterial.scaleIBLAmbient.y;
178
+ diffuse *= pbrMaterial.scaleIBLAmbient.x;
179
+ specular *= pbrMaterial.scaleIBLAmbient.y;
185
180
 
186
181
  return diffuse + specular;
187
182
  }
@@ -273,32 +268,32 @@ vec4 pbr_filterColor(vec4 colorUnused)
273
268
  {
274
269
  // The albedo may be defined from a base texture or a flat color
275
270
  #ifdef HAS_BASECOLORMAP
276
- vec4 baseColor = SRGBtoLINEAR(texture2D(u_BaseColorSampler, pbr_vUV)) * u_pbrMaterial.baseColorFactor;
271
+ vec4 baseColor = SRGBtoLINEAR(texture(pbr_baseColorSampler, pbr_vUV)) * pbrMaterial.baseColorFactor;
277
272
  #else
278
- vec4 baseColor = u_pbrMaterial.baseColorFactor;
273
+ vec4 baseColor = pbrMaterial.baseColorFactor;
279
274
  #endif
280
275
 
281
276
  #ifdef ALPHA_CUTOFF
282
- if (baseColor.a < u_pbrMaterial.alphaCutoff) {
277
+ if (baseColor.a < pbrMaterial.alphaCutoff) {
283
278
  discard;
284
279
  }
285
280
  #endif
286
281
 
287
282
  vec3 color = vec3(0, 0, 0);
288
283
 
289
- if(u_pbrMaterial.unlit){
284
+ if(pbrMaterial.unlit){
290
285
  color.rgb = baseColor.rgb;
291
286
  }
292
287
  else{
293
288
  // Metallic and Roughness material properties are packed together
294
289
  // In glTF, these factors can be specified by fixed scalar values
295
290
  // or from a metallic-roughness map
296
- float perceptualRoughness = u_pbrMaterial.metallicRoughnessValues.y;
297
- float metallic = u_pbrMaterial.metallicRoughnessValues.x;
291
+ float perceptualRoughness = pbrMaterial.metallicRoughnessValues.y;
292
+ float metallic = pbrMaterial.metallicRoughnessValues.x;
298
293
  #ifdef HAS_METALROUGHNESSMAP
299
294
  // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
300
295
  // This layout intentionally reserves the 'r' channel for (optional) occlusion map data
301
- vec4 mrSample = texture2D(u_MetallicRoughnessSampler, pbr_vUV);
296
+ vec4 mrSample = texture(pbr_metallicRoughnessSampler, pbr_vUV);
302
297
  perceptualRoughness = mrSample.g * perceptualRoughness;
303
298
  metallic = mrSample.b * metallic;
304
299
  #endif
@@ -325,7 +320,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
325
320
  vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;
326
321
 
327
322
  vec3 n = getNormal(); // normal at surface point
328
- vec3 v = normalize(u_Camera - pbr_vPosition); // Vector from surface point to camera
323
+ vec3 v = normalize(pbrProjection.camera - pbr_vPosition); // Vector from surface point to camera
329
324
 
330
325
  float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
331
326
  vec3 reflection = -normalize(reflect(v, n));
@@ -347,47 +342,48 @@ vec4 pbr_filterColor(vec4 colorUnused)
347
342
  v
348
343
  );
349
344
 
345
+
350
346
  #ifdef USE_LIGHTS
351
347
  // Apply ambient light
352
348
  PBRInfo_setAmbientLight(pbrInfo);
353
- color += calculateFinalColor(pbrInfo, lighting_uAmbientLight.color);
349
+ color += calculateFinalColor(pbrInfo, lighting.ambientColor);
354
350
 
355
351
  // Apply directional light
356
- for(int i = 0; i < lighting_uDirectionalLightCount; i++) {
357
- if (i < lighting_uDirectionalLightCount) {
358
- PBRInfo_setDirectionalLight(pbrInfo, lighting_uDirectionalLight[i].direction);
359
- color += calculateFinalColor(pbrInfo, lighting_uDirectionalLight[i].color);
352
+ for(int i = 0; i < lighting.directionalLightCount; i++) {
353
+ if (i < lighting.directionalLightCount) {
354
+ PBRInfo_setDirectionalLight(pbrInfo, lighting_getDirectionalLight(i).direction);
355
+ color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);
360
356
  }
361
357
  }
362
358
 
363
359
  // Apply point light
364
- for(int i = 0; i < lighting_uPointLightCount; i++) {
365
- if (i < lighting_uPointLightCount) {
366
- PBRInfo_setPointLight(pbrInfo, lighting_uPointLight[i]);
367
- float attenuation = getPointLightAttenuation(lighting_uPointLight[i], distance(lighting_uPointLight[i].position, pbr_vPosition));
368
- color += calculateFinalColor(pbrInfo, lighting_uPointLight[i].color / attenuation);
360
+ for(int i = 0; i < lighting.pointLightCount; i++) {
361
+ if (i < lighting.pointLightCount) {
362
+ PBRInfo_setPointLight(pbrInfo, lighting_getPointLight(i));
363
+ float attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));
364
+ color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);
369
365
  }
370
366
  }
371
367
  #endif
372
368
 
373
369
  // Calculate lighting contribution from image based lighting source (IBL)
374
370
  #ifdef USE_IBL
375
- if (u_pbrMateral.IBLEnabled) {
371
+ if (pbrMaterial.IBLenabled) {
376
372
  color += getIBLContribution(pbrInfo, n, reflection);
377
373
  }
378
374
  #endif
379
375
 
380
- // Apply optional PBR terms for additional (optional) shading
376
+ // Apply optional PBR terms for additional (optional) shading
381
377
  #ifdef HAS_OCCLUSIONMAP
382
- if (u_pbrMaterial.occlusionMapEnabled) {
383
- float ao = texture2D(u_OcclusionSampler, pbr_vUV).r;
384
- color = mix(color, color * ao, u_pbrMaterial.occlusionStrength);
378
+ if (pbrMaterial.occlusionMapEnabled) {
379
+ float ao = texture(pbr_occlusionSampler, pbr_vUV).r;
380
+ color = mix(color, color * ao, pbrMaterial.occlusionStrength);
385
381
  }
386
382
  #endif
387
383
 
388
384
  #ifdef HAS_EMISSIVEMAP
389
- if (u_pbrMaterial.emmissiveMapEnabled) {
390
- vec3 emissive = SRGBtoLINEAR(texture2D(u_EmissiveSampler, pbr_vUV)).rgb * u_pbrMaterial.emissiveFactor;
385
+ if (pbrMaterial.emissiveMapEnabled) {
386
+ vec3 emissive = SRGBtoLINEAR(texture(pbr_emissiveSampler, pbr_vUV)).rgb * pbrMaterial.emissiveFactor;
391
387
  color += emissive;
392
388
  }
393
389
  #endif
@@ -397,15 +393,15 @@ vec4 pbr_filterColor(vec4 colorUnused)
397
393
  #ifdef PBR_DEBUG
398
394
  // TODO: Figure out how to debug multiple lights
399
395
 
400
- // color = mix(color, F, u_ScaleFGDSpec.x);
401
- // color = mix(color, vec3(G), u_ScaleFGDSpec.y);
402
- // color = mix(color, vec3(D), u_ScaleFGDSpec.z);
403
- // color = mix(color, specContrib, u_ScaleFGDSpec.w);
396
+ // color = mix(color, F, pbr_scaleFGDSpec.x);
397
+ // color = mix(color, vec3(G), pbr_scaleFGDSpec.y);
398
+ // color = mix(color, vec3(D), pbr_scaleFGDSpec.z);
399
+ // color = mix(color, specContrib, pbr_scaleFGDSpec.w);
404
400
 
405
- // color = mix(color, diffuseContrib, u_ScaleDiffBaseMR.x);
406
- color = mix(color, baseColor.rgb, u_pbrMaterial.scaleDiffBaseMR.y);
407
- color = mix(color, vec3(metallic), u_pbrMaterial.scaleDiffBaseMR.z);
408
- color = mix(color, vec3(perceptualRoughness), u_pbrMaterial.scaleDiffBaseMR.w);
401
+ // color = mix(color, diffuseContrib, pbr_scaleDiffBaseMR.x);
402
+ color = mix(color, baseColor.rgb, pbrMaterial.scaleDiffBaseMR.y);
403
+ color = mix(color, vec3(metallic), pbrMaterial.scaleDiffBaseMR.z);
404
+ color = mix(color, vec3(perceptualRoughness), pbrMaterial.scaleDiffBaseMR.w);
409
405
  #endif
410
406
 
411
407
  }