@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,224 @@
1
+ import { ObservableVector3, ObservableQuaternion, Matrix4x4, Vector3, Vector4 } from '@zephyr3d/base';
2
+
3
+ /**
4
+ * Presents a transformation from one space to another
5
+ * @public
6
+ */ class XForm {
7
+ /** @internal */ _parent;
8
+ /** @internal */ _children;
9
+ /** @internal */ _position;
10
+ /** @internal */ _scaling;
11
+ /** @internal */ _rotation;
12
+ /** @internal */ _localMatrix;
13
+ /** @internal */ _worldMatrix;
14
+ /** @internal */ _worldMatrixDet;
15
+ /** @internal */ _invWorldMatrix;
16
+ /** @internal */ _tmpLocalMatrix;
17
+ /** @internal */ _tmpWorldMatrix;
18
+ /** @internal */ _transformTag;
19
+ /**
20
+ * Creates an instance of XForm
21
+ */ constructor(){
22
+ this._parent = null;
23
+ this._children = [];
24
+ const cb = ()=>{
25
+ this._onTransformChanged(true);
26
+ };
27
+ this._position = new ObservableVector3(0, 0, 0);
28
+ this._position.callback = cb;
29
+ this._scaling = new ObservableVector3(1, 1, 1);
30
+ this._scaling.callback = cb;
31
+ this._rotation = new ObservableQuaternion();
32
+ this._rotation.callback = cb;
33
+ this._worldMatrix = null;
34
+ this._worldMatrixDet = null;
35
+ this._invWorldMatrix = null;
36
+ this._localMatrix = null;
37
+ this._transformTag = 0;
38
+ this._tmpLocalMatrix = Matrix4x4.identity();
39
+ this._tmpWorldMatrix = Matrix4x4.identity();
40
+ }
41
+ /** Parent of the xform */ get parent() {
42
+ return this._parent;
43
+ }
44
+ set parent(p) {
45
+ p = p || null;
46
+ if (p !== this._parent) {
47
+ this._setParent(p);
48
+ }
49
+ }
50
+ /** Children of this xform */ get children() {
51
+ return this._children;
52
+ }
53
+ /**
54
+ * Resets the transformation matrix
55
+ * @returns self
56
+ */ resetTransform() {
57
+ this._position.setXYZ(0, 0, 0);
58
+ this._rotation.identity();
59
+ this._scaling.setXYZ(1, 1, 1);
60
+ return this;
61
+ }
62
+ /**
63
+ * Position of the xform relative to it's parent
64
+ */ get position() {
65
+ return this._position;
66
+ }
67
+ set position(val) {
68
+ this._position.setXYZ(val[0], val[1], val[2]);
69
+ }
70
+ worldToThis(v, result) {
71
+ if (v instanceof Vector3) {
72
+ result = result || new Vector3();
73
+ this.invWorldMatrix.transformPointAffine(v, result);
74
+ return result;
75
+ } else {
76
+ result = result || new Vector4();
77
+ this.invWorldMatrix.transformAffine(v, result);
78
+ return result;
79
+ }
80
+ }
81
+ otherToThis(other, v, result) {
82
+ return this.worldToThis(other.thisToWorld(v, result), result);
83
+ }
84
+ thisToWorld(v, result) {
85
+ if (v instanceof Vector3) {
86
+ result = result || new Vector3();
87
+ this.worldMatrix.transformPointAffine(v, result);
88
+ return result;
89
+ } else {
90
+ result = result || new Vector4();
91
+ this.worldMatrix.transformAffine(v, result);
92
+ return result;
93
+ }
94
+ }
95
+ thisToOther(other, v, result) {
96
+ return other.worldToThis(this.thisToWorld(v, result), result);
97
+ }
98
+ /**
99
+ * Gets the position of the xform in world space
100
+ * @returns position of the xform in world space
101
+ */ getWorldPosition() {
102
+ return new Vector3(this.worldMatrix.m03, this.worldMatrix.m13, this.worldMatrix.m23);
103
+ }
104
+ /**
105
+ * Moves the xform by an offset vector
106
+ * @param delta - The offset vector
107
+ * @returns self
108
+ */ moveBy(delta) {
109
+ this._position.addBy(delta);
110
+ return this;
111
+ }
112
+ /**
113
+ * Scales the xform by a given scale factor
114
+ * @param factor - The scale factor
115
+ * @returns self
116
+ */ scaleBy(factor) {
117
+ this._scaling.mulBy(factor);
118
+ return this;
119
+ }
120
+ /**
121
+ * Scaling of the xform
122
+ */ get scale() {
123
+ return this._scaling;
124
+ }
125
+ set scale(val) {
126
+ this._scaling.setXYZ(val[0], val[1], val[2]);
127
+ }
128
+ /**
129
+ * Rotation of the xform
130
+ */ get rotation() {
131
+ return this._rotation;
132
+ }
133
+ set rotation(val) {
134
+ this._rotation.setXYZW(val[0], val[1], val[2], val[3]);
135
+ }
136
+ /**
137
+ * Sets the local transform matrix of the xform
138
+ * @param m - The transform matrix to set
139
+ * @returns self
140
+ */ setLocalTransform(m) {
141
+ m.decompose(this._scaling, this._rotation, this._position);
142
+ return this;
143
+ }
144
+ /** Local transformation matrix of the xform */ get localMatrix() {
145
+ if (!this._localMatrix) {
146
+ this._localMatrix = this._tmpLocalMatrix;
147
+ this._localMatrix.scaling(this._scaling).rotateLeft(new Matrix4x4(this._rotation)).translateLeft(this._position);
148
+ }
149
+ return this._localMatrix;
150
+ }
151
+ /** World transformation matrix of the xform */ get worldMatrix() {
152
+ if (!this._worldMatrix) {
153
+ this._worldMatrix = this._tmpWorldMatrix;
154
+ if (this._parent) {
155
+ Matrix4x4.multiplyAffine(this._parent.worldMatrix, this.localMatrix, this._worldMatrix);
156
+ } else {
157
+ this._worldMatrix.set(this.localMatrix);
158
+ }
159
+ }
160
+ return this._worldMatrix;
161
+ }
162
+ /** The determinant of world matrix */ get worldMatrixDet() {
163
+ if (this._worldMatrixDet === null) {
164
+ this._worldMatrixDet = this.worldMatrix.det();
165
+ }
166
+ return this._worldMatrixDet;
167
+ }
168
+ /** Inverse of the world transformation matrix of the xform */ get invWorldMatrix() {
169
+ if (!this._invWorldMatrix) {
170
+ this._invWorldMatrix = Matrix4x4.invertAffine(this.worldMatrix);
171
+ }
172
+ return this._invWorldMatrix;
173
+ }
174
+ /**
175
+ * Sets the local tranformation matrix by a look-at matrix
176
+ * @param eye - The eye position used to make the look-at matrix
177
+ * @param target - The target position used to make the look-at matrix
178
+ * @param up - The up vector used to make the look-at matrix
179
+ * @returns self
180
+ */ lookAt(eye, target, up) {
181
+ Matrix4x4.lookAt(eye, target, up).decompose(this._scaling, this._rotation, this._position);
182
+ return this;
183
+ }
184
+ /**
185
+ * Removes this node from it's parent and add this node to another parent node if required
186
+ * @param p - The new parent node that this node should be added to or null
187
+ * @returns self
188
+ */ reparent(p) {
189
+ this.parent = p;
190
+ return this;
191
+ }
192
+ /** @internal */ getTag() {
193
+ return this._transformTag;
194
+ }
195
+ /** @internal */ _onTransformChanged(invalidateLocal) {
196
+ if (invalidateLocal) {
197
+ this._localMatrix = null;
198
+ }
199
+ if (this._worldMatrix) {
200
+ this._worldMatrix = null;
201
+ this._invWorldMatrix = null;
202
+ this._transformTag++;
203
+ for (const child of this._children){
204
+ child._onTransformChanged(false);
205
+ }
206
+ }
207
+ this._worldMatrixDet = null;
208
+ }
209
+ /** @internal */ _setParent(p) {
210
+ if (this._parent !== p) {
211
+ if (this._parent) {
212
+ this._parent._children.splice(this._parent._children.indexOf(this), 1);
213
+ }
214
+ this._parent = p;
215
+ if (this._parent) {
216
+ this._parent._children.push(this);
217
+ }
218
+ this._onTransformChanged(false);
219
+ }
220
+ }
221
+ }
222
+
223
+ export { XForm };
224
+ //# sourceMappingURL=xform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xform.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,110 @@
1
+ import { ShaderFramework } from './framework.js';
2
+ import { encodeColorOutput } from './misc.js';
3
+ import '../app.js';
4
+ import { ScatteringLut } from '../render/scatteringlut.js';
5
+
6
+ const MESH_MATERIAL = {
7
+ FRAGMENT_SHADER (scope, ctx) {
8
+ ShaderFramework.prepareFragmentShader(scope.$builder, ctx);
9
+ },
10
+ VERTEX_SHADER (scope, ctx) {
11
+ ShaderFramework.prepareVertexShader(scope.$builder, ctx);
12
+ },
13
+ FTRANSFORM (scope) {
14
+ ShaderFramework.ftransform(scope);
15
+ },
16
+ DEFINE_VERTEX_COLOR (color) {
17
+ return color.tag(ShaderFramework.USAGE_VERTEX_COLOR);
18
+ },
19
+ DEFINE_WORLD_NORMAL (normal) {
20
+ return normal.tag(ShaderFramework.USAGE_WORLD_NORMAL);
21
+ },
22
+ DEFINE_WORLD_TANGENT (tangent) {
23
+ return tangent.tag(ShaderFramework.USAGE_WORLD_TANGENT);
24
+ },
25
+ DEFINE_WORLD_BINORMAL (binormal) {
26
+ return binormal.tag(ShaderFramework.USAGE_WORLD_BINORMAL);
27
+ },
28
+ DEFINE_WORLD_POSITION (pos) {
29
+ return pos.tag(ShaderFramework.USAGE_WORLD_POSITION);
30
+ },
31
+ FRAGMENT_OUTPUT (scope, color) {
32
+ return encodeColorOutput(scope, color);
33
+ },
34
+ GET_WORLD_MATRIX (scope) {
35
+ return ShaderFramework.getWorldMatrix(scope);
36
+ },
37
+ GET_VIEW_PROJ_MATRIX (scope) {
38
+ return ShaderFramework.getViewProjectionMatrix(scope);
39
+ },
40
+ GET_ENVLIGHT_STRENGTH (scope) {
41
+ return ShaderFramework.getEnvLightStrength(scope);
42
+ },
43
+ GET_CAMERA_POSITION (scope) {
44
+ return ShaderFramework.getCameraPosition(scope);
45
+ },
46
+ GET_CAMERA_PARAMS (scope) {
47
+ return ShaderFramework.getCameraParams(scope);
48
+ },
49
+ GET_WORLD_POSITION (scope) {
50
+ return ShaderFramework.getWorldPosition(scope);
51
+ },
52
+ GET_WORLD_NORMAL (scope) {
53
+ return ShaderFramework.getWorldNormal(scope);
54
+ },
55
+ GET_WORLD_TANGENT (scope) {
56
+ return ShaderFramework.getWorldTangent(scope);
57
+ },
58
+ GET_WORLD_BINORMAL (scope) {
59
+ return ShaderFramework.getWorldBinormal(scope);
60
+ },
61
+ SET_CLIP_SPACE_POSITION (scope, pos) {
62
+ ShaderFramework.setClipSpacePosition(scope, pos);
63
+ },
64
+ DISCARD_IF_CLIPPED (scope) {
65
+ ShaderFramework.discardIfClipped(scope);
66
+ },
67
+ APPLY_FOG (scope, color, ctx) {
68
+ if (ctx.applyFog) {
69
+ const pb = scope.$builder;
70
+ if (ctx.env.sky.drawScatteredFog(ctx)) {
71
+ const funcName = 'applyAerialPerspective';
72
+ pb.func(funcName, [
73
+ pb.vec4('color').inout()
74
+ ], function() {
75
+ this.$l.viewDir = pb.sub(ShaderFramework.getWorldPosition(this).xyz, ShaderFramework.getCameraPosition(this));
76
+ this.viewDir.y = pb.max(this.viewDir.y, 0);
77
+ this.$l.distance = pb.mul(pb.length(this.viewDir), ShaderFramework.getWorldUnit(this));
78
+ this.$l.sliceDist = pb.div(pb.mul(ShaderFramework.getCameraParams(this).y, ShaderFramework.getWorldUnit(this)), ScatteringLut.aerialPerspectiveSliceZ);
79
+ this.$l.slice0 = pb.floor(pb.div(this.distance, this.sliceDist));
80
+ this.$l.slice1 = pb.add(this.slice0, 1);
81
+ this.$l.factor = pb.sub(pb.div(this.distance, this.sliceDist), this.slice0);
82
+ this.$l.viewNormal = pb.normalize(this.viewDir);
83
+ this.$l.zenithAngle = pb.asin(this.viewNormal.y);
84
+ this.$l.horizonAngle = pb.atan2(this.viewNormal.z, this.viewNormal.x);
85
+ this.$l.u0 = pb.div(pb.add(this.slice0, pb.div(this.horizonAngle, Math.PI * 2)), ScatteringLut.aerialPerspectiveSliceZ);
86
+ this.$l.u1 = pb.add(this.u0, 1 / ScatteringLut.aerialPerspectiveSliceZ);
87
+ this.$l.v = pb.div(this.zenithAngle, Math.PI / 2);
88
+ this.$l.t0 = pb.textureSampleLevel(ShaderFramework.getAerialPerspectiveLUT(this), pb.vec2(this.u0, this.v), 0);
89
+ this.$l.t1 = pb.textureSampleLevel(ShaderFramework.getAerialPerspectiveLUT(this), pb.vec2(this.u1, this.v), 0);
90
+ this.$l.t = pb.mix(this.t0, this.t1, this.factor);
91
+ this.color = pb.vec4(pb.add(pb.mul(this.color.rgb, this.factor), this.t.rgb), this.color.a);
92
+ });
93
+ scope[funcName](color);
94
+ } else {
95
+ const funcName = 'applyFog';
96
+ pb.func(funcName, [
97
+ pb.vec4('color').inout()
98
+ ], function() {
99
+ this.$l.viewDir = pb.sub(ShaderFramework.getWorldPosition(this).xyz, ShaderFramework.getCameraPosition(this));
100
+ this.$l.fogFactor = ShaderFramework.computeFogFactor(this, this.viewDir, ShaderFramework.getFogType(this), ShaderFramework.getFogParams(this));
101
+ this.color = pb.vec4(pb.mix(this.color.rgb, ShaderFramework.getFogColor(this).rgb, pb.mul(this.fogFactor, this.color.a, this.color.a)), this.color.a);
102
+ });
103
+ scope[funcName](color);
104
+ }
105
+ }
106
+ }
107
+ };
108
+
109
+ export { MESH_MATERIAL };
110
+ //# sourceMappingURL=builtins.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builtins.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}