@zephyr3d/scene 0.1.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 (236) hide show
  1. package/dist/animation/animation.js +173 -0
  2. package/dist/animation/animation.js.map +1 -0
  3. package/dist/animation/animationset.js +95 -0
  4. package/dist/animation/animationset.js.map +1 -0
  5. package/dist/animation/animationtrack.js +38 -0
  6. package/dist/animation/animationtrack.js.map +1 -0
  7. package/dist/animation/eulerrotationtrack.js +33 -0
  8. package/dist/animation/eulerrotationtrack.js.map +1 -0
  9. package/dist/animation/rotationtrack.js +37 -0
  10. package/dist/animation/rotationtrack.js.map +1 -0
  11. package/dist/animation/scaletrack.js +36 -0
  12. package/dist/animation/scaletrack.js.map +1 -0
  13. package/dist/animation/skeleton.js +97 -0
  14. package/dist/animation/skeleton.js.map +1 -0
  15. package/dist/animation/translationtrack.js +36 -0
  16. package/dist/animation/translationtrack.js.map +1 -0
  17. package/dist/animation/usertrack.js +47 -0
  18. package/dist/animation/usertrack.js.map +1 -0
  19. package/dist/app.js +173 -0
  20. package/dist/app.js.map +1 -0
  21. package/dist/asset/assetmanager.js +476 -0
  22. package/dist/asset/assetmanager.js.map +1 -0
  23. package/dist/asset/builtin.js +373 -0
  24. package/dist/asset/builtin.js.map +1 -0
  25. package/dist/asset/loaders/dds/dds.js +472 -0
  26. package/dist/asset/loaders/dds/dds.js.map +1 -0
  27. package/dist/asset/loaders/dds/dds_loader.js +38 -0
  28. package/dist/asset/loaders/dds/dds_loader.js.map +1 -0
  29. package/dist/asset/loaders/gltf/gltf_loader.js +981 -0
  30. package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -0
  31. package/dist/asset/loaders/gltf/helpers.js +314 -0
  32. package/dist/asset/loaders/gltf/helpers.js.map +1 -0
  33. package/dist/asset/loaders/hdr/hdr.js +175 -0
  34. package/dist/asset/loaders/hdr/hdr.js.map +1 -0
  35. package/dist/asset/loaders/image/tga_Loader.js +117 -0
  36. package/dist/asset/loaders/image/tga_Loader.js.map +1 -0
  37. package/dist/asset/loaders/image/webimage_loader.js +50 -0
  38. package/dist/asset/loaders/image/webimage_loader.js.map +1 -0
  39. package/dist/asset/loaders/loader.js +45 -0
  40. package/dist/asset/loaders/loader.js.map +1 -0
  41. package/dist/asset/model.js +264 -0
  42. package/dist/asset/model.js.map +1 -0
  43. package/dist/blitter/blitter.js +389 -0
  44. package/dist/blitter/blitter.js.map +1 -0
  45. package/dist/blitter/box.js +118 -0
  46. package/dist/blitter/box.js.map +1 -0
  47. package/dist/blitter/copy.js +22 -0
  48. package/dist/blitter/copy.js.map +1 -0
  49. package/dist/blitter/depthlimitedgaussion.js +166 -0
  50. package/dist/blitter/depthlimitedgaussion.js.map +1 -0
  51. package/dist/blitter/gaussianblur.js +229 -0
  52. package/dist/blitter/gaussianblur.js.map +1 -0
  53. package/dist/camera/base.js +90 -0
  54. package/dist/camera/base.js.map +1 -0
  55. package/dist/camera/camera.js +358 -0
  56. package/dist/camera/camera.js.map +1 -0
  57. package/dist/camera/fps.js +246 -0
  58. package/dist/camera/fps.js.map +1 -0
  59. package/dist/camera/orbit.js +157 -0
  60. package/dist/camera/orbit.js.map +1 -0
  61. package/dist/camera/orthocamera.js +126 -0
  62. package/dist/camera/orthocamera.js.map +1 -0
  63. package/dist/camera/perspectivecamera.js +133 -0
  64. package/dist/camera/perspectivecamera.js.map +1 -0
  65. package/dist/index.d.ts +8402 -0
  66. package/dist/index.js +87 -0
  67. package/dist/index.js.map +1 -0
  68. package/dist/input/inputmgr.js +242 -0
  69. package/dist/input/inputmgr.js.map +1 -0
  70. package/dist/material/blinn.js +75 -0
  71. package/dist/material/blinn.js.map +1 -0
  72. package/dist/material/grassmaterial.js +221 -0
  73. package/dist/material/grassmaterial.js.map +1 -0
  74. package/dist/material/lambert.js +52 -0
  75. package/dist/material/lambert.js.map +1 -0
  76. package/dist/material/lightmodel.js +2074 -0
  77. package/dist/material/lightmodel.js.map +1 -0
  78. package/dist/material/lit.js +578 -0
  79. package/dist/material/lit.js.map +1 -0
  80. package/dist/material/material.js +458 -0
  81. package/dist/material/material.js.map +1 -0
  82. package/dist/material/meshmaterial.js +311 -0
  83. package/dist/material/meshmaterial.js.map +1 -0
  84. package/dist/material/mixins/albedocolor.js +130 -0
  85. package/dist/material/mixins/albedocolor.js.map +1 -0
  86. package/dist/material/mixins/texture.js +110 -0
  87. package/dist/material/mixins/texture.js.map +1 -0
  88. package/dist/material/mixins/vertexcolor.js +45 -0
  89. package/dist/material/mixins/vertexcolor.js.map +1 -0
  90. package/dist/material/pbr.js +27 -0
  91. package/dist/material/pbr.js.map +1 -0
  92. package/dist/material/standard.js +282 -0
  93. package/dist/material/standard.js.map +1 -0
  94. package/dist/material/terrainlightmodel.js +259 -0
  95. package/dist/material/terrainlightmodel.js.map +1 -0
  96. package/dist/material/terrainmaterial.js +139 -0
  97. package/dist/material/terrainmaterial.js.map +1 -0
  98. package/dist/material/unlit.js +29 -0
  99. package/dist/material/unlit.js.map +1 -0
  100. package/dist/posteffect/bloom.js +398 -0
  101. package/dist/posteffect/bloom.js.map +1 -0
  102. package/dist/posteffect/compositor.js +264 -0
  103. package/dist/posteffect/compositor.js.map +1 -0
  104. package/dist/posteffect/fxaa.js +291 -0
  105. package/dist/posteffect/fxaa.js.map +1 -0
  106. package/dist/posteffect/grayscale.js +87 -0
  107. package/dist/posteffect/grayscale.js.map +1 -0
  108. package/dist/posteffect/posteffect.js +165 -0
  109. package/dist/posteffect/posteffect.js.map +1 -0
  110. package/dist/posteffect/sao.js +327 -0
  111. package/dist/posteffect/sao.js.map +1 -0
  112. package/dist/posteffect/tonemap.js +112 -0
  113. package/dist/posteffect/tonemap.js.map +1 -0
  114. package/dist/posteffect/water.js +535 -0
  115. package/dist/posteffect/water.js.map +1 -0
  116. package/dist/render/clipmap.js +462 -0
  117. package/dist/render/clipmap.js.map +1 -0
  118. package/dist/render/cluster_light.js +329 -0
  119. package/dist/render/cluster_light.js.map +1 -0
  120. package/dist/render/cull_visitor.js +124 -0
  121. package/dist/render/cull_visitor.js.map +1 -0
  122. package/dist/render/depth_pass.js +47 -0
  123. package/dist/render/depth_pass.js.map +1 -0
  124. package/dist/render/envlight.js +282 -0
  125. package/dist/render/envlight.js.map +1 -0
  126. package/dist/render/forward.js +186 -0
  127. package/dist/render/forward.js.map +1 -0
  128. package/dist/render/forward_pass.js +137 -0
  129. package/dist/render/forward_pass.js.map +1 -0
  130. package/dist/render/helper.js +38 -0
  131. package/dist/render/helper.js.map +1 -0
  132. package/dist/render/primitive.js +246 -0
  133. package/dist/render/primitive.js.map +1 -0
  134. package/dist/render/render_queue.js +163 -0
  135. package/dist/render/render_queue.js.map +1 -0
  136. package/dist/render/renderpass.js +151 -0
  137. package/dist/render/renderpass.js.map +1 -0
  138. package/dist/render/renderscheme.js +61 -0
  139. package/dist/render/renderscheme.js.map +1 -0
  140. package/dist/render/scatteringlut.js +634 -0
  141. package/dist/render/scatteringlut.js.map +1 -0
  142. package/dist/render/shadowmap_pass.js +70 -0
  143. package/dist/render/shadowmap_pass.js.map +1 -0
  144. package/dist/render/sky.js +881 -0
  145. package/dist/render/sky.js.map +1 -0
  146. package/dist/render/temporalcache.js +222 -0
  147. package/dist/render/temporalcache.js.map +1 -0
  148. package/dist/render/watermesh.js +835 -0
  149. package/dist/render/watermesh.js.map +1 -0
  150. package/dist/scene/environment.js +146 -0
  151. package/dist/scene/environment.js.map +1 -0
  152. package/dist/scene/graph_node.js +69 -0
  153. package/dist/scene/graph_node.js.map +1 -0
  154. package/dist/scene/light.js +436 -0
  155. package/dist/scene/light.js.map +1 -0
  156. package/dist/scene/mesh.js +215 -0
  157. package/dist/scene/mesh.js.map +1 -0
  158. package/dist/scene/model.js +111 -0
  159. package/dist/scene/model.js.map +1 -0
  160. package/dist/scene/octree.js +651 -0
  161. package/dist/scene/octree.js.map +1 -0
  162. package/dist/scene/octree_update_visitor.js +16 -0
  163. package/dist/scene/octree_update_visitor.js.map +1 -0
  164. package/dist/scene/raycast_visitor.js +72 -0
  165. package/dist/scene/raycast_visitor.js.map +1 -0
  166. package/dist/scene/scene.js +225 -0
  167. package/dist/scene/scene.js.map +1 -0
  168. package/dist/scene/scene_node.js +299 -0
  169. package/dist/scene/scene_node.js.map +1 -0
  170. package/dist/scene/terrain/grass.js +277 -0
  171. package/dist/scene/terrain/grass.js.map +1 -0
  172. package/dist/scene/terrain/heightfield.js +391 -0
  173. package/dist/scene/terrain/heightfield.js.map +1 -0
  174. package/dist/scene/terrain/patch.js +530 -0
  175. package/dist/scene/terrain/patch.js.map +1 -0
  176. package/dist/scene/terrain/quadtree.js +430 -0
  177. package/dist/scene/terrain/quadtree.js.map +1 -0
  178. package/dist/scene/terrain/terrain.js +258 -0
  179. package/dist/scene/terrain/terrain.js.map +1 -0
  180. package/dist/scene/xform.js +224 -0
  181. package/dist/scene/xform.js.map +1 -0
  182. package/dist/shaders/builtins.js +110 -0
  183. package/dist/shaders/builtins.js.map +1 -0
  184. package/dist/shaders/framework.js +709 -0
  185. package/dist/shaders/framework.js.map +1 -0
  186. package/dist/shaders/lighting.js +335 -0
  187. package/dist/shaders/lighting.js.map +1 -0
  188. package/dist/shaders/misc.js +405 -0
  189. package/dist/shaders/misc.js.map +1 -0
  190. package/dist/shaders/noise.js +157 -0
  191. package/dist/shaders/noise.js.map +1 -0
  192. package/dist/shaders/pbr.js +132 -0
  193. package/dist/shaders/pbr.js.map +1 -0
  194. package/dist/shaders/shadow.js +642 -0
  195. package/dist/shaders/shadow.js.map +1 -0
  196. package/dist/shaders/water.js +630 -0
  197. package/dist/shaders/water.js.map +1 -0
  198. package/dist/shadow/esm.js +235 -0
  199. package/dist/shadow/esm.js.map +1 -0
  200. package/dist/shadow/pcf_opt.js +182 -0
  201. package/dist/shadow/pcf_opt.js.map +1 -0
  202. package/dist/shadow/pcf_pd.js +190 -0
  203. package/dist/shadow/pcf_pd.js.map +1 -0
  204. package/dist/shadow/shadow_impl.js +15 -0
  205. package/dist/shadow/shadow_impl.js.map +1 -0
  206. package/dist/shadow/shadowmapper.js +709 -0
  207. package/dist/shadow/shadowmapper.js.map +1 -0
  208. package/dist/shadow/ssm.js +194 -0
  209. package/dist/shadow/ssm.js.map +1 -0
  210. package/dist/shadow/vsm.js +298 -0
  211. package/dist/shadow/vsm.js.map +1 -0
  212. package/dist/shapes/box.js +313 -0
  213. package/dist/shapes/box.js.map +1 -0
  214. package/dist/shapes/cylinder.js +74 -0
  215. package/dist/shapes/cylinder.js.map +1 -0
  216. package/dist/shapes/plane.js +48 -0
  217. package/dist/shapes/plane.js.map +1 -0
  218. package/dist/shapes/shape.js +33 -0
  219. package/dist/shapes/shape.js.map +1 -0
  220. package/dist/shapes/sphere.js +91 -0
  221. package/dist/shapes/sphere.js.map +1 -0
  222. package/dist/shapes/torus.js +100 -0
  223. package/dist/shapes/torus.js.map +1 -0
  224. package/dist/utility/aabbtree.js +390 -0
  225. package/dist/utility/aabbtree.js.map +1 -0
  226. package/dist/utility/bounding_volume.js +78 -0
  227. package/dist/utility/bounding_volume.js.map +1 -0
  228. package/dist/utility/panorama.js +163 -0
  229. package/dist/utility/panorama.js.map +1 -0
  230. package/dist/utility/pmrem.js +345 -0
  231. package/dist/utility/pmrem.js.map +1 -0
  232. package/dist/utility/shprojection.js +448 -0
  233. package/dist/utility/shprojection.js.map +1 -0
  234. package/dist/values.js +48 -0
  235. package/dist/values.js.map +1 -0
  236. package/package.json +70 -0
@@ -0,0 +1,235 @@
1
+ import { ShadowImpl } from './shadow_impl.js';
2
+ import '@zephyr3d/base';
3
+ import { Application } from '../app.js';
4
+ import { ShaderFramework } from '../shaders/framework.js';
5
+ import { decodeNormalizedFloatFromRGBA, encodeNormalizedFloatToRGBA } from '../shaders/misc.js';
6
+ import { GaussianBlurBlitter } from '../blitter/gaussianblur.js';
7
+ import { computeShadowMapDepth, filterShadowESM } from '../shaders/shadow.js';
8
+ import '../scene/octree.js';
9
+ import { LIGHT_TYPE_POINT } from '../values.js';
10
+ import '../material/material.js';
11
+ import '@zephyr3d/device';
12
+ import '../render/scatteringlut.js';
13
+ import '../material/lambert.js';
14
+ import '../material/blinn.js';
15
+ import '../material/unlit.js';
16
+ import '../material/lightmodel.js';
17
+ import '../render/forward.js';
18
+ import '../render/sky.js';
19
+ import '../render/clipmap.js';
20
+ import { TemporalCache } from '../render/temporalcache.js';
21
+ import '../render/watermesh.js';
22
+
23
+ class BlurBlitter extends GaussianBlurBlitter {
24
+ _packFloat;
25
+ get packFloat() {
26
+ return this._packFloat;
27
+ }
28
+ set packFloat(b) {
29
+ if (this._packFloat !== !!b) {
30
+ this._packFloat = !!b;
31
+ this.invalidateHash();
32
+ }
33
+ }
34
+ readTexel(scope, type, srcTex, srcUV, srcLayer, sampleType) {
35
+ const pb = scope.$builder;
36
+ const texel = super.readTexel(scope, type, srcTex, srcUV, srcLayer, sampleType);
37
+ if (this.packFloat) {
38
+ return pb.vec4(decodeNormalizedFloatFromRGBA(scope, texel), 0, 0, 1);
39
+ } else {
40
+ return texel;
41
+ }
42
+ }
43
+ writeTexel(scope, type, srcUV, texel) {
44
+ const outTexel = super.writeTexel(scope, type, srcUV, texel);
45
+ if (this.packFloat) {
46
+ return encodeNormalizedFloatToRGBA(scope, outTexel.r);
47
+ } else {
48
+ return outTexel;
49
+ }
50
+ }
51
+ calcHash() {
52
+ return `${super.calcHash()}-${Number(this.packFloat)}`;
53
+ }
54
+ }
55
+ /** @internal */ class ESM extends ShadowImpl {
56
+ /** @internal */ _depthScale;
57
+ /** @internal */ _blur;
58
+ /** @internal */ _kernelSize;
59
+ /** @internal */ _blurSize;
60
+ /** @internal */ _logSpace;
61
+ /** @internal */ _blitterH;
62
+ /** @internal */ _blitterV;
63
+ /** @internal */ _mipmap;
64
+ constructor(kernelSize, blurSize, depthScale){
65
+ super();
66
+ this._blur = true;
67
+ this._depthScale = depthScale ?? 500;
68
+ this._kernelSize = kernelSize ?? 5;
69
+ this._blurSize = blurSize ?? 1;
70
+ this._logSpace = true;
71
+ this._mipmap = true;
72
+ this._blitterH = new BlurBlitter('horizonal', this._kernelSize, 4, 1 / 1024);
73
+ this._blitterV = new BlurBlitter('vertical', this._kernelSize, 4, 1 / 1024);
74
+ }
75
+ resourceDirty() {
76
+ return this._resourceDirty;
77
+ }
78
+ get blur() {
79
+ return this._blur;
80
+ }
81
+ set blur(val) {
82
+ if (this._blur !== !!val) {
83
+ this._blur = !!val;
84
+ this._resourceDirty = true;
85
+ }
86
+ }
87
+ get mipmap() {
88
+ return this._mipmap;
89
+ }
90
+ set mipmap(b) {
91
+ if (this._mipmap !== !!b) {
92
+ this._mipmap = !!b;
93
+ if (this._blur) {
94
+ this._resourceDirty = true;
95
+ }
96
+ }
97
+ }
98
+ get kernelSize() {
99
+ return this._kernelSize;
100
+ }
101
+ set kernelSize(val) {
102
+ this._kernelSize = val;
103
+ }
104
+ get blurSize() {
105
+ return this._blurSize;
106
+ }
107
+ set blurSize(val) {
108
+ this._blurSize = val;
109
+ }
110
+ get logSpace() {
111
+ return this._logSpace;
112
+ }
113
+ set logSpace(val) {
114
+ this._logSpace = !!val;
115
+ }
116
+ getType() {
117
+ return 'esm';
118
+ }
119
+ getShadowMapBorder(shadowMapParams) {
120
+ return this._blur ? Math.ceil((this._kernelSize + 1) / 2 * this._blurSize) : 0;
121
+ }
122
+ getShadowMap(shadowMapParams) {
123
+ const implData = shadowMapParams.implData;
124
+ return implData ? implData.blurFramebuffer2.getColorAttachments()[0] : shadowMapParams.shadowMapFramebuffer.getColorAttachments()[0];
125
+ }
126
+ doUpdateResources(shadowMapParams) {
127
+ const implData = {
128
+ blurFramebuffer: null,
129
+ blurFramebuffer2: null
130
+ };
131
+ shadowMapParams.implData = implData;
132
+ const colorFormat = this.getShadowMapColorFormat(shadowMapParams);
133
+ const target = shadowMapParams.shadowMapFramebuffer.getColorAttachments()[0].target;
134
+ const shadowMapWidth = shadowMapParams.shadowMapFramebuffer.getColorAttachments()[0].width;
135
+ const shadowMapHeight = shadowMapParams.shadowMapFramebuffer.getColorAttachments()[0].height;
136
+ if (this._blur) {
137
+ shadowMapParams.implData = {
138
+ blurFramebuffer: TemporalCache.getFramebufferFixedSize(shadowMapWidth, shadowMapHeight, shadowMapParams.numShadowCascades, colorFormat, null, target, null, false),
139
+ blurFramebuffer2: TemporalCache.getFramebufferFixedSize(shadowMapWidth, shadowMapHeight, shadowMapParams.numShadowCascades, colorFormat, null, target, null, this._mipmap)
140
+ };
141
+ }
142
+ shadowMapParams.shadowMap = this.getShadowMap(shadowMapParams);
143
+ shadowMapParams.shadowMapSampler = shadowMapParams.shadowMap?.getDefaultSampler(false) ?? null;
144
+ }
145
+ postRenderShadowMap(shadowMapParams) {
146
+ if (shadowMapParams.implData) {
147
+ const implData = shadowMapParams.implData;
148
+ const colorAttachment = shadowMapParams.shadowMapFramebuffer.getColorAttachments()[0];
149
+ this._blitterH.blurSize = this._blurSize / colorAttachment.width;
150
+ this._blitterH.kernelSize = this._kernelSize;
151
+ this._blitterH.logSpace = this._logSpace;
152
+ this._blitterH.packFloat = colorAttachment.format === 'rgba8unorm';
153
+ this._blitterV.blurSize = this._blurSize / colorAttachment.height;
154
+ this._blitterV.kernelSize = this._kernelSize;
155
+ this._blitterV.logSpace = this._logSpace;
156
+ this._blitterV.packFloat = colorAttachment.format === 'rgba8unorm';
157
+ this._blitterH.blit(colorAttachment, implData.blurFramebuffer);
158
+ this._blitterV.blit(implData.blurFramebuffer.getColorAttachments()[0], implData.blurFramebuffer2);
159
+ }
160
+ }
161
+ releaseTemporalResources(shadowMapParams) {
162
+ const implData = shadowMapParams.implData;
163
+ if (implData) {
164
+ TemporalCache.releaseFramebuffer(implData.blurFramebuffer);
165
+ TemporalCache.releaseFramebuffer(implData.blurFramebuffer2);
166
+ }
167
+ }
168
+ getDepthScale() {
169
+ return this._depthScale;
170
+ }
171
+ setDepthScale(val) {
172
+ this._depthScale = val;
173
+ }
174
+ getShaderHash() {
175
+ return '';
176
+ }
177
+ getShadowMapColorFormat(shadowMapParams) {
178
+ const device = Application.instance.device;
179
+ return device.getDeviceCaps().textureCaps.supportHalfFloatColorBuffer ? device.type === 'webgl' ? 'rgba16f' : 'r16f' : device.getDeviceCaps().textureCaps.supportFloatColorBuffer ? device.type === 'webgl' ? 'rgba32f' : 'r32f' : 'rgba8unorm';
180
+ }
181
+ getShadowMapDepthFormat(shadowMapParams) {
182
+ return 'd24s8';
183
+ }
184
+ computeShadowMapDepth(shadowMapParams, scope) {
185
+ return computeShadowMapDepth(scope, shadowMapParams.shadowMap.format);
186
+ }
187
+ computeShadowCSM(shadowMapParams, scope, shadowVertex, NdotL, split) {
188
+ const funcNameComputeShadowCSM = 'lib_computeShadowCSM';
189
+ const pb = scope.$builder;
190
+ pb.func(funcNameComputeShadowCSM, [
191
+ pb.vec4('shadowVertex'),
192
+ pb.float('NdotL'),
193
+ pb.int('split')
194
+ ], function() {
195
+ this.$l.shadowCoord = pb.div(this.shadowVertex, this.shadowVertex.w);
196
+ this.$l.shadowCoord = pb.add(pb.mul(this.shadowCoord, 0.5), 0.5);
197
+ this.$l.inShadow = pb.all(pb.bvec2(pb.all(pb.bvec4(pb.greaterThanEqual(this.shadowCoord.x, 0), pb.lessThanEqual(this.shadowCoord.x, 1), pb.greaterThanEqual(this.shadowCoord.y, 0), pb.lessThanEqual(this.shadowCoord.y, 1))), pb.lessThanEqual(this.shadowCoord.z, 1)));
198
+ this.$l.shadow = pb.float(1);
199
+ this.$if(this.inShadow, function() {
200
+ this.shadow = filterShadowESM(this, shadowMapParams.lightType, shadowMapParams.shadowMap.format, this.shadowCoord, this.split);
201
+ });
202
+ this.$return(this.shadow);
203
+ });
204
+ return pb.getGlobalScope()[funcNameComputeShadowCSM](shadowVertex, NdotL, split);
205
+ }
206
+ computeShadow(shadowMapParams, scope, shadowVertex, NdotL) {
207
+ const funcNameComputeShadow = 'lib_computeShadow';
208
+ const pb = scope.$builder;
209
+ pb.func(funcNameComputeShadow, [
210
+ pb.vec4('shadowVertex'),
211
+ pb.float('NdotL')
212
+ ], function() {
213
+ if (shadowMapParams.lightType === LIGHT_TYPE_POINT) {
214
+ this.$l.dir = pb.sub(this.shadowVertex.xyz, ShaderFramework.getLightPositionAndRangeForShadow(this).xyz);
215
+ this.$return(filterShadowESM(this, LIGHT_TYPE_POINT, shadowMapParams.shadowMap.format, this.dir));
216
+ } else {
217
+ this.$l.shadowCoord = pb.div(this.shadowVertex, this.shadowVertex.w);
218
+ this.$l.shadowCoord = pb.add(pb.mul(this.shadowCoord, 0.5), 0.5);
219
+ this.$l.inShadow = pb.all(pb.bvec2(pb.all(pb.bvec4(pb.greaterThanEqual(this.shadowCoord.x, 0), pb.lessThanEqual(this.shadowCoord.x, 1), pb.greaterThanEqual(this.shadowCoord.y, 0), pb.lessThanEqual(this.shadowCoord.y, 1))), pb.lessThanEqual(this.shadowCoord.z, 1)));
220
+ this.$l.shadow = pb.float(1);
221
+ this.$if(this.inShadow, function() {
222
+ this.shadow = filterShadowESM(this, shadowMapParams.lightType, shadowMapParams.shadowMap.format, this.shadowCoord);
223
+ });
224
+ this.$return(this.shadow);
225
+ }
226
+ });
227
+ return pb.getGlobalScope()[funcNameComputeShadow](shadowVertex, NdotL);
228
+ }
229
+ useNativeShadowMap(shadowMapParams) {
230
+ return false;
231
+ }
232
+ }
233
+
234
+ export { ESM };
235
+ //# sourceMappingURL=esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,182 @@
1
+ import { ShadowImpl } from './shadow_impl.js';
2
+ import { linearDepthToNonLinear, decodeNormalizedFloatFromRGBA } from '../shaders/misc.js';
3
+ import { computeShadowMapDepth, computeReceiverPlaneDepthBias, filterShadowPCF } from '../shaders/shadow.js';
4
+ import { ShadowMapper } from './shadowmapper.js';
5
+ import { ShaderFramework } from '../shaders/framework.js';
6
+ import { Application } from '../app.js';
7
+ import { LIGHT_TYPE_POINT } from '../values.js';
8
+
9
+ /** @internal */ class PCFOPT extends ShadowImpl {
10
+ _kernelSize;
11
+ _shadowSampler;
12
+ constructor(kernelSize){
13
+ super();
14
+ this._kernelSize = kernelSize ?? 5;
15
+ this._shadowSampler = null;
16
+ }
17
+ get kernelSize() {
18
+ return this._kernelSize;
19
+ }
20
+ set kernelSize(val) {
21
+ val = val !== 3 && val !== 5 && val !== 7 ? 5 : val;
22
+ this._kernelSize = val;
23
+ }
24
+ getType() {
25
+ return 'pcf-opt';
26
+ }
27
+ dispose() {
28
+ this._shadowSampler = null;
29
+ }
30
+ resourceDirty() {
31
+ return false;
32
+ }
33
+ getShadowMapBorder(shadowMapParams) {
34
+ return this._kernelSize;
35
+ }
36
+ getShadowMap(shadowMapParams) {
37
+ return this.useNativeShadowMap(shadowMapParams) ? shadowMapParams.shadowMapFramebuffer.getDepthAttachment() : shadowMapParams.shadowMapFramebuffer.getColorAttachments()[0];
38
+ }
39
+ doUpdateResources(shadowMapParams) {
40
+ shadowMapParams.shadowMap = this.getShadowMap(shadowMapParams);
41
+ shadowMapParams.shadowMapSampler = shadowMapParams.shadowMap?.getDefaultSampler(this.useNativeShadowMap(shadowMapParams)) || null;
42
+ }
43
+ postRenderShadowMap() {}
44
+ releaseTemporalResources(shadowMapParams) {}
45
+ getDepthScale() {
46
+ return 1;
47
+ }
48
+ setDepthScale(val) {}
49
+ getShaderHash() {
50
+ return `${this._kernelSize}`;
51
+ }
52
+ getShadowMapColorFormat(shadowMapParams) {
53
+ return this.useNativeShadowMap(shadowMapParams) ? null : 'rgba8unorm';
54
+ }
55
+ getShadowMapDepthFormat(shadowMapParams) {
56
+ return Application.instance.device.type === 'webgl' ? 'd24s8' : 'd32f';
57
+ }
58
+ computeShadowMapDepth(shadowMapParams, scope) {
59
+ return computeShadowMapDepth(scope, shadowMapParams.shadowMap.format);
60
+ }
61
+ computeShadowCSM(shadowMapParams, scope, shadowVertex, NdotL, split) {
62
+ const funcNameComputeShadowCSM = 'lib_computeShadowCSM';
63
+ const pb = scope.$builder;
64
+ const that = this;
65
+ pb.func(funcNameComputeShadowCSM, [
66
+ pb.vec4('shadowVertex'),
67
+ pb.float('NdotL'),
68
+ pb.int('split')
69
+ ], function() {
70
+ this.$l.shadowCoord = pb.div(this.shadowVertex, this.shadowVertex.w);
71
+ this.$l.shadowCoord = pb.add(pb.mul(this.shadowCoord, 0.5), 0.5);
72
+ this.$l.inShadow = pb.all(pb.bvec2(pb.all(pb.bvec4(pb.greaterThanEqual(this.shadowCoord.x, 0), pb.lessThanEqual(this.shadowCoord.x, 1), pb.greaterThanEqual(this.shadowCoord.y, 0), pb.lessThanEqual(this.shadowCoord.y, 1))), pb.lessThanEqual(this.shadowCoord.z, 1)));
73
+ this.$l.shadow = pb.float(1);
74
+ this.$l.receiverPlaneDepthBias = computeReceiverPlaneDepthBias(this, this.shadowCoord);
75
+ this.$if(this.inShadow, function() {
76
+ this.$l.shadowBias = ShadowMapper.computeShadowBiasCSM(shadowMapParams, this, this.NdotL, this.split);
77
+ this.shadowCoord.z = pb.sub(this.shadowCoord.z, this.shadowBias);
78
+ this.shadow = filterShadowPCF(this, shadowMapParams.lightType, shadowMapParams.shadowMap.format, that._kernelSize, this.shadowCoord, this.receiverPlaneDepthBias, this.split);
79
+ });
80
+ this.$return(this.shadow);
81
+ });
82
+ return pb.getGlobalScope()[funcNameComputeShadowCSM](shadowVertex, NdotL, split);
83
+ }
84
+ computeShadow(shadowMapParams, scope, shadowVertex, NdotL) {
85
+ const funcNameComputeShadow = 'lib_computeShadow';
86
+ const pb = scope.$builder;
87
+ const that = this;
88
+ pb.func(funcNameComputeShadow, [
89
+ pb.vec4('shadowVertex'),
90
+ pb.float('NdotL')
91
+ ], function() {
92
+ if (shadowMapParams.lightType === LIGHT_TYPE_POINT) {
93
+ this.$l.dir = pb.sub(this.shadowVertex.xyz, ShaderFramework.getLightPositionAndRangeForShadow(this).xyz);
94
+ if (that.useNativeShadowMap(shadowMapParams)) {
95
+ this.$l.nearFar = ShaderFramework.getShadowCameraParams(this).xy;
96
+ this.$l.maxZ = pb.max(pb.max(pb.abs(this.dir.x), pb.abs(this.dir.y)), pb.abs(this.dir.z));
97
+ this.$l.distance = linearDepthToNonLinear(this, this.maxZ, this.nearFar);
98
+ this.$l.shadowBias = ShadowMapper.computeShadowBias(shadowMapParams, this, pb.div(this.maxZ, ShaderFramework.getLightPositionAndRangeForShadow(this).w), this.NdotL, true);
99
+ this.$return(that.sampleShadowMap(shadowMapParams, this, this.dir, this.distance, this.shadowBias));
100
+ } else {
101
+ this.$l.distance = pb.div(pb.length(this.dir), ShaderFramework.getLightPositionAndRangeForShadow(this).w);
102
+ this.$l.shadowBias = ShadowMapper.computeShadowBias(shadowMapParams, this, this.distance, this.NdotL, true);
103
+ this.$return(that.sampleShadowMap(shadowMapParams, this, this.dir, this.distance, this.shadowBias));
104
+ }
105
+ } else {
106
+ this.$l.shadowCoord = pb.div(this.shadowVertex, this.shadowVertex.w);
107
+ this.$l.shadowCoord = pb.add(pb.mul(this.shadowCoord, 0.5), 0.5);
108
+ this.$l.inShadow = pb.all(pb.bvec2(pb.all(pb.bvec4(pb.greaterThanEqual(this.shadowCoord.x, 0), pb.lessThanEqual(this.shadowCoord.x, 1), pb.greaterThanEqual(this.shadowCoord.y, 0), pb.lessThanEqual(this.shadowCoord.y, 1))), pb.lessThanEqual(this.shadowCoord.z, 1)));
109
+ this.$l.shadow = pb.float(1);
110
+ this.$l.receiverPlaneDepthBias = computeReceiverPlaneDepthBias(this, this.shadowCoord);
111
+ this.$if(this.inShadow, function() {
112
+ this.$l.shadowBias = ShadowMapper.computeShadowBias(shadowMapParams, this, this.shadowCoord.z, this.NdotL, false);
113
+ this.shadowCoord.z = pb.sub(this.shadowCoord.z, this.shadowBias);
114
+ this.shadow = filterShadowPCF(this, shadowMapParams.lightType, shadowMapParams.shadowMap.format, that._kernelSize, this.shadowCoord, this.receiverPlaneDepthBias);
115
+ });
116
+ this.$return(this.shadow);
117
+ }
118
+ });
119
+ return pb.getGlobalScope()[funcNameComputeShadow](shadowVertex, NdotL);
120
+ }
121
+ useNativeShadowMap(shadowMapParams) {
122
+ return Application.instance.device.type !== 'webgl';
123
+ }
124
+ /** @internal */ sampleShadowMap(shadowMapParams, scope, coords, z, bias) {
125
+ const funcNameSampleShadowMap = `lib_sampleShadowMap`;
126
+ const pb = scope.$builder;
127
+ const that = this;
128
+ pb.func(funcNameSampleShadowMap, [
129
+ pb.vec3('coords'),
130
+ pb.float('z'),
131
+ pb.float('bias')
132
+ ], function() {
133
+ const floatDepthTexture = shadowMapParams.shadowMap.format !== 'rgba8unorm';
134
+ if (that.useNativeShadowMap(shadowMapParams)) {
135
+ this.$return(pb.clamp(pb.textureSampleCompareLevel(this.shadowMap, this.coords, pb.sub(this.z, this.bias)), 0, 1));
136
+ } else {
137
+ this.$l.shadowTex = pb.textureSampleLevel(this.shadowMap, this.coords, 0);
138
+ if (!floatDepthTexture) {
139
+ this.shadowTex.x = decodeNormalizedFloatFromRGBA(this, this.shadowTex);
140
+ }
141
+ this.$l.distance = pb.sub(this.z, this.bias);
142
+ this.$return(pb.step(this.distance, this.shadowTex.x));
143
+ }
144
+ });
145
+ return pb.getGlobalScope()[funcNameSampleShadowMap](coords, z, bias);
146
+ }
147
+ /** @internal */ sampleShadowMapCSM(shadowMapParams, scope, coords, split, z, bias) {
148
+ const funcNameSampleShadowMapCSM = 'lib_sampleShadowMapCSM';
149
+ const pb = scope.$builder;
150
+ const that = this;
151
+ pb.func(funcNameSampleShadowMapCSM, [
152
+ pb.vec4('coords'),
153
+ pb.int('split'),
154
+ pb.float('z'),
155
+ pb.float('bias')
156
+ ], function() {
157
+ const floatDepthTexture = shadowMapParams.shadowMap.format !== 'rgba8unorm';
158
+ this.$l.distance = pb.sub(this.z, this.bias);
159
+ if (that.useNativeShadowMap(shadowMapParams)) {
160
+ if (shadowMapParams.shadowMap.isTexture2DArray()) {
161
+ this.$return(pb.clamp(pb.textureArraySampleCompareLevel(this.shadowMap, this.coords.xy, this.split, this.distance), 0, 1));
162
+ } else {
163
+ this.$return(pb.clamp(pb.textureSampleCompareLevel(this.shadowMap, this.coords.xy, this.distance), 0, 1));
164
+ }
165
+ } else {
166
+ if (shadowMapParams.shadowMap.isTexture2DArray()) {
167
+ this.$l.shadowTex = pb.textureArraySampleLevel(this.shadowMap, this.coords.xy, this.split, 0);
168
+ } else {
169
+ this.$l.shadowTex = pb.textureSampleLevel(this.shadowMap, this.coords.xy, 0);
170
+ }
171
+ if (!floatDepthTexture) {
172
+ this.shadowTex.x = decodeNormalizedFloatFromRGBA(this, this.shadowTex);
173
+ }
174
+ this.$return(pb.step(this.distance, this.shadowTex.x));
175
+ }
176
+ });
177
+ return pb.getGlobalScope()[funcNameSampleShadowMapCSM](coords, split, z, bias);
178
+ }
179
+ }
180
+
181
+ export { PCFOPT };
182
+ //# sourceMappingURL=pcf_opt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pcf_opt.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,190 @@
1
+ import { ShadowImpl } from './shadow_impl.js';
2
+ import { computeShadowMapDepth, computeReceiverPlaneDepthBias, filterShadowPoissonDisc } from '../shaders/shadow.js';
3
+ import { ShadowMapper } from './shadowmapper.js';
4
+ import { linearDepthToNonLinear, decodeNormalizedFloatFromRGBA } from '../shaders/misc.js';
5
+ import { ShaderFramework } from '../shaders/framework.js';
6
+ import { Application } from '../app.js';
7
+ import { LIGHT_TYPE_POINT } from '../values.js';
8
+
9
+ /** @internal */ class PCFPD extends ShadowImpl {
10
+ _tapCount;
11
+ _sampleRadius;
12
+ _shadowSampler;
13
+ constructor(tapCount, sampleRadius){
14
+ super();
15
+ this._tapCount = tapCount ?? 3;
16
+ this._sampleRadius = sampleRadius ?? 1;
17
+ this._shadowSampler = null;
18
+ }
19
+ get tapCount() {
20
+ return this._tapCount;
21
+ }
22
+ set tapCount(val) {
23
+ this._tapCount = val;
24
+ }
25
+ getType() {
26
+ return 'pcf-pd';
27
+ }
28
+ dispose() {
29
+ this._shadowSampler = null;
30
+ }
31
+ resourceDirty() {
32
+ return false;
33
+ }
34
+ getShadowMapBorder(shadowMapParams) {
35
+ return this._sampleRadius + 1;
36
+ }
37
+ getShadowMap(shadowMapParams) {
38
+ return this.useNativeShadowMap(shadowMapParams) ? shadowMapParams.shadowMapFramebuffer.getDepthAttachment() : shadowMapParams.shadowMapFramebuffer.getColorAttachments()[0];
39
+ }
40
+ doUpdateResources(shadowMapParams) {
41
+ shadowMapParams.shadowMap = this.getShadowMap(shadowMapParams);
42
+ shadowMapParams.shadowMapSampler = shadowMapParams.shadowMap?.getDefaultSampler(this.useNativeShadowMap(shadowMapParams)) || null;
43
+ }
44
+ postRenderShadowMap() {}
45
+ releaseTemporalResources(shadowMapParams) {}
46
+ getDepthScale() {
47
+ return this._sampleRadius;
48
+ }
49
+ setDepthScale(val) {
50
+ this._sampleRadius = val;
51
+ }
52
+ getShaderHash() {
53
+ return `${this._tapCount}`;
54
+ }
55
+ getShadowMapColorFormat(shadowMapParams) {
56
+ if (this.useNativeShadowMap(shadowMapParams)) {
57
+ return null;
58
+ } else {
59
+ const device = Application.instance.device;
60
+ return device.getDeviceCaps().textureCaps.supportHalfFloatColorBuffer ? device.type === 'webgl' ? 'rgba16f' : 'r16f' : device.getDeviceCaps().textureCaps.supportFloatColorBuffer ? device.type === 'webgl' ? 'rgba32f' : 'r32f' : 'rgba8unorm';
61
+ }
62
+ }
63
+ getShadowMapDepthFormat(shadowMapParams) {
64
+ return Application.instance.device.type === 'webgl' ? 'd24s8' : 'd32f';
65
+ }
66
+ computeShadowMapDepth(shadowMapParams, scope) {
67
+ return computeShadowMapDepth(scope, shadowMapParams.shadowMap.format);
68
+ }
69
+ computeShadowCSM(shadowMapParams, scope, shadowVertex, NdotL, split) {
70
+ const funcNameComputeShadowCSM = 'lib_computeShadowCSM';
71
+ const pb = scope.$builder;
72
+ const that = this;
73
+ pb.func(funcNameComputeShadowCSM, [
74
+ pb.vec4('shadowVertex'),
75
+ pb.float('NdotL'),
76
+ pb.int('split')
77
+ ], function() {
78
+ this.$l.shadowCoord = pb.div(this.shadowVertex, this.shadowVertex.w);
79
+ this.$l.shadowCoord = pb.add(pb.mul(this.shadowCoord, 0.5), 0.5);
80
+ this.$l.inShadow = pb.all(pb.bvec2(pb.all(pb.bvec4(pb.greaterThanEqual(this.shadowCoord.x, 0), pb.lessThanEqual(this.shadowCoord.x, 1), pb.greaterThanEqual(this.shadowCoord.y, 0), pb.lessThanEqual(this.shadowCoord.y, 1))), pb.lessThanEqual(this.shadowCoord.z, 1)));
81
+ this.$l.shadow = pb.float(1);
82
+ this.$l.receiverPlaneDepthBias = computeReceiverPlaneDepthBias(this, this.shadowCoord);
83
+ this.$if(this.inShadow, function() {
84
+ this.$l.shadowBias = ShadowMapper.computeShadowBiasCSM(shadowMapParams, this, this.NdotL, this.split);
85
+ this.shadowCoord.z = pb.sub(this.shadowCoord.z, this.shadowBias);
86
+ this.shadow = filterShadowPoissonDisc(this, shadowMapParams.lightType, shadowMapParams.shadowMap.format, that._tapCount, this.shadowCoord, this.receiverPlaneDepthBias, this.split);
87
+ });
88
+ this.$return(this.shadow);
89
+ });
90
+ return pb.getGlobalScope()[funcNameComputeShadowCSM](shadowVertex, NdotL, split);
91
+ }
92
+ computeShadow(shadowMapParams, scope, shadowVertex, NdotL) {
93
+ const funcNameComputeShadow = 'lib_computeShadow';
94
+ const pb = scope.$builder;
95
+ const that = this;
96
+ pb.func(funcNameComputeShadow, [
97
+ pb.vec4('shadowVertex'),
98
+ pb.float('NdotL')
99
+ ], function() {
100
+ if (shadowMapParams.lightType === LIGHT_TYPE_POINT) {
101
+ this.$l.dir = pb.sub(this.shadowVertex.xyz, ShaderFramework.getLightPositionAndRangeForShadow(this).xyz);
102
+ if (that.useNativeShadowMap(shadowMapParams)) {
103
+ this.$l.nearFar = ShaderFramework.getShadowCameraParams(this).xy;
104
+ this.$l.maxZ = pb.max(pb.max(pb.abs(this.dir.x), pb.abs(this.dir.y)), pb.abs(this.dir.z));
105
+ this.$l.distance = linearDepthToNonLinear(this, this.maxZ, this.nearFar);
106
+ this.$l.shadowBias = ShadowMapper.computeShadowBias(shadowMapParams, this, pb.div(this.maxZ, ShaderFramework.getLightPositionAndRangeForShadow(this).w), this.NdotL, true);
107
+ this.$return(that.sampleShadowMap(shadowMapParams, this, this.dir, this.distance, this.shadowBias));
108
+ } else {
109
+ this.$l.distance = pb.div(pb.length(this.dir), ShaderFramework.getLightPositionAndRangeForShadow(this).w);
110
+ this.$l.shadowBias = ShadowMapper.computeShadowBias(shadowMapParams, this, this.distance, this.NdotL, true);
111
+ this.$return(that.sampleShadowMap(shadowMapParams, this, this.dir, this.distance, this.shadowBias));
112
+ }
113
+ } else {
114
+ this.$l.shadowCoord = pb.div(this.shadowVertex, this.shadowVertex.w);
115
+ this.$l.shadowCoord = pb.add(pb.mul(this.shadowCoord, 0.5), 0.5);
116
+ this.$l.inShadow = pb.all(pb.bvec2(pb.all(pb.bvec4(pb.greaterThanEqual(this.shadowCoord.x, 0), pb.lessThanEqual(this.shadowCoord.x, 1), pb.greaterThanEqual(this.shadowCoord.y, 0), pb.lessThanEqual(this.shadowCoord.y, 1))), pb.lessThanEqual(this.shadowCoord.z, 1)));
117
+ this.$l.shadow = pb.float(1);
118
+ this.$l.receiverPlaneDepthBias = computeReceiverPlaneDepthBias(this, this.shadowCoord);
119
+ this.$if(this.inShadow, function() {
120
+ this.$l.shadowBias = ShadowMapper.computeShadowBias(shadowMapParams, this, this.shadowCoord.z, this.NdotL, false);
121
+ this.shadowCoord.z = pb.sub(this.shadowCoord.z, this.shadowBias);
122
+ this.shadow = filterShadowPoissonDisc(this, shadowMapParams.lightType, shadowMapParams.shadowMap.format, that._tapCount, this.shadowCoord, this.receiverPlaneDepthBias);
123
+ });
124
+ this.$return(this.shadow);
125
+ }
126
+ });
127
+ return pb.getGlobalScope()[funcNameComputeShadow](shadowVertex, NdotL);
128
+ }
129
+ useNativeShadowMap(shadowMapParams) {
130
+ return Application.instance.device.type !== 'webgl';
131
+ }
132
+ /** @internal */ sampleShadowMap(shadowMapParams, scope, coords, z, bias) {
133
+ const funcNameSampleShadowMap = 'lib_sampleShadowMap';
134
+ const pb = scope.$builder;
135
+ const that = this;
136
+ pb.func(funcNameSampleShadowMap, [
137
+ pb.vec3('coords'),
138
+ pb.float('z'),
139
+ pb.float('bias')
140
+ ], function() {
141
+ const floatDepthTexture = shadowMapParams.shadowMap.format !== 'rgba8unorm';
142
+ if (that.useNativeShadowMap(shadowMapParams)) {
143
+ this.$return(pb.clamp(pb.textureSampleCompareLevel(this.shadowMap, this.coords, pb.sub(this.z, this.bias)), 0, 1));
144
+ } else {
145
+ this.$l.shadowTex = pb.textureSampleLevel(this.shadowMap, this.coords, 0);
146
+ if (!floatDepthTexture) {
147
+ this.shadowTex.x = decodeNormalizedFloatFromRGBA(this, this.shadowTex);
148
+ }
149
+ this.$l.distance = pb.sub(this.z, this.bias);
150
+ this.$return(pb.step(this.distance, this.shadowTex.x));
151
+ }
152
+ });
153
+ return pb.getGlobalScope()[funcNameSampleShadowMap](coords, z, bias);
154
+ }
155
+ /** @internal */ sampleShadowMapCSM(shadowMapParams, scope, coords, split, z, bias) {
156
+ const funcNameSampleShadowMapCSM = 'lib_sampleShadowMapCSM';
157
+ const pb = scope.$builder;
158
+ const that = this;
159
+ pb.func(funcNameSampleShadowMapCSM, [
160
+ pb.vec4('coords'),
161
+ pb.int('split'),
162
+ pb.float('z'),
163
+ pb.float('bias')
164
+ ], function() {
165
+ const floatDepthTexture = shadowMapParams.shadowMap.format !== 'rgba8unorm';
166
+ this.$l.distance = pb.sub(this.z, this.bias);
167
+ if (that.useNativeShadowMap(shadowMapParams)) {
168
+ if (shadowMapParams.shadowMap.isTexture2DArray()) {
169
+ this.$return(pb.clamp(pb.textureArraySampleCompareLevel(this.shadowMap, this.coords.xy, this.split, this.distance), 0, 1));
170
+ } else {
171
+ this.$return(pb.clamp(pb.textureSampleCompareLevel(this.shadowMap, this.coords.xy, this.distance), 0, 1));
172
+ }
173
+ } else {
174
+ if (shadowMapParams.shadowMap.isTexture2DArray()) {
175
+ this.$l.shadowTex = pb.textureArraySampleLevel(this.shadowMap, this.coords.xy, this.split, 0);
176
+ } else {
177
+ this.$l.shadowTex = pb.textureSampleLevel(this.shadowMap, this.coords.xy, 0);
178
+ }
179
+ if (!floatDepthTexture) {
180
+ this.shadowTex.x = decodeNormalizedFloatFromRGBA(this, this.shadowTex);
181
+ }
182
+ this.$return(pb.step(this.distance, this.shadowTex.x));
183
+ }
184
+ });
185
+ return pb.getGlobalScope()[funcNameSampleShadowMapCSM](coords, split, z, bias);
186
+ }
187
+ }
188
+
189
+ export { PCFPD };
190
+ //# sourceMappingURL=pcf_pd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pcf_pd.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,15 @@
1
+ /** @internal */ class ShadowImpl {
2
+ _resourceDirty;
3
+ constructor(){
4
+ this._resourceDirty = true;
5
+ }
6
+ invalidateResource() {
7
+ this._resourceDirty = true;
8
+ }
9
+ updateResources(shadowMapParams) {
10
+ this.doUpdateResources(shadowMapParams);
11
+ }
12
+ }
13
+
14
+ export { ShadowImpl };
15
+ //# sourceMappingURL=shadow_impl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shadow_impl.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;"}