@zephyr3d/scene 0.9.6 → 0.9.7

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 (203) hide show
  1. package/dist/animation/joint_dynamics/controller.js +92 -32
  2. package/dist/animation/joint_dynamics/controller.js.map +1 -1
  3. package/dist/animation/joint_dynamics/convex_collider.js +320 -0
  4. package/dist/animation/joint_dynamics/convex_collider.js.map +1 -0
  5. package/dist/animation/joint_dynamics/joint_dynamics_system.js +57 -19
  6. package/dist/animation/joint_dynamics/joint_dynamics_system.js.map +1 -1
  7. package/dist/animation/joint_dynamics/solver.js +71 -27
  8. package/dist/animation/joint_dynamics/solver.js.map +1 -1
  9. package/dist/animation/joint_dynamics_modifier.js +21 -20
  10. package/dist/animation/joint_dynamics_modifier.js.map +1 -1
  11. package/dist/animation/skeleton.js +7 -10
  12. package/dist/animation/skeleton.js.map +1 -1
  13. package/dist/app/engine.js +134 -140
  14. package/dist/app/engine.js.map +1 -1
  15. package/dist/app/scriptregistry.js +47 -16
  16. package/dist/app/scriptregistry.js.map +1 -1
  17. package/dist/asset/assetmanager.js +3 -1
  18. package/dist/asset/assetmanager.js.map +1 -1
  19. package/dist/asset/model.js +346 -7
  20. package/dist/asset/model.js.map +1 -1
  21. package/dist/avatar/wardrobe.js +20 -16
  22. package/dist/avatar/wardrobe.js.map +1 -1
  23. package/dist/camera/camera.js +416 -210
  24. package/dist/camera/camera.js.map +1 -1
  25. package/dist/index.d.ts +1349 -621
  26. package/dist/index.js +6 -11
  27. package/dist/index.js.map +1 -1
  28. package/dist/material/blinn.js +1 -1
  29. package/dist/material/blinn.js.map +1 -1
  30. package/dist/material/lambert.js +1 -1
  31. package/dist/material/lambert.js.map +1 -1
  32. package/dist/material/material.js +23 -1
  33. package/dist/material/material.js.map +1 -1
  34. package/dist/material/meshmaterial.js +178 -23
  35. package/dist/material/meshmaterial.js.map +1 -1
  36. package/dist/material/mixins/albedocolor.js +4 -4
  37. package/dist/material/mixins/albedocolor.js.map +1 -1
  38. package/dist/material/mixins/lightmodel/blinnphong.js +2 -1
  39. package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
  40. package/dist/material/mixins/lightmodel/lambert.js +2 -1
  41. package/dist/material/mixins/lightmodel/lambert.js.map +1 -1
  42. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js +63 -16
  43. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js.map +1 -1
  44. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +105 -32
  45. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
  46. package/dist/material/mixins/lightmodel/pbrspecularglossness.js +16 -6
  47. package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
  48. package/dist/material/mixins/lit.js +1 -1
  49. package/dist/material/mixins/lit.js.map +1 -1
  50. package/dist/material/mixins/pbr/common.js +276 -65
  51. package/dist/material/mixins/pbr/common.js.map +1 -1
  52. package/dist/material/mixins/texture.js +3 -3
  53. package/dist/material/mixins/texture.js.map +1 -1
  54. package/dist/material/mixins/vertexcolor.js +2 -2
  55. package/dist/material/mixins/vertexcolor.js.map +1 -1
  56. package/dist/material/mtoon.js +574 -0
  57. package/dist/material/mtoon.js.map +1 -0
  58. package/dist/material/pbrblueprint.js +499 -336
  59. package/dist/material/pbrblueprint.js.map +1 -1
  60. package/dist/material/pbrmr.js +118 -100
  61. package/dist/material/pbrmr.js.map +1 -1
  62. package/dist/material/pbrsg.js +1 -1
  63. package/dist/material/pbrsg.js.map +1 -1
  64. package/dist/material/shader/helper.js +324 -294
  65. package/dist/material/shader/helper.js.map +1 -1
  66. package/dist/material/subsurfaceprofile.js +812 -0
  67. package/dist/material/subsurfaceprofile.js.map +1 -0
  68. package/dist/material/unlit.js +1 -1
  69. package/dist/material/unlit.js.map +1 -1
  70. package/dist/posteffect/compositor.js +46 -11
  71. package/dist/posteffect/compositor.js.map +1 -1
  72. package/dist/posteffect/ssr.js +422 -96
  73. package/dist/posteffect/ssr.js.map +1 -1
  74. package/dist/posteffect/sss.js +1053 -0
  75. package/dist/posteffect/sss.js.map +1 -0
  76. package/dist/posteffect/taa.js +61 -60
  77. package/dist/posteffect/taa.js.map +1 -1
  78. package/dist/render/abuffer_oit.js +63 -12
  79. package/dist/render/abuffer_oit.js.map +1 -1
  80. package/dist/render/cluster_light.js +6 -5
  81. package/dist/render/cluster_light.js.map +1 -1
  82. package/dist/render/drawable.js +1 -5
  83. package/dist/render/drawable.js.map +1 -1
  84. package/dist/render/drawable_mixin.js +2 -1
  85. package/dist/render/drawable_mixin.js.map +1 -1
  86. package/dist/render/fbm_wavegenerator.js +2 -1
  87. package/dist/render/fbm_wavegenerator.js.map +1 -1
  88. package/dist/render/gerstner_wavegenerator.js +2 -1
  89. package/dist/render/gerstner_wavegenerator.js.map +1 -1
  90. package/dist/render/globalbindgroup_allocator.js +2 -1
  91. package/dist/render/globalbindgroup_allocator.js.map +1 -1
  92. package/dist/render/lightpass.js +110 -23
  93. package/dist/render/lightpass.js.map +1 -1
  94. package/dist/render/render_queue.js +51 -8
  95. package/dist/render/render_queue.js.map +1 -1
  96. package/dist/render/renderer.js +80 -66
  97. package/dist/render/renderer.js.map +1 -1
  98. package/dist/render/rendergraph/device_pool_allocator.js +8 -0
  99. package/dist/render/rendergraph/device_pool_allocator.js.map +1 -1
  100. package/dist/render/rendergraph/forward_plus_builder.js +481 -95
  101. package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
  102. package/dist/render/rendergraph/history_resource_manager.js +55 -0
  103. package/dist/render/rendergraph/history_resource_manager.js.map +1 -1
  104. package/dist/render/rendergraph/history_resources.js +3 -1
  105. package/dist/render/rendergraph/history_resources.js.map +1 -1
  106. package/dist/render/rendergraph/types.js.map +1 -1
  107. package/dist/render/renderpass.js +10 -4
  108. package/dist/render/renderpass.js.map +1 -1
  109. package/dist/render/sky.js +31 -1
  110. package/dist/render/sky.js.map +1 -1
  111. package/dist/render/weightedblended_oit.js +23 -5
  112. package/dist/render/weightedblended_oit.js.map +1 -1
  113. package/dist/scene/basesprite.js +4 -2
  114. package/dist/scene/basesprite.js.map +1 -1
  115. package/dist/scene/batchgroup.js +3 -1
  116. package/dist/scene/batchgroup.js.map +1 -1
  117. package/dist/scene/environment.js +11 -1
  118. package/dist/scene/environment.js.map +1 -1
  119. package/dist/scene/light.js +21 -3
  120. package/dist/scene/light.js.map +1 -1
  121. package/dist/scene/mesh.js +29 -14
  122. package/dist/scene/mesh.js.map +1 -1
  123. package/dist/scene/meshdrawable.js +6 -0
  124. package/dist/scene/meshdrawable.js.map +1 -1
  125. package/dist/scene/msdftext.js +5 -2
  126. package/dist/scene/msdftext.js.map +1 -1
  127. package/dist/scene/msdftextsprite.js +5 -3
  128. package/dist/scene/msdftextsprite.js.map +1 -1
  129. package/dist/scene/particlesys.js +3 -1
  130. package/dist/scene/particlesys.js.map +1 -1
  131. package/dist/scene/scene.js +6 -5
  132. package/dist/scene/scene.js.map +1 -1
  133. package/dist/scene/terrain-cm/grass.js +4 -2
  134. package/dist/scene/terrain-cm/grass.js.map +1 -1
  135. package/dist/scene/terrain-cm/grassmaterial.js +2 -1
  136. package/dist/scene/terrain-cm/grassmaterial.js.map +1 -1
  137. package/dist/scene/terrain-cm/terrain-cm.js +4 -2
  138. package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
  139. package/dist/scene/water.js +4 -2
  140. package/dist/scene/water.js.map +1 -1
  141. package/dist/shaders/shadow.js +26 -393
  142. package/dist/shaders/shadow.js.map +1 -1
  143. package/dist/shadow/esm.js +112 -12
  144. package/dist/shadow/esm.js.map +1 -1
  145. package/dist/shadow/pcf_opt.js +2 -2
  146. package/dist/shadow/pcf_opt.js.map +1 -1
  147. package/dist/shadow/pcf_pd.js +19 -10
  148. package/dist/shadow/pcf_pd.js.map +1 -1
  149. package/dist/shadow/shader.js +58 -7
  150. package/dist/shadow/shader.js.map +1 -1
  151. package/dist/shadow/shadow_impl.js +6 -0
  152. package/dist/shadow/shadow_impl.js.map +1 -1
  153. package/dist/shadow/shadow_region.js +229 -0
  154. package/dist/shadow/shadow_region.js.map +1 -0
  155. package/dist/shadow/shadowmapper.js +67 -59
  156. package/dist/shadow/shadowmapper.js.map +1 -1
  157. package/dist/shadow/vsm.js +45 -19
  158. package/dist/shadow/vsm.js.map +1 -1
  159. package/dist/utility/blueprint/common/constants.js +8 -8
  160. package/dist/utility/blueprint/common/constants.js.map +1 -1
  161. package/dist/utility/blueprint/material/pbr.js +31 -4
  162. package/dist/utility/blueprint/material/pbr.js.map +1 -1
  163. package/dist/utility/blueprint/material/texture.js +1 -17
  164. package/dist/utility/blueprint/material/texture.js.map +1 -1
  165. package/dist/utility/serialization/manager.js +327 -359
  166. package/dist/utility/serialization/manager.js.map +1 -1
  167. package/dist/utility/serialization/scene/animation.js +5 -2
  168. package/dist/utility/serialization/scene/animation.js.map +1 -1
  169. package/dist/utility/serialization/scene/batch.js +4 -1
  170. package/dist/utility/serialization/scene/batch.js.map +1 -1
  171. package/dist/utility/serialization/scene/camera.js +249 -54
  172. package/dist/utility/serialization/scene/camera.js.map +1 -1
  173. package/dist/utility/serialization/scene/common.js +37 -1
  174. package/dist/utility/serialization/scene/common.js.map +1 -1
  175. package/dist/utility/serialization/scene/light.js +42 -3
  176. package/dist/utility/serialization/scene/light.js.map +1 -1
  177. package/dist/utility/serialization/scene/material.js +1112 -646
  178. package/dist/utility/serialization/scene/material.js.map +1 -1
  179. package/dist/utility/serialization/scene/mesh.js +7 -4
  180. package/dist/utility/serialization/scene/mesh.js.map +1 -1
  181. package/dist/utility/serialization/scene/node.js +31 -12
  182. package/dist/utility/serialization/scene/node.js.map +1 -1
  183. package/dist/utility/serialization/scene/particle.js +4 -1
  184. package/dist/utility/serialization/scene/particle.js.map +1 -1
  185. package/dist/utility/serialization/scene/primitive.js +3 -1
  186. package/dist/utility/serialization/scene/primitive.js.map +1 -1
  187. package/dist/utility/serialization/scene/scene.js +18 -0
  188. package/dist/utility/serialization/scene/scene.js.map +1 -1
  189. package/dist/utility/serialization/scene/sprite.js +6 -3
  190. package/dist/utility/serialization/scene/sprite.js.map +1 -1
  191. package/dist/utility/serialization/scene/terrain.js +5 -2
  192. package/dist/utility/serialization/scene/terrain.js.map +1 -1
  193. package/dist/utility/serialization/scene/text.js +3 -1
  194. package/dist/utility/serialization/scene/text.js.map +1 -1
  195. package/dist/utility/serialization/scene/water.js +4 -1
  196. package/dist/utility/serialization/scene/water.js.map +1 -1
  197. package/dist/utility/textures/ltcdata.js +6 -0
  198. package/dist/utility/textures/ltcdata.js.map +1 -0
  199. package/dist/utility/textures/ltclut.js +61 -0
  200. package/dist/utility/textures/ltclut.js.map +1 -0
  201. package/dist/values.js +9 -1
  202. package/dist/values.js.map +1 -1
  203. package/package.json +3 -3
@@ -0,0 +1,574 @@
1
+ import { Vector3, Vector2 } from '@zephyr3d/base';
2
+ import { applyMaterialMixins, MeshMaterial } from './meshmaterial.js';
3
+ import { mixinAlbedoColor } from './mixins/albedocolor.js';
4
+ import { mixinLambert } from './mixins/lightmodel/lambert.js';
5
+ import { mixinTextureProps } from './mixins/texture.js';
6
+ import { QUEUE_TRANSPARENT, QUEUE_OPAQUE, RENDER_PASS_TYPE_LIGHT } from '../values.js';
7
+ import { ShaderHelper } from './shader/helper.js';
8
+
9
+ const ToonMaterialBase = applyMaterialMixins(MeshMaterial, mixinAlbedoColor, mixinLambert, mixinTextureProps('shadeMultiply'), mixinTextureProps('shadingShift'), mixinTextureProps('matcap'), mixinTextureProps('rimMultiply'), mixinTextureProps('outlineWidthMultiply'), mixinTextureProps('uvAnimationMask'), mixinTextureProps('emissive'));
10
+ /**
11
+ * MToonMaterial is a material that implements the MToon shader, which is a stylized shader commonly used for rendering anime-style characters. It supports features such as rim lighting, matcap, and outline rendering.
12
+ *
13
+ * @public
14
+ */ class MToonMaterial extends ToonMaterialBase {
15
+ static FEATURE_OUTLINE_WIDTH_MODE = this.defineFeature();
16
+ static FEATURE_OUTLINE_TANGENT_NORMALS = this.defineFeature();
17
+ _shadeColorFactor;
18
+ _matcapFactor;
19
+ _parametricRimColorFactor;
20
+ _outlineColorFactor;
21
+ _uvAnimationScroll;
22
+ _emissiveColor;
23
+ _shadingShiftFactor;
24
+ _shadingShiftTextureScale;
25
+ _shadingToonyFactor;
26
+ _giEqualizationFactor;
27
+ _parametricRimFresnelPowerFactor;
28
+ _parametricRimLiftFactor;
29
+ _rimLightingMixFactor;
30
+ _outlineWidthFactor;
31
+ _outlineLightingMixFactor;
32
+ _uvAnimationRotationSpeedFactor;
33
+ _emissiveStrength;
34
+ _transparentWithZWrite;
35
+ _renderQueueOffsetNumber;
36
+ constructor(){
37
+ super();
38
+ this._shadeColorFactor = new Vector3(0, 0, 0);
39
+ this._matcapFactor = new Vector3(1, 1, 1);
40
+ this._parametricRimColorFactor = new Vector3(0, 0, 0);
41
+ this._outlineColorFactor = new Vector3(0, 0, 0);
42
+ this._uvAnimationScroll = new Vector2(0, 0);
43
+ this._emissiveColor = new Vector3(0, 0, 0);
44
+ this._shadingShiftFactor = 0;
45
+ this._shadingShiftTextureScale = 1;
46
+ this._shadingToonyFactor = 0.9;
47
+ this._giEqualizationFactor = 0.9;
48
+ this._parametricRimFresnelPowerFactor = 5;
49
+ this._parametricRimLiftFactor = 0;
50
+ this._rimLightingMixFactor = 1;
51
+ this._outlineWidthFactor = 0;
52
+ this._outlineLightingMixFactor = 1;
53
+ this._uvAnimationRotationSpeedFactor = 0;
54
+ this._emissiveStrength = 1;
55
+ this._transparentWithZWrite = false;
56
+ this._renderQueueOffsetNumber = 0;
57
+ this.outlineWidthMode = 'none';
58
+ this.outlineUsesTangentNormals = false;
59
+ }
60
+ get shadeColorFactor() {
61
+ return this._shadeColorFactor;
62
+ }
63
+ set shadeColorFactor(val) {
64
+ this._shadeColorFactor.set(val);
65
+ this.uniformChanged();
66
+ }
67
+ get shadingShiftFactor() {
68
+ return this._shadingShiftFactor;
69
+ }
70
+ set shadingShiftFactor(val) {
71
+ if (val !== this._shadingShiftFactor) {
72
+ this._shadingShiftFactor = val;
73
+ this.uniformChanged();
74
+ }
75
+ }
76
+ get shadingShiftTextureScale() {
77
+ return this._shadingShiftTextureScale;
78
+ }
79
+ set shadingShiftTextureScale(val) {
80
+ if (val !== this._shadingShiftTextureScale) {
81
+ this._shadingShiftTextureScale = val;
82
+ this.uniformChanged();
83
+ }
84
+ }
85
+ get shadingToonyFactor() {
86
+ return this._shadingToonyFactor;
87
+ }
88
+ set shadingToonyFactor(val) {
89
+ const toony = Math.min(Math.max(val, 0), 0.99);
90
+ if (toony !== this._shadingToonyFactor) {
91
+ this._shadingToonyFactor = toony;
92
+ this.uniformChanged();
93
+ }
94
+ }
95
+ get giEqualizationFactor() {
96
+ return this._giEqualizationFactor;
97
+ }
98
+ set giEqualizationFactor(val) {
99
+ const factor = Math.min(Math.max(val, 0), 1);
100
+ if (factor !== this._giEqualizationFactor) {
101
+ this._giEqualizationFactor = factor;
102
+ this.uniformChanged();
103
+ }
104
+ }
105
+ get matcapFactor() {
106
+ return this._matcapFactor;
107
+ }
108
+ set matcapFactor(val) {
109
+ this._matcapFactor.set(val);
110
+ this.uniformChanged();
111
+ }
112
+ get parametricRimColorFactor() {
113
+ return this._parametricRimColorFactor;
114
+ }
115
+ set parametricRimColorFactor(val) {
116
+ this._parametricRimColorFactor.set(val);
117
+ this.uniformChanged();
118
+ }
119
+ get parametricRimFresnelPowerFactor() {
120
+ return this._parametricRimFresnelPowerFactor;
121
+ }
122
+ set parametricRimFresnelPowerFactor(val) {
123
+ if (val !== this._parametricRimFresnelPowerFactor) {
124
+ this._parametricRimFresnelPowerFactor = val;
125
+ this.uniformChanged();
126
+ }
127
+ }
128
+ get parametricRimLiftFactor() {
129
+ return this._parametricRimLiftFactor;
130
+ }
131
+ set parametricRimLiftFactor(val) {
132
+ if (val !== this._parametricRimLiftFactor) {
133
+ this._parametricRimLiftFactor = val;
134
+ this.uniformChanged();
135
+ }
136
+ }
137
+ get rimLightingMixFactor() {
138
+ return this._rimLightingMixFactor;
139
+ }
140
+ set rimLightingMixFactor(val) {
141
+ const factor = Math.min(Math.max(val, 0), 1);
142
+ if (factor !== this._rimLightingMixFactor) {
143
+ this._rimLightingMixFactor = factor;
144
+ this.uniformChanged();
145
+ }
146
+ }
147
+ get outlineWidthMode() {
148
+ return this.featureUsed(MToonMaterial.FEATURE_OUTLINE_WIDTH_MODE);
149
+ }
150
+ set outlineWidthMode(val) {
151
+ if (val !== 'none' && this.numPasses < 2) {
152
+ this.numPasses = 2;
153
+ }
154
+ this.useFeature(MToonMaterial.FEATURE_OUTLINE_WIDTH_MODE, val);
155
+ this.numPasses = val === 'none' ? 1 : 2;
156
+ }
157
+ get outlineWidthFactor() {
158
+ return this._outlineWidthFactor;
159
+ }
160
+ set outlineWidthFactor(val) {
161
+ if (val !== this._outlineWidthFactor) {
162
+ this._outlineWidthFactor = val;
163
+ this.uniformChanged();
164
+ }
165
+ }
166
+ get outlineColorFactor() {
167
+ return this._outlineColorFactor;
168
+ }
169
+ set outlineColorFactor(val) {
170
+ this._outlineColorFactor.set(val);
171
+ this.uniformChanged();
172
+ }
173
+ get outlineLightingMixFactor() {
174
+ return this._outlineLightingMixFactor;
175
+ }
176
+ set outlineLightingMixFactor(val) {
177
+ const factor = Math.min(Math.max(val, 0), 1);
178
+ if (factor !== this._outlineLightingMixFactor) {
179
+ this._outlineLightingMixFactor = factor;
180
+ this.uniformChanged();
181
+ }
182
+ }
183
+ get outlineUsesTangentNormals() {
184
+ return !!this.featureUsed(MToonMaterial.FEATURE_OUTLINE_TANGENT_NORMALS);
185
+ }
186
+ set outlineUsesTangentNormals(val) {
187
+ this.useFeature(MToonMaterial.FEATURE_OUTLINE_TANGENT_NORMALS, !!val);
188
+ }
189
+ get transparentWithZWrite() {
190
+ return this._transparentWithZWrite;
191
+ }
192
+ set transparentWithZWrite(val) {
193
+ if (!!val !== this._transparentWithZWrite) {
194
+ this._transparentWithZWrite = !!val;
195
+ this.uniformChanged();
196
+ }
197
+ }
198
+ get renderQueueOffsetNumber() {
199
+ return this._renderQueueOffsetNumber;
200
+ }
201
+ set renderQueueOffsetNumber(val) {
202
+ const offset = Math.trunc(val);
203
+ if (offset !== this._renderQueueOffsetNumber) {
204
+ this._renderQueueOffsetNumber = offset;
205
+ this.uniformChanged();
206
+ }
207
+ }
208
+ get uvAnimationScrollXSpeedFactor() {
209
+ return this._uvAnimationScroll.x;
210
+ }
211
+ set uvAnimationScrollXSpeedFactor(val) {
212
+ if (val !== this._uvAnimationScroll.x) {
213
+ this._uvAnimationScroll.x = val;
214
+ this.uniformChanged();
215
+ }
216
+ }
217
+ get uvAnimationScrollYSpeedFactor() {
218
+ return this._uvAnimationScroll.y;
219
+ }
220
+ set uvAnimationScrollYSpeedFactor(val) {
221
+ if (val !== this._uvAnimationScroll.y) {
222
+ this._uvAnimationScroll.y = val;
223
+ this.uniformChanged();
224
+ }
225
+ }
226
+ get uvAnimationRotationSpeedFactor() {
227
+ return this._uvAnimationRotationSpeedFactor;
228
+ }
229
+ set uvAnimationRotationSpeedFactor(val) {
230
+ if (val !== this._uvAnimationRotationSpeedFactor) {
231
+ this._uvAnimationRotationSpeedFactor = val;
232
+ this.uniformChanged();
233
+ }
234
+ }
235
+ get emissiveColor() {
236
+ return this._emissiveColor;
237
+ }
238
+ set emissiveColor(val) {
239
+ this._emissiveColor.set(val);
240
+ this.uniformChanged();
241
+ }
242
+ get emissiveStrength() {
243
+ return this._emissiveStrength;
244
+ }
245
+ set emissiveStrength(val) {
246
+ if (val !== this._emissiveStrength) {
247
+ this._emissiveStrength = val;
248
+ this.uniformChanged();
249
+ }
250
+ }
251
+ clone() {
252
+ const other = new MToonMaterial();
253
+ other.copyFrom(this);
254
+ return other;
255
+ }
256
+ copyFrom(other) {
257
+ super.copyFrom(other);
258
+ this.shadeColorFactor = other.shadeColorFactor;
259
+ this.shadingShiftFactor = other.shadingShiftFactor;
260
+ this.shadingShiftTextureScale = other.shadingShiftTextureScale;
261
+ this.shadingToonyFactor = other.shadingToonyFactor;
262
+ this.giEqualizationFactor = other.giEqualizationFactor;
263
+ this.matcapFactor = other.matcapFactor;
264
+ this.parametricRimColorFactor = other.parametricRimColorFactor;
265
+ this.parametricRimFresnelPowerFactor = other.parametricRimFresnelPowerFactor;
266
+ this.parametricRimLiftFactor = other.parametricRimLiftFactor;
267
+ this.rimLightingMixFactor = other.rimLightingMixFactor;
268
+ this.outlineWidthMode = other.outlineWidthMode;
269
+ this.outlineWidthFactor = other.outlineWidthFactor;
270
+ this.outlineColorFactor = other.outlineColorFactor;
271
+ this.outlineLightingMixFactor = other.outlineLightingMixFactor;
272
+ this.outlineUsesTangentNormals = other.outlineUsesTangentNormals;
273
+ this.transparentWithZWrite = other.transparentWithZWrite;
274
+ this.renderQueueOffsetNumber = other.renderQueueOffsetNumber;
275
+ this.uvAnimationScrollXSpeedFactor = other.uvAnimationScrollXSpeedFactor;
276
+ this.uvAnimationScrollYSpeedFactor = other.uvAnimationScrollYSpeedFactor;
277
+ this.uvAnimationRotationSpeedFactor = other.uvAnimationRotationSpeedFactor;
278
+ this.emissiveColor = other.emissiveColor;
279
+ this.emissiveStrength = other.emissiveStrength;
280
+ }
281
+ getQueueType() {
282
+ return this.isTransparentPass(0) ? QUEUE_TRANSPARENT : QUEUE_OPAQUE;
283
+ }
284
+ passToHash(pass) {
285
+ return super.passToHash(pass > 0 ? 1 : 0);
286
+ }
287
+ isTransparentPass(pass, ctx) {
288
+ return pass === 0 && super.isTransparentPass(pass, ctx);
289
+ }
290
+ updateRenderStates(pass, stateSet, ctx) {
291
+ super.updateRenderStates(pass, stateSet, ctx);
292
+ if (pass > 0) {
293
+ stateSet.useRasterizerState().cullMode = 'front';
294
+ stateSet.defaultBlendingState();
295
+ stateSet.useDepthState().enableTest(true).enableWrite(true).setCompareFunc('lt');
296
+ } else if (this._transparentWithZWrite && this.isTransparentPass(pass, ctx)) {
297
+ stateSet.useDepthState().enableTest(true).enableWrite(true);
298
+ }
299
+ }
300
+ draw(primitive, ctx, numInstances = 0) {
301
+ const material = this;
302
+ if (this.numPasses > 1 && ctx.renderPass.type === RENDER_PASS_TYPE_LIGHT && !ctx.lightBlending) {
303
+ // Draw the inflated hull first so the regular pass hides interior outline fragments.
304
+ material.bind(ctx.device, 1);
305
+ this.drawPrimitive(1, primitive, ctx, numInstances);
306
+ material.bind(ctx.device, 0);
307
+ this.drawPrimitive(0, primitive, ctx, numInstances);
308
+ } else {
309
+ MeshMaterial.prototype.draw.call(this, primitive, ctx, numInstances);
310
+ }
311
+ }
312
+ drawPrimitive(pass, primitive, ctx, numInstances) {
313
+ if (pass > 0 && (ctx.renderPass.type !== RENDER_PASS_TYPE_LIGHT || ctx.lightBlending)) {
314
+ return;
315
+ }
316
+ super.drawPrimitive(pass, primitive, ctx, numInstances);
317
+ }
318
+ applyUniformValues(bindGroup, ctx, pass) {
319
+ super.applyUniformValues(bindGroup, ctx, pass);
320
+ if (this.needFragmentColorInput(ctx)) {
321
+ bindGroup.setValue('shadeColorFactor', this._shadeColorFactor);
322
+ bindGroup.setValue('shadingShiftFactor', this._shadingShiftFactor);
323
+ bindGroup.setValue('shadingShiftTextureScale', this._shadingShiftTextureScale);
324
+ bindGroup.setValue('shadingToonyFactor', this._shadingToonyFactor);
325
+ bindGroup.setValue('giEqualizationFactor', this._giEqualizationFactor);
326
+ bindGroup.setValue('matcapFactor', this._matcapFactor);
327
+ bindGroup.setValue('parametricRimColorFactor', this._parametricRimColorFactor);
328
+ bindGroup.setValue('parametricRimFresnelPowerFactor', this._parametricRimFresnelPowerFactor);
329
+ bindGroup.setValue('parametricRimLiftFactor', this._parametricRimLiftFactor);
330
+ bindGroup.setValue('rimLightingMixFactor', this._rimLightingMixFactor);
331
+ bindGroup.setValue('uvAnimationScroll', this._uvAnimationScroll);
332
+ bindGroup.setValue('uvAnimationRotationSpeedFactor', this._uvAnimationRotationSpeedFactor);
333
+ bindGroup.setValue('emissiveColor', this._emissiveColor);
334
+ bindGroup.setValue('emissiveStrength', this._emissiveStrength);
335
+ } else if (pass > 0 && this.outlineWidthMultiplyTexture && this.usesAnimatedUV()) {
336
+ bindGroup.setValue('uvAnimationScroll', this._uvAnimationScroll);
337
+ bindGroup.setValue('uvAnimationRotationSpeedFactor', this._uvAnimationRotationSpeedFactor);
338
+ }
339
+ if (pass > 0) {
340
+ bindGroup.setValue('outlineWidthFactor', this._outlineWidthFactor);
341
+ if (this.outlineWidthMultiplyTexture) {
342
+ bindGroup.setTexture('outlineWidthTex', this.outlineWidthMultiplyTexture, this.outlineWidthMultiplyTextureSampler);
343
+ if (this.uvAnimationMaskTexture && this.usesAnimatedUV()) {
344
+ bindGroup.setTexture('uvAnimationMaskTex', this.uvAnimationMaskTexture, this.uvAnimationMaskTextureSampler);
345
+ }
346
+ if (this.outlineWidthMultiplyTexCoordMatrix) {
347
+ bindGroup.setValue('outlineWidthTextureMatrix', this.outlineWidthMultiplyTexCoordMatrix);
348
+ }
349
+ }
350
+ }
351
+ if (pass > 0 && ctx.renderPass.type === RENDER_PASS_TYPE_LIGHT) {
352
+ bindGroup.setValue('outlineColorFactor', this._outlineColorFactor);
353
+ bindGroup.setValue('outlineLightingMixFactor', this._outlineLightingMixFactor);
354
+ }
355
+ }
356
+ usesAnimatedUV() {
357
+ return this._uvAnimationScroll.x !== 0 || this._uvAnimationScroll.y !== 0 || this._uvAnimationRotationSpeedFactor !== 0;
358
+ }
359
+ applyUVAnimation(scope, uv) {
360
+ if (!this.usesAnimatedUV()) {
361
+ return uv;
362
+ }
363
+ const pb = scope.$builder;
364
+ const funcName = 'Z_mtoonUVAnimation';
365
+ const that = this;
366
+ if (!scope.uvAnimationScroll) {
367
+ scope.uvAnimationScroll = pb.vec2().uniform(2);
368
+ }
369
+ if (!scope.uvAnimationRotationSpeedFactor) {
370
+ scope.uvAnimationRotationSpeedFactor = pb.float().uniform(2);
371
+ }
372
+ if (that.uvAnimationMaskTexture && pb.shaderKind !== 'fragment' && !scope.uvAnimationMaskTex) {
373
+ scope.uvAnimationMaskTex = pb.tex2D().uniform(2);
374
+ }
375
+ pb.func(funcName, [
376
+ pb.vec2('uv')
377
+ ], function() {
378
+ this.$l.mask = that.uvAnimationMaskTexture ? pb.shaderKind === 'fragment' ? pb.textureSample(that.getUvAnimationMaskTextureUniform(this), this.uv).b : pb.textureSampleLevel(this.uvAnimationMaskTex, this.uv, 0).b : pb.float(1);
379
+ this.$l.time = ShaderHelper.getElapsedTime(this);
380
+ this.$l.rotation = pb.mul(this.time, this.uvAnimationRotationSpeedFactor, this.mask);
381
+ this.$l.c = pb.cos(this.rotation);
382
+ this.$l.s = pb.sin(this.rotation);
383
+ this.$l.centeredUv = pb.sub(this.uv, pb.vec2(0.5));
384
+ this.$l.rotatedUv = pb.add(pb.vec2(pb.add(pb.mul(this.c, this.centeredUv.x), pb.mul(this.s, this.centeredUv.y)), pb.add(pb.mul(pb.neg(this.s), this.centeredUv.x), pb.mul(this.c, this.centeredUv.y))), pb.vec2(0.5));
385
+ this.$return(pb.add(this.rotatedUv, pb.mul(this.uvAnimationScroll, this.time, this.mask)));
386
+ });
387
+ return pb.getGlobalScope()[funcName](uv);
388
+ }
389
+ getMToonBaseUV(scope) {
390
+ return this.albedoTexture ? this.applyUVAnimation(scope, this.getAlbedoTexCoord(scope)) : scope.$builder.vec2(0);
391
+ }
392
+ getMToonNormalUV(scope) {
393
+ return this.normalTexture ? this.applyUVAnimation(scope, this.getNormalTexCoord(scope)) : scope.$builder.vec2(0);
394
+ }
395
+ sampleAlbedo(scope, uv) {
396
+ return this.calculateAlbedoColor(scope, uv);
397
+ }
398
+ sampleShadeColor(scope) {
399
+ const pb = scope.$builder;
400
+ return this.shadeMultiplyTexture ? pb.mul(scope.shadeColorFactor, this.sampleShadeMultiplyTexture(scope, this.applyUVAnimation(scope, this.getShadeMultiplyTexCoord(scope))).rgb) : scope.shadeColorFactor;
401
+ }
402
+ sampleNormal(scope, uv) {
403
+ const pb = scope.$builder;
404
+ if (!this.normalTexture) {
405
+ return pb.normalize(scope.$inputs.wNorm);
406
+ }
407
+ scope.$l.TBN = this.calculateTBN(scope, scope.$inputs.worldPos, scope.$inputs.wNorm);
408
+ scope.$l.normalTex = pb.sub(pb.mul(this.sampleNormalTexture(scope, uv).rgb, 2), pb.vec3(1));
409
+ scope.normalTex = pb.mul(scope.normalTex, pb.vec3(pb.vec3(this.getUniformNormalScale(scope)).xx, 1));
410
+ return pb.normalize(pb.mul(scope.TBN, scope.normalTex));
411
+ }
412
+ calculateMToonDirectLighting(scope, worldPos, normal, baseColor, shadeColor, shadingShift) {
413
+ const pb = scope.$builder;
414
+ const that = this;
415
+ const funcName = 'Z_mtoonDirectLighting';
416
+ pb.func(funcName, [
417
+ pb.vec3('worldPos'),
418
+ pb.vec3('normal'),
419
+ pb.vec3('baseColor'),
420
+ pb.vec3('shadeColor'),
421
+ pb.float('shadingShift')
422
+ ], function() {
423
+ this.$l.directColor = pb.vec3(0);
424
+ that.forEachLight(this, function(type, posRange, dirCutoff, colorIntensity, extra, shadow) {
425
+ this.$l.lightAtten = that.calculateLightAttenuation(this, type, this.worldPos, posRange, dirCutoff);
426
+ this.$l.lightDir = that.calculateLightDirection(this, type, this.worldPos, posRange, dirCutoff);
427
+ this.$l.lightColor = pb.mul(colorIntensity.rgb, colorIntensity.a, this.lightAtten);
428
+ this.$l.NoL = pb.dot(this.normal, this.lightDir);
429
+ this.$l.shiftedShading = pb.add(this.NoL, this.shadingShift);
430
+ this.$l.shading = pb.clamp(pb.div(pb.sub(this.shiftedShading, pb.add(-1, this.shadingToonyFactor)), pb.max(pb.sub(2, pb.mul(this.shadingToonyFactor, 2)), 0.00001)), 0, 1);
431
+ this.$l.lightDiffuse = pb.mix(this.shadeColor, this.baseColor, this.shading);
432
+ if (shadow) {
433
+ this.$l.shadowValue = that.calculateShadow(this, this.worldPos, pb.clamp(this.NoL, 0, 1));
434
+ this.lightDiffuse = pb.mix(this.shadeColor, this.lightDiffuse, this.shadowValue);
435
+ }
436
+ this.directColor = pb.add(this.directColor, pb.mul(this.lightDiffuse, this.lightColor));
437
+ });
438
+ this.$return(this.directColor);
439
+ });
440
+ return pb.getGlobalScope()[funcName](worldPos, normal, baseColor, shadeColor, shadingShift);
441
+ }
442
+ calculateMToonGI(scope, normal, baseColor) {
443
+ const pb = scope.$builder;
444
+ if (!this.needCalculateEnvLight()) {
445
+ return pb.vec3(0);
446
+ }
447
+ scope.$l.rawGi = this.getEnvLightIrradiance(scope, normal);
448
+ scope.$l.uniformGi = pb.mul(pb.add(this.getEnvLightIrradiance(scope, pb.vec3(0, 1, 0)), this.getEnvLightIrradiance(scope, pb.vec3(0, -1, 0))), 0.5);
449
+ scope.$l.gi = pb.mix(scope.rawGi, scope.uniformGi, scope.giEqualizationFactor);
450
+ return pb.mul(scope.gi, baseColor);
451
+ }
452
+ calculateMToonRim(scope, normal, viewVec, uv, lighting) {
453
+ const pb = scope.$builder;
454
+ scope.$l.rim = pb.vec3(0);
455
+ if (this.matcapTexture) {
456
+ scope.$l.worldViewX = pb.normalize(pb.vec3(viewVec.z, 0, pb.neg(viewVec.x)));
457
+ scope.$l.worldViewY = pb.normalize(pb.cross(viewVec, scope.worldViewX));
458
+ scope.$l.matcapUv = pb.add(pb.mul(pb.vec2(pb.dot(scope.worldViewX, normal), pb.dot(scope.worldViewY, normal)), 0.495), pb.vec2(0.5));
459
+ scope.rim = pb.add(scope.rim, pb.mul(scope.matcapFactor, this.sampleMatcapTexture(scope, scope.matcapUv).rgb));
460
+ }
461
+ scope.$l.NoV = pb.clamp(pb.dot(normal, viewVec), 0, 1);
462
+ scope.$l.parametricRim = pb.pow(pb.clamp(pb.add(pb.sub(1, scope.NoV), scope.parametricRimLiftFactor), 0, 1), pb.max(scope.parametricRimFresnelPowerFactor, 0.00001));
463
+ scope.rim = pb.add(scope.rim, pb.mul(scope.parametricRimColorFactor, scope.parametricRim));
464
+ if (this.rimMultiplyTexture) {
465
+ scope.rim = pb.mul(scope.rim, this.sampleRimMultiplyTexture(scope, this.applyUVAnimation(scope, this.getRimMultiplyTexCoord(scope))).rgb);
466
+ }
467
+ return pb.mul(scope.rim, pb.mix(pb.vec3(1), lighting, scope.rimLightingMixFactor));
468
+ }
469
+ calculateMToonEmission(scope) {
470
+ const pb = scope.$builder;
471
+ return this.emissiveTexture ? pb.mul(scope.emissiveColor, scope.emissiveStrength, this.sampleEmissiveTexture(scope, this.applyUVAnimation(scope, this.getEmissiveTexCoord(scope))).rgb) : pb.mul(scope.emissiveColor, scope.emissiveStrength);
472
+ }
473
+ vertexShader(scope) {
474
+ super.vertexShader(scope);
475
+ const pb = scope.$builder;
476
+ scope.$l.oPos = ShaderHelper.resolveVertexPosition(scope);
477
+ scope.$l.oNorm = ShaderHelper.resolveVertexNormal(scope);
478
+ if (this.pass > 0 && this.outlineUsesTangentNormals) {
479
+ scope.$l.oOutlineNorm = ShaderHelper.resolveVertexTangent(scope).xyz;
480
+ }
481
+ scope.$l.worldNormal = pb.normalize(pb.mul(ShaderHelper.getNormalMatrix(scope), pb.vec4(scope.oNorm, 0)).xyz);
482
+ scope.$l.worldOutlineNormal = this.pass > 0 && this.outlineUsesTangentNormals ? pb.normalize(pb.mul(ShaderHelper.getNormalMatrix(scope), pb.vec4(scope.oOutlineNorm, 0)).xyz) : scope.worldNormal;
483
+ scope.$l.worldPos = pb.mul(ShaderHelper.getWorldMatrix(scope), pb.vec4(scope.oPos, 1)).xyz;
484
+ if (this.pass > 0) {
485
+ scope.outlineWidthFactor = pb.float().uniform(2);
486
+ scope.$l.width = scope.outlineWidthFactor;
487
+ if (this.outlineWidthMultiplyTexture) {
488
+ scope.outlineWidthTex = pb.tex2D().uniform(2);
489
+ const uvIndex = this.outlineWidthMultiplyTexCoordIndex;
490
+ const semantic = `texCoord${uvIndex}`;
491
+ if (!scope.$getVertexAttrib(semantic)) {
492
+ scope.$inputs[semantic] = pb.vec2().attrib(semantic);
493
+ }
494
+ if (this.outlineWidthMultiplyTexCoordMatrix) {
495
+ scope.outlineWidthTextureMatrix = pb.mat4().uniform(2);
496
+ scope.$l.outlineUv = pb.mul(scope.outlineWidthTextureMatrix, pb.vec4(this.applyUVAnimation(scope, scope.$inputs[semantic]), 0, 1)).xy;
497
+ } else {
498
+ scope.$l.outlineUv = this.applyUVAnimation(scope, scope.$inputs[semantic]);
499
+ }
500
+ scope.width = pb.mul(scope.width, pb.textureSampleLevel(scope.outlineWidthTex, scope.outlineUv, 0).g);
501
+ }
502
+ if (this.outlineWidthMode === 'worldCoordinates') {
503
+ scope.worldPos = pb.add(scope.worldPos, pb.mul(scope.worldOutlineNormal, scope.width));
504
+ } else if (this.outlineWidthMode === 'screenCoordinates') {
505
+ scope.$l.clipNormalPos = pb.mul(ShaderHelper.getViewProjectionMatrix(scope), pb.vec4(pb.add(scope.worldPos, scope.worldOutlineNormal), 1));
506
+ scope.$l.clipPos = pb.mul(ShaderHelper.getViewProjectionMatrix(scope), pb.vec4(scope.worldPos, 1));
507
+ scope.$l.screenNormal = pb.sub(pb.div(scope.clipNormalPos.xy, pb.max(scope.clipNormalPos.w, 0.00001)), pb.div(scope.clipPos.xy, pb.max(scope.clipPos.w, 0.00001)));
508
+ scope.screenNormal = pb.normalize(pb.mul(scope.screenNormal, pb.vec2(1, pb.div(ShaderHelper.getRenderSize(scope).x, ShaderHelper.getRenderSize(scope).y))));
509
+ //scope.clipPos.xy = pb.add(scope.clipPos.xy, pb.mul(scope.screenNormal, scope.width, scope.clipPos.w));
510
+ scope.clipPos = pb.vec4(pb.add(scope.clipPos.xy, pb.mul(scope.screenNormal, scope.width, scope.clipPos.w)), scope.clipPos.zw);
511
+ scope.$outputs.worldPos = scope.worldPos;
512
+ scope.$outputs.wNorm = scope.worldOutlineNormal;
513
+ ShaderHelper.setClipSpacePosition(scope, scope.clipPos);
514
+ return;
515
+ }
516
+ }
517
+ scope.$outputs.worldPos = scope.worldPos;
518
+ scope.$outputs.wNorm = this.pass > 0 ? scope.worldOutlineNormal : scope.worldNormal;
519
+ ShaderHelper.setClipSpacePosition(scope, pb.mul(ShaderHelper.getViewProjectionMatrix(scope), pb.vec4(scope.$outputs.worldPos, 1)));
520
+ }
521
+ fragmentShader(scope) {
522
+ super.fragmentShader(scope);
523
+ const pb = scope.$builder;
524
+ if (this.needFragmentColorInput()) {
525
+ scope.shadeColorFactor = pb.vec3().uniform(2);
526
+ scope.shadingShiftFactor = pb.float().uniform(2);
527
+ scope.shadingShiftTextureScale = pb.float().uniform(2);
528
+ scope.shadingToonyFactor = pb.float().uniform(2);
529
+ scope.giEqualizationFactor = pb.float().uniform(2);
530
+ scope.matcapFactor = pb.vec3().uniform(2);
531
+ scope.parametricRimColorFactor = pb.vec3().uniform(2);
532
+ scope.parametricRimFresnelPowerFactor = pb.float().uniform(2);
533
+ scope.parametricRimLiftFactor = pb.float().uniform(2);
534
+ scope.rimLightingMixFactor = pb.float().uniform(2);
535
+ scope.uvAnimationScroll = pb.vec2().uniform(2);
536
+ scope.uvAnimationRotationSpeedFactor = pb.float().uniform(2);
537
+ scope.emissiveColor = pb.vec3().uniform(2);
538
+ scope.emissiveStrength = pb.float().uniform(2);
539
+ if (this.pass > 0) {
540
+ scope.outlineColorFactor = pb.vec3().uniform(2);
541
+ scope.outlineLightingMixFactor = pb.float().uniform(2);
542
+ scope.$l.albedo = this.sampleAlbedo(scope, this.getMToonBaseUV(scope));
543
+ scope.$l.outlineLighting = pb.mix(pb.vec3(1), scope.albedo.rgb, scope.outlineLightingMixFactor);
544
+ this.outputFragmentColor(scope, scope.$inputs.worldPos, pb.vec4(pb.mul(scope.outlineColorFactor, scope.outlineLighting), scope.albedo.a));
545
+ } else {
546
+ scope.$l.uv = this.getMToonBaseUV(scope);
547
+ scope.$l.albedo = this.sampleAlbedo(scope, scope.uv);
548
+ if (this.drawContext.renderPass.type === RENDER_PASS_TYPE_LIGHT) {
549
+ scope.$l.normal = this.sampleNormal(scope, this.getMToonNormalUV(scope));
550
+ scope.$l.shadingShift = scope.shadingShiftFactor;
551
+ if (this.shadingShiftTexture) {
552
+ scope.shadingShift = pb.add(scope.shadingShift, pb.mul(this.sampleShadingShiftTexture(scope, this.applyUVAnimation(scope, this.getShadingShiftTexCoord(scope))).r, scope.shadingShiftTextureScale));
553
+ }
554
+ scope.$l.shadeColor = this.sampleShadeColor(scope);
555
+ scope.$l.viewVec = this.calculateViewVector(scope, scope.$inputs.worldPos);
556
+ scope.$l.directLighting = this.calculateMToonDirectLighting(scope, scope.$inputs.worldPos, scope.normal, scope.albedo.rgb, scope.shadeColor, scope.shadingShift);
557
+ scope.$l.giLighting = this.calculateMToonGI(scope, scope.normal, scope.albedo.rgb);
558
+ scope.$l.lighting = pb.max(scope.directLighting, scope.giLighting);
559
+ scope.$l.rim = this.calculateMToonRim(scope, scope.normal, scope.viewVec, scope.uv, scope.lighting);
560
+ scope.$l.emission = this.calculateMToonEmission(scope);
561
+ scope.$l.outColor = pb.vec4(pb.add(scope.directLighting, scope.giLighting, scope.rim, scope.emission), scope.albedo.a);
562
+ this.outputFragmentColor(scope, scope.$inputs.worldPos, scope.outColor, pb.vec4(1, 1, 0, 1), pb.vec4(pb.add(pb.mul(scope.normal, 0.5), pb.vec3(0.5)), 1));
563
+ } else {
564
+ this.outputFragmentColor(scope, scope.$inputs.worldPos, scope.albedo);
565
+ }
566
+ }
567
+ } else {
568
+ this.outputFragmentColor(scope, scope.$inputs.worldPos, null);
569
+ }
570
+ }
571
+ }
572
+
573
+ export { MToonMaterial };
574
+ //# sourceMappingURL=mtoon.js.map