@zephyr3d/scene 0.3.1 → 0.5.0

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 (174) hide show
  1. package/dist/animation/animation.js +25 -117
  2. package/dist/animation/animation.js.map +1 -1
  3. package/dist/animation/animationset.js +164 -24
  4. package/dist/animation/animationset.js.map +1 -1
  5. package/dist/animation/animationtrack.js +6 -18
  6. package/dist/animation/animationtrack.js.map +1 -1
  7. package/dist/animation/eulerrotationtrack.js +16 -6
  8. package/dist/animation/eulerrotationtrack.js.map +1 -1
  9. package/dist/animation/morphtarget.js +104 -0
  10. package/dist/animation/morphtarget.js.map +1 -0
  11. package/dist/animation/morphtrack.js +68 -0
  12. package/dist/animation/morphtrack.js.map +1 -0
  13. package/dist/animation/rotationtrack.js +15 -7
  14. package/dist/animation/rotationtrack.js.map +1 -1
  15. package/dist/animation/scaletrack.js +15 -7
  16. package/dist/animation/scaletrack.js.map +1 -1
  17. package/dist/animation/skeleton.js +101 -1
  18. package/dist/animation/skeleton.js.map +1 -1
  19. package/dist/animation/translationtrack.js +15 -7
  20. package/dist/animation/translationtrack.js.map +1 -1
  21. package/dist/animation/usertrack.js +2 -2
  22. package/dist/app.js +4 -26
  23. package/dist/app.js.map +1 -1
  24. package/dist/asset/assetmanager.js +58 -107
  25. package/dist/asset/assetmanager.js.map +1 -1
  26. package/dist/asset/loaders/dds/dds.js +77 -3
  27. package/dist/asset/loaders/dds/dds.js.map +1 -1
  28. package/dist/asset/loaders/dds/dds_loader.js +1 -1
  29. package/dist/asset/loaders/gltf/gltf_loader.js +284 -45
  30. package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -1
  31. package/dist/asset/loaders/image/tga_Loader.js +1 -1
  32. package/dist/asset/model.js +13 -0
  33. package/dist/asset/model.js.map +1 -1
  34. package/dist/blitter/blitter.js +2 -2
  35. package/dist/camera/camera.js +83 -5
  36. package/dist/camera/camera.js.map +1 -1
  37. package/dist/index.d.ts +5212 -4785
  38. package/dist/index.js +6 -7
  39. package/dist/index.js.map +1 -1
  40. package/dist/material/blinn.js +9 -4
  41. package/dist/material/blinn.js.map +1 -1
  42. package/dist/material/grassmat.js +127 -0
  43. package/dist/material/grassmat.js.map +1 -0
  44. package/dist/material/grassmaterial.js +15 -0
  45. package/dist/material/grassmaterial.js.map +1 -1
  46. package/dist/material/lambert.js +22 -17
  47. package/dist/material/lambert.js.map +1 -1
  48. package/dist/material/lightmodel.js +7 -6
  49. package/dist/material/lightmodel.js.map +1 -1
  50. package/dist/material/lit.js +99 -5
  51. package/dist/material/lit.js.map +1 -1
  52. package/dist/material/material.js +88 -347
  53. package/dist/material/material.js.map +1 -1
  54. package/dist/material/meshmaterial.js +122 -102
  55. package/dist/material/meshmaterial.js.map +1 -1
  56. package/dist/material/mixins/albedocolor.js +11 -3
  57. package/dist/material/mixins/albedocolor.js.map +1 -1
  58. package/dist/material/mixins/lightmodel/blinnphong.js +1 -1
  59. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +3 -3
  60. package/dist/material/mixins/lightmodel/pbrspecularglossness.js +3 -3
  61. package/dist/material/mixins/lit.js +2 -2
  62. package/dist/material/mixins/pbr/common.js +433 -10
  63. package/dist/material/mixins/pbr/common.js.map +1 -1
  64. package/dist/material/pbrmr.js +17 -6
  65. package/dist/material/pbrmr.js.map +1 -1
  66. package/dist/material/pbrsg.js +16 -9
  67. package/dist/material/pbrsg.js.map +1 -1
  68. package/dist/material/shader/helper.js +186 -117
  69. package/dist/material/shader/helper.js.map +1 -1
  70. package/dist/material/terrainlightmodel.js +3 -1
  71. package/dist/material/terrainlightmodel.js.map +1 -1
  72. package/dist/material/terrainmat.js +357 -0
  73. package/dist/material/terrainmat.js.map +1 -0
  74. package/dist/material/terrainmaterial.js +16 -0
  75. package/dist/material/terrainmaterial.js.map +1 -1
  76. package/dist/material/unlit.js +8 -4
  77. package/dist/material/unlit.js.map +1 -1
  78. package/dist/posteffect/bloom.js +34 -45
  79. package/dist/posteffect/bloom.js.map +1 -1
  80. package/dist/posteffect/compositor.js +11 -41
  81. package/dist/posteffect/compositor.js.map +1 -1
  82. package/dist/posteffect/fxaa.js +1 -2
  83. package/dist/posteffect/fxaa.js.map +1 -1
  84. package/dist/posteffect/grayscale.js +1 -2
  85. package/dist/posteffect/grayscale.js.map +1 -1
  86. package/dist/posteffect/posteffect.js +0 -74
  87. package/dist/posteffect/posteffect.js.map +1 -1
  88. package/dist/posteffect/sao.js +13 -29
  89. package/dist/posteffect/sao.js.map +1 -1
  90. package/dist/posteffect/tonemap.js +1 -2
  91. package/dist/posteffect/tonemap.js.map +1 -1
  92. package/dist/posteffect/water.js +20 -18
  93. package/dist/posteffect/water.js.map +1 -1
  94. package/dist/render/abuffer_oit.js +352 -0
  95. package/dist/render/abuffer_oit.js.map +1 -0
  96. package/dist/render/cull_visitor.js +3 -3
  97. package/dist/render/depth_pass.js +3 -2
  98. package/dist/render/depth_pass.js.map +1 -1
  99. package/dist/render/depthpass.js +16 -19
  100. package/dist/render/depthpass.js.map +1 -1
  101. package/dist/render/drawable_mixin.js +152 -0
  102. package/dist/render/drawable_mixin.js.map +1 -0
  103. package/dist/render/envlight.js +165 -31
  104. package/dist/render/envlight.js.map +1 -1
  105. package/dist/render/forward.js +3 -6
  106. package/dist/render/forward.js.map +1 -1
  107. package/dist/render/forward_pass.js +6 -5
  108. package/dist/render/forward_pass.js.map +1 -1
  109. package/dist/render/globalbindgroup_allocator.js +58 -0
  110. package/dist/render/globalbindgroup_allocator.js.map +1 -0
  111. package/dist/render/lightpass.js +83 -49
  112. package/dist/render/lightpass.js.map +1 -1
  113. package/dist/render/objectcolorpass.js +50 -0
  114. package/dist/render/objectcolorpass.js.map +1 -0
  115. package/dist/render/objectpool.js +295 -0
  116. package/dist/render/objectpool.js.map +1 -0
  117. package/dist/render/oit.js +16 -0
  118. package/dist/render/oit.js.map +1 -0
  119. package/dist/render/render_queue.js +294 -107
  120. package/dist/render/render_queue.js.map +1 -1
  121. package/dist/render/renderbundle_wrapper.js +20 -0
  122. package/dist/render/renderbundle_wrapper.js.map +1 -0
  123. package/dist/render/renderer.js +108 -28
  124. package/dist/render/renderer.js.map +1 -1
  125. package/dist/render/renderpass.js +96 -34
  126. package/dist/render/renderpass.js.map +1 -1
  127. package/dist/render/shadowmap_pass.js +18 -37
  128. package/dist/render/shadowmap_pass.js.map +1 -1
  129. package/dist/render/sky.js +2 -2
  130. package/dist/render/watermesh.js +140 -48
  131. package/dist/render/watermesh.js.map +1 -1
  132. package/dist/render/weightedblended_oit.js +171 -0
  133. package/dist/render/weightedblended_oit.js.map +1 -0
  134. package/dist/scene/batchgroup.js +8 -35
  135. package/dist/scene/batchgroup.js.map +1 -1
  136. package/dist/scene/environment.js +24 -4
  137. package/dist/scene/environment.js.map +1 -1
  138. package/dist/scene/graph_node.js +1 -10
  139. package/dist/scene/graph_node.js.map +1 -1
  140. package/dist/scene/mesh.js +42 -32
  141. package/dist/scene/mesh.js.map +1 -1
  142. package/dist/scene/scene.js +7 -37
  143. package/dist/scene/scene.js.map +1 -1
  144. package/dist/scene/scene_node.js +6 -2
  145. package/dist/scene/scene_node.js.map +1 -1
  146. package/dist/scene/terrain/grass.js +26 -11
  147. package/dist/scene/terrain/grass.js.map +1 -1
  148. package/dist/scene/terrain/patch.js +27 -15
  149. package/dist/scene/terrain/patch.js.map +1 -1
  150. package/dist/scene/terrain/quadtree.js +3 -3
  151. package/dist/scene/terrain/terrain.js +0 -8
  152. package/dist/scene/terrain/terrain.js.map +1 -1
  153. package/dist/shaders/lighting.js +14 -10
  154. package/dist/shaders/lighting.js.map +1 -1
  155. package/dist/shaders/water.js +4 -4
  156. package/dist/shadow/esm.js +4 -23
  157. package/dist/shadow/esm.js.map +1 -1
  158. package/dist/shadow/shadowmapper.js +45 -21
  159. package/dist/shadow/shadowmapper.js.map +1 -1
  160. package/dist/shadow/vsm.js +4 -25
  161. package/dist/shadow/vsm.js.map +1 -1
  162. package/dist/utility/draco/decoder.js +116 -0
  163. package/dist/utility/draco/decoder.js.map +1 -0
  164. package/dist/utility/sheenlut.js +196 -0
  165. package/dist/utility/sheenlut.js.map +1 -0
  166. package/dist/values.js +18 -1
  167. package/dist/values.js.map +1 -1
  168. package/package.json +7 -6
  169. package/dist/utility/noisetexture.js +0 -66
  170. package/dist/utility/noisetexture.js.map +0 -1
  171. package/dist/utility/textures/gradientnoise.js +0 -66
  172. package/dist/utility/textures/gradientnoise.js.map +0 -1
  173. package/dist/utility/textures/randomnoise.js +0 -41
  174. package/dist/utility/textures/randomnoise.js.map +0 -1
@@ -38,10 +38,14 @@ import { Application } from '../app.js';
38
38
  pb.vec3('attenuation')
39
39
  ], function() {
40
40
  this.$l.dist = pb.distance(this.lightPositionRange.xyz, ShaderFramework.getWorldPosition(this).xyz);
41
- this.$l.falloff = pb.max(0, pb.sub(1, pb.div(this.dist, this.lightPositionRange.w)));
42
- this.$l.falloff2 = pb.mul(this.falloff, this.falloff);
43
- this.$if(pb.greaterThan(this.falloff2, 0), function() {
44
- lm.directBRDF(this, this.lightDir, pb.mul(this.attenuation, this.falloff2));
41
+ this.$l.a = pb.div(1, pb.add(1, pb.mul(this.dist, this.dist)));
42
+ this.$l.falloff = pb.mul(this.a, pb.clamp(pb.sub(1, pb.div(this.dist, this.lightPositionRange.w)), 0, 1));
43
+ //this.$l.t = pb.div(pb.mul(this.dist, 16), this.lightPositionRange.w);
44
+ //this.$l.falloff = pb.div(1, pb.add(1, pb.mul(this.t, this.t)));
45
+ //this.$l.falloff = pb.div(1, ) pb.max(0, pb.sub(1, pb.div(this.dist, this.lightPositionRange.w)));
46
+ //this.falloff = pb.mul(this.falloff, this.falloff);
47
+ this.$if(pb.greaterThan(this.falloff, 0), function() {
48
+ lm.directBRDF(this, this.lightDir, pb.mul(this.attenuation, this.falloff));
45
49
  });
46
50
  });
47
51
  pb.getGlobalScope()[funcNameIllumPointLight](...args);
@@ -166,12 +170,12 @@ import { Application } from '../app.js';
166
170
  this.lightDir = this.directionCutoff.xyz;
167
171
  this.$l.nl = pb.dot(this.surfaceData.normal, this.lightDir);
168
172
  this.$l.NdotL = pb.clamp(pb.neg(this.nl), 0, 1);
169
- this.shadowBound = pb.vec4(0, 0, 1, 1);
170
- this.linearDepth = nonLinearDepthToLinear(this, this.$builtins.fragCoord.z);
171
- this.splitDistances = ShaderFramework.getCascadeDistances(this);
172
- this.comparison = pb.vec4(pb.greaterThan(pb.vec4(this.linearDepth), this.splitDistances));
173
- this.cascadeFlags = pb.vec4(pb.float(pb.greaterThan(this.shadowCascades, 0)), pb.float(pb.greaterThan(this.shadowCascades, 1)), pb.float(pb.greaterThan(this.shadowCascades, 2)), pb.float(pb.greaterThan(this.shadowCascades, 3)));
174
- this.split = pb.int(pb.dot(this.comparison, this.cascadeFlags));
173
+ this.$l.shadowBound = pb.vec4(0, 0, 1, 1);
174
+ this.$l.linearDepth = nonLinearDepthToLinear(this, this.$builtins.fragCoord.z);
175
+ this.$l.splitDistances = ShaderFramework.getCascadeDistances(this);
176
+ this.$l.comparison = pb.vec4(pb.greaterThan(pb.vec4(this.linearDepth), this.splitDistances));
177
+ this.$l.cascadeFlags = pb.vec4(pb.float(pb.greaterThan(this.shadowCascades, 0)), pb.float(pb.greaterThan(this.shadowCascades, 1)), pb.float(pb.greaterThan(this.shadowCascades, 2)), pb.float(pb.greaterThan(this.shadowCascades, 3)));
178
+ this.$l.split = pb.int(pb.dot(this.comparison, this.cascadeFlags));
175
179
  this.$l.shadowVertex = pb.vec4();
176
180
  if (Application.instance.device.type === 'webgl') {
177
181
  this.$for(pb.int('cascade'), 0, 4, function() {
@@ -1 +1 @@
1
- {"version":3,"file":"lighting.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"lighting.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -12,13 +12,13 @@ import { Application } from '../app.js';
12
12
  this.$outputs.uv2 = pb.vec2();
13
13
  this.flip = pb.int().uniform(0);
14
14
  this.viewProjMatrix = pb.mat4().uniform(0);
15
- this.modelMatrix = pb.mat4().uniform(0);
16
- this.gridScale = pb.float().uniform(0);
15
+ this.modelMatrix = pb.mat4().uniform(1);
16
+ this.gridScale = pb.float().uniform(1);
17
17
  this.level = pb.float().uniform(0);
18
18
  this.sizes = pb.vec4().uniform(0);
19
19
  this.croppinesses = pb.vec4().uniform(0);
20
- this.offset = pb.vec2().uniform(0);
21
- this.scale = pb.float().uniform(0);
20
+ this.offset = pb.vec2().uniform(1);
21
+ this.scale = pb.float().uniform(1);
22
22
  this.dx_hy_dz_dxdz0 = pb.tex2D().uniform(0);
23
23
  this.sx_sz_dxdx_dzdz0 = pb.tex2D().uniform(0);
24
24
  this.dx_hy_dz_dxdz1 = pb.tex2D().uniform(0);
@@ -5,23 +5,9 @@ import '@zephyr3d/device';
5
5
  import { decodeNormalizedFloatFromRGBA, encodeNormalizedFloatToRGBA } from '../shaders/misc.js';
6
6
  import { GaussianBlurBlitter } from '../blitter/gaussianblur.js';
7
7
  import { computeShadowMapDepth, filterShadowESM } from '../shaders/shadow.js';
8
- import '../scene/octree.js';
9
8
  import { LIGHT_TYPE_POINT } from '../values.js';
9
+ import { ShadowMapper } from './shadowmapper.js';
10
10
  import { ShaderHelper } from '../material/shader/helper.js';
11
- import '../material/lambert.js';
12
- import '../material/blinn.js';
13
- import '../material/unlit.js';
14
- import '../material/material.js';
15
- import '../material/meshmaterial.js';
16
- import '../material/grassmaterial.js';
17
- import '../material/terrainmaterial.js';
18
- import '../material/pbrmr.js';
19
- import '../material/pbrsg.js';
20
- import '../render/renderer.js';
21
- import '../render/sky.js';
22
- import '../render/clipmap.js';
23
- import { TemporalCache } from '../render/temporalcache.js';
24
- import '../render/watermesh.js';
25
11
 
26
12
  class BlurBlitter extends GaussianBlurBlitter {
27
13
  _packFloat;
@@ -133,13 +119,12 @@ class BlurBlitter extends GaussianBlurBlitter {
133
119
  };
134
120
  shadowMapParams.implData = implData;
135
121
  const colorFormat = this.getShadowMapColorFormat(shadowMapParams);
136
- const target = shadowMapParams.shadowMapFramebuffer.getColorAttachments()[0].target;
137
122
  const shadowMapWidth = shadowMapParams.shadowMapFramebuffer.getColorAttachments()[0].width;
138
123
  const shadowMapHeight = shadowMapParams.shadowMapFramebuffer.getColorAttachments()[0].height;
139
124
  if (this._blur) {
140
125
  shadowMapParams.implData = {
141
- blurFramebuffer: TemporalCache.getFramebufferFixedSize(shadowMapWidth, shadowMapHeight, shadowMapParams.numShadowCascades, colorFormat, null, target, null, false),
142
- blurFramebuffer2: TemporalCache.getFramebufferFixedSize(shadowMapWidth, shadowMapHeight, shadowMapParams.numShadowCascades, colorFormat, null, target, null, this._mipmap)
126
+ blurFramebuffer: ShadowMapper.fetchTemporalFramebuffer(true, shadowMapParams.lightType, shadowMapParams.numShadowCascades, shadowMapWidth, shadowMapHeight, colorFormat, null, false),
127
+ blurFramebuffer2: ShadowMapper.fetchTemporalFramebuffer(true, shadowMapParams.lightType, shadowMapParams.numShadowCascades, shadowMapWidth, shadowMapHeight, colorFormat, null, true)
143
128
  };
144
129
  }
145
130
  shadowMapParams.shadowMap = this.getShadowMap(shadowMapParams);
@@ -162,11 +147,7 @@ class BlurBlitter extends GaussianBlurBlitter {
162
147
  }
163
148
  }
164
149
  releaseTemporalResources(shadowMapParams) {
165
- const implData = shadowMapParams.implData;
166
- if (implData) {
167
- TemporalCache.releaseFramebuffer(implData.blurFramebuffer);
168
- TemporalCache.releaseFramebuffer(implData.blurFramebuffer2);
169
- }
150
+ return;
170
151
  }
171
152
  getDepthScale() {
172
153
  return this._depthScale;
@@ -1 +1 @@
1
- {"version":3,"file":"esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -6,24 +6,8 @@ import { VSM } from './vsm.js';
6
6
  import { PCFPD } from './pcf_pd.js';
7
7
  import { PCFOPT } from './pcf_opt.js';
8
8
  import { Application } from '../app.js';
9
- import '../scene/octree.js';
10
- import { LIGHT_TYPE_NONE, LIGHT_TYPE_DIRECTIONAL } from '../values.js';
9
+ import { LIGHT_TYPE_NONE, LIGHT_TYPE_DIRECTIONAL, LIGHT_TYPE_POINT } from '../values.js';
11
10
  import { ShaderHelper } from '../material/shader/helper.js';
12
- import '../material/lambert.js';
13
- import '../material/blinn.js';
14
- import '../material/unlit.js';
15
- import '../material/material.js';
16
- import '../material/meshmaterial.js';
17
- import '../material/grassmaterial.js';
18
- import '../material/terrainmaterial.js';
19
- import '../material/pbrmr.js';
20
- import '../material/pbrsg.js';
21
- import '@zephyr3d/device';
22
- import '../render/renderer.js';
23
- import '../render/sky.js';
24
- import '../render/clipmap.js';
25
- import { TemporalCache } from '../render/temporalcache.js';
26
- import '../render/watermesh.js';
27
11
 
28
12
  const tmpMatrix = new Matrix4x4();
29
13
  const tmpFrustum = new Frustum(Matrix4x4.identity());
@@ -289,7 +273,7 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
289
273
  if (ctx.shadowMapInfo) {
290
274
  for (const k of ctx.shadowMapInfo.keys()){
291
275
  const shadowMapParams = ctx.shadowMapInfo.get(k);
292
- TemporalCache.releaseFramebuffer(shadowMapParams.shadowMapFramebuffer);
276
+ ctx.device.pool.releaseFrameBuffer(shadowMapParams.shadowMapFramebuffer);
293
277
  shadowMapParams.impl.releaseTemporalResources(shadowMapParams);
294
278
  shadowMapParams.lightType = LIGHT_TYPE_NONE;
295
279
  shadowMapParams.depthClampEnabled = false;
@@ -345,6 +329,26 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
345
329
  return null;
346
330
  }
347
331
  }
332
+ /** @internal */ static fetchTemporalFramebuffer(autoRelease, lightType, numCascades, width, height, colorFormat, depthFormat, mipmapping) {
333
+ const device = Application.instance.device;
334
+ const useTextureArray = numCascades > 1 && device.type !== 'webgl';
335
+ const colorAttachments = colorFormat ? useTextureArray ? [
336
+ device.pool.fetchTemporalTexture2DArray(false, colorFormat, width, height, numCascades, mipmapping)
337
+ ] : lightType === LIGHT_TYPE_POINT ? [
338
+ device.pool.fetchTemporalTextureCube(false, colorFormat, width, mipmapping)
339
+ ] : [
340
+ device.pool.fetchTemporalTexture2D(false, colorFormat, width, height, mipmapping)
341
+ ] : null;
342
+ const depthAttachment = depthFormat ? useTextureArray ? device.pool.fetchTemporalTexture2DArray(false, depthFormat, width, height, numCascades, false) : device.type !== 'webgl' && lightType === LIGHT_TYPE_POINT ? device.pool.fetchTemporalTextureCube(false, depthFormat, width, false) : device.pool.fetchTemporalTexture2D(false, depthFormat, width, height, false) : null;
343
+ const fb = device.pool.createTemporalFramebuffer(autoRelease, colorAttachments, depthAttachment);
344
+ if (colorAttachments) {
345
+ device.pool.releaseTexture(colorAttachments[0]);
346
+ }
347
+ if (depthAttachment) {
348
+ device.pool.releaseTexture(depthAttachment);
349
+ }
350
+ return fb;
351
+ }
348
352
  /** @internal */ updateResources(shadowMapParams) {
349
353
  const device = Application.instance.device;
350
354
  const colorFormat = shadowMapParams.impl.getShadowMapColorFormat(shadowMapParams);
@@ -353,9 +357,29 @@ const tmpFrustum = new Frustum(Matrix4x4.identity());
353
357
  const useTextureArray = numCascades > 1 && device.type !== 'webgl';
354
358
  const shadowMapWidth = numCascades > 1 && !useTextureArray ? 2 * this._config.shadowMapSize : this._config.shadowMapSize;
355
359
  const shadowMapHeight = numCascades > 2 && !useTextureArray ? 2 * this._config.shadowMapSize : this._config.shadowMapSize;
356
- const colorTarget = useTextureArray ? '2darray' : this._light.isPointLight() ? 'cube' : '2d';
357
- const depthTarget = device.type === 'webgl' ? '2d' : colorTarget;
358
- shadowMapParams.shadowMapFramebuffer = TemporalCache.getFramebufferFixedSize(shadowMapWidth, shadowMapHeight, numCascades, colorFormat, depthFormat, colorTarget, depthTarget, false, 1);
360
+ /*
361
+ const colorAttachments = colorFormat
362
+ ? useTextureArray
363
+ ? [device.pool.fetchTemporalTexture2DArray(false, colorFormat, shadowMapWidth, shadowMapHeight, numCascades, false)]
364
+ : this._light.isPointLight()
365
+ ? [device.pool.fetchTemporalTextureCube(false, colorFormat, shadowMapWidth, false)]
366
+ : [device.pool.fetchTemporalTexture2D(false, colorFormat, shadowMapWidth, shadowMapHeight, false)]
367
+ : null;
368
+ const depthAttachment = depthFormat
369
+ ? useTextureArray
370
+ ? device.pool.fetchTemporalTexture2DArray(false, depthFormat, shadowMapWidth, shadowMapHeight, numCascades, false)
371
+ : device.type !== 'webgl' && this._light.isPointLight()
372
+ ? device.pool.fetchTemporalTextureCube(false, depthFormat, shadowMapWidth, false)
373
+ : device.pool.fetchTemporalTexture2D(false, depthFormat, shadowMapWidth, shadowMapHeight, false)
374
+ : null;
375
+ shadowMapParams.shadowMapFramebuffer = device.pool.createTemporalFramebuffer(false, colorAttachments, depthAttachment);
376
+ if (colorAttachments) {
377
+ device.pool.releaseTexture(colorAttachments[0]);
378
+ }
379
+ if (depthAttachment) {
380
+ device.pool.releaseTexture(depthAttachment);
381
+ }
382
+ */ shadowMapParams.shadowMapFramebuffer = ShadowMapper.fetchTemporalFramebuffer(false, this._light.lightType, numCascades, shadowMapWidth, shadowMapHeight, colorFormat, depthFormat);
359
383
  shadowMapParams.impl = this._impl;
360
384
  this._impl.updateResources(shadowMapParams);
361
385
  }
@@ -1 +1 @@
1
- {"version":3,"file":"shadowmapper.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"shadowmapper.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -4,25 +4,8 @@ import { decodeNormalizedFloatFromRGBA, decode2HalfFromRGBA, encode2HalfToRGBA }
4
4
  import { Application } from '../app.js';
5
5
  import { computeShadowMapDepth, filterShadowVSM } from '../shaders/shadow.js';
6
6
  import { ShadowMapper } from './shadowmapper.js';
7
- import '@zephyr3d/base';
8
- import '../scene/octree.js';
9
7
  import { LIGHT_TYPE_POINT, LIGHT_TYPE_SPOT } from '../values.js';
10
8
  import { ShaderHelper } from '../material/shader/helper.js';
11
- import '../material/lambert.js';
12
- import '../material/blinn.js';
13
- import '../material/unlit.js';
14
- import '../material/material.js';
15
- import '../material/meshmaterial.js';
16
- import '../material/grassmaterial.js';
17
- import '../material/terrainmaterial.js';
18
- import '../material/pbrmr.js';
19
- import '../material/pbrsg.js';
20
- import '@zephyr3d/device';
21
- import '../render/renderer.js';
22
- import '../render/sky.js';
23
- import '../render/clipmap.js';
24
- import { TemporalCache } from '../render/temporalcache.js';
25
- import '../render/watermesh.js';
26
9
 
27
10
  class VSMBlitter extends Blitter {
28
11
  _phase;
@@ -192,13 +175,13 @@ class VSMBlitter extends Blitter {
192
175
  }
193
176
  doUpdateResources(shadowMapParams) {
194
177
  const colorFormat = this.getShadowMapColorFormat(shadowMapParams);
195
- const target = shadowMapParams.shadowMapFramebuffer.getColorAttachments()[0].target;
178
+ //const target = shadowMapParams.shadowMapFramebuffer.getColorAttachments()[0].target;
196
179
  const shadowMapWidth = shadowMapParams.shadowMapFramebuffer.getColorAttachments()[0].width;
197
180
  const shadowMapHeight = shadowMapParams.shadowMapFramebuffer.getColorAttachments()[0].height;
198
181
  if (this._blur) {
199
182
  shadowMapParams.implData = {
200
- blurFramebuffer: TemporalCache.getFramebufferFixedSize(shadowMapWidth, shadowMapHeight, shadowMapParams.numShadowCascades, colorFormat, null, target, null, false),
201
- blurFramebuffer2: TemporalCache.getFramebufferFixedSize(shadowMapWidth, shadowMapHeight, shadowMapParams.numShadowCascades, colorFormat, null, target, null, this._mipmap)
183
+ blurFramebuffer: ShadowMapper.fetchTemporalFramebuffer(true, shadowMapParams.lightType, shadowMapParams.numShadowCascades, shadowMapWidth, shadowMapHeight, colorFormat, null, false),
184
+ blurFramebuffer2: ShadowMapper.fetchTemporalFramebuffer(true, shadowMapParams.lightType, shadowMapParams.numShadowCascades, shadowMapWidth, shadowMapHeight, colorFormat, null, this._mipmap)
202
185
  };
203
186
  }
204
187
  shadowMapParams.shadowMap = this.getShadowMap(shadowMapParams);
@@ -218,11 +201,7 @@ class VSMBlitter extends Blitter {
218
201
  }
219
202
  }
220
203
  releaseTemporalResources(shadowMapParams) {
221
- const implData = shadowMapParams.implData;
222
- if (implData) {
223
- TemporalCache.releaseFramebuffer(implData.blurFramebuffer);
224
- TemporalCache.releaseFramebuffer(implData.blurFramebuffer2);
225
- }
204
+ return;
226
205
  }
227
206
  getShaderHash() {
228
207
  return '';
@@ -1 +1 @@
1
- {"version":3,"file":"vsm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"vsm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,116 @@
1
+ class DracoMeshDecoder {
2
+ _module;
3
+ _decoder;
4
+ _mesh;
5
+ constructor(data, decoderModule){
6
+ this._module = decoderModule;
7
+ this._decoder = new this._module.Decoder();
8
+ const buffer = new this._module.DecoderBuffer();
9
+ buffer.Init(data, data.byteLength);
10
+ const geometryType = this._decoder.GetEncodedGeometryType(buffer);
11
+ if (geometryType !== this._module.TRIANGULAR_MESH) {
12
+ this._module.destroy(buffer);
13
+ this._module.destroy(this._decoder);
14
+ this._decoder = null;
15
+ throw new Error(`Unsupported geometry type: ${geometryType}`);
16
+ }
17
+ this._mesh = new this._module.Mesh();
18
+ const status = this._decoder.DecodeBufferToMesh(buffer, this._mesh);
19
+ this._module.destroy(buffer);
20
+ if (!status.ok() || this._mesh.ptr === 0) {
21
+ this._module.destroy(this._decoder);
22
+ this._decoder = null;
23
+ this._module.destroy(this._mesh);
24
+ this._mesh = null;
25
+ throw new Error(status.error_msg());
26
+ }
27
+ }
28
+ getIndexBuffer() {
29
+ if (!this._decoder || !this._mesh) {
30
+ return null;
31
+ }
32
+ const numFaces = this._mesh.num_faces();
33
+ const numIndices = numFaces * 3;
34
+ // Uint32
35
+ const indexBuffer = new Uint32Array(numIndices);
36
+ const ptr = this._module._malloc(indexBuffer.byteLength);
37
+ this._decoder.GetTrianglesUInt32Array(this._mesh, indexBuffer.byteLength, ptr);
38
+ const tmpBuffer = new Uint32Array(this._module.HEAPU32.buffer, ptr, numIndices);
39
+ indexBuffer.set(tmpBuffer);
40
+ this._module._free(ptr);
41
+ return indexBuffer;
42
+ }
43
+ getAttributeBuffer(id, buffer) {
44
+ if (!this._decoder || !this._mesh) {
45
+ return null;
46
+ }
47
+ const attribute = this._decoder.GetAttributeByUniqueId(this._mesh, id);
48
+ if (!attribute) {
49
+ return null;
50
+ }
51
+ const numComponents = attribute.num_components();
52
+ const numPoints = this._mesh.num_points();
53
+ const numValues = numPoints * numComponents;
54
+ if (buffer.length !== numValues) {
55
+ console.error(`getAttributeBuffer(): buffer length must be ${numValues}`);
56
+ return null;
57
+ }
58
+ const ptr = this._module._malloc(buffer.byteLength);
59
+ this._decoder.GetAttributeDataArrayForAllPoints(this._mesh, attribute, this.getDracoDataType(buffer), buffer.byteLength, ptr);
60
+ const tmpBuffer = new buffer.constructor(this.getDracoHeap(buffer).buffer, ptr, numValues);
61
+ buffer.set(tmpBuffer);
62
+ this._module._free(ptr);
63
+ return buffer;
64
+ }
65
+ getDracoDataType(buffer) {
66
+ if (buffer instanceof Float32Array) {
67
+ return this._module.DT_FLOAT32;
68
+ }
69
+ if (buffer instanceof Int8Array) {
70
+ return this._module.DT_INT8;
71
+ }
72
+ if (buffer instanceof Int16Array) {
73
+ return this._module.DT_INT16;
74
+ }
75
+ if (buffer instanceof Int32Array) {
76
+ return this._module.DT_INT32;
77
+ }
78
+ if (buffer instanceof Uint8Array) {
79
+ return this._module.DT_UINT8;
80
+ }
81
+ if (buffer instanceof Uint16Array) {
82
+ return this._module.DT_UINT16;
83
+ }
84
+ if (buffer instanceof Uint32Array) {
85
+ return this._module.DT_UINT32;
86
+ }
87
+ throw new Error(`getDracoDataType(): invalid buffer type`);
88
+ }
89
+ getDracoHeap(buffer) {
90
+ if (buffer instanceof Float32Array) {
91
+ return this._module.HEAPF32;
92
+ }
93
+ if (buffer instanceof Int8Array) {
94
+ return this._module.HEAP8;
95
+ }
96
+ if (buffer instanceof Int16Array) {
97
+ return this._module.HEAP16;
98
+ }
99
+ if (buffer instanceof Int32Array) {
100
+ return this._module.HEAP32;
101
+ }
102
+ if (buffer instanceof Uint8Array) {
103
+ return this._module.HEAPU8;
104
+ }
105
+ if (buffer instanceof Uint16Array) {
106
+ return this._module.HEAPU16;
107
+ }
108
+ if (buffer instanceof Uint32Array) {
109
+ return this._module.HEAPU32;
110
+ }
111
+ throw new Error(`getDracoHeap(): invalid buffer type`);
112
+ }
113
+ }
114
+
115
+ export { DracoMeshDecoder };
116
+ //# sourceMappingURL=decoder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decoder.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,196 @@
1
+ import { Vector3, Vector2 } from '@zephyr3d/base';
2
+ import { Application } from '../app.js';
3
+
4
+ const bits = new Uint32Array(1);
5
+ //Van der Corput radical inverse
6
+ function radicalInverse_VdC(i) {
7
+ bits[0] = i;
8
+ bits[0] = (bits[0] << 16 | bits[0] >> 16) >>> 0;
9
+ bits[0] = (bits[0] & 0x55555555) << 1 | (bits[0] & 0xaaaaaaaa) >>> 1 >>> 0;
10
+ bits[0] = (bits[0] & 0x33333333) << 2 | (bits[0] & 0xcccccccc) >>> 2 >>> 0;
11
+ bits[0] = (bits[0] & 0x0f0f0f0f) << 4 | (bits[0] & 0xf0f0f0f0) >>> 4 >>> 0;
12
+ bits[0] = (bits[0] & 0x00ff00ff) << 8 | (bits[0] & 0xff00ff00) >>> 8 >>> 0;
13
+ return bits[0] * 2.3283064365386963e-10; // / 0x100000000 or / 4294967296
14
+ }
15
+ function hammersley(i, iN, out) {
16
+ out.setXY(i * iN, radicalInverse_VdC(i));
17
+ }
18
+ function distributionCharlie(NdotH, roughness) {
19
+ // roughness = Math.max(roughness, 0.000001);
20
+ const invAlpha = 1 / roughness;
21
+ const cos2h = NdotH * NdotH;
22
+ const sin2h = 1 - cos2h;
23
+ return (2 + invAlpha) * Math.pow(sin2h, invAlpha * 0.5) / (2 * Math.PI);
24
+ }
25
+ function visibilityAshikhmin(NdotV, NdotL) {
26
+ return Math.min(Math.max(1 / (4 * (NdotL + NdotV - NdotL * NdotV)), 0), 1);
27
+ }
28
+ function hemisphereUniformSample(u, out) {
29
+ const phi = 2 * Math.PI * u.x;
30
+ const cosTheta = 1 - u.y;
31
+ const sinTheta = Math.sqrt(1 - cosTheta * cosTheta);
32
+ out.setXYZ(sinTheta * Math.cos(phi), sinTheta * Math.sin(phi), cosTheta);
33
+ }
34
+ function dfvCharlieUniform(NdotV, roughness, numSamples) {
35
+ let r = 0;
36
+ const V = new Vector3(Math.sqrt(1 - NdotV * NdotV), 0, NdotV);
37
+ const u = new Vector2();
38
+ const H = new Vector3();
39
+ const L = new Vector3();
40
+ for(let i = 0; i < numSamples; i++){
41
+ hammersley(i, 1 / numSamples, u);
42
+ hemisphereUniformSample(u, H);
43
+ Vector3.scale(H, Vector3.dot(V, H) * 2, L).subBy(V);
44
+ const VdotH = Math.min(Math.max(Vector3.dot(V, H), 0), 1);
45
+ const NdotL = Math.min(Math.max(L.z, 0), 1);
46
+ const NdotH = Math.min(Math.max(H.z, 0), 1);
47
+ if (NdotL > 0) {
48
+ const v = visibilityAshikhmin(NdotV, NdotL);
49
+ // const v = visibilityCharlie(NdotV, NdotL, roughness);
50
+ const d = distributionCharlie(NdotH, roughness);
51
+ r += v * d * NdotL * VdotH;
52
+ }
53
+ }
54
+ return r * (4 * 2 * Math.PI / numSamples);
55
+ }
56
+ const _tables = function _generateTables() {
57
+ // float32 to float16 helpers
58
+ const buffer = new ArrayBuffer(4);
59
+ const floatView = new Float32Array(buffer);
60
+ const uint32View = new Uint32Array(buffer);
61
+ const baseTable = new Uint32Array(512);
62
+ const shiftTable = new Uint32Array(512);
63
+ for(let i = 0; i < 256; ++i){
64
+ const e = i - 127;
65
+ // very small number (0, -0)
66
+ if (e < -27) {
67
+ baseTable[i] = 0x0000;
68
+ baseTable[i | 0x100] = 0x8000;
69
+ shiftTable[i] = 24;
70
+ shiftTable[i | 0x100] = 24;
71
+ // small number (denorm)
72
+ } else if (e < -14) {
73
+ baseTable[i] = 0x0400 >> -e - 14;
74
+ baseTable[i | 0x100] = 0x0400 >> -e - 14 | 0x8000;
75
+ shiftTable[i] = -e - 1;
76
+ shiftTable[i | 0x100] = -e - 1;
77
+ // normal number
78
+ } else if (e <= 15) {
79
+ baseTable[i] = e + 15 << 10;
80
+ baseTable[i | 0x100] = e + 15 << 10 | 0x8000;
81
+ shiftTable[i] = 13;
82
+ shiftTable[i | 0x100] = 13;
83
+ // large number (Infinity, -Infinity)
84
+ } else if (e < 128) {
85
+ baseTable[i] = 0x7c00;
86
+ baseTable[i | 0x100] = 0xfc00;
87
+ shiftTable[i] = 24;
88
+ shiftTable[i | 0x100] = 24;
89
+ // stay (NaN, Infinity, -Infinity)
90
+ } else {
91
+ baseTable[i] = 0x7c00;
92
+ baseTable[i | 0x100] = 0xfc00;
93
+ shiftTable[i] = 13;
94
+ shiftTable[i | 0x100] = 13;
95
+ }
96
+ }
97
+ // float16 to float32 helpers
98
+ const mantissaTable = new Uint32Array(2048);
99
+ const exponentTable = new Uint32Array(64);
100
+ const offsetTable = new Uint32Array(64);
101
+ for(let i = 1; i < 1024; ++i){
102
+ let m = i << 13; // zero pad mantissa bits
103
+ let e = 0; // zero exponent
104
+ // normalized
105
+ while((m & 0x00800000) === 0){
106
+ m <<= 1;
107
+ e -= 0x00800000; // decrement exponent
108
+ }
109
+ m &= ~0x00800000; // clear leading 1 bit
110
+ e += 0x38800000; // adjust bias
111
+ mantissaTable[i] = m | e;
112
+ }
113
+ for(let i = 1024; i < 2048; ++i){
114
+ mantissaTable[i] = 0x38000000 + (i - 1024 << 13);
115
+ }
116
+ for(let i = 1; i < 31; ++i){
117
+ exponentTable[i] = i << 23;
118
+ }
119
+ exponentTable[31] = 0x47800000;
120
+ exponentTable[32] = 0x80000000;
121
+ for(let i = 33; i < 63; ++i){
122
+ exponentTable[i] = 0x80000000 + (i - 32 << 23);
123
+ }
124
+ exponentTable[63] = 0xc7800000;
125
+ for(let i = 1; i < 64; ++i){
126
+ if (i !== 32) {
127
+ offsetTable[i] = 1024;
128
+ }
129
+ }
130
+ return {
131
+ floatView: floatView,
132
+ uint32View: uint32View,
133
+ baseTable: baseTable,
134
+ shiftTable: shiftTable,
135
+ mantissaTable: mantissaTable,
136
+ exponentTable: exponentTable,
137
+ offsetTable: offsetTable
138
+ };
139
+ }();
140
+ function encodeF16(val) {
141
+ val = Math.min(Math.max(val, -65504), 65504);
142
+ _tables.floatView[0] = val;
143
+ const f = _tables.uint32View[0];
144
+ const e = f >> 23 & 0x1ff;
145
+ return _tables.baseTable[e] + ((f & 0x007fffff) >> _tables.shiftTable[e]);
146
+ }
147
+ /*
148
+ function decodeF16(val: number) {
149
+ const exponent = (val & 0x7c00) >> 10;
150
+ const fraction = val & 0x03ff;
151
+ return (
152
+ (val >> 15 ? -1 : 1) *
153
+ (exponent
154
+ ? exponent === 0x1f
155
+ ? fraction
156
+ ? NaN
157
+ : Infinity
158
+ : Math.pow(2, exponent - 15) * (1 + fraction / 0x400)
159
+ : 6.103515625e-5 * (fraction / 0x400))
160
+ );
161
+ }
162
+ */ async function createSheenLUT(textureSize, texture) {
163
+ if (texture) {
164
+ if (!texture.isTexture2D()) {
165
+ throw new Error('can not reload sheen lut texture: invalid texture type');
166
+ }
167
+ if (texture.format !== 'rgba16f') {
168
+ throw new Error('can not reload sheen lut texture: invalid texture format');
169
+ }
170
+ if (texture.width !== textureSize || texture.height !== textureSize) {
171
+ throw new Error('can not reload sheen lut texture: invalid texture size');
172
+ }
173
+ }
174
+ const tex = texture || Application.instance.device.createTexture2D('rgba16f', textureSize, textureSize);
175
+ const image = new Uint16Array(textureSize * textureSize * 4);
176
+ let p = 0;
177
+ const one = encodeF16(1);
178
+ for(let y = textureSize - 1; y >= 0; y--){
179
+ const coord = Math.min(Math.max((y + 0.5) / textureSize, 0), 1);
180
+ const roughness = coord * coord;
181
+ for(let x = 0; x < textureSize; x++){
182
+ const NdotV = Math.min(Math.max((x + 0.5) / textureSize, 0), 1);
183
+ const c = dfvCharlieUniform(NdotV, roughness, 512);
184
+ const f16 = encodeF16(c);
185
+ image[p++] = 0;
186
+ image[p++] = 0;
187
+ image[p++] = f16;
188
+ image[p++] = one;
189
+ }
190
+ }
191
+ tex.update(image, 0, 0, textureSize, textureSize);
192
+ return tex;
193
+ }
194
+
195
+ export { createSheenLUT };
196
+ //# sourceMappingURL=sheenlut.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sheenlut.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/values.js CHANGED
@@ -10,6 +10,10 @@
10
10
  * Depth only render pass type
11
11
  * @public
12
12
  */ const RENDER_PASS_TYPE_DEPTH = 2;
13
+ /**
14
+ * Object color render pass type
15
+ * @public
16
+ */ const RENDER_PASS_TYPE_OBJECT_COLOR = 3;
13
17
  /**
14
18
  * Builtin texture name for sheen LUT
15
19
  * @public
@@ -46,6 +50,19 @@
46
50
  * Transparent render queue type
47
51
  * @public
48
52
  */ const QUEUE_TRANSPARENT = 2;
53
+ // Morph target attributes
54
+ /** @internal */ const MORPH_TARGET_POSITION = 0;
55
+ /** @internal */ const MORPH_TARGET_NORMAL = 1;
56
+ /** @internal */ const MORPH_TARGET_TANGENT = 2;
57
+ /** @internal */ const MORPH_TARGET_COLOR = 3;
58
+ /** @internal */ const MORPH_TARGET_TEX0 = 4;
59
+ /** @internal */ const MORPH_TARGET_TEX1 = 5;
60
+ /** @internal */ const MORPH_TARGET_TEX2 = 6;
61
+ /** @internal */ const MORPH_TARGET_TEX3 = 7;
62
+ /** @internal */ const MAX_MORPH_ATTRIBUTES = 8;
63
+ /** @internal */ const MAX_MORPH_TARGETS = 256;
64
+ /** @internal */ const MORPH_WEIGHTS_VECTOR_COUNT = MAX_MORPH_TARGETS + 3 >> 2;
65
+ /** @internal */ const MORPH_ATTRIBUTE_VECTOR_COUNT = MAX_MORPH_ATTRIBUTES + 3 >> 2;
49
66
 
50
- export { BUILTIN_ASSET_TEST_CUBEMAP, BUILTIN_ASSET_TEXTURE_SHEEN_LUT, LIGHT_TYPE_DIRECTIONAL, LIGHT_TYPE_NONE, LIGHT_TYPE_POINT, LIGHT_TYPE_SPOT, MAX_CLUSTERED_LIGHTS, QUEUE_OPAQUE, QUEUE_TRANSPARENT, RENDER_PASS_TYPE_DEPTH, RENDER_PASS_TYPE_LIGHT, RENDER_PASS_TYPE_SHADOWMAP };
67
+ export { BUILTIN_ASSET_TEST_CUBEMAP, BUILTIN_ASSET_TEXTURE_SHEEN_LUT, LIGHT_TYPE_DIRECTIONAL, LIGHT_TYPE_NONE, LIGHT_TYPE_POINT, LIGHT_TYPE_SPOT, MAX_CLUSTERED_LIGHTS, MAX_MORPH_ATTRIBUTES, MAX_MORPH_TARGETS, MORPH_ATTRIBUTE_VECTOR_COUNT, MORPH_TARGET_COLOR, MORPH_TARGET_NORMAL, MORPH_TARGET_POSITION, MORPH_TARGET_TANGENT, MORPH_TARGET_TEX0, MORPH_TARGET_TEX1, MORPH_TARGET_TEX2, MORPH_TARGET_TEX3, MORPH_WEIGHTS_VECTOR_COUNT, QUEUE_OPAQUE, QUEUE_TRANSPARENT, RENDER_PASS_TYPE_DEPTH, RENDER_PASS_TYPE_LIGHT, RENDER_PASS_TYPE_OBJECT_COLOR, RENDER_PASS_TYPE_SHADOWMAP };
51
68
  //# sourceMappingURL=values.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"values.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"values.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}