@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,282 @@
1
+ import { Vector4 } from '@zephyr3d/base';
2
+ import { Application } from '../app.js';
3
+
4
+ /**
5
+ * Base class for any kind of environment light
6
+ * @public
7
+ */ class EnvironmentLighting {
8
+ /**
9
+ * Whether this is an instance of EnvIBL
10
+ * @returns true if this is an instance of EnvIBL
11
+ */ isIBL() {
12
+ return false;
13
+ }
14
+ /**
15
+ * Whether this is an instance of EnvConstantAmbient
16
+ * @returns true if this is an instance of EnvConstantAmbient
17
+ */ isConstant() {
18
+ return false;
19
+ }
20
+ /**
21
+ * Whether this is an instance of EnvHemisphericAmbient
22
+ * @returns true if this is an instance of EnvHemisphericAmbient
23
+ */ isHemispheric() {
24
+ return false;
25
+ }
26
+ }
27
+ /**
28
+ * IBL based environment lighting
29
+ * @public
30
+ */ class EnvIBL extends EnvironmentLighting {
31
+ /** @internal */ static USAGE_IBL_RADIANCE_MAP = 'usage_ibl_radiance_map';
32
+ /** @internal */ static USAGE_IBL_RADIANCE_MAP_MAX_LOD = 'usage_ibl_radiance_map_maxlod';
33
+ /** @internal */ static USAGE_IBL_IRRADIANCE_MAP = 'usage_ibl_irradiance_map';
34
+ /** @internal */ _radianceMap;
35
+ /** @internal */ _irradianceMap;
36
+ /**
37
+ * Creates an instance of EnvIBL
38
+ * @param radianceMap - The radiance map
39
+ * @param irradianceMap - The irradiance map
40
+ */ constructor(radianceMap, irradianceMap){
41
+ super();
42
+ this._radianceMap = radianceMap || null;
43
+ this._irradianceMap = irradianceMap || null;
44
+ }
45
+ /**
46
+ * {@inheritDoc EnvironmentLighting.getType}
47
+ * @override
48
+ */ getType() {
49
+ return 'ibl';
50
+ }
51
+ /** The radiance map */ get radianceMap() {
52
+ return this._radianceMap;
53
+ }
54
+ set radianceMap(tex) {
55
+ this._radianceMap = tex;
56
+ }
57
+ /** The irradiance map */ get irradianceMap() {
58
+ return this._irradianceMap;
59
+ }
60
+ set irradianceMap(tex) {
61
+ this._irradianceMap = tex;
62
+ }
63
+ /**
64
+ * {@inheritDoc EnvironmentLighting.initShaderBindings}
65
+ * @override
66
+ */ initShaderBindings(pb) {
67
+ if (pb.shaderKind === 'fragment') {
68
+ pb.getGlobalScope().iblRadianceMap = pb.texCube().uniform(0).tag(EnvIBL.USAGE_IBL_RADIANCE_MAP);
69
+ pb.getGlobalScope().iblIrradianceMap = pb.texCube().uniform(0).tag(EnvIBL.USAGE_IBL_IRRADIANCE_MAP);
70
+ pb.getGlobalScope().radianceMaxLod = pb.float('radianceMaxLod').uniform(0).tag(EnvIBL.USAGE_IBL_RADIANCE_MAP_MAX_LOD);
71
+ }
72
+ }
73
+ /**
74
+ * {@inheritDoc EnvironmentLighting.updateBindGroup}
75
+ * @override
76
+ */ updateBindGroup(bg) {
77
+ if (this._radianceMap) {
78
+ bg.setValue('radianceMaxLod', this._radianceMap.mipLevelCount - 1);
79
+ bg.setTexture('iblRadianceMap', this._radianceMap);
80
+ }
81
+ if (this._irradianceMap) {
82
+ bg.setTexture('iblIrradianceMap', this._irradianceMap);
83
+ }
84
+ }
85
+ /**
86
+ * {@inheritDoc EnvironmentLighting.getRadiance}
87
+ * @override
88
+ */ getRadiance(scope, refl, roughness) {
89
+ const pb = scope.$builder;
90
+ return Application.instance.device.getDeviceCaps().shaderCaps.supportShaderTextureLod ? pb.textureSampleLevel(scope.iblRadianceMap, refl, pb.mul(roughness, scope.radianceMaxLod)).rgb : pb.textureSample(scope.iblRadianceMap, refl).rgb;
91
+ }
92
+ /**
93
+ * {@inheritDoc EnvironmentLighting.getIrradiance}
94
+ * @override
95
+ */ getIrradiance(scope, normal) {
96
+ const pb = scope.$builder;
97
+ return pb.textureSampleLevel(scope.iblIrradianceMap, normal, 0).rgb;
98
+ }
99
+ /**
100
+ * {@inheritDoc EnvironmentLighting.hasRadiance}
101
+ * @override
102
+ */ hasRadiance() {
103
+ return !!this._radianceMap;
104
+ }
105
+ /**
106
+ * {@inheritDoc EnvironmentLighting.hasIrradiance}
107
+ * @override
108
+ */ hasIrradiance() {
109
+ return !!this._irradianceMap;
110
+ }
111
+ /**
112
+ * {@inheritDoc EnvironmentLighting.isIBL}
113
+ * @override
114
+ */ isIBL() {
115
+ return true;
116
+ }
117
+ }
118
+ /**
119
+ * Constant ambient light
120
+ * @public
121
+ */ class EnvConstantAmbient extends EnvironmentLighting {
122
+ /** @internal */ static USAGE_CONSTANT_AMBIENT_LIGHTING = 'usage_env_constant_ambient';
123
+ /** @internal */ static funcNameGetAmbient = 'lib_getConstantAmbient';
124
+ /** @internal */ _ambientColor;
125
+ /**
126
+ * Creates an instance of EnvConstantAmbient
127
+ * @param ambientColor - The ambient color
128
+ */ constructor(ambientColor){
129
+ super();
130
+ this._ambientColor = ambientColor ? new Vector4(ambientColor) : new Vector4(0, 0, 0, 1);
131
+ }
132
+ /** The ambient color */ get ambientColor() {
133
+ return this._ambientColor;
134
+ }
135
+ set ambientColor(ambientColor) {
136
+ if (ambientColor) {
137
+ this._ambientColor.set(ambientColor);
138
+ }
139
+ }
140
+ /**
141
+ * {@inheritDoc EnvironmentLighting.getType}
142
+ * @override
143
+ */ getType() {
144
+ return 'constant';
145
+ }
146
+ /**
147
+ * {@inheritDoc EnvironmentLighting.initShaderBindings}
148
+ * @override
149
+ */ initShaderBindings(pb) {
150
+ if (pb.shaderKind === 'fragment') {
151
+ pb.getGlobalScope().ambientLight = pb.vec4().uniform(0).tag(EnvConstantAmbient.USAGE_CONSTANT_AMBIENT_LIGHTING);
152
+ }
153
+ }
154
+ /**
155
+ * {@inheritDoc EnvironmentLighting.updateBindGroup}
156
+ * @override
157
+ */ updateBindGroup(bg) {
158
+ bg.setValue('ambientLight', this._ambientColor);
159
+ }
160
+ /**
161
+ * {@inheritDoc EnvironmentLighting.getRadiance}
162
+ * @override
163
+ */ getRadiance(scope, refl, roughness) {
164
+ return null;
165
+ }
166
+ /**
167
+ * {@inheritDoc EnvironmentLighting.getIrradiance}
168
+ * @override
169
+ */ getIrradiance(scope, normal) {
170
+ return scope.ambientLight.rgb;
171
+ }
172
+ /**
173
+ * {@inheritDoc EnvironmentLighting.hasRadiance}
174
+ * @override
175
+ */ hasRadiance() {
176
+ return false;
177
+ }
178
+ /**
179
+ * {@inheritDoc EnvironmentLighting.hasIrradiance}
180
+ * @override
181
+ */ hasIrradiance() {
182
+ return true;
183
+ }
184
+ /**
185
+ * {@inheritDoc EnvironmentLighting.isConstant}
186
+ * @override
187
+ */ isConstant() {
188
+ return true;
189
+ }
190
+ }
191
+ /**
192
+ * Hemispheric ambient light
193
+ * @public
194
+ */ class EnvHemisphericAmbient extends EnvironmentLighting {
195
+ /** @internal */ static USAGE_CONSTANT_AMBIENT_UP = 'usage_env_ambient_up';
196
+ /** @internal */ static USAGE_CONSTANT_AMBIENT_DOWN = 'usage_env_ambient_down';
197
+ /** @internal */ static funcNameGetAmbient = 'lib_getConstantAmbient';
198
+ /** @internal */ _ambientUp;
199
+ /** @internal */ _ambientDown;
200
+ /**
201
+ * Creates an instance of EnvConstantAmbient
202
+ * @param ambientUp - The upside ambient color
203
+ * @param ambientDown - The downside ambient color
204
+ */ constructor(ambientUp, ambientDown){
205
+ super();
206
+ this._ambientUp = new Vector4(ambientUp);
207
+ this._ambientDown = new Vector4(ambientDown);
208
+ }
209
+ /** The upside ambient color */ get ambientUp() {
210
+ return this._ambientUp;
211
+ }
212
+ set ambientUp(color) {
213
+ if (color) {
214
+ this._ambientUp.set(color);
215
+ }
216
+ }
217
+ /** The downside ambient color */ get ambientDown() {
218
+ return this._ambientDown;
219
+ }
220
+ set ambientDown(color) {
221
+ if (color) {
222
+ this._ambientDown.set(color);
223
+ }
224
+ }
225
+ /**
226
+ * {@inheritDoc EnvironmentLighting.getType}
227
+ * @override
228
+ */ getType() {
229
+ return 'hemisphere';
230
+ }
231
+ /**
232
+ * {@inheritDoc EnvironmentLighting.initShaderBindings}
233
+ * @override
234
+ */ initShaderBindings(pb) {
235
+ if (pb.shaderKind === 'fragment') {
236
+ pb.getGlobalScope().ambientUp = pb.vec4().uniform(0).tag(EnvHemisphericAmbient.USAGE_CONSTANT_AMBIENT_UP);
237
+ pb.getGlobalScope().ambientDown = pb.vec4().uniform(0).tag(EnvHemisphericAmbient.USAGE_CONSTANT_AMBIENT_DOWN);
238
+ }
239
+ }
240
+ /**
241
+ * {@inheritDoc EnvironmentLighting.updateBindGroup}
242
+ * @override
243
+ */ updateBindGroup(bg) {
244
+ bg.setValue('ambientUp', this._ambientUp);
245
+ bg.setValue('ambientDown', this._ambientDown);
246
+ }
247
+ /**
248
+ * {@inheritDoc EnvironmentLighting.getRadiance}
249
+ * @override
250
+ */ getRadiance(scope, refl, roughness) {
251
+ return null;
252
+ }
253
+ /**
254
+ * {@inheritDoc EnvironmentLighting.getIrradiance}
255
+ * @override
256
+ */ getIrradiance(scope, normal) {
257
+ const pb = scope.$builder;
258
+ const factor = pb.add(pb.mul(normal.y, 0.5), 0.5);
259
+ return pb.mix(scope.ambientDown, scope.ambientUp, factor).rgb;
260
+ }
261
+ /**
262
+ * {@inheritDoc EnvironmentLighting.hasRadiance}
263
+ * @override
264
+ */ hasRadiance() {
265
+ return false;
266
+ }
267
+ /**
268
+ * {@inheritDoc EnvironmentLighting.hasIrradiance}
269
+ * @override
270
+ */ hasIrradiance() {
271
+ return true;
272
+ }
273
+ /**
274
+ * {@inheritDoc EnvironmentLighting.isHemispheric}
275
+ * @override
276
+ */ isHemispheric() {
277
+ return true;
278
+ }
279
+ }
280
+
281
+ export { EnvConstantAmbient, EnvHemisphericAmbient, EnvIBL, EnvironmentLighting };
282
+ //# sourceMappingURL=envlight.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envlight.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,186 @@
1
+ import { ForwardRenderPass } from './forward_pass.js';
2
+ import { ShadowMapPass } from './shadowmap_pass.js';
3
+ import { DepthRenderPass } from './depth_pass.js';
4
+ import { Vector4 } from '@zephyr3d/base';
5
+ import { Application } from '../app.js';
6
+ import '../shaders/framework.js';
7
+ import '@zephyr3d/device';
8
+ import { CopyBlitter } from '../blitter/copy.js';
9
+ import '../scene/octree.js';
10
+ import '../material/material.js';
11
+ import './scatteringlut.js';
12
+ import '../material/lambert.js';
13
+ import '../material/blinn.js';
14
+ import '../material/unlit.js';
15
+ import '../material/lightmodel.js';
16
+ import './sky.js';
17
+ import './clipmap.js';
18
+ import { TemporalCache } from './temporalcache.js';
19
+ import './watermesh.js';
20
+ import { ShadowMapper } from '../shadow/shadowmapper.js';
21
+ import { ClusteredLight } from './cluster_light.js';
22
+
23
+ /**
24
+ * Forward render scheme
25
+ * @internal
26
+ */ class ForwardRenderScheme {
27
+ /** @internal */ static _scenePass = new ForwardRenderPass();
28
+ /** @internal */ static _depthPass = new DepthRenderPass();
29
+ /** @internal */ static _shadowMapPass = new ShadowMapPass();
30
+ /** @internal */ static _enableDepthPass = false;
31
+ /** @internal */ static _clusters = [];
32
+ /** @internal */ static setClearColor(color) {
33
+ this._scenePass.clearColor = color;
34
+ }
35
+ /** @internal */ static getClusteredLight() {
36
+ if (this._clusters.length > 0) {
37
+ return this._clusters.pop();
38
+ }
39
+ return new ClusteredLight();
40
+ }
41
+ /** @internal */ static freeClusteredLight(clusteredLight) {
42
+ this._clusters.push(clusteredLight);
43
+ }
44
+ /**
45
+ * Renders a scene by given camera
46
+ * @param scene - The scene to be rendered
47
+ * @param camera - The camera that will be used to render the scene
48
+ * @param compositor - The compositor that will be used to apply postprocess effects
49
+ */ static renderScene(scene, camera, compositor, logger) {
50
+ const device = Application.instance.device;
51
+ const ctx = {
52
+ scene,
53
+ primaryCamera: camera,
54
+ camera,
55
+ compositor: compositor?.needDrawPostEffects() ? compositor : null,
56
+ timestamp: device.frameInfo.frameTimestamp,
57
+ logger,
58
+ target: null,
59
+ renderPass: null,
60
+ renderPassHash: null,
61
+ applyFog: false,
62
+ flip: false,
63
+ drawEnvLight: false,
64
+ env: null
65
+ };
66
+ scene.frameUpdate();
67
+ if (camera && !device.isContextLost()) {
68
+ this._renderScene(ctx);
69
+ }
70
+ }
71
+ /** @internal */ static _renderSceneDepth(ctx, renderQueue, depthFramebuffer) {
72
+ const device = Application.instance.device;
73
+ device.pushDeviceStates();
74
+ device.setFramebuffer(depthFramebuffer);
75
+ this._depthPass.clearColor = device.type === 'webgl' ? new Vector4(0, 0, 0, 1) : new Vector4(1, 1, 1, 1);
76
+ this._depthPass.render(ctx, null, renderQueue);
77
+ device.popDeviceStates();
78
+ }
79
+ /** @internal */ static _renderScene(ctx) {
80
+ const device = Application.instance.device;
81
+ const vp = ctx.camera.viewport;
82
+ const scissor = ctx.camera.scissor;
83
+ const finalFramebuffer = device.getFramebuffer();
84
+ const drawingBufferWidth = device.getDrawingBufferWidth();
85
+ const drawingBufferHeight = device.getDrawingBufferHeight();
86
+ ctx.depthFormat = 'd24s8';
87
+ ctx.viewportX = finalFramebuffer ? vp?.[0] ?? 0 : device.screenToDevice(vp?.[0] ?? 0);
88
+ ctx.viewportY = finalFramebuffer ? vp?.[1] ?? 0 : device.screenToDevice(vp?.[1] ?? 0);
89
+ ctx.viewportWidth = finalFramebuffer ? vp?.[2] ?? finalFramebuffer.getWidth() : vp ? device.screenToDevice(vp[2]) : device.getDrawingBufferWidth();
90
+ ctx.viewportHeight = finalFramebuffer ? vp?.[3] ?? finalFramebuffer.getHeight() : vp ? device.screenToDevice(vp[3]) : device.getDrawingBufferHeight();
91
+ ctx.defaultViewport = !finalFramebuffer && !vp;
92
+ const oversizedViewport = vp && !device.getDeviceCaps().miscCaps.supportOversizedViewport && (ctx.viewportX < 0 || ctx.viewportY < 0 || ctx.viewportX + ctx.viewportWidth > drawingBufferWidth || ctx.viewportY + ctx.viewportHeight > drawingBufferHeight);
93
+ // TODO: determin the color buffer format
94
+ const colorFmt = device.getDeviceCaps().textureCaps.supportHalfFloatColorBuffer ? 'rgba16f' : 'rgba8unorm';
95
+ let tempFramebuffer = null;
96
+ let depthFramebuffer = null;
97
+ const renderQueue = this._scenePass.cullScene(ctx, ctx.camera);
98
+ ctx.sunLight = renderQueue.sunLight;
99
+ ctx.clusteredLight = this.getClusteredLight();
100
+ ctx.clusteredLight.calculateLightIndex(ctx.camera, renderQueue);
101
+ this.renderShadowMaps(ctx, renderQueue.shadowedLights);
102
+ const sampleCount = ctx.compositor ? 1 : ctx.primaryCamera.sampleCount;
103
+ if (this._enableDepthPass || oversizedViewport || ctx.scene.env.needSceneDepthTexture() || ctx.compositor?.requireLinearDepth()) {
104
+ const format = device.type === 'webgl' ? 'rgba8unorm' : 'r32f';
105
+ if (!finalFramebuffer && !vp) {
106
+ depthFramebuffer = TemporalCache.getFramebufferVariantSize(drawingBufferWidth, drawingBufferHeight, 1, format, ctx.depthFormat, '2d', '2d', false);
107
+ } else {
108
+ const originDepth = finalFramebuffer?.getDepthAttachment();
109
+ depthFramebuffer = originDepth?.isTexture2D() ? TemporalCache.getFramebufferFixedSizeWithDepth(originDepth, 1, format, '2d', false) : TemporalCache.getFramebufferFixedSize(ctx.viewportWidth, ctx.viewportHeight, 1, format, ctx.depthFormat, '2d', '2d', false);
110
+ }
111
+ this._renderSceneDepth(ctx, renderQueue, depthFramebuffer);
112
+ ctx.linearDepthTexture = depthFramebuffer.getColorAttachments()[0];
113
+ ctx.depthTexture = depthFramebuffer.getDepthAttachment();
114
+ if (ctx.depthTexture === finalFramebuffer?.getDepthAttachment()) {
115
+ tempFramebuffer = finalFramebuffer;
116
+ } else {
117
+ if (ctx.defaultViewport) {
118
+ tempFramebuffer = TemporalCache.getFramebufferVariantSize(ctx.depthTexture.width, ctx.depthTexture.height, 1, colorFmt, ctx.depthFormat, '2d', '2d', false, sampleCount);
119
+ } else {
120
+ tempFramebuffer = TemporalCache.getFramebufferFixedSize(ctx.depthTexture.width, ctx.depthTexture.height, 1, colorFmt, ctx.depthFormat, '2d', '2d', false, sampleCount);
121
+ }
122
+ }
123
+ } else {
124
+ ctx.linearDepthTexture = null;
125
+ ctx.depthTexture = null;
126
+ if (!vp) {
127
+ tempFramebuffer = finalFramebuffer;
128
+ } else {
129
+ tempFramebuffer = TemporalCache.getFramebufferFixedSize(ctx.viewportWidth, ctx.viewportHeight, 1, colorFmt, ctx.depthFormat, '2d', '2d', false, sampleCount);
130
+ }
131
+ }
132
+ if (tempFramebuffer && tempFramebuffer !== finalFramebuffer) {
133
+ device.pushDeviceStates();
134
+ device.setFramebuffer(tempFramebuffer);
135
+ } else {
136
+ device.setViewport(vp);
137
+ device.setScissor(scissor);
138
+ }
139
+ this._scenePass.clearDepth = 1; //ctx.depthTexture ? null : 1;
140
+ this._scenePass.clearStencil = 0; //ctx.depthTexture ? null : 0;
141
+ ctx.compositor?.begin(ctx);
142
+ this._scenePass.render(ctx, null, renderQueue);
143
+ ctx.compositor?.end(ctx);
144
+ if (tempFramebuffer && tempFramebuffer !== finalFramebuffer) {
145
+ const blitter = new CopyBlitter();
146
+ if (oversizedViewport) {
147
+ blitter.destRect = [
148
+ ctx.viewportX,
149
+ ctx.viewportY,
150
+ ctx.viewportWidth,
151
+ ctx.viewportHeight
152
+ ];
153
+ } else {
154
+ blitter.viewport = vp;
155
+ }
156
+ blitter.scissor = scissor;
157
+ blitter.srgbOut = !finalFramebuffer;
158
+ const srcTex = tempFramebuffer.getColorAttachments()[0];
159
+ blitter.blit(srcTex, finalFramebuffer ?? null, device.createSampler({
160
+ magFilter: 'nearest',
161
+ minFilter: 'nearest',
162
+ mipFilter: 'none'
163
+ }));
164
+ device.popDeviceStates();
165
+ }
166
+ if (depthFramebuffer) {
167
+ TemporalCache.releaseFramebuffer(depthFramebuffer);
168
+ }
169
+ if (tempFramebuffer && tempFramebuffer !== finalFramebuffer) {
170
+ TemporalCache.releaseFramebuffer(tempFramebuffer);
171
+ }
172
+ ShadowMapper.releaseTemporalResources(ctx);
173
+ this.freeClusteredLight(ctx.clusteredLight);
174
+ }
175
+ /** @internal */ static renderShadowMaps(ctx, lights) {
176
+ ctx.renderPass = this._shadowMapPass;
177
+ Application.instance.device.pushDeviceStates();
178
+ for (const light of lights){
179
+ light.shadow.render(ctx, this._shadowMapPass);
180
+ }
181
+ Application.instance.device.popDeviceStates();
182
+ }
183
+ }
184
+
185
+ export { ForwardRenderScheme };
186
+ //# sourceMappingURL=forward.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forward.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,137 @@
1
+ import { RenderPass } from './renderpass.js';
2
+ import { RENDER_PASS_TYPE_FORWARD } from '../values.js';
3
+ import { ShaderFramework } from '../shaders/framework.js';
4
+ import '@zephyr3d/device';
5
+ import { Application } from '../app.js';
6
+ import { Vector4 } from '@zephyr3d/base';
7
+
8
+ /**
9
+ * Forward render pass
10
+ * @internal
11
+ */ class ForwardRenderPass extends RenderPass {
12
+ /** @internal */ _overridenState;
13
+ /** @internal */ _overridenStateTrans;
14
+ /** @internal */ _shadowMapHash;
15
+ /**
16
+ * Creates an instance of ForwardRenderPass
17
+ */ constructor(){
18
+ super(RENDER_PASS_TYPE_FORWARD);
19
+ this._overridenState = null;
20
+ this._overridenStateTrans = null;
21
+ this._shadowMapHash = null;
22
+ }
23
+ /** @internal */ applyRenderStates(device, stateSet, ctx) {
24
+ const overridenStateSet = ctx.userData;
25
+ if (overridenStateSet) {
26
+ const depthState = overridenStateSet.depthState;
27
+ const blendingState = overridenStateSet.blendingState;
28
+ overridenStateSet.copyFrom(stateSet);
29
+ overridenStateSet.useBlendingState(blendingState);
30
+ if (depthState) {
31
+ overridenStateSet.useDepthState(depthState);
32
+ }
33
+ stateSet = overridenStateSet;
34
+ }
35
+ device.setRenderStates(stateSet);
36
+ }
37
+ /** @internal */ get overridenState() {
38
+ if (!this._overridenState) {
39
+ this._overridenState = Application.instance.device.createRenderStateSet();
40
+ this._overridenState.useBlendingState().enable(true).setBlendFunc('one', 'one');
41
+ }
42
+ return this._overridenState;
43
+ }
44
+ /** @internal */ get overridenStateTrans() {
45
+ if (!this._overridenStateTrans) {
46
+ this._overridenStateTrans = Application.instance.device.createRenderStateSet();
47
+ this._overridenStateTrans.useBlendingState().enable(true).setBlendFunc('one', 'inv-src-alpha');
48
+ this._overridenStateTrans.useDepthState().enableTest(true).enableWrite(false);
49
+ }
50
+ return this._overridenStateTrans;
51
+ }
52
+ /** @internal */ _getGlobalBindGroupHash(ctx) {
53
+ //return `${ctx.environment?.constructor.name || ''}:${this._shadowMapHash}`;
54
+ //const envLightHash = ctx.drawEnvLight ? ctx.env.light.type : 'none';
55
+ //const fogHash = ctx.applyFog ? ctx.env.sky.fogType ?? 'none' : 'none';
56
+ return `${this._shadowMapHash}:${ctx.env.getHash(ctx)}`;
57
+ }
58
+ /** @internal */ renderLightPass(camera, renderQueue, ctx, items, lights, trans, blend) {
59
+ const device = Application.instance.device;
60
+ const baseLightPass = !blend;
61
+ ctx.drawEnvLight = baseLightPass && ctx.env.light.type !== 'none' && (ctx.env.light.envLight.hasRadiance() || ctx.env.light.envLight.hasIrradiance());
62
+ ctx.renderPassHash = this.getGlobalBindGroupHash(ctx);
63
+ const info = this.getGlobalBindGroupInfo(ctx);
64
+ ShaderFramework.setCameraUniforms(info.bindGroup, ctx, !!device.getFramebuffer());
65
+ if (ctx.currentShadowLight) {
66
+ ShaderFramework.setLightUniformsShadow(info.bindGroup, ctx, lights[0]);
67
+ } else {
68
+ ShaderFramework.setLightUniforms(info.bindGroup, ctx, ctx.clusteredLight.clusterParam, ctx.clusteredLight.countParam, ctx.clusteredLight.lightBuffer, ctx.clusteredLight.lightIndexTexture);
69
+ }
70
+ if (ctx.applyFog) {
71
+ ShaderFramework.setFogUniforms(info.bindGroup, ctx.env.sky.mappedFogType, baseLightPass ? ctx.env.sky.fogColor : Vector4.zero(), ctx.env.sky.fogParams, ctx.env.sky.getAerialPerspectiveLUT(ctx));
72
+ }
73
+ device.setBindGroup(0, info.bindGroup);
74
+ if (blend) {
75
+ ctx.userData = this.overridenState;
76
+ } else if (trans) {
77
+ ctx.userData = this.overridenStateTrans;
78
+ }
79
+ const reverseWinding = ctx.camera.worldMatrixDet < 0;
80
+ for (const item of items){
81
+ // unlit objects should only be drawn once
82
+ if (!blend || !item.drawable.isUnlit()) {
83
+ ctx.instanceData = item.instanceData;
84
+ ctx.target = item.drawable;
85
+ this.drawItem(device, item, ctx, reverseWinding);
86
+ }
87
+ }
88
+ }
89
+ /** @internal */ renderItems(ctx, renderQueue) {
90
+ ctx.applyFog = false;
91
+ ctx.target = null;
92
+ ctx.renderPassHash = null;
93
+ ctx.env = ctx.scene.env;
94
+ ctx.drawEnvLight = false;
95
+ ctx.flip = this.isAutoFlip();
96
+ renderQueue.sortItems();
97
+ const orders = Object.keys(renderQueue.items).map((val)=>Number(val)).sort((a, b)=>a - b);
98
+ for(let i = 0; i < 2; i++){
99
+ ctx.applyFog = i === 1 && ctx.env.sky.fogType !== 'none';
100
+ for (const order of orders){
101
+ const items = renderQueue.items[order];
102
+ const lists = [
103
+ items.opaqueList,
104
+ items.transList
105
+ ];
106
+ const list = lists[i];
107
+ let lightIndex = 0;
108
+ if (ctx.shadowMapInfo) {
109
+ for (const k of ctx.shadowMapInfo.keys()){
110
+ ctx.currentShadowLight = k;
111
+ this._shadowMapHash = ctx.shadowMapInfo.get(k).shaderHash;
112
+ this.renderLightPass(ctx.camera, renderQueue, ctx, list, [
113
+ k
114
+ ], i > 0, lightIndex > 0);
115
+ lightIndex++;
116
+ }
117
+ }
118
+ if (lightIndex === 0 || renderQueue.unshadowedLights.length > 0) {
119
+ ctx.currentShadowLight = null;
120
+ this._shadowMapHash = '';
121
+ this.renderLightPass(ctx.camera, renderQueue, ctx, list, renderQueue.unshadowedLights, i > 0, lightIndex > 0);
122
+ }
123
+ }
124
+ if (i === 0) {
125
+ ctx.env.sky.skyWorldMatrix = ctx.scene.rootNode.worldMatrix;
126
+ ctx.env.sky.renderSky(ctx);
127
+ }
128
+ ctx.compositor?.drawPostEffects(ctx, i === 0, ctx.linearDepthTexture);
129
+ if (i === 0) {
130
+ ctx.env.sky.renderFog(ctx);
131
+ }
132
+ }
133
+ }
134
+ }
135
+
136
+ export { ForwardRenderPass };
137
+ //# sourceMappingURL=forward_pass.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forward_pass.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,38 @@
1
+ import { Application } from '../app.js';
2
+
3
+ let quadVertexLayout = null;
4
+ let quadRenderStateSet = null;
5
+ function drawFullscreenQuad(renderStates) {
6
+ const device = Application.instance.device;
7
+ if (!quadVertexLayout) {
8
+ quadVertexLayout = device.createVertexLayout({
9
+ vertexBuffers: [
10
+ {
11
+ buffer: device.createVertexBuffer('position_f32x2', new Float32Array([
12
+ -1,
13
+ -1,
14
+ 1,
15
+ -1,
16
+ -1,
17
+ 1,
18
+ 1,
19
+ 1
20
+ ]))
21
+ }
22
+ ]
23
+ });
24
+ }
25
+ if (!quadRenderStateSet) {
26
+ quadRenderStateSet = device.createRenderStateSet();
27
+ quadRenderStateSet.useRasterizerState().setCullMode('none');
28
+ quadRenderStateSet.useDepthState().enableTest(false).enableWrite(false);
29
+ }
30
+ const saveRenderStateSet = device.getRenderStates();
31
+ device.setRenderStates(renderStates ?? quadRenderStateSet);
32
+ device.setVertexLayout(quadVertexLayout);
33
+ device.draw('triangle-strip', 0, 4);
34
+ device.setRenderStates(saveRenderStateSet);
35
+ }
36
+
37
+ export { drawFullscreenQuad };
38
+ //# sourceMappingURL=helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helper.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}