@zephyr3d/scene 0.9.6 → 0.9.8

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 (205) hide show
  1. package/dist/animation/animationset.js +52 -55
  2. package/dist/animation/animationset.js.map +1 -1
  3. package/dist/animation/joint_dynamics/controller.js +92 -32
  4. package/dist/animation/joint_dynamics/controller.js.map +1 -1
  5. package/dist/animation/joint_dynamics/convex_collider.js +320 -0
  6. package/dist/animation/joint_dynamics/convex_collider.js.map +1 -0
  7. package/dist/animation/joint_dynamics/joint_dynamics_system.js +57 -19
  8. package/dist/animation/joint_dynamics/joint_dynamics_system.js.map +1 -1
  9. package/dist/animation/joint_dynamics/solver.js +71 -27
  10. package/dist/animation/joint_dynamics/solver.js.map +1 -1
  11. package/dist/animation/joint_dynamics_modifier.js +4 -3
  12. package/dist/animation/joint_dynamics_modifier.js.map +1 -1
  13. package/dist/animation/skeleton.js +7 -10
  14. package/dist/animation/skeleton.js.map +1 -1
  15. package/dist/app/engine.js +3 -9
  16. package/dist/app/engine.js.map +1 -1
  17. package/dist/app/scriptregistry.js +47 -16
  18. package/dist/app/scriptregistry.js.map +1 -1
  19. package/dist/asset/assetmanager.js +3 -1
  20. package/dist/asset/assetmanager.js.map +1 -1
  21. package/dist/asset/model.js +346 -7
  22. package/dist/asset/model.js.map +1 -1
  23. package/dist/avatar/wardrobe.js +7 -3
  24. package/dist/avatar/wardrobe.js.map +1 -1
  25. package/dist/camera/camera.js +240 -34
  26. package/dist/camera/camera.js.map +1 -1
  27. package/dist/index.d.ts +1350 -622
  28. package/dist/index.js +6 -11
  29. package/dist/index.js.map +1 -1
  30. package/dist/material/blinn.js +1 -1
  31. package/dist/material/blinn.js.map +1 -1
  32. package/dist/material/lambert.js +1 -1
  33. package/dist/material/lambert.js.map +1 -1
  34. package/dist/material/material.js +23 -1
  35. package/dist/material/material.js.map +1 -1
  36. package/dist/material/meshmaterial.js +178 -23
  37. package/dist/material/meshmaterial.js.map +1 -1
  38. package/dist/material/mixins/albedocolor.js +4 -4
  39. package/dist/material/mixins/albedocolor.js.map +1 -1
  40. package/dist/material/mixins/lightmodel/blinnphong.js +2 -1
  41. package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
  42. package/dist/material/mixins/lightmodel/lambert.js +2 -1
  43. package/dist/material/mixins/lightmodel/lambert.js.map +1 -1
  44. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js +63 -16
  45. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js.map +1 -1
  46. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +100 -27
  47. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
  48. package/dist/material/mixins/lightmodel/pbrspecularglossness.js +16 -6
  49. package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
  50. package/dist/material/mixins/lit.js +1 -1
  51. package/dist/material/mixins/lit.js.map +1 -1
  52. package/dist/material/mixins/pbr/common.js +276 -65
  53. package/dist/material/mixins/pbr/common.js.map +1 -1
  54. package/dist/material/mixins/texture.js +3 -3
  55. package/dist/material/mixins/texture.js.map +1 -1
  56. package/dist/material/mixins/vertexcolor.js +2 -2
  57. package/dist/material/mixins/vertexcolor.js.map +1 -1
  58. package/dist/material/mtoon.js +574 -0
  59. package/dist/material/mtoon.js.map +1 -0
  60. package/dist/material/pbrblueprint.js +494 -331
  61. package/dist/material/pbrblueprint.js.map +1 -1
  62. package/dist/material/pbrmr.js +118 -100
  63. package/dist/material/pbrmr.js.map +1 -1
  64. package/dist/material/pbrsg.js +1 -1
  65. package/dist/material/pbrsg.js.map +1 -1
  66. package/dist/material/shader/helper.js +45 -15
  67. package/dist/material/shader/helper.js.map +1 -1
  68. package/dist/material/subsurfaceprofile.js +812 -0
  69. package/dist/material/subsurfaceprofile.js.map +1 -0
  70. package/dist/material/unlit.js +1 -1
  71. package/dist/material/unlit.js.map +1 -1
  72. package/dist/posteffect/compositor.js +46 -11
  73. package/dist/posteffect/compositor.js.map +1 -1
  74. package/dist/posteffect/ssr.js +413 -87
  75. package/dist/posteffect/ssr.js.map +1 -1
  76. package/dist/posteffect/sss.js +1053 -0
  77. package/dist/posteffect/sss.js.map +1 -0
  78. package/dist/posteffect/taa.js +61 -60
  79. package/dist/posteffect/taa.js.map +1 -1
  80. package/dist/render/abuffer_oit.js +63 -12
  81. package/dist/render/abuffer_oit.js.map +1 -1
  82. package/dist/render/cluster_light.js +6 -5
  83. package/dist/render/cluster_light.js.map +1 -1
  84. package/dist/render/drawable.js +1 -5
  85. package/dist/render/drawable.js.map +1 -1
  86. package/dist/render/drawable_mixin.js +2 -1
  87. package/dist/render/drawable_mixin.js.map +1 -1
  88. package/dist/render/fbm_wavegenerator.js +2 -1
  89. package/dist/render/fbm_wavegenerator.js.map +1 -1
  90. package/dist/render/gerstner_wavegenerator.js +2 -1
  91. package/dist/render/gerstner_wavegenerator.js.map +1 -1
  92. package/dist/render/globalbindgroup_allocator.js +2 -1
  93. package/dist/render/globalbindgroup_allocator.js.map +1 -1
  94. package/dist/render/lightpass.js +105 -18
  95. package/dist/render/lightpass.js.map +1 -1
  96. package/dist/render/render_queue.js +51 -8
  97. package/dist/render/render_queue.js.map +1 -1
  98. package/dist/render/renderer.js +73 -59
  99. package/dist/render/renderer.js.map +1 -1
  100. package/dist/render/rendergraph/device_pool_allocator.js +8 -0
  101. package/dist/render/rendergraph/device_pool_allocator.js.map +1 -1
  102. package/dist/render/rendergraph/forward_plus_builder.js +481 -95
  103. package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
  104. package/dist/render/rendergraph/history_resource_manager.js +55 -0
  105. package/dist/render/rendergraph/history_resource_manager.js.map +1 -1
  106. package/dist/render/rendergraph/history_resources.js +3 -1
  107. package/dist/render/rendergraph/history_resources.js.map +1 -1
  108. package/dist/render/rendergraph/types.js.map +1 -1
  109. package/dist/render/renderpass.js +10 -4
  110. package/dist/render/renderpass.js.map +1 -1
  111. package/dist/render/sky.js +31 -1
  112. package/dist/render/sky.js.map +1 -1
  113. package/dist/render/weightedblended_oit.js +23 -5
  114. package/dist/render/weightedblended_oit.js.map +1 -1
  115. package/dist/scene/basesprite.js +4 -2
  116. package/dist/scene/basesprite.js.map +1 -1
  117. package/dist/scene/batchgroup.js +3 -1
  118. package/dist/scene/batchgroup.js.map +1 -1
  119. package/dist/scene/environment.js +11 -1
  120. package/dist/scene/environment.js.map +1 -1
  121. package/dist/scene/light.js +21 -3
  122. package/dist/scene/light.js.map +1 -1
  123. package/dist/scene/mesh.js +29 -14
  124. package/dist/scene/mesh.js.map +1 -1
  125. package/dist/scene/meshdrawable.js +6 -0
  126. package/dist/scene/meshdrawable.js.map +1 -1
  127. package/dist/scene/msdftext.js +5 -2
  128. package/dist/scene/msdftext.js.map +1 -1
  129. package/dist/scene/msdftextsprite.js +5 -3
  130. package/dist/scene/msdftextsprite.js.map +1 -1
  131. package/dist/scene/particlesys.js +3 -1
  132. package/dist/scene/particlesys.js.map +1 -1
  133. package/dist/scene/scene.js +6 -5
  134. package/dist/scene/scene.js.map +1 -1
  135. package/dist/scene/terrain-cm/grass.js +4 -2
  136. package/dist/scene/terrain-cm/grass.js.map +1 -1
  137. package/dist/scene/terrain-cm/grassmaterial.js +2 -1
  138. package/dist/scene/terrain-cm/grassmaterial.js.map +1 -1
  139. package/dist/scene/terrain-cm/terrain-cm.js +4 -2
  140. package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
  141. package/dist/scene/water.js +4 -2
  142. package/dist/scene/water.js.map +1 -1
  143. package/dist/shaders/shadow.js +26 -393
  144. package/dist/shaders/shadow.js.map +1 -1
  145. package/dist/shadow/esm.js +112 -12
  146. package/dist/shadow/esm.js.map +1 -1
  147. package/dist/shadow/pcf_opt.js +2 -2
  148. package/dist/shadow/pcf_opt.js.map +1 -1
  149. package/dist/shadow/pcf_pd.js +19 -10
  150. package/dist/shadow/pcf_pd.js.map +1 -1
  151. package/dist/shadow/shader.js +58 -7
  152. package/dist/shadow/shader.js.map +1 -1
  153. package/dist/shadow/shadow_impl.js +6 -0
  154. package/dist/shadow/shadow_impl.js.map +1 -1
  155. package/dist/shadow/shadow_region.js +229 -0
  156. package/dist/shadow/shadow_region.js.map +1 -0
  157. package/dist/shadow/shadowmapper.js +67 -59
  158. package/dist/shadow/shadowmapper.js.map +1 -1
  159. package/dist/shadow/vsm.js +45 -19
  160. package/dist/shadow/vsm.js.map +1 -1
  161. package/dist/utility/blueprint/common/constants.js +8 -8
  162. package/dist/utility/blueprint/common/constants.js.map +1 -1
  163. package/dist/utility/blueprint/material/pbr.js +31 -4
  164. package/dist/utility/blueprint/material/pbr.js.map +1 -1
  165. package/dist/utility/blueprint/material/texture.js +1 -17
  166. package/dist/utility/blueprint/material/texture.js.map +1 -1
  167. package/dist/utility/serialization/manager.js +66 -98
  168. package/dist/utility/serialization/manager.js.map +1 -1
  169. package/dist/utility/serialization/scene/animation.js +5 -2
  170. package/dist/utility/serialization/scene/animation.js.map +1 -1
  171. package/dist/utility/serialization/scene/batch.js +4 -1
  172. package/dist/utility/serialization/scene/batch.js.map +1 -1
  173. package/dist/utility/serialization/scene/camera.js +249 -54
  174. package/dist/utility/serialization/scene/camera.js.map +1 -1
  175. package/dist/utility/serialization/scene/common.js +37 -1
  176. package/dist/utility/serialization/scene/common.js.map +1 -1
  177. package/dist/utility/serialization/scene/light.js +42 -3
  178. package/dist/utility/serialization/scene/light.js.map +1 -1
  179. package/dist/utility/serialization/scene/material.js +1112 -646
  180. package/dist/utility/serialization/scene/material.js.map +1 -1
  181. package/dist/utility/serialization/scene/mesh.js +7 -4
  182. package/dist/utility/serialization/scene/mesh.js.map +1 -1
  183. package/dist/utility/serialization/scene/node.js +31 -12
  184. package/dist/utility/serialization/scene/node.js.map +1 -1
  185. package/dist/utility/serialization/scene/particle.js +4 -1
  186. package/dist/utility/serialization/scene/particle.js.map +1 -1
  187. package/dist/utility/serialization/scene/primitive.js +3 -1
  188. package/dist/utility/serialization/scene/primitive.js.map +1 -1
  189. package/dist/utility/serialization/scene/scene.js +18 -0
  190. package/dist/utility/serialization/scene/scene.js.map +1 -1
  191. package/dist/utility/serialization/scene/sprite.js +6 -3
  192. package/dist/utility/serialization/scene/sprite.js.map +1 -1
  193. package/dist/utility/serialization/scene/terrain.js +5 -2
  194. package/dist/utility/serialization/scene/terrain.js.map +1 -1
  195. package/dist/utility/serialization/scene/text.js +3 -1
  196. package/dist/utility/serialization/scene/text.js.map +1 -1
  197. package/dist/utility/serialization/scene/water.js +4 -1
  198. package/dist/utility/serialization/scene/water.js.map +1 -1
  199. package/dist/utility/textures/ltcdata.js +6 -0
  200. package/dist/utility/textures/ltcdata.js.map +1 -0
  201. package/dist/utility/textures/ltclut.js +61 -0
  202. package/dist/utility/textures/ltclut.js.map +1 -0
  203. package/dist/values.js +9 -1
  204. package/dist/values.js.map +1 -1
  205. package/package.json +3 -3
@@ -2,307 +2,8 @@ import { hasDepthChannel } from '@zephyr3d/device';
2
2
  import { LIGHT_TYPE_DIRECTIONAL, LIGHT_TYPE_RECT, LIGHT_TYPE_POINT, LIGHT_TYPE_SPOT } from '../values.js';
3
3
  import { encodeNormalizedFloatToRGBA, decode2HalfFromRGBA, decodeNormalizedFloatFromRGBA } from './misc.js';
4
4
  import { ShaderHelper } from '../material/shader/helper.js';
5
- import { interleavedGradientNoise } from './noise.js';
6
5
  import { getDevice } from '../app/api.js';
7
6
 
8
- /*
9
- const PCF_KERNEL_3x3 = [
10
- [0.5, 1.0, 0.5],
11
- [1.0, 1.0, 1.0],
12
- [0.5, 1.0, 0.5]
13
- ];
14
- const PCF_KERNEL_SUM_3x3 = 7;
15
-
16
- const PCF_KERNEL_5x5 = [
17
- [0.0, 0.5, 1.0, 0.5, 0.0],
18
- [0.5, 1.0, 1.0, 1.0, 0.5],
19
- [1.0, 1.0, 1.0, 1.0, 1.0],
20
- [0.5, 1.0, 1.0, 1.0, 0.5],
21
- [0.0, 0.5, 1.0, 0.5, 0.0]
22
- ];
23
- const PCF_KERNEL_SUM_5x5 = 17;
24
-
25
- const PCF_KERNEL_7x7 = [
26
- [0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0],
27
- [0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0],
28
- [0.5, 1.0, 1.0, 1.0, 1.0, 1.0, 0.5],
29
- [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
30
- [0.5, 1.0, 1.0, 1.0, 1.0, 1.0, 0.5],
31
- [0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0],
32
- [0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0]
33
- ];
34
- const PCF_KERNEL_SUM_7x7 = 33;
35
-
36
- const PCF_KERNEL_9x9 = [
37
- [0.0, 0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0, 0.0],
38
- [0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0],
39
- [0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0],
40
- [0.5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.5],
41
- [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
42
- [0.5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.5],
43
- [0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0],
44
- [0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0],
45
- [0.0, 0.0, 0.0, 0.5, 1.0, 0.5, 0.0, 0.0, 0.0]
46
- ];
47
- const PCF_KERNEL_SUM_9x9 = 53;
48
- */ const PCF_POISSON_DISC = [
49
- [
50
- 0.511749,
51
- 0.547686
52
- ],
53
- [
54
- 0.58929,
55
- 0.257224
56
- ],
57
- [
58
- 0.165018,
59
- 0.57663
60
- ],
61
- [
62
- 0.407692,
63
- 0.742285
64
- ],
65
- [
66
- 0.707012,
67
- 0.646523
68
- ],
69
- [
70
- 0.31463,
71
- 0.466825
72
- ],
73
- [
74
- 0.801257,
75
- 0.485186
76
- ],
77
- [
78
- 0.418136,
79
- 0.146517
80
- ],
81
- [
82
- 0.579889,
83
- 0.0368284
84
- ],
85
- [
86
- 0.79801,
87
- 0.140114
88
- ],
89
- [
90
- -0.0413185,
91
- 0.371455
92
- ],
93
- [
94
- -0.0529108,
95
- 0.627352
96
- ],
97
- [
98
- 0.0821375,
99
- 0.882071
100
- ],
101
- [
102
- 0.17308,
103
- 0.301207
104
- ],
105
- [
106
- -0.120452,
107
- 0.867216
108
- ],
109
- [
110
- 0.371096,
111
- 0.916454
112
- ],
113
- [
114
- -0.178381,
115
- 0.146101
116
- ],
117
- [
118
- -0.276489,
119
- 0.550525
120
- ],
121
- [
122
- 0.12542,
123
- 0.126643
124
- ],
125
- [
126
- -0.296654,
127
- 0.286879
128
- ],
129
- [
130
- 0.261744,
131
- -604975e-8
132
- ],
133
- [
134
- -0.213417,
135
- 0.715776
136
- ],
137
- [
138
- 0.425684,
139
- -0.153211
140
- ],
141
- [
142
- -0.480054,
143
- 0.321357
144
- ],
145
- [
146
- -0.0717878,
147
- -0.0250567
148
- ],
149
- [
150
- -0.328775,
151
- -0.169666
152
- ],
153
- [
154
- -0.394923,
155
- 0.130802
156
- ],
157
- [
158
- -0.553681,
159
- -0.176777
160
- ],
161
- [
162
- -0.722615,
163
- 0.120616
164
- ],
165
- [
166
- -0.693065,
167
- 0.309017
168
- ],
169
- [
170
- 0.603193,
171
- 0.791471
172
- ],
173
- [
174
- -0.0754941,
175
- -0.297988
176
- ],
177
- [
178
- 0.109303,
179
- -0.156472
180
- ],
181
- [
182
- 0.260605,
183
- -0.280111
184
- ],
185
- [
186
- 0.129731,
187
- -0.487954
188
- ],
189
- [
190
- -0.537315,
191
- 0.520494
192
- ],
193
- [
194
- -0.42758,
195
- 0.800607
196
- ],
197
- [
198
- 0.77309,
199
- -0.0728102
200
- ],
201
- [
202
- 0.908777,
203
- 0.328356
204
- ],
205
- [
206
- 0.985341,
207
- 0.0759158
208
- ],
209
- [
210
- 0.947536,
211
- -0.11837
212
- ],
213
- [
214
- -0.103315,
215
- -0.610747
216
- ],
217
- [
218
- 0.337171,
219
- -0.584
220
- ],
221
- [
222
- 0.210919,
223
- -0.720055
224
- ],
225
- [
226
- 0.41894,
227
- -0.36769
228
- ],
229
- [
230
- -0.254228,
231
- -0.49368
232
- ],
233
- [
234
- -0.428562,
235
- -0.404037
236
- ],
237
- [
238
- -0.831732,
239
- -0.189615
240
- ],
241
- [
242
- -0.922642,
243
- 0.0888026
244
- ],
245
- [
246
- -0.865914,
247
- 0.427795
248
- ],
249
- [
250
- 0.706117,
251
- -0.311662
252
- ],
253
- [
254
- 0.545465,
255
- -0.520942
256
- ],
257
- [
258
- -0.695738,
259
- 0.664492
260
- ],
261
- [
262
- 0.389421,
263
- -0.899007
264
- ],
265
- [
266
- 0.48842,
267
- -0.708054
268
- ],
269
- [
270
- 0.760298,
271
- -0.62735
272
- ],
273
- [
274
- -0.390788,
275
- -0.707388
276
- ],
277
- [
278
- -0.591046,
279
- -0.686721
280
- ],
281
- [
282
- -0.769903,
283
- -0.413775
284
- ],
285
- [
286
- -0.604457,
287
- -0.502571
288
- ],
289
- [
290
- -0.557234,
291
- 0.00451362
292
- ],
293
- [
294
- 0.147572,
295
- -0.924353
296
- ],
297
- [
298
- -0.0662488,
299
- -0.892081
300
- ],
301
- [
302
- 0.863832,
303
- -0.4072
304
- ]
305
- ];
306
7
  function getShadowMapTexelSize(scope) {
307
8
  return scope.$builder.div(1, ShaderHelper.getShadowCameraParams(scope).z);
308
9
  }
@@ -355,23 +56,8 @@ function getShadowMapSize(scope) {
355
56
  });
356
57
  return pb.getGlobalScope()[funcNameComputeReceiverPlaneDepthBias](texCoord);
357
58
  }
358
- function getRandomRotationMatrix(scope, fragCoord) {
359
- const funcNameGetRandomRotationMatrix = 'lib_getRandomRotationMatrix';
360
- const pb = scope.$builder;
361
- pb.func(funcNameGetRandomRotationMatrix, [
362
- pb.vec2('fragCoord')
363
- ], function() {
364
- this.$l.randomAngle = pb.mul(interleavedGradientNoise(this, fragCoord), 2 * Math.PI);
365
- this.$l.randomBase = pb.vec2(pb.cos(this.randomAngle), pb.sin(this.randomAngle));
366
- this.$return(pb.mat2(this.randomBase.x, this.randomBase.y, pb.neg(this.randomBase.y), this.randomBase.x));
367
- });
368
- return pb.getGlobalScope()[funcNameGetRandomRotationMatrix](fragCoord);
369
- }
370
- function getPoissonDiscSampleRadius(scope) {
371
- return ShaderHelper.getDepthBiasValues(scope).z;
372
- }
373
59
  function sampleShadowMapPCF(scope, shadowMapFormat, pos, offset, depth, cascade) {
374
- const funcName = cascade ? 'lib_sampleShadowMapCascadePCF' : 'lib_sampleShadowMapPCF';
60
+ const funcName = `${cascade ? 'lib_sampleShadowMapCascadePCF' : 'lib_sampleShadowMapPCF'}_${shadowMapFormat}`;
375
61
  const pb = scope.$builder;
376
62
  const nativeShadowMap = hasDepthChannel(shadowMapFormat);
377
63
  pb.func(funcName, [
@@ -398,57 +84,26 @@ function sampleShadowMapPCF(scope, shadowMapFormat, pos, offset, depth, cascade)
398
84
  cascade
399
85
  ] : []);
400
86
  }
401
- function sampleShadowMap(scope, lightType, shadowMapFormat, pos, depth, cascade) {
402
- const funcNameSampleShadowMap = 'lib_sampleShadowMap';
403
- const pb = scope.$builder;
404
- const nativeShadowMap = hasDepthChannel(shadowMapFormat);
405
- pb.func(funcNameSampleShadowMap, [
406
- lightType === LIGHT_TYPE_POINT ? pb.vec3('coords') : pb.vec2('coords'),
407
- pb.float('z'),
408
- ...cascade ? [
409
- pb.int('cascade')
410
- ] : []
411
- ], function() {
412
- if (lightType === LIGHT_TYPE_POINT) {
413
- if (nativeShadowMap) {
414
- this.$return(pb.clamp(pb.textureSampleCompareLevel(ShaderHelper.getShadowMap(this), this.coords, this.z), 0, 1));
415
- } else {
416
- this.$l.shadowTex = pb.textureSampleLevel(ShaderHelper.getShadowMap(this), this.coords, 0);
417
- if (shadowMapFormat === 'rgba8unorm') {
418
- this.shadowTex.x = decodeNormalizedFloatFromRGBA(this, this.shadowTex);
419
- }
420
- this.$return(pb.step(this.z, this.shadowTex.x));
421
- }
422
- } else {
423
- if (nativeShadowMap) {
424
- this.$return(cascade && getDevice().type !== 'webgl' ? pb.textureArraySampleCompareLevel(ShaderHelper.getShadowMap(this), this.coords, this.cascade, this.z) : pb.textureSampleCompareLevel(ShaderHelper.getShadowMap(this), this.coords, this.z));
425
- } else {
426
- this.$l.shadowTex = cascade && getDevice().type !== 'webgl' ? pb.textureArraySampleLevel(ShaderHelper.getShadowMap(this), this.coords, this.cascade, 0) : pb.textureSampleLevel(ShaderHelper.getShadowMap(this), this.coords, 0);
427
- if (shadowMapFormat === 'rgba8unorm') {
428
- this.shadowTex.x = decodeNormalizedFloatFromRGBA(this, this.shadowTex);
429
- }
430
- this.$return(pb.step(this.z, this.shadowTex.x));
431
- }
432
- }
433
- });
434
- return cascade ? pb.getGlobalScope()[funcNameSampleShadowMap](pos, depth, cascade) : pb.getGlobalScope()[funcNameSampleShadowMap](pos, depth);
435
- }
436
87
  function chebyshevUpperBound(scope, distance, occluder) {
437
88
  const funcNameChebyshevUpperBound = 'lib_chebyshevUpperBound';
438
89
  const pb = scope.$builder;
439
90
  pb.func(funcNameChebyshevUpperBound, [
440
91
  pb.float('distance'),
441
- pb.vec2('occluder')
92
+ pb.vec3('occluder')
442
93
  ], function() {
443
94
  this.$l.shadow = pb.float(1);
444
- this.$l.test = pb.step(this.distance, this.occluder.x);
95
+ this.$l.coverage = this.occluder.z;
96
+ this.$l.invCoverage = pb.div(1, pb.max(this.coverage, 0.00001));
97
+ this.$l.moments = pb.mul(this.occluder.xy, this.invCoverage);
98
+ this.$l.test = pb.step(this.distance, this.moments.x);
445
99
  this.$if(pb.notEqual(this.test, 1), function() {
446
- this.$l.d = pb.sub(this.distance, this.occluder.x);
447
- this.$l.variance = pb.max(pb.mul(this.occluder.y, this.occluder.y), 0);
100
+ this.$l.d = pb.sub(this.distance, this.moments.x);
101
+ this.$l.variance = pb.max(pb.sub(this.moments.y, pb.mul(this.moments.x, this.moments.x)), 0.000002);
448
102
  const darkness = ShaderHelper.getDepthBiasValues(this).z;
449
103
  this.shadow = pb.div(this.variance, pb.add(this.variance, pb.mul(this.d, this.d)));
450
104
  this.shadow = pb.clamp(pb.div(pb.sub(this.shadow, darkness), pb.sub(1, darkness)), 0, 1);
451
105
  });
106
+ this.shadow = pb.mix(1, this.shadow, pb.clamp(this.coverage, 0, 1));
452
107
  this.$return(this.shadow);
453
108
  });
454
109
  return pb.getGlobalScope()[funcNameChebyshevUpperBound](distance, occluder);
@@ -464,27 +119,30 @@ function chebyshevUpperBound(scope, distance, occluder) {
464
119
  ], function() {
465
120
  if (lightType === LIGHT_TYPE_POINT) {
466
121
  this.$l.shadowTex = pb.textureSampleLevel(ShaderHelper.getShadowMap(this), this.texCoord.xyz, 0);
467
- this.$return(chebyshevUpperBound(this, this.texCoord.w, shadowMapFormat === 'rgba8unorm' ? decode2HalfFromRGBA(this, this.shadowTex) : this.shadowTex.rg));
122
+ this.$return(chebyshevUpperBound(this, this.texCoord.w, shadowMapFormat === 'rgba8unorm' ? pb.vec3(decode2HalfFromRGBA(this, this.shadowTex), 1) : this.shadowTex.rgb));
468
123
  } else {
469
124
  if (getDevice().type !== 'webgl' && cascade) {
470
125
  this.$l.shadowTex = pb.textureArraySampleLevel(ShaderHelper.getShadowMap(this), this.texCoord.xy, this.cascade, 0);
471
126
  } else {
472
127
  this.$l.shadowTex = pb.textureSampleLevel(ShaderHelper.getShadowMap(this), this.texCoord.xy, 0);
473
128
  }
474
- this.$return(chebyshevUpperBound(this, this.texCoord.z, shadowMapFormat === 'rgba8unorm' ? decode2HalfFromRGBA(this, this.shadowTex) : this.shadowTex.rg));
129
+ this.$return(chebyshevUpperBound(this, this.texCoord.z, shadowMapFormat === 'rgba8unorm' ? pb.vec3(decode2HalfFromRGBA(this, this.shadowTex), 1) : this.shadowTex.rgb));
475
130
  }
476
131
  });
477
132
  return pb.getGlobalScope()[funcNameFilterShadowVSM](texCoord, ...cascade ? [
478
133
  cascade
479
134
  ] : []);
480
135
  }
481
- /** @internal */ function filterShadowESM(scope, lightType, shadowMapFormat, shadowVertex, cascade) {
136
+ /** @internal */ function filterShadowESM(scope, lightType, shadowMapFormat, logSpace, shadowVertex, cascade, depthBias) {
482
137
  const funcNameFilterShadowESM = 'lib_filterShadowESM';
483
138
  const pb = scope.$builder;
484
139
  pb.func(funcNameFilterShadowESM, [
485
140
  lightType === LIGHT_TYPE_POINT ? pb.vec3('shadowVertex') : pb.vec4('shadowVertex'),
486
141
  ...cascade ? [
487
142
  pb.int('cascade')
143
+ ] : [],
144
+ ...depthBias ? [
145
+ pb.float('depthBias')
488
146
  ] : []
489
147
  ], function() {
490
148
  if (lightType === LIGHT_TYPE_POINT) {
@@ -509,11 +167,20 @@ function chebyshevUpperBound(scope, distance, occluder) {
509
167
  this.$l.depth = this.shadowVertex.z;
510
168
  }
511
169
  }
170
+ if (depthBias) {
171
+ this.depth = pb.max(0, pb.sub(this.depth, this.depthBias));
172
+ }
512
173
  const depthScale = ShaderHelper.getDepthBiasValues(this).z;
513
- this.$return(pb.clamp(pb.exp(pb.min(87, pb.mul(depthScale, pb.sub(this.shadowTex.x, this.depth)))), 0, 1));
174
+ this.$l.shadow = logSpace ? pb.clamp(pb.exp(pb.min(87, pb.sub(this.shadowTex.x, pb.mul(depthScale, this.depth)))), 0, 1) : pb.clamp(pb.exp(pb.min(87, pb.mul(depthScale, pb.sub(this.shadowTex.x, this.depth)))), 0, 1);
175
+ if (shadowMapFormat !== 'rgba8unorm') {
176
+ this.shadow = pb.mix(1, this.shadow, pb.clamp(this.shadowTex.y, 0, 1));
177
+ }
178
+ this.$return(this.shadow);
514
179
  });
515
180
  return pb.getGlobalScope()[funcNameFilterShadowESM](shadowVertex, ...cascade ? [
516
181
  cascade
182
+ ] : [], ...depthBias ? [
183
+ depthBias
517
184
  ] : []);
518
185
  }
519
186
  /** @internal */ function filterShadowPCF(scope, lightType, shadowMapFormat, kernelSize, texCoord, receiverPlaneDepthBias, cascade) {
@@ -597,40 +264,6 @@ function chebyshevUpperBound(scope, distance, occluder) {
597
264
  cascade
598
265
  ] : []);
599
266
  }
600
- /** @internal */ function filterShadowPoissonDisc(scope, lightType, shadowMapFormat, tapCount, texCoord, receiverPlaneDepthBias, cascade) {
601
- const funcNameFilterShadowPoissonDisc = 'lib_filterShadowPoissonDisc';
602
- const pb = scope.$builder;
603
- pb.func(funcNameFilterShadowPoissonDisc, [
604
- pb.vec4('texCoord'),
605
- ...receiverPlaneDepthBias ? [
606
- pb.vec3('receiverPlaneDepthBias')
607
- ] : [],
608
- ...cascade ? [
609
- pb.int('cascade')
610
- ] : []
611
- ], function() {
612
- this.$l.lightDepth = this.texCoord.z;
613
- if (receiverPlaneDepthBias) {
614
- this.lightDepth = pb.sub(this.lightDepth, this.receiverPlaneDepthBias.z);
615
- }
616
- this.$l.duv = pb.vec2();
617
- this.$l.filterRadius = pb.mul(getShadowMapTexelSize(this), getPoissonDiscSampleRadius(this));
618
- this.$l.matrix = getRandomRotationMatrix(this, this.$builtins.fragCoord.xy);
619
- this.$l.shadow = pb.float(0);
620
- for(let i = 0; i < tapCount; i++){
621
- this.duv = pb.mul(this.matrix, pb.mul(pb.vec2(PCF_POISSON_DISC[i][0], PCF_POISSON_DISC[i][1]), this.filterRadius));
622
- const sampleDepth = receiverPlaneDepthBias ? pb.add(this.lightDepth, pb.dot(this.duv, this.receiverPlaneDepthBias.xy)) : this.lightDepth;
623
- this.shadow = pb.add(this.shadow, sampleShadowMap(this, lightType, shadowMapFormat, pb.add(this.texCoord.xy, this.duv), sampleDepth, this.cascade));
624
- }
625
- this.shadow = pb.div(this.shadow, tapCount);
626
- this.$return(this.shadow);
627
- });
628
- return pb.getGlobalScope()[funcNameFilterShadowPoissonDisc](texCoord, ...receiverPlaneDepthBias ? [
629
- receiverPlaneDepthBias
630
- ] : [], ...cascade ? [
631
- cascade
632
- ] : []);
633
- }
634
267
 
635
- export { computeReceiverPlaneDepthBias, computeShadowMapDepth, filterShadowESM, filterShadowPCF, filterShadowPoissonDisc, filterShadowVSM };
268
+ export { computeReceiverPlaneDepthBias, computeShadowMapDepth, filterShadowESM, filterShadowPCF, filterShadowVSM };
636
269
  //# sourceMappingURL=shadow.js.map