@zephyr3d/scene 0.8.2 → 0.9.1

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 (241) hide show
  1. package/dist/animation/animationset.js +473 -60
  2. package/dist/animation/animationset.js.map +1 -1
  3. package/dist/animation/cloth/gpu_cloth_system.js +2516 -0
  4. package/dist/animation/cloth/gpu_cloth_system.js.map +1 -0
  5. package/dist/animation/fixed_geometry_cache_track.js +138 -0
  6. package/dist/animation/fixed_geometry_cache_track.js.map +1 -0
  7. package/dist/animation/geometry_cache_utils.js +120 -0
  8. package/dist/animation/geometry_cache_utils.js.map +1 -0
  9. package/dist/animation/ik_modifier.js +9 -1
  10. package/dist/animation/ik_modifier.js.map +1 -1
  11. package/dist/animation/joint_dynamics/collision.js +469 -0
  12. package/dist/animation/joint_dynamics/collision.js.map +1 -0
  13. package/dist/animation/joint_dynamics/constraints.js +329 -0
  14. package/dist/animation/joint_dynamics/constraints.js.map +1 -0
  15. package/dist/animation/joint_dynamics/controller.js +699 -0
  16. package/dist/animation/joint_dynamics/controller.js.map +1 -0
  17. package/dist/animation/joint_dynamics/joint_dynamics_system.js +393 -0
  18. package/dist/animation/joint_dynamics/joint_dynamics_system.js.map +1 -0
  19. package/dist/animation/joint_dynamics/solver.js +794 -0
  20. package/dist/animation/joint_dynamics/solver.js.map +1 -0
  21. package/dist/animation/joint_dynamics/types.js +19 -0
  22. package/dist/animation/joint_dynamics/types.js.map +1 -0
  23. package/dist/animation/joint_dynamics/vrm_spring_bone.js +46 -0
  24. package/dist/animation/joint_dynamics/vrm_spring_bone.js.map +1 -0
  25. package/dist/animation/joint_dynamics_modifier.js +51 -0
  26. package/dist/animation/joint_dynamics_modifier.js.map +1 -0
  27. package/dist/animation/pca_geometry_cache_track.js +222 -0
  28. package/dist/animation/pca_geometry_cache_track.js.map +1 -0
  29. package/dist/animation/skeleton.js +2011 -139
  30. package/dist/animation/skeleton.js.map +1 -1
  31. package/dist/animation/skeleton_modifier.js +3 -5
  32. package/dist/animation/skeleton_modifier.js.map +1 -1
  33. package/dist/animation/spring/multi_chain_spring_system.js +2 -0
  34. package/dist/animation/spring/multi_chain_spring_system.js.map +1 -1
  35. package/dist/animation/spring/spring_chain.js +3 -2
  36. package/dist/animation/spring/spring_chain.js.map +1 -1
  37. package/dist/animation/spring/spring_collider.js +35 -5
  38. package/dist/animation/spring/spring_collider.js.map +1 -1
  39. package/dist/animation/spring/spring_particle.js +1 -0
  40. package/dist/animation/spring/spring_particle.js.map +1 -1
  41. package/dist/animation/spring/spring_system.js +325 -28
  42. package/dist/animation/spring/spring_system.js.map +1 -1
  43. package/dist/animation/spring2/collision.js +469 -0
  44. package/dist/animation/spring2/collision.js.map +1 -0
  45. package/dist/animation/spring2/constraints.js +329 -0
  46. package/dist/animation/spring2/constraints.js.map +1 -0
  47. package/dist/animation/spring2/controller.js +434 -0
  48. package/dist/animation/spring2/controller.js.map +1 -0
  49. package/dist/animation/spring2/math.js +16 -0
  50. package/dist/animation/spring2/math.js.map +1 -0
  51. package/dist/animation/spring2/solver.js +624 -0
  52. package/dist/animation/spring2/solver.js.map +1 -0
  53. package/dist/animation/spring2/spring_system.js +118 -0
  54. package/dist/animation/spring2/spring_system.js.map +1 -0
  55. package/dist/animation/spring2/types.js +19 -0
  56. package/dist/animation/spring2/types.js.map +1 -0
  57. package/dist/animation/spring_modifier.js +17 -1
  58. package/dist/animation/spring_modifier.js.map +1 -1
  59. package/dist/app/engine.js +42 -15
  60. package/dist/app/engine.js.map +1 -1
  61. package/dist/app/runtimescript.js +132 -1
  62. package/dist/app/runtimescript.js.map +1 -1
  63. package/dist/app/screen.js +3 -3
  64. package/dist/app/screen.js.map +1 -1
  65. package/dist/app/scriptingsystem.js +69 -37
  66. package/dist/app/scriptingsystem.js.map +1 -1
  67. package/dist/app/scriptregistry.js +14 -3
  68. package/dist/app/scriptregistry.js.map +1 -1
  69. package/dist/asset/assetmanager.js +2 -1
  70. package/dist/asset/assetmanager.js.map +1 -1
  71. package/dist/asset/loaders/zabc/zabc_loader.js +570 -0
  72. package/dist/asset/loaders/zabc/zabc_loader.js.map +1 -0
  73. package/dist/asset/model.js +192 -0
  74. package/dist/asset/model.js.map +1 -1
  75. package/dist/camera/base.js +26 -7
  76. package/dist/camera/base.js.map +1 -1
  77. package/dist/camera/camera.js +146 -24
  78. package/dist/camera/camera.js.map +1 -1
  79. package/dist/camera/fps.js +2 -2
  80. package/dist/camera/fps.js.map +1 -1
  81. package/dist/camera/orbit.js +2 -2
  82. package/dist/camera/orbit.js.map +1 -1
  83. package/dist/index.d.ts +11728 -8535
  84. package/dist/index.js +29 -8
  85. package/dist/index.js.map +1 -1
  86. package/dist/material/lambert.js +1 -1
  87. package/dist/material/lambert.js.map +1 -1
  88. package/dist/material/material.js +9 -3
  89. package/dist/material/material.js.map +1 -1
  90. package/dist/material/meshmaterial.js +54 -7
  91. package/dist/material/meshmaterial.js.map +1 -1
  92. package/dist/material/mixins/lightmodel/blinnphong.js +17 -7
  93. package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
  94. package/dist/material/mixins/lightmodel/lambert.js +7 -2
  95. package/dist/material/mixins/lightmodel/lambert.js.map +1 -1
  96. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js +108 -16
  97. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js.map +1 -1
  98. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +209 -14
  99. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
  100. package/dist/material/mixins/lightmodel/pbrspecularglossness.js +24 -12
  101. package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
  102. package/dist/material/mixins/lit.js +11 -8
  103. package/dist/material/mixins/lit.js.map +1 -1
  104. package/dist/material/mixins/pbr/common.js +72 -5
  105. package/dist/material/mixins/pbr/common.js.map +1 -1
  106. package/dist/material/pbrblueprint.js +148 -1
  107. package/dist/material/pbrblueprint.js.map +1 -1
  108. package/dist/material/pbrmr.js +115 -2
  109. package/dist/material/pbrmr.js.map +1 -1
  110. package/dist/material/shader/helper.js +10 -4
  111. package/dist/material/shader/helper.js.map +1 -1
  112. package/dist/material/water.js +2 -2
  113. package/dist/material/water.js.map +1 -1
  114. package/dist/posteffect/coloradjust.js +145 -0
  115. package/dist/posteffect/coloradjust.js.map +1 -0
  116. package/dist/posteffect/taa.js +68 -32
  117. package/dist/posteffect/taa.js.map +1 -1
  118. package/dist/render/cluster_light.js +17 -12
  119. package/dist/render/cluster_light.js.map +1 -1
  120. package/dist/render/deferredlightpass.js +510 -0
  121. package/dist/render/deferredlightpass.js.map +1 -0
  122. package/dist/render/deferredshadowlightpass.js +428 -0
  123. package/dist/render/deferredshadowlightpass.js.map +1 -0
  124. package/dist/render/drawable.js.map +1 -1
  125. package/dist/render/drawable_mixin.js +21 -12
  126. package/dist/render/drawable_mixin.js.map +1 -1
  127. package/dist/render/envlight.js +20 -22
  128. package/dist/render/envlight.js.map +1 -1
  129. package/dist/render/gbufferpass.js +50 -0
  130. package/dist/render/gbufferpass.js.map +1 -0
  131. package/dist/render/lightpass.js +1 -2
  132. package/dist/render/lightpass.js.map +1 -1
  133. package/dist/render/primitive.js +1 -1
  134. package/dist/render/primitive.js.map +1 -1
  135. package/dist/render/render_queue.js +3 -2
  136. package/dist/render/render_queue.js.map +1 -1
  137. package/dist/render/renderer.js +5 -358
  138. package/dist/render/renderer.js.map +1 -1
  139. package/dist/render/rendergraph/executor.js +15 -12
  140. package/dist/render/rendergraph/executor.js.map +1 -1
  141. package/dist/render/rendergraph/forward_plus_builder.js +144 -88
  142. package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
  143. package/dist/render/rendergraph/history_resource_manager.js +178 -0
  144. package/dist/render/rendergraph/history_resource_manager.js.map +1 -0
  145. package/dist/render/rendergraph/rendergraph.js +12 -1
  146. package/dist/render/rendergraph/rendergraph.js.map +1 -1
  147. package/dist/render/rendergraph/types.js +2 -2
  148. package/dist/render/rendergraph/types.js.map +1 -1
  149. package/dist/render/sky.js +26 -9
  150. package/dist/render/sky.js.map +1 -1
  151. package/dist/scene/basesprite.js +4 -3
  152. package/dist/scene/basesprite.js.map +1 -1
  153. package/dist/scene/batchgroup.js +4 -4
  154. package/dist/scene/environment.js +7 -4
  155. package/dist/scene/environment.js.map +1 -1
  156. package/dist/scene/light.js +184 -18
  157. package/dist/scene/light.js.map +1 -1
  158. package/dist/scene/mesh.js +30 -0
  159. package/dist/scene/mesh.js.map +1 -1
  160. package/dist/scene/particlesys.js +3 -2
  161. package/dist/scene/particlesys.js.map +1 -1
  162. package/dist/scene/raycast_visitor.js +29 -3
  163. package/dist/scene/raycast_visitor.js.map +1 -1
  164. package/dist/scene/scene.js +86 -19
  165. package/dist/scene/scene.js.map +1 -1
  166. package/dist/scene/scene_node.js +87 -31
  167. package/dist/scene/scene_node.js.map +1 -1
  168. package/dist/scene/script_attachment.js +59 -0
  169. package/dist/scene/script_attachment.js.map +1 -0
  170. package/dist/scene/terrain-cm/grass.js +3 -2
  171. package/dist/scene/terrain-cm/grass.js.map +1 -1
  172. package/dist/scene/terrain-cm/terrain-cm.js +4 -3
  173. package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
  174. package/dist/scene/water.js +3 -2
  175. package/dist/scene/water.js.map +1 -1
  176. package/dist/shaders/shadow.js +2 -2
  177. package/dist/shaders/shadow.js.map +1 -1
  178. package/dist/shadow/shadowmapper.js +74 -4
  179. package/dist/shadow/shadowmapper.js.map +1 -1
  180. package/dist/shapes/box.js +163 -0
  181. package/dist/shapes/box.js.map +1 -1
  182. package/dist/shapes/capsule.js +216 -0
  183. package/dist/shapes/capsule.js.map +1 -0
  184. package/dist/shapes/cylinder.js +91 -0
  185. package/dist/shapes/cylinder.js.map +1 -1
  186. package/dist/shapes/plane.js +32 -0
  187. package/dist/shapes/plane.js.map +1 -1
  188. package/dist/shapes/tetrahedron.js +211 -0
  189. package/dist/shapes/tetrahedron.js.map +1 -1
  190. package/dist/shapes/torus.js +173 -0
  191. package/dist/shapes/torus.js.map +1 -1
  192. package/dist/utility/blueprint/common/math.js +111 -1
  193. package/dist/utility/blueprint/common/math.js.map +1 -1
  194. package/dist/utility/blueprint/material/inputs.js +235 -1
  195. package/dist/utility/blueprint/material/inputs.js.map +1 -1
  196. package/dist/utility/blueprint/material/ir.js +154 -10
  197. package/dist/utility/blueprint/material/ir.js.map +1 -1
  198. package/dist/utility/blueprint/material/texture.js +273 -19
  199. package/dist/utility/blueprint/material/texture.js.map +1 -1
  200. package/dist/utility/serialization/json.js +12 -2
  201. package/dist/utility/serialization/json.js.map +1 -1
  202. package/dist/utility/serialization/manager.js +30 -11
  203. package/dist/utility/serialization/manager.js.map +1 -1
  204. package/dist/utility/serialization/scene/animation.js +250 -7
  205. package/dist/utility/serialization/scene/animation.js.map +1 -1
  206. package/dist/utility/serialization/scene/batch.js +4 -2
  207. package/dist/utility/serialization/scene/batch.js.map +1 -1
  208. package/dist/utility/serialization/scene/camera.js +154 -2
  209. package/dist/utility/serialization/scene/camera.js.map +1 -1
  210. package/dist/utility/serialization/scene/cloth_script.js +834 -0
  211. package/dist/utility/serialization/scene/cloth_script.js.map +1 -0
  212. package/dist/utility/serialization/scene/common.js +7 -0
  213. package/dist/utility/serialization/scene/common.js.map +1 -1
  214. package/dist/utility/serialization/scene/light.js +120 -4
  215. package/dist/utility/serialization/scene/light.js.map +1 -1
  216. package/dist/utility/serialization/scene/material.js +453 -1
  217. package/dist/utility/serialization/scene/material.js.map +1 -1
  218. package/dist/utility/serialization/scene/mesh.js +4 -2
  219. package/dist/utility/serialization/scene/mesh.js.map +1 -1
  220. package/dist/utility/serialization/scene/node.js +298 -10
  221. package/dist/utility/serialization/scene/node.js.map +1 -1
  222. package/dist/utility/serialization/scene/particle.js +4 -2
  223. package/dist/utility/serialization/scene/particle.js.map +1 -1
  224. package/dist/utility/serialization/scene/primitive.js +100 -3
  225. package/dist/utility/serialization/scene/primitive.js.map +1 -1
  226. package/dist/utility/serialization/scene/scene.js +130 -3
  227. package/dist/utility/serialization/scene/scene.js.map +1 -1
  228. package/dist/utility/serialization/scene/script.js +66 -0
  229. package/dist/utility/serialization/scene/script.js.map +1 -0
  230. package/dist/utility/serialization/scene/spring_script.js +596 -0
  231. package/dist/utility/serialization/scene/spring_script.js.map +1 -0
  232. package/dist/utility/serialization/scene/sprite.js +5 -3
  233. package/dist/utility/serialization/scene/sprite.js.map +1 -1
  234. package/dist/utility/serialization/scene/terrain.js +4 -2
  235. package/dist/utility/serialization/scene/terrain.js.map +1 -1
  236. package/dist/utility/serialization/scene/water.js +4 -2
  237. package/dist/utility/serialization/scene/water.js.map +1 -1
  238. package/dist/utility/serialization/types.js.map +1 -1
  239. package/dist/values.js +5 -1
  240. package/dist/values.js.map +1 -1
  241. package/package.json +3 -3
@@ -1,11 +1,17 @@
1
1
  import { applyMaterialMixins, MeshMaterial } from './meshmaterial.js';
2
2
  import { ShaderHelper } from './shader/helper.js';
3
3
  import { RENDER_PASS_TYPE_LIGHT, MaterialVaryingFlags } from '../values.js';
4
- import { DRef, Vector4 } from '@zephyr3d/base';
4
+ import { Vector3, Vector2, DRef, Vector4 } from '@zephyr3d/base';
5
5
  import { mixinPBRBluePrint } from './mixins/lightmodel/pbrblueprintmixin.js';
6
6
  import { MaterialBlueprintIR } from '../utility/blueprint/material/ir.js';
7
7
  import { PBRBlockNode, VertexBlockNode } from '../utility/blueprint/material/pbr.js';
8
8
 
9
+ const PBR_REFLECTION_MODE = {
10
+ none: 0,
11
+ ggx: 1,
12
+ anisotropic: 2,
13
+ glint: 3
14
+ };
9
15
  /**
10
16
  * Physically-based rendering material driven by blueprint graphs.
11
17
  *
@@ -27,10 +33,19 @@ import { PBRBlockNode, VertexBlockNode } from '../utility/blueprint/material/pbr
27
33
  */ class PBRBluePrintMaterial extends applyMaterialMixins(MeshMaterial, mixinPBRBluePrint) {
28
34
  /** @internal */ static FEATURE_VERTEX_COLOR = this.defineFeature();
29
35
  /** @internal */ static FEATURE_VERTEX_UV = this.defineFeature();
36
+ /** @internal */ static FEATURE_SUBSURFACE_SCATTERING = this.defineFeature();
30
37
  /** @internal */ _irFrag;
31
38
  /** @internal */ _irVertex;
32
39
  /** @internal */ _uniformValues;
33
40
  /** @internal */ _uniformTextures;
41
+ /** @internal */ _reflectionMode;
42
+ /** @internal */ _subsurfaceColor;
43
+ /** @internal */ _subsurfaceScale;
44
+ /** @internal */ _subsurfacePower;
45
+ /** @internal */ _subsurfaceIntensity;
46
+ /** @internal */ _anisotropy;
47
+ /** @internal */ _anisotropyDirection;
48
+ /** @internal */ _anisotropyDirectionScaleBias;
34
49
  /**
35
50
  * Creates a new {@link PBRBluePrintMaterial} instance.
36
51
  *
@@ -100,9 +115,97 @@ import { PBRBlockNode, VertexBlockNode } from '../utility/blueprint/material/pbr
100
115
  });
101
116
  this._uniformValues = uniformValues ?? [];
102
117
  this._uniformTextures = uniformTextures ?? [];
118
+ this._reflectionMode = 'ggx';
119
+ this._subsurfaceColor = new Vector3(1, 0.3, 0.2);
120
+ this._subsurfaceScale = 0.5;
121
+ this._subsurfacePower = 1.5;
122
+ this._subsurfaceIntensity = 0.5;
123
+ this._anisotropy = 0.75;
124
+ this._anisotropyDirection = 0;
125
+ this._anisotropyDirectionScaleBias = new Vector2(1, 0);
126
+ this.useFeature(PBRBluePrintMaterial.FEATURE_SUBSURFACE_SCATTERING, false);
103
127
  this.useFeature(PBRBluePrintMaterial.FEATURE_VERTEX_COLOR, this._irVertex.behaviors.useVertexColor);
104
128
  this.useFeature(PBRBluePrintMaterial.FEATURE_VERTEX_UV, this._irVertex.behaviors.useVertexUV);
105
129
  }
130
+ get reflectionMode() {
131
+ return this._reflectionMode;
132
+ }
133
+ set reflectionMode(val) {
134
+ if (val !== this._reflectionMode) {
135
+ this._reflectionMode = val;
136
+ this.uniformChanged();
137
+ }
138
+ }
139
+ get subsurfaceScattering() {
140
+ return this.featureUsed(PBRBluePrintMaterial.FEATURE_SUBSURFACE_SCATTERING);
141
+ }
142
+ set subsurfaceScattering(val) {
143
+ this.useFeature(PBRBluePrintMaterial.FEATURE_SUBSURFACE_SCATTERING, !!val);
144
+ }
145
+ get subsurfaceColor() {
146
+ return this._subsurfaceColor;
147
+ }
148
+ set subsurfaceColor(val) {
149
+ if (!val.equalsTo(this._subsurfaceColor)) {
150
+ this._subsurfaceColor.set(val);
151
+ this.uniformChanged();
152
+ }
153
+ }
154
+ get subsurfaceScale() {
155
+ return this._subsurfaceScale;
156
+ }
157
+ set subsurfaceScale(val) {
158
+ if (val !== this._subsurfaceScale) {
159
+ this._subsurfaceScale = val;
160
+ this.uniformChanged();
161
+ }
162
+ }
163
+ get subsurfacePower() {
164
+ return this._subsurfacePower;
165
+ }
166
+ set subsurfacePower(val) {
167
+ if (val !== this._subsurfacePower) {
168
+ this._subsurfacePower = val;
169
+ this.uniformChanged();
170
+ }
171
+ }
172
+ get subsurfaceIntensity() {
173
+ return this._subsurfaceIntensity;
174
+ }
175
+ set subsurfaceIntensity(val) {
176
+ if (val !== this._subsurfaceIntensity) {
177
+ this._subsurfaceIntensity = val;
178
+ this.uniformChanged();
179
+ }
180
+ }
181
+ get anisotropy() {
182
+ return this._anisotropy;
183
+ }
184
+ set anisotropy(val) {
185
+ const clamped = Math.max(-0.95, Math.min(0.95, val));
186
+ if (clamped !== this._anisotropy) {
187
+ this._anisotropy = clamped;
188
+ this.uniformChanged();
189
+ }
190
+ }
191
+ get anisotropyDirection() {
192
+ return this._anisotropyDirection;
193
+ }
194
+ set anisotropyDirection(val) {
195
+ if (val !== this._anisotropyDirection) {
196
+ this._anisotropyDirection = val;
197
+ this.uniformChanged();
198
+ }
199
+ }
200
+ get anisotropyDirectionScaleBias() {
201
+ return this._anisotropyDirectionScaleBias;
202
+ }
203
+ set anisotropyDirectionScaleBias(val) {
204
+ if (!val.equalsTo(this._anisotropyDirectionScaleBias)) {
205
+ this._anisotropyDirectionScaleBias.set(val);
206
+ this.uniformChanged();
207
+ }
208
+ }
106
209
  /**
107
210
  * Gets the fragment blueprint IR.
108
211
  */ get fragmentIR() {
@@ -184,6 +287,18 @@ import { PBRBlockNode, VertexBlockNode } from '../utility/blueprint/material/pbr
184
287
  other.copyFrom(this);
185
288
  return other;
186
289
  }
290
+ copyFrom(other) {
291
+ super.copyFrom(other);
292
+ this.reflectionMode = other.reflectionMode;
293
+ this.subsurfaceScattering = other.subsurfaceScattering;
294
+ this.subsurfaceColor = other.subsurfaceColor;
295
+ this.subsurfaceScale = other.subsurfaceScale;
296
+ this.subsurfacePower = other.subsurfacePower;
297
+ this.subsurfaceIntensity = other.subsurfaceIntensity;
298
+ this.anisotropy = other.anisotropy;
299
+ this.anisotropyDirection = other.anisotropyDirection;
300
+ this.anisotropyDirectionScaleBias = other.anisotropyDirectionScaleBias;
301
+ }
187
302
  /**
188
303
  * Builds the vertex shader for this PBR blueprint material.
189
304
  *
@@ -230,7 +345,16 @@ import { PBRBlockNode, VertexBlockNode } from '../utility/blueprint/material/pbr
230
345
  */ fragmentShader(scope) {
231
346
  super.fragmentShader(scope);
232
347
  const pb = scope.$builder;
348
+ if (this.subsurfaceScattering && this.needFragmentColor() && this.drawContext.renderPass.type === RENDER_PASS_TYPE_LIGHT) {
349
+ scope.zSubsurfaceColor = pb.vec3().uniform(2);
350
+ scope.zSubsurfaceScale = pb.float().uniform(2);
351
+ scope.zSubsurfacePower = pb.float().uniform(2);
352
+ scope.zSubsurfaceIntensity = pb.float().uniform(2);
353
+ }
233
354
  if (this.needFragmentColor()) {
355
+ scope.zAnisotropy = pb.float().uniform(2);
356
+ scope.zAnisotropyDirection = pb.float().uniform(2);
357
+ scope.zAnisotropyDirectionScaleBias = pb.vec2().uniform(2);
234
358
  for (const u of [
235
359
  ...this._uniformValues,
236
360
  ...this._uniformTextures
@@ -247,9 +371,15 @@ import { PBRBlockNode, VertexBlockNode } from '../utility/blueprint/material/pbr
247
371
  if (this.drawContext.materialFlags & MaterialVaryingFlags.SSR_STORE_ROUGHNESS) {
248
372
  scope.$l.outRoughness = pb.vec4();
249
373
  scope.$l.litColor = this.PBRLight(scope, scope.$inputs.worldPos, scope.viewVec, scope.commonData, scope.outRoughness);
374
+ if (this.subsurfaceScattering) {
375
+ scope.litColor = this.applySubsurfaceScattering(scope, scope.litColor, scope.commonData.albedo.rgb, scope.commonData.normal, scope.viewVec);
376
+ }
250
377
  this.outputFragmentColor(scope, scope.$inputs.worldPos, scope.litColor, scope.outRoughness, pb.vec4(pb.add(pb.mul(scope.commonData.normal, 0.5), pb.vec3(0.5)), 1));
251
378
  } else {
252
379
  scope.$l.litColor = this.PBRLight(scope, scope.$inputs.worldPos, scope.viewVec, scope.commonData);
380
+ if (this.subsurfaceScattering) {
381
+ scope.litColor = this.applySubsurfaceScattering(scope, scope.litColor, scope.commonData.albedo.rgb, scope.commonData.normal, scope.viewVec);
382
+ }
253
383
  this.outputFragmentColor(scope, scope.$inputs.worldPos, scope.litColor);
254
384
  }
255
385
  } else {
@@ -273,12 +403,22 @@ import { PBRBlockNode, VertexBlockNode } from '../utility/blueprint/material/pbr
273
403
  */ applyUniformValues(bindGroup, ctx, pass) {
274
404
  super.applyUniformValues(bindGroup, ctx, pass);
275
405
  if (this.needFragmentColor(ctx)) {
406
+ bindGroup.setValue('zReflectionMode', PBR_REFLECTION_MODE[this._reflectionMode]);
407
+ bindGroup.setValue('zAnisotropy', this._anisotropy);
408
+ bindGroup.setValue('zAnisotropyDirection', this._anisotropyDirection);
409
+ bindGroup.setValue('zAnisotropyDirectionScaleBias', this._anisotropyDirectionScaleBias);
276
410
  for (const u of this._uniformValues){
277
411
  bindGroup.setValue(u.name, u.finalValue);
278
412
  }
279
413
  for (const u of this._uniformTextures){
280
414
  bindGroup.setTexture(u.name, u.finalTexture.get(), u.finalSampler);
281
415
  }
416
+ if (this.subsurfaceScattering && ctx.renderPass.type === RENDER_PASS_TYPE_LIGHT) {
417
+ bindGroup.setValue('zSubsurfaceColor', this._subsurfaceColor);
418
+ bindGroup.setValue('zSubsurfaceScale', this._subsurfaceScale);
419
+ bindGroup.setValue('zSubsurfacePower', this._subsurfacePower);
420
+ bindGroup.setValue('zSubsurfaceIntensity', this._subsurfaceIntensity);
421
+ }
282
422
  }
283
423
  }
284
424
  /**
@@ -338,6 +478,13 @@ import { PBRBlockNode, VertexBlockNode } from '../utility/blueprint/material/pbr
338
478
  */ getOutput(outputs, name) {
339
479
  return outputs.find((output)=>output.name === name)?.exp;
340
480
  }
481
+ applySubsurfaceScattering(scope, litColor, albedoRGB, normal, viewVec) {
482
+ const pb = scope.$builder;
483
+ scope.$l.NoV = pb.clamp(pb.dot(normal, viewVec), 0, 1);
484
+ scope.$l.wrapNdotV = pb.clamp(pb.div(pb.add(pb.sub(1, scope.NoV), scope.zSubsurfaceScale), pb.add(1, scope.zSubsurfaceScale)), 0, 1);
485
+ scope.$l.sssFactor = pb.mul(pb.pow(scope.wrapNdotV, scope.zSubsurfacePower), scope.zSubsurfaceIntensity);
486
+ return pb.vec4(pb.add(litColor.rgb, pb.mul(albedoRGB, scope.zSubsurfaceColor, scope.sssFactor)), litColor.a);
487
+ }
341
488
  }
342
489
 
343
490
  export { PBRBluePrintMaterial };
@@ -1 +1 @@
1
- {"version":3,"file":"pbrblueprint.js","sources":["../../src/material/pbrblueprint.ts"],"sourcesContent":["import { MeshMaterial, applyMaterialMixins } from './meshmaterial';\r\nimport type { BindGroup, PBFunctionScope, PBShaderExp } from '@zephyr3d/device';\r\nimport { ShaderHelper } from './shader/helper';\r\nimport { MaterialVaryingFlags, RENDER_PASS_TYPE_LIGHT } from '../values';\r\nimport { DRef, Vector4, type Clonable } from '@zephyr3d/base';\r\nimport { mixinPBRBluePrint } from './mixins/lightmodel/pbrblueprintmixin';\r\nimport type { BluePrintUniformTexture, BluePrintUniformValue } from '../utility/blueprint/material/ir';\r\nimport { MaterialBlueprintIR } from '../utility/blueprint/material/ir';\r\nimport type { DrawContext } from '../render/drawable';\r\nimport { PBRBlockNode, VertexBlockNode } from '../utility/blueprint/material/pbr';\r\n\r\n/**\r\n * Physically-based rendering material driven by blueprint graphs.\r\n *\r\n * @remarks\r\n * This material extends {@link MeshMaterial} with PBR behavior via\r\n * {@link mixinPBRBluePrint}, and uses {@link MaterialBlueprintIR}\r\n * graphs for both vertex and fragment stages.\r\n *\r\n * - The **vertex blueprint IR** (`vertexIR`) controls vertex\r\n * transformations and per-vertex data.\r\n * - The **fragment blueprint IR** (`fragmentIR`) produces inputs\r\n * for the PBR shading model (albedo, roughness, metalness, etc.).\r\n *\r\n * Uniform values and textures for the blueprints are provided via\r\n * {@link PBRBluePrintMaterial.uniformValues} and\r\n * {@link PBRBluePrintMaterial.uniformTextures}.\r\n *\r\n * @public\r\n */\r\nexport class PBRBluePrintMaterial\r\n extends applyMaterialMixins(MeshMaterial, mixinPBRBluePrint)\r\n implements Clonable<PBRBluePrintMaterial>\r\n{\r\n /** @internal */\r\n private static readonly FEATURE_VERTEX_COLOR = this.defineFeature();\r\n /** @internal */\r\n private static readonly FEATURE_VERTEX_UV = this.defineFeature();\r\n /** @internal */\r\n private _irFrag: MaterialBlueprintIR;\r\n /** @internal */\r\n private _irVertex: MaterialBlueprintIR;\r\n /** @internal */\r\n private _uniformValues: BluePrintUniformValue[];\r\n /** @internal */\r\n private _uniformTextures: BluePrintUniformTexture[];\r\n /**\r\n * Creates a new {@link PBRBluePrintMaterial} instance.\r\n *\r\n * @param irFrag - Optional fragment blueprint IR. If omitted, a default\r\n * IR containing a single {@link PBRBlockNode} is created.\r\n * @param irVertex - Optional vertex blueprint IR. If omitted, a default\r\n * IR containing a single {@link VertexBlockNode} is created.\r\n * @param uniformValues - Optional initial list of uniform value descriptors.\r\n * @param uniformTextures - Optional initial list of texture uniform descriptors.\r\n */\r\n constructor(\r\n irFrag?: MaterialBlueprintIR,\r\n irVertex?: MaterialBlueprintIR,\r\n uniformValues?: BluePrintUniformValue[],\r\n uniformTextures?: BluePrintUniformTexture[]\r\n ) {\r\n super();\r\n this._irFrag =\r\n irFrag ??\r\n new MaterialBlueprintIR(\r\n {\r\n nodeMap: { '1': new PBRBlockNode() },\r\n roots: [1],\r\n order: [1],\r\n graph: { incoming: {}, outgoing: {} }\r\n },\r\n '',\r\n {\r\n nodes: [{ id: 1, title: '', locked: true, node: { ClassName: 'PBRBlockNode', Object: '' } }],\r\n links: []\r\n }\r\n );\r\n this._irVertex =\r\n irVertex ??\r\n new MaterialBlueprintIR(\r\n {\r\n nodeMap: { '1': new VertexBlockNode() },\r\n roots: [1],\r\n order: [1],\r\n graph: { incoming: {}, outgoing: {} }\r\n },\r\n '',\r\n {\r\n nodes: [{ id: 1, title: '', locked: true, node: { ClassName: 'VertexBlockNode', Object: '' } }],\r\n links: []\r\n }\r\n );\r\n this._uniformValues = uniformValues ?? [];\r\n this._uniformTextures = uniformTextures ?? [];\r\n this.useFeature(PBRBluePrintMaterial.FEATURE_VERTEX_COLOR, this._irVertex.behaviors.useVertexColor);\r\n this.useFeature(PBRBluePrintMaterial.FEATURE_VERTEX_UV, this._irVertex.behaviors.useVertexUV);\r\n }\r\n /**\r\n * Gets the fragment blueprint IR.\r\n */\r\n get fragmentIR() {\r\n return this._irFrag;\r\n }\r\n set fragmentIR(ir: MaterialBlueprintIR) {\r\n if (ir && ir !== this._irFrag) {\r\n this._irFrag = ir;\r\n this.clearCache();\r\n this.optionChanged(true);\r\n }\r\n }\r\n /**\r\n * Gets the vertex blueprint IR.\r\n */\r\n get vertexIR() {\r\n return this._irVertex;\r\n }\r\n set vertexIR(ir: MaterialBlueprintIR) {\r\n if (ir && ir !== this._irVertex) {\r\n this._irVertex = ir;\r\n this.useFeature(PBRBluePrintMaterial.FEATURE_VERTEX_COLOR, this._irVertex.behaviors.useVertexColor);\r\n this.useFeature(PBRBluePrintMaterial.FEATURE_VERTEX_UV, this._irVertex.behaviors.useVertexUV);\r\n this.clearCache();\r\n this.optionChanged(true);\r\n }\r\n }\r\n /**\r\n * Gets the list of uniform value descriptors used by the blueprints.\r\n */\r\n get uniformValues() {\r\n return this._uniformValues;\r\n }\r\n set uniformValues(val: BluePrintUniformValue[]) {\r\n this._uniformValues = (val ?? []).map((v) => ({ ...v }));\r\n this.uniformChanged();\r\n }\r\n /**\r\n * Gets the list of texture uniform descriptors used by the blueprints.\r\n */\r\n get uniformTextures() {\r\n return this._uniformTextures;\r\n }\r\n set uniformTextures(val: BluePrintUniformTexture[]) {\r\n if (val !== this._uniformTextures) {\r\n const newUniforms = val.map((v) => ({\r\n finalTexture: new DRef(v.finalTexture!.get()),\r\n finalSampler: v.finalSampler,\r\n name: v.name,\r\n params: v.params?.clone() ?? Vector4.zero(),\r\n texture: v.texture,\r\n type: v.type,\r\n sRGB: v.sRGB,\r\n wrapS: v.wrapS,\r\n wrapT: v.wrapT,\r\n inFragmentShader: v.inFragmentShader,\r\n inVertexShader: v.inVertexShader,\r\n minFilter: v.minFilter,\r\n magFilter: v.magFilter,\r\n mipFilter: v.mipFilter\r\n }));\r\n for (const u of this._uniformTextures) {\r\n u.finalTexture!.dispose();\r\n }\r\n this._uniformTextures = newUniforms;\r\n this.uniformChanged();\r\n }\r\n }\r\n /**\r\n * Creates a deep copy of this material.\r\n *\r\n * @remarks\r\n * The clone shares the same vertex/fragment IR references and copies\r\n * the current blueprint uniform descriptors, then calls `copyFrom`\r\n * to copy base-class and mixin state.\r\n *\r\n * @returns A new {@link PBRBluePrintMaterial} instance.\r\n */\r\n clone() {\r\n const other = new PBRBluePrintMaterial(\r\n this._irFrag,\r\n this._irVertex,\r\n this._uniformValues,\r\n this._uniformTextures\r\n );\r\n other.copyFrom(this);\r\n return other;\r\n }\r\n /**\r\n * Builds the vertex shader for this PBR blueprint material.\r\n *\r\n * @param scope - The current vertex shader function scope.\r\n */\r\n vertexShader(scope: PBFunctionScope) {\r\n super.vertexShader(scope);\r\n const pb = scope.$builder;\r\n scope.$inputs.zVertexPos = pb.vec3().attrib('position');\r\n scope.$inputs.zVertexNormal = pb.vec3().attrib('normal');\r\n scope.$inputs.zVertexTangent = pb.vec4().attrib('tangent');\r\n if (this.featureUsed(PBRBluePrintMaterial.FEATURE_VERTEX_COLOR)) {\r\n scope.$inputs.zVertexColor = pb.vec4().attrib('diffuse');\r\n }\r\n if (this.featureUsed(PBRBluePrintMaterial.FEATURE_VERTEX_UV)) {\r\n scope.$inputs.zVertexUV = pb.vec2().attrib('texCoord0');\r\n }\r\n\r\n for (const u of [...this._uniformValues, ...this._uniformTextures]) {\r\n if (u.inVertexShader) {\r\n // @ts-ignore\r\n pb.getGlobalScope()[u.name] = pb[u.type]().uniform(2);\r\n }\r\n }\r\n const outputs = this._irVertex.create(pb)!;\r\n scope.$l.oPos = this.getOutput(outputs, 'Position') ?? ShaderHelper.resolveVertexPosition(scope);\r\n const worldMatrix = ShaderHelper.getWorldMatrix(scope);\r\n scope.$outputs.worldPos = pb.mul(worldMatrix, pb.vec4(scope.oPos, 1)).xyz;\r\n scope.$l.csPos = pb.mul(ShaderHelper.getViewProjectionMatrix(scope), pb.vec4(scope.$outputs.worldPos, 1));\r\n ShaderHelper.setClipSpacePosition(scope, scope.csPos);\r\n scope.$outputs.zVertexColor =\r\n this.getOutput(outputs, 'Color') ??\r\n (this.featureUsed(PBRBluePrintMaterial.FEATURE_VERTEX_COLOR) ? scope.$inputs.zVertexColor : pb.vec4(1));\r\n scope.$outputs.zVertexUV =\r\n this.getOutput(outputs, 'UV') ??\r\n (this.featureUsed(PBRBluePrintMaterial.FEATURE_VERTEX_UV) ? scope.$inputs.zVertexUV : pb.vec2(0));\r\n scope.$l.oNorm = this.getOutput(outputs, 'Normal') ?? ShaderHelper.resolveVertexNormal(scope);\r\n scope.$outputs.zVertexNormal = pb.mul(ShaderHelper.getNormalMatrix(scope), pb.vec4(scope.oNorm, 0)).xyz;\r\n scope.$l.oTangent = this.getOutput(outputs, 'Tangent') ?? ShaderHelper.resolveVertexTangent(scope);\r\n scope.$outputs.zVertexTangent = pb.mul(\r\n ShaderHelper.getNormalMatrix(scope),\r\n pb.vec4(scope.oTangent.xyz, 0)\r\n ).xyz;\r\n scope.$outputs.zVertexBinormal = pb.mul(\r\n pb.cross(scope.$outputs.zVertexNormal, scope.$outputs.zVertexTangent),\r\n scope.oTangent.w\r\n );\r\n }\r\n /**\r\n * Builds the fragment shader for this PBR blueprint material.\r\n *\r\n * @param scope - The current fragment shader function scope.\r\n */\r\n fragmentShader(scope: PBFunctionScope) {\r\n super.fragmentShader(scope);\r\n const pb = scope.$builder;\r\n if (this.needFragmentColor()) {\r\n for (const u of [...this._uniformValues, ...this._uniformTextures]) {\r\n if (u.inFragmentShader) {\r\n // @ts-ignore\r\n pb.getGlobalScope()[u.name] = pb[u.type]().uniform(2);\r\n }\r\n }\r\n scope.$l.viewVec = this.calculateViewVector(scope, scope.$inputs.worldPos);\r\n scope.$l.commonData = this.getCommonDatasStruct(scope)();\r\n this.getCommonData(\r\n scope,\r\n scope.commonData,\r\n scope.viewVec,\r\n scope.$inputs.worldPos,\r\n scope.$inputs.zVertexNormal,\r\n scope.$inputs.zVertexTangent,\r\n scope.$inputs.zVertexBinormal,\r\n scope.$inputs.zVertexColor,\r\n scope.$inputs.zVertexUV,\r\n this._irFrag\r\n );\r\n if (this.drawContext.renderPass!.type === RENDER_PASS_TYPE_LIGHT) {\r\n if (this.drawContext.materialFlags & MaterialVaryingFlags.SSR_STORE_ROUGHNESS) {\r\n scope.$l.outRoughness = pb.vec4();\r\n scope.$l.litColor = this.PBRLight(\r\n scope,\r\n scope.$inputs.worldPos,\r\n scope.viewVec,\r\n scope.commonData,\r\n scope.outRoughness\r\n );\r\n this.outputFragmentColor(\r\n scope,\r\n scope.$inputs.worldPos,\r\n scope.litColor,\r\n scope.outRoughness,\r\n pb.vec4(pb.add(pb.mul(scope.commonData.normal, 0.5), pb.vec3(0.5)), 1)\r\n );\r\n } else {\r\n scope.$l.litColor = this.PBRLight(scope, scope.$inputs.worldPos, scope.viewVec, scope.commonData);\r\n this.outputFragmentColor(scope, scope.$inputs.worldPos, scope.litColor);\r\n }\r\n } else {\r\n this.outputFragmentColor(scope, scope.$inputs.worldPos, scope.commonData.albedo);\r\n }\r\n } else {\r\n this.outputFragmentColor(scope, scope.$inputs.worldPos, null);\r\n }\r\n }\r\n /**\r\n * Applies runtime uniform values and textures to the given bind group.\r\n *\r\n * @remarks\r\n * - Calls the base implementation first to bind standard mesh/PBR uniforms.\r\n * - If fragment color is needed for the current context, all blueprint\r\n * scalar/vector uniform values and textures are then bound by name.\r\n *\r\n * @param bindGroup - The bind group to which material resources are bound.\r\n * @param ctx - The current draw context.\r\n * @param pass - Index of the active render pass.\r\n */\r\n applyUniformValues(bindGroup: BindGroup, ctx: DrawContext, pass: number) {\r\n super.applyUniformValues(bindGroup, ctx, pass);\r\n if (this.needFragmentColor(ctx)) {\r\n for (const u of this._uniformValues) {\r\n bindGroup.setValue(u.name, u.finalValue!);\r\n }\r\n for (const u of this._uniformTextures) {\r\n bindGroup.setTexture(u.name, u.finalTexture!.get()!, u.finalSampler);\r\n }\r\n }\r\n }\r\n /**\r\n * Creates a unique hash string used for program caching.\r\n *\r\n * @remarks\r\n * The hash includes:\r\n * - The base material hash (`super._createHash()`).\r\n * - The fragment IR hash.\r\n * - The vertex IR hash.\r\n *\r\n * Different blueprint graphs will therefore produce different programs.\r\n *\r\n * @returns A hash string that uniquely identifies this material configuration.\r\n */\r\n protected _createHash() {\r\n return `${super._createHash()}:${this._irFrag.hash}:${this._irVertex.hash}`;\r\n }\r\n /**\r\n * Creates the GPU program for this blueprint PBR material.\r\n *\r\n * @remarks\r\n * This calls the base implementation and returns its result.\r\n * Commented-out `console.log` lines are provided for debugging the\r\n * generated vertex and fragment shader sources.\r\n *\r\n * @param ctx - The current draw context.\r\n * @param pass - Index of the active render pass.\r\n * @returns The created GPU program.\r\n */\r\n protected createProgram(ctx: DrawContext, pass: number) {\r\n const program = super.createProgram(ctx, pass);\r\n //console.log(program.getShaderSource('vertex'));\r\n //console.log(program.getShaderSource('fragment'));\r\n return program;\r\n }\r\n /**\r\n * Disposes resources associated with this material.\r\n *\r\n * @remarks\r\n * - Calls the base `onDispose` to clean up inherited resources.\r\n * - Disposes all `finalTexture` references from the blueprint\r\n * texture uniform descriptors.\r\n *\r\n * This method is intended to be called by the engine's resource\r\n * management system rather than directly by user code.\r\n */\r\n protected onDispose() {\r\n super.onDispose();\r\n for (const u of this._uniformTextures) {\r\n u.finalTexture!.dispose();\r\n }\r\n }\r\n /**\r\n * Retrieves a named output expression from a blueprint output list.\r\n *\r\n * @param outputs - The list of outputs generated by a blueprint graph.\r\n * @param name - The desired output name (e.g. `\"Position\"`, `\"Color\"`, `\"UV\"`).\r\n * @returns The expression associated with the given name, or `undefined` if not found.\r\n */\r\n private getOutput(\r\n outputs: {\r\n name: string;\r\n exp: number | boolean | PBShaderExp;\r\n }[],\r\n name: string\r\n ) {\r\n return outputs.find((output) => output.name === name)?.exp;\r\n }\r\n}\r\n"],"names":["PBRBluePrintMaterial","applyMaterialMixins","MeshMaterial","mixinPBRBluePrint","FEATURE_VERTEX_COLOR","defineFeature","FEATURE_VERTEX_UV","irFrag","irVertex","uniformValues","uniformTextures","_irFrag","MaterialBlueprintIR","nodeMap","PBRBlockNode","roots","order","graph","incoming","outgoing","nodes","id","title","locked","node","ClassName","Object","links","_irVertex","VertexBlockNode","_uniformValues","_uniformTextures","useFeature","behaviors","useVertexColor","useVertexUV","fragmentIR","ir","clearCache","optionChanged","vertexIR","val","map","v","uniformChanged","newUniforms","finalTexture","DRef","get","finalSampler","name","params","clone","Vector4","zero","texture","type","sRGB","wrapS","wrapT","inFragmentShader","inVertexShader","minFilter","magFilter","mipFilter","u","dispose","other","copyFrom","vertexShader","scope","pb","$builder","$inputs","zVertexPos","vec3","attrib","zVertexNormal","zVertexTangent","vec4","featureUsed","zVertexColor","zVertexUV","vec2","getGlobalScope","uniform","outputs","create","$l","oPos","getOutput","ShaderHelper","resolveVertexPosition","worldMatrix","getWorldMatrix","$outputs","worldPos","mul","xyz","csPos","getViewProjectionMatrix","setClipSpacePosition","oNorm","resolveVertexNormal","getNormalMatrix","oTangent","resolveVertexTangent","zVertexBinormal","cross","w","fragmentShader","needFragmentColor","viewVec","calculateViewVector","commonData","getCommonDatasStruct","getCommonData","drawContext","renderPass","RENDER_PASS_TYPE_LIGHT","materialFlags","MaterialVaryingFlags","SSR_STORE_ROUGHNESS","outRoughness","litColor","PBRLight","outputFragmentColor","add","normal","albedo","applyUniformValues","bindGroup","ctx","pass","setValue","finalValue","setTexture","_createHash","hash","createProgram","program","onDispose","find","output","exp"],"mappings":";;;;;;;;AAWA;;;;;;;;;;;;;;;;;;AAkBC,IACM,MAAMA,oBACHC,SAAAA,mBAAAA,CAAoBC,YAAcC,EAAAA,iBAAAA,CAAAA,CAAAA;AAG1C,qBACA,OAAwBC,oBAAAA,GAAuB,IAAI,CAACC,aAAa,EAAG;AACpE,qBACA,OAAwBC,iBAAAA,GAAoB,IAAI,CAACD,aAAa,EAAG;qBAEjE,OAAqC;qBAErC,SAAuC;qBAEvC,cAAgD;qBAEhD,gBAAoD;AACpD;;;;;;;;;MAUA,WAAA,CACEE,MAA4B,EAC5BC,QAA8B,EAC9BC,aAAuC,EACvCC,eAA2C,CAC3C;QACA,KAAK,EAAA;AACL,QAAA,IAAI,CAACC,OAAO,GACVJ,MAAAA,IACA,IAAIK,mBACF,CAAA;YACEC,OAAS,EAAA;AAAE,gBAAA,GAAA,EAAK,IAAIC,YAAAA;AAAe,aAAA;YACnCC,KAAO,EAAA;AAAC,gBAAA;AAAE,aAAA;YACVC,KAAO,EAAA;AAAC,gBAAA;AAAE,aAAA;YACVC,KAAO,EAAA;AAAEC,gBAAAA,QAAAA,EAAU,EAAC;AAAGC,gBAAAA,QAAAA,EAAU;AAAG;AACtC,SAAA,EACA,EACA,EAAA;YACEC,KAAO,EAAA;AAAC,gBAAA;oBAAEC,EAAI,EAAA,CAAA;oBAAGC,KAAO,EAAA,EAAA;oBAAIC,MAAQ,EAAA,IAAA;oBAAMC,IAAM,EAAA;wBAAEC,SAAW,EAAA,cAAA;wBAAgBC,MAAQ,EAAA;AAAG;AAAE;AAAE,aAAA;AA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BAAAA,SAAAA,CAAUG,QAAQ,CAACrE,CAAAA,CAAEf,IAAI,EAAEe,EAAEsE,UAAU,CAAA;AACzC;AACA,YAAA,KAAK,MAAMtE,CAAAA,IAAK,IAAI,CAAClC,gBAAgB,CAAE;gBACrCoG,SAAUK,CAAAA,UAAU,CAACvE,CAAAA,CAAEf,IAAI,EAAEe,CAAEnB,CAAAA,YAAY,CAAEE,GAAG,EAAKiB,EAAAA,CAAAA,CAAEhB,YAAY,CAAA;AACrE;AACF;AACF;AACA;;;;;;;;;;;;AAYC,MACD,WAAwB,GAAA;AACtB,QAAA,OAAO,GAAG,KAAK,CAACwF,cAAc,CAAC,EAAE,IAAI,CAAC9H,OAAO,CAAC+H,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC9G,SAAS,CAAC8G,IAAI,CAAE,CAAA;AAC7E;AACA;;;;;;;;;;;AAWC,MACD,aAAUC,CAAcP,GAAgB,EAAEC,IAAY,EAAE;AACtD,QAAA,MAAMO,OAAU,GAAA,KAAK,CAACD,aAAAA,CAAcP,GAAKC,EAAAA,IAAAA,CAAAA;;;QAGzC,OAAOO,OAAAA;AACT;AACA;;;;;;;;;;AAUC,MACD,SAAsB,GAAA;AACpB,QAAA,KAAK,CAACC,SAAAA,EAAAA;AACN,QAAA,KAAK,MAAM5E,CAAAA,IAAK,IAAI,CAAClC,gBAAgB,CAAE;YACrCkC,CAAEnB,CAAAA,YAAY,CAAEoB,OAAO,EAAA;AACzB;AACF;AACA;;;;;;AAMC,MACD,SAAQwB,CACNJ,OAGG,EACHpC,IAAY,EACZ;QACA,OAAOoC,OAAAA,CAAQwD,IAAI,CAAC,CAACC,SAAWA,MAAO7F,CAAAA,IAAI,KAAKA,IAAO8F,CAAAA,EAAAA,GAAAA;AACzD;AACF;;;;"}
1
+ {"version":3,"file":"pbrblueprint.js","sources":["../../src/material/pbrblueprint.ts"],"sourcesContent":["import { MeshMaterial, applyMaterialMixins } from './meshmaterial';\r\nimport type { BindGroup, PBFunctionScope, PBInsideFunctionScope, PBShaderExp } from '@zephyr3d/device';\r\nimport { ShaderHelper } from './shader/helper';\r\nimport { MaterialVaryingFlags, RENDER_PASS_TYPE_LIGHT } from '../values';\r\nimport { DRef, Vector2, Vector3, Vector4, type Clonable, type Immutable } from '@zephyr3d/base';\r\nimport { mixinPBRBluePrint } from './mixins/lightmodel/pbrblueprintmixin';\r\nimport type { BluePrintUniformTexture, BluePrintUniformValue } from '../utility/blueprint/material/ir';\r\nimport { MaterialBlueprintIR } from '../utility/blueprint/material/ir';\r\nimport type { DrawContext } from '../render/drawable';\r\nimport { PBRBlockNode, VertexBlockNode } from '../utility/blueprint/material/pbr';\r\nimport type { PBRReflectionMode } from './mixins/lightmodel/pbrmetallicroughness';\r\n\r\nconst PBR_REFLECTION_MODE: Record<PBRReflectionMode, number> = {\r\n none: 0,\r\n ggx: 1,\r\n anisotropic: 2,\r\n glint: 3\r\n};\r\n\r\n/**\r\n * Physically-based rendering material driven by blueprint graphs.\r\n *\r\n * @remarks\r\n * This material extends {@link MeshMaterial} with PBR behavior via\r\n * {@link mixinPBRBluePrint}, and uses {@link MaterialBlueprintIR}\r\n * graphs for both vertex and fragment stages.\r\n *\r\n * - The **vertex blueprint IR** (`vertexIR`) controls vertex\r\n * transformations and per-vertex data.\r\n * - The **fragment blueprint IR** (`fragmentIR`) produces inputs\r\n * for the PBR shading model (albedo, roughness, metalness, etc.).\r\n *\r\n * Uniform values and textures for the blueprints are provided via\r\n * {@link PBRBluePrintMaterial.uniformValues} and\r\n * {@link PBRBluePrintMaterial.uniformTextures}.\r\n *\r\n * @public\r\n */\r\nexport class PBRBluePrintMaterial\r\n extends applyMaterialMixins(MeshMaterial, mixinPBRBluePrint)\r\n implements Clonable<PBRBluePrintMaterial>\r\n{\r\n /** @internal */\r\n private static readonly FEATURE_VERTEX_COLOR = this.defineFeature();\r\n /** @internal */\r\n private static readonly FEATURE_VERTEX_UV = this.defineFeature();\r\n /** @internal */\r\n private static readonly FEATURE_SUBSURFACE_SCATTERING = this.defineFeature();\r\n /** @internal */\r\n private _irFrag: MaterialBlueprintIR;\r\n /** @internal */\r\n private _irVertex: MaterialBlueprintIR;\r\n /** @internal */\r\n private _uniformValues: BluePrintUniformValue[];\r\n /** @internal */\r\n private _uniformTextures: BluePrintUniformTexture[];\r\n /** @internal */\r\n private _reflectionMode: PBRReflectionMode;\r\n /** @internal */\r\n private readonly _subsurfaceColor: Vector3;\r\n /** @internal */\r\n private _subsurfaceScale: number;\r\n /** @internal */\r\n private _subsurfacePower: number;\r\n /** @internal */\r\n private _subsurfaceIntensity: number;\r\n /** @internal */\r\n private _anisotropy: number;\r\n /** @internal */\r\n private _anisotropyDirection: number;\r\n /** @internal */\r\n private readonly _anisotropyDirectionScaleBias: Vector2;\r\n /**\r\n * Creates a new {@link PBRBluePrintMaterial} instance.\r\n *\r\n * @param irFrag - Optional fragment blueprint IR. If omitted, a default\r\n * IR containing a single {@link PBRBlockNode} is created.\r\n * @param irVertex - Optional vertex blueprint IR. If omitted, a default\r\n * IR containing a single {@link VertexBlockNode} is created.\r\n * @param uniformValues - Optional initial list of uniform value descriptors.\r\n * @param uniformTextures - Optional initial list of texture uniform descriptors.\r\n */\r\n constructor(\r\n irFrag?: MaterialBlueprintIR,\r\n irVertex?: MaterialBlueprintIR,\r\n uniformValues?: BluePrintUniformValue[],\r\n uniformTextures?: BluePrintUniformTexture[]\r\n ) {\r\n super();\r\n this._irFrag =\r\n irFrag ??\r\n new MaterialBlueprintIR(\r\n {\r\n nodeMap: { '1': new PBRBlockNode() },\r\n roots: [1],\r\n order: [1],\r\n graph: { incoming: {}, outgoing: {} }\r\n },\r\n '',\r\n {\r\n nodes: [{ id: 1, title: '', locked: true, node: { ClassName: 'PBRBlockNode', Object: '' } }],\r\n links: []\r\n }\r\n );\r\n this._irVertex =\r\n irVertex ??\r\n new MaterialBlueprintIR(\r\n {\r\n nodeMap: { '1': new VertexBlockNode() },\r\n roots: [1],\r\n order: [1],\r\n graph: { incoming: {}, outgoing: {} }\r\n },\r\n '',\r\n {\r\n nodes: [{ id: 1, title: '', locked: true, node: { ClassName: 'VertexBlockNode', Object: '' } }],\r\n links: []\r\n }\r\n );\r\n this._uniformValues = uniformValues ?? [];\r\n this._uniformTextures = uniformTextures ?? [];\r\n this._reflectionMode = 'ggx';\r\n this._subsurfaceColor = new Vector3(1, 0.3, 0.2);\r\n this._subsurfaceScale = 0.5;\r\n this._subsurfacePower = 1.5;\r\n this._subsurfaceIntensity = 0.5;\r\n this._anisotropy = 0.75;\r\n this._anisotropyDirection = 0;\r\n this._anisotropyDirectionScaleBias = new Vector2(1, 0);\r\n this.useFeature(PBRBluePrintMaterial.FEATURE_SUBSURFACE_SCATTERING, false);\r\n this.useFeature(PBRBluePrintMaterial.FEATURE_VERTEX_COLOR, this._irVertex.behaviors.useVertexColor);\r\n this.useFeature(PBRBluePrintMaterial.FEATURE_VERTEX_UV, this._irVertex.behaviors.useVertexUV);\r\n }\r\n get reflectionMode() {\r\n return this._reflectionMode;\r\n }\r\n set reflectionMode(val: PBRReflectionMode) {\r\n if (val !== this._reflectionMode) {\r\n this._reflectionMode = val;\r\n this.uniformChanged();\r\n }\r\n }\r\n get subsurfaceScattering() {\r\n return this.featureUsed<boolean>(PBRBluePrintMaterial.FEATURE_SUBSURFACE_SCATTERING);\r\n }\r\n set subsurfaceScattering(val: boolean) {\r\n this.useFeature(PBRBluePrintMaterial.FEATURE_SUBSURFACE_SCATTERING, !!val);\r\n }\r\n get subsurfaceColor(): Immutable<Vector3> {\r\n return this._subsurfaceColor;\r\n }\r\n set subsurfaceColor(val: Immutable<Vector3>) {\r\n if (!val.equalsTo(this._subsurfaceColor)) {\r\n this._subsurfaceColor.set(val);\r\n this.uniformChanged();\r\n }\r\n }\r\n get subsurfaceScale() {\r\n return this._subsurfaceScale;\r\n }\r\n set subsurfaceScale(val: number) {\r\n if (val !== this._subsurfaceScale) {\r\n this._subsurfaceScale = val;\r\n this.uniformChanged();\r\n }\r\n }\r\n get subsurfacePower() {\r\n return this._subsurfacePower;\r\n }\r\n set subsurfacePower(val: number) {\r\n if (val !== this._subsurfacePower) {\r\n this._subsurfacePower = val;\r\n this.uniformChanged();\r\n }\r\n }\r\n get subsurfaceIntensity() {\r\n return this._subsurfaceIntensity;\r\n }\r\n set subsurfaceIntensity(val: number) {\r\n if (val !== this._subsurfaceIntensity) {\r\n this._subsurfaceIntensity = val;\r\n this.uniformChanged();\r\n }\r\n }\r\n get anisotropy() {\r\n return this._anisotropy;\r\n }\r\n set anisotropy(val: number) {\r\n const clamped = Math.max(-0.95, Math.min(0.95, val));\r\n if (clamped !== this._anisotropy) {\r\n this._anisotropy = clamped;\r\n this.uniformChanged();\r\n }\r\n }\r\n get anisotropyDirection() {\r\n return this._anisotropyDirection;\r\n }\r\n set anisotropyDirection(val: number) {\r\n if (val !== this._anisotropyDirection) {\r\n this._anisotropyDirection = val;\r\n this.uniformChanged();\r\n }\r\n }\r\n get anisotropyDirectionScaleBias(): Immutable<Vector2> {\r\n return this._anisotropyDirectionScaleBias;\r\n }\r\n set anisotropyDirectionScaleBias(val: Immutable<Vector2>) {\r\n if (!val.equalsTo(this._anisotropyDirectionScaleBias)) {\r\n this._anisotropyDirectionScaleBias.set(val);\r\n this.uniformChanged();\r\n }\r\n }\r\n /**\r\n * Gets the fragment blueprint IR.\r\n */\r\n get fragmentIR() {\r\n return this._irFrag;\r\n }\r\n set fragmentIR(ir: MaterialBlueprintIR) {\r\n if (ir && ir !== this._irFrag) {\r\n this._irFrag = ir;\r\n this.clearCache();\r\n this.optionChanged(true);\r\n }\r\n }\r\n /**\r\n * Gets the vertex blueprint IR.\r\n */\r\n get vertexIR() {\r\n return this._irVertex;\r\n }\r\n set vertexIR(ir: MaterialBlueprintIR) {\r\n if (ir && ir !== this._irVertex) {\r\n this._irVertex = ir;\r\n this.useFeature(PBRBluePrintMaterial.FEATURE_VERTEX_COLOR, this._irVertex.behaviors.useVertexColor);\r\n this.useFeature(PBRBluePrintMaterial.FEATURE_VERTEX_UV, this._irVertex.behaviors.useVertexUV);\r\n this.clearCache();\r\n this.optionChanged(true);\r\n }\r\n }\r\n /**\r\n * Gets the list of uniform value descriptors used by the blueprints.\r\n */\r\n get uniformValues() {\r\n return this._uniformValues;\r\n }\r\n set uniformValues(val: BluePrintUniformValue[]) {\r\n this._uniformValues = (val ?? []).map((v) => ({ ...v }));\r\n this.uniformChanged();\r\n }\r\n /**\r\n * Gets the list of texture uniform descriptors used by the blueprints.\r\n */\r\n get uniformTextures() {\r\n return this._uniformTextures;\r\n }\r\n set uniformTextures(val: BluePrintUniformTexture[]) {\r\n if (val !== this._uniformTextures) {\r\n const newUniforms = val.map((v) => ({\r\n finalTexture: new DRef(v.finalTexture!.get()),\r\n finalSampler: v.finalSampler,\r\n name: v.name,\r\n params: v.params?.clone() ?? Vector4.zero(),\r\n texture: v.texture,\r\n type: v.type,\r\n sRGB: v.sRGB,\r\n wrapS: v.wrapS,\r\n wrapT: v.wrapT,\r\n inFragmentShader: v.inFragmentShader,\r\n inVertexShader: v.inVertexShader,\r\n minFilter: v.minFilter,\r\n magFilter: v.magFilter,\r\n mipFilter: v.mipFilter\r\n }));\r\n for (const u of this._uniformTextures) {\r\n u.finalTexture!.dispose();\r\n }\r\n this._uniformTextures = newUniforms;\r\n this.uniformChanged();\r\n }\r\n }\r\n /**\r\n * Creates a deep copy of this material.\r\n *\r\n * @remarks\r\n * The clone shares the same vertex/fragment IR references and copies\r\n * the current blueprint uniform descriptors, then calls `copyFrom`\r\n * to copy base-class and mixin state.\r\n *\r\n * @returns A new {@link PBRBluePrintMaterial} instance.\r\n */\r\n clone() {\r\n const other = new PBRBluePrintMaterial(\r\n this._irFrag,\r\n this._irVertex,\r\n this._uniformValues,\r\n this._uniformTextures\r\n );\r\n other.copyFrom(this);\r\n return other;\r\n }\r\n copyFrom(other: this) {\r\n super.copyFrom(other);\r\n this.reflectionMode = other.reflectionMode;\r\n this.subsurfaceScattering = other.subsurfaceScattering;\r\n this.subsurfaceColor = other.subsurfaceColor;\r\n this.subsurfaceScale = other.subsurfaceScale;\r\n this.subsurfacePower = other.subsurfacePower;\r\n this.subsurfaceIntensity = other.subsurfaceIntensity;\r\n this.anisotropy = other.anisotropy;\r\n this.anisotropyDirection = other.anisotropyDirection;\r\n this.anisotropyDirectionScaleBias = other.anisotropyDirectionScaleBias;\r\n }\r\n /**\r\n * Builds the vertex shader for this PBR blueprint material.\r\n *\r\n * @param scope - The current vertex shader function scope.\r\n */\r\n vertexShader(scope: PBFunctionScope) {\r\n super.vertexShader(scope);\r\n const pb = scope.$builder;\r\n scope.$inputs.zVertexPos = pb.vec3().attrib('position');\r\n scope.$inputs.zVertexNormal = pb.vec3().attrib('normal');\r\n scope.$inputs.zVertexTangent = pb.vec4().attrib('tangent');\r\n if (this.featureUsed(PBRBluePrintMaterial.FEATURE_VERTEX_COLOR)) {\r\n scope.$inputs.zVertexColor = pb.vec4().attrib('diffuse');\r\n }\r\n if (this.featureUsed(PBRBluePrintMaterial.FEATURE_VERTEX_UV)) {\r\n scope.$inputs.zVertexUV = pb.vec2().attrib('texCoord0');\r\n }\r\n\r\n for (const u of [...this._uniformValues, ...this._uniformTextures]) {\r\n if (u.inVertexShader) {\r\n // @ts-ignore\r\n pb.getGlobalScope()[u.name] = pb[u.type]().uniform(2);\r\n }\r\n }\r\n const outputs = this._irVertex.create(pb)!;\r\n scope.$l.oPos = this.getOutput(outputs, 'Position') ?? ShaderHelper.resolveVertexPosition(scope);\r\n const worldMatrix = ShaderHelper.getWorldMatrix(scope);\r\n scope.$outputs.worldPos = pb.mul(worldMatrix, pb.vec4(scope.oPos, 1)).xyz;\r\n scope.$l.csPos = pb.mul(ShaderHelper.getViewProjectionMatrix(scope), pb.vec4(scope.$outputs.worldPos, 1));\r\n ShaderHelper.setClipSpacePosition(scope, scope.csPos);\r\n scope.$outputs.zVertexColor =\r\n this.getOutput(outputs, 'Color') ??\r\n (this.featureUsed(PBRBluePrintMaterial.FEATURE_VERTEX_COLOR) ? scope.$inputs.zVertexColor : pb.vec4(1));\r\n scope.$outputs.zVertexUV =\r\n this.getOutput(outputs, 'UV') ??\r\n (this.featureUsed(PBRBluePrintMaterial.FEATURE_VERTEX_UV) ? scope.$inputs.zVertexUV : pb.vec2(0));\r\n scope.$l.oNorm = this.getOutput(outputs, 'Normal') ?? ShaderHelper.resolveVertexNormal(scope);\r\n scope.$outputs.zVertexNormal = pb.mul(ShaderHelper.getNormalMatrix(scope), pb.vec4(scope.oNorm, 0)).xyz;\r\n scope.$l.oTangent = this.getOutput(outputs, 'Tangent') ?? ShaderHelper.resolveVertexTangent(scope);\r\n scope.$outputs.zVertexTangent = pb.mul(\r\n ShaderHelper.getNormalMatrix(scope),\r\n pb.vec4(scope.oTangent.xyz, 0)\r\n ).xyz;\r\n scope.$outputs.zVertexBinormal = pb.mul(\r\n pb.cross(scope.$outputs.zVertexNormal, scope.$outputs.zVertexTangent),\r\n scope.oTangent.w\r\n );\r\n }\r\n /**\r\n * Builds the fragment shader for this PBR blueprint material.\r\n *\r\n * @param scope - The current fragment shader function scope.\r\n */\r\n fragmentShader(scope: PBFunctionScope) {\r\n super.fragmentShader(scope);\r\n const pb = scope.$builder;\r\n if (\r\n this.subsurfaceScattering &&\r\n this.needFragmentColor() &&\r\n this.drawContext.renderPass!.type === RENDER_PASS_TYPE_LIGHT\r\n ) {\r\n scope.zSubsurfaceColor = pb.vec3().uniform(2);\r\n scope.zSubsurfaceScale = pb.float().uniform(2);\r\n scope.zSubsurfacePower = pb.float().uniform(2);\r\n scope.zSubsurfaceIntensity = pb.float().uniform(2);\r\n }\r\n if (this.needFragmentColor()) {\r\n scope.zAnisotropy = pb.float().uniform(2);\r\n scope.zAnisotropyDirection = pb.float().uniform(2);\r\n scope.zAnisotropyDirectionScaleBias = pb.vec2().uniform(2);\r\n for (const u of [...this._uniformValues, ...this._uniformTextures]) {\r\n if (u.inFragmentShader) {\r\n // @ts-ignore\r\n pb.getGlobalScope()[u.name] = pb[u.type]().uniform(2);\r\n }\r\n }\r\n scope.$l.viewVec = this.calculateViewVector(scope, scope.$inputs.worldPos);\r\n scope.$l.commonData = this.getCommonDatasStruct(scope)();\r\n this.getCommonData(\r\n scope,\r\n scope.commonData,\r\n scope.viewVec,\r\n scope.$inputs.worldPos,\r\n scope.$inputs.zVertexNormal,\r\n scope.$inputs.zVertexTangent,\r\n scope.$inputs.zVertexBinormal,\r\n scope.$inputs.zVertexColor,\r\n scope.$inputs.zVertexUV,\r\n this._irFrag\r\n );\r\n if (this.drawContext.renderPass!.type === RENDER_PASS_TYPE_LIGHT) {\r\n if (this.drawContext.materialFlags & MaterialVaryingFlags.SSR_STORE_ROUGHNESS) {\r\n scope.$l.outRoughness = pb.vec4();\r\n scope.$l.litColor = this.PBRLight(\r\n scope,\r\n scope.$inputs.worldPos,\r\n scope.viewVec,\r\n scope.commonData,\r\n scope.outRoughness\r\n );\r\n if (this.subsurfaceScattering) {\r\n scope.litColor = this.applySubsurfaceScattering(\r\n scope,\r\n scope.litColor,\r\n scope.commonData.albedo.rgb,\r\n scope.commonData.normal,\r\n scope.viewVec\r\n );\r\n }\r\n this.outputFragmentColor(\r\n scope,\r\n scope.$inputs.worldPos,\r\n scope.litColor,\r\n scope.outRoughness,\r\n pb.vec4(pb.add(pb.mul(scope.commonData.normal, 0.5), pb.vec3(0.5)), 1)\r\n );\r\n } else {\r\n scope.$l.litColor = this.PBRLight(scope, scope.$inputs.worldPos, scope.viewVec, scope.commonData);\r\n if (this.subsurfaceScattering) {\r\n scope.litColor = this.applySubsurfaceScattering(\r\n scope,\r\n scope.litColor,\r\n scope.commonData.albedo.rgb,\r\n scope.commonData.normal,\r\n scope.viewVec\r\n );\r\n }\r\n this.outputFragmentColor(scope, scope.$inputs.worldPos, scope.litColor);\r\n }\r\n } else {\r\n this.outputFragmentColor(scope, scope.$inputs.worldPos, scope.commonData.albedo);\r\n }\r\n } else {\r\n this.outputFragmentColor(scope, scope.$inputs.worldPos, null);\r\n }\r\n }\r\n /**\r\n * Applies runtime uniform values and textures to the given bind group.\r\n *\r\n * @remarks\r\n * - Calls the base implementation first to bind standard mesh/PBR uniforms.\r\n * - If fragment color is needed for the current context, all blueprint\r\n * scalar/vector uniform values and textures are then bound by name.\r\n *\r\n * @param bindGroup - The bind group to which material resources are bound.\r\n * @param ctx - The current draw context.\r\n * @param pass - Index of the active render pass.\r\n */\r\n applyUniformValues(bindGroup: BindGroup, ctx: DrawContext, pass: number) {\r\n super.applyUniformValues(bindGroup, ctx, pass);\r\n if (this.needFragmentColor(ctx)) {\r\n bindGroup.setValue('zReflectionMode', PBR_REFLECTION_MODE[this._reflectionMode]);\r\n bindGroup.setValue('zAnisotropy', this._anisotropy);\r\n bindGroup.setValue('zAnisotropyDirection', this._anisotropyDirection);\r\n bindGroup.setValue('zAnisotropyDirectionScaleBias', this._anisotropyDirectionScaleBias);\r\n for (const u of this._uniformValues) {\r\n bindGroup.setValue(u.name, u.finalValue!);\r\n }\r\n for (const u of this._uniformTextures) {\r\n bindGroup.setTexture(u.name, u.finalTexture!.get()!, u.finalSampler);\r\n }\r\n if (this.subsurfaceScattering && ctx.renderPass!.type === RENDER_PASS_TYPE_LIGHT) {\r\n bindGroup.setValue('zSubsurfaceColor', this._subsurfaceColor);\r\n bindGroup.setValue('zSubsurfaceScale', this._subsurfaceScale);\r\n bindGroup.setValue('zSubsurfacePower', this._subsurfacePower);\r\n bindGroup.setValue('zSubsurfaceIntensity', this._subsurfaceIntensity);\r\n }\r\n }\r\n }\r\n /**\r\n * Creates a unique hash string used for program caching.\r\n *\r\n * @remarks\r\n * The hash includes:\r\n * - The base material hash (`super._createHash()`).\r\n * - The fragment IR hash.\r\n * - The vertex IR hash.\r\n *\r\n * Different blueprint graphs will therefore produce different programs.\r\n *\r\n * @returns A hash string that uniquely identifies this material configuration.\r\n */\r\n protected _createHash() {\r\n return `${super._createHash()}:${this._irFrag.hash}:${this._irVertex.hash}`;\r\n }\r\n /**\r\n * Creates the GPU program for this blueprint PBR material.\r\n *\r\n * @remarks\r\n * This calls the base implementation and returns its result.\r\n * Commented-out `console.log` lines are provided for debugging the\r\n * generated vertex and fragment shader sources.\r\n *\r\n * @param ctx - The current draw context.\r\n * @param pass - Index of the active render pass.\r\n * @returns The created GPU program.\r\n */\r\n protected createProgram(ctx: DrawContext, pass: number) {\r\n const program = super.createProgram(ctx, pass);\r\n //console.log(program.getShaderSource('vertex'));\r\n //console.log(program.getShaderSource('fragment'));\r\n return program;\r\n }\r\n /**\r\n * Disposes resources associated with this material.\r\n *\r\n * @remarks\r\n * - Calls the base `onDispose` to clean up inherited resources.\r\n * - Disposes all `finalTexture` references from the blueprint\r\n * texture uniform descriptors.\r\n *\r\n * This method is intended to be called by the engine's resource\r\n * management system rather than directly by user code.\r\n */\r\n protected onDispose() {\r\n super.onDispose();\r\n for (const u of this._uniformTextures) {\r\n u.finalTexture!.dispose();\r\n }\r\n }\r\n /**\r\n * Retrieves a named output expression from a blueprint output list.\r\n *\r\n * @param outputs - The list of outputs generated by a blueprint graph.\r\n * @param name - The desired output name (e.g. `\"Position\"`, `\"Color\"`, `\"UV\"`).\r\n * @returns The expression associated with the given name, or `undefined` if not found.\r\n */\r\n private getOutput(\r\n outputs: {\r\n name: string;\r\n exp: number | boolean | PBShaderExp;\r\n }[],\r\n name: string\r\n ) {\r\n return outputs.find((output) => output.name === name)?.exp;\r\n }\r\n private applySubsurfaceScattering(\r\n scope: PBInsideFunctionScope,\r\n litColor: PBShaderExp,\r\n albedoRGB: PBShaderExp,\r\n normal: PBShaderExp,\r\n viewVec: PBShaderExp\r\n ) {\r\n const pb = scope.$builder;\r\n scope.$l.NoV = pb.clamp(pb.dot(normal, viewVec), 0, 1);\r\n scope.$l.wrapNdotV = pb.clamp(\r\n pb.div(pb.add(pb.sub(1, scope.NoV), scope.zSubsurfaceScale), pb.add(1, scope.zSubsurfaceScale)),\r\n 0,\r\n 1\r\n );\r\n scope.$l.sssFactor = pb.mul(pb.pow(scope.wrapNdotV, scope.zSubsurfacePower), scope.zSubsurfaceIntensity);\r\n return pb.vec4(\r\n pb.add(litColor.rgb, pb.mul(albedoRGB, scope.zSubsurfaceColor, scope.sssFactor)),\r\n litColor.a\r\n );\r\n }\r\n}\r\n"],"names":["PBR_REFLECTION_MODE","none","ggx","anisotropic","glint","PBRBluePrintMaterial","applyMaterialMixins","MeshMaterial","mixinPBRBluePrint","FEATURE_VERTEX_COLOR","defineFeature","FEATURE_VERTEX_UV","FEATURE_SUBSURFACE_SCATTERING","irFrag","irVertex","uniformValues","uniformTextures","_irFrag","MaterialBlueprintIR","nodeMap","PBRBlockNode","roots","order","graph","incoming","outgoing","nodes","id","title","locked","node","ClassName","Object","links","_irVertex","VertexBlockNode","_uniformValues","_uniformTextures","_reflectionMode","_subsurfaceColor","Vector3","_subsurfaceScale","_subsurfacePower","_subsurfaceIntensity","_anisotropy","_anisotropyDirection","_anisotropyDirectionScaleBias","Vector2","useFeature","behaviors","useVertexColor","useVertexUV","reflectionMode","val","uniformChanged","subsurfaceScattering","featureUsed","subsurfaceColor","equalsTo","set","subsurfaceScale","subsurfacePower","subsurfaceIntensity","anisotropy","clamped","Math","max","min","anisotropyDirection","anisotropyDirectionScaleBias","fragmentIR","ir","clearCache","optionChanged","vertexIR","map","v","newUniforms","finalTexture","DRef","get","finalSampler","name","params","clone","Vector4","zero","texture","type","sRGB","wrapS","wrapT","inFragmentShader","inVertexShader","minFilter","magFilter","mipFilter","u","dispose","other","copyFrom","vertexShader","scope","pb","$builder","$inputs","zVertexPos","vec3","attrib","zVertexNormal","zVertexTangent","vec4","zVertexColor","zVertexUV","vec2","getGlobalScope","uniform","outputs","create","$l","oPos","getOutput","ShaderHelper","resolveVertexPosition","worldMatrix","getWorldMatrix","$outputs","worldPos","mul","xyz","csPos","getViewProjectionMatrix","setClipSpacePosition","oNorm","resolveVertexNormal","getNormalMatrix","oTangent","resolveVertexTangent","zVertexBinormal","cross","w","fragmentShader","needFragmentColor","drawContext","renderPass","RENDER_PASS_TYPE_LIGHT","zSubsurfaceColor","zSubsurfaceScale","float","zSubsurfacePower","zSubsurfaceIntensity","zAnisotropy","zAnisotropyDirection","zAnisotropyDirectionScaleBias","viewVec","calculateViewVector","commonData","getCommonDatasStruct","getCommonData","materialFlags","MaterialVaryingFlags","SSR_STORE_ROUGHNESS","outRoughness","litColor","PBRLight","applySubsurfaceScattering","albedo","rgb","normal","outputFragmentColor","add","applyUniformValues","bindGroup","ctx","pass","setValue","finalValue","setTexture","_createHash","hash","createProgram","program","onDispose","find","output","exp","albedoRGB","NoV","clamp","dot","wrapNdotV","div","sub","sssFactor","pow","a"],"mappings":";;;;;;;;AAYA,MAAMA,mBAAyD,GAAA;IAC7DC,IAAM,EAAA,CAAA;IACNC,GAAK,EAAA,CAAA;IACLC,WAAa,EAAA,CAAA;IACbC,KAAO,EAAA;AACT,CAAA;AAEA;;;;;;;;;;;;;;;;;;AAkBC,IACM,MAAMC,oBACHC,SAAAA,mBAAAA,CAAoBC,YAAcC,EAAAA,iBAAAA,CAAAA,CAAAA;AAG1C,qBACA,OAAwBC,oBAAAA,GAAuB,IAAI,CAACC,aAAa,EAAG;AACpE,qBACA,OAAwBC,iBAAAA,GAAoB,IAAI,CAACD,aAAa,EAAG;AACjE,qBACA,OAAwBE,6BAAAA,GAAgC,IAAI,CAACF,aAAa,EAAG;qBAE7E,OAAqC;qBAErC,SAAuC;qBAEvC,cAAgD;qBAEhD,gBAAoD;qBAEpD,eAA2C;qBAE3C,gBAA2C;qBAE3C,gBAAiC;qBAEjC,gBAAiC;qBAEjC,oBAAqC;qBAErC,WAA4B;qBAE5B,oBAAqC;qBAErC,6BAAwD;AACxD;;;;;;;;;MAUA,WAAA,CACEG,MAA4B,EAC5BC,QAA8B,EAC9BC,aAAuC,EACvCC,eAA2C,CAC3C;QACA,KAAK,EAAA;AACL,QAAA,IAAI,CAACC,OAAO,GACVJ,MAAAA,IACA,IAAIK,mBACF,CAAA;YACEC,OAAS,EAAA;AAAE,gBAAA,GAAA,EAAK,IAAIC,YAAAA;A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1,20 +1,37 @@
1
1
  import { applyMaterialMixins, MeshMaterial } from './meshmaterial.js';
2
2
  import { mixinVertexColor } from './mixins/vertexcolor.js';
3
3
  import { mixinPBRMetallicRoughness } from './mixins/lightmodel/pbrmetallicroughness.js';
4
+ import { mixinTextureProps } from './mixins/texture.js';
4
5
  import { ShaderHelper } from './shader/helper.js';
5
- import { RENDER_PASS_TYPE_LIGHT, MaterialVaryingFlags } from '../values.js';
6
+ import { MaterialVaryingFlags, RENDER_PASS_TYPE_LIGHT } from '../values.js';
7
+ import { Vector3 } from '@zephyr3d/base';
6
8
 
7
9
  /**
8
10
  * PBRMetallicRoughnessMaterial class
9
11
  * @public
10
- */ class PBRMetallicRoughnessMaterial extends applyMaterialMixins(MeshMaterial, mixinPBRMetallicRoughness, mixinVertexColor) {
12
+ */ class PBRMetallicRoughnessMaterial extends applyMaterialMixins(MeshMaterial, mixinPBRMetallicRoughness, mixinVertexColor, mixinTextureProps('subsurface')) {
11
13
  /** @internal */ static FEATURE_VERTEX_NORMAL = this.defineFeature();
12
14
  /** @internal */ static FEATURE_VERTEX_TANGENT = this.defineFeature();
15
+ /** @internal */ static FEATURE_SUBSURFACE_SCATTERING = this.defineFeature();
16
+ _subsurfaceColor;
17
+ _subsurfaceScale;
18
+ _subsurfacePower;
19
+ _subsurfaceIntensity;
13
20
  /**
14
21
  * Creates an instance of PBRMetallicRoughnessMaterial class
15
22
  */ constructor(){
16
23
  super();
24
+ this._subsurfaceColor = new Vector3(1, 0.3, 0.2);
25
+ this._subsurfaceScale = 0.5;
26
+ this._subsurfacePower = 1.5;
27
+ this._subsurfaceIntensity = 0.5;
17
28
  this.useFeature(PBRMetallicRoughnessMaterial.FEATURE_VERTEX_NORMAL, true);
29
+ this.useFeature(PBRMetallicRoughnessMaterial.FEATURE_SUBSURFACE_SCATTERING, false);
30
+ this.transmission = false;
31
+ this.transmissionFactor = 0.2;
32
+ this.thicknessFactor = 0.35;
33
+ this.attenuationColor = new Vector3(1, 0.5, 0.4);
34
+ this.attenuationDistance = 0.6;
18
35
  }
19
36
  clone() {
20
37
  const other = new PBRMetallicRoughnessMaterial();
@@ -25,6 +42,11 @@ import { RENDER_PASS_TYPE_LIGHT, MaterialVaryingFlags } from '../values.js';
25
42
  super.copyFrom(other);
26
43
  this.vertexNormal = other.vertexNormal;
27
44
  this.vertexTangent = other.vertexTangent;
45
+ this.subsurfaceScattering = other.subsurfaceScattering;
46
+ this.subsurfaceColor = other.subsurfaceColor;
47
+ this.subsurfaceScale = other.subsurfaceScale;
48
+ this.subsurfacePower = other.subsurfacePower;
49
+ this.subsurfaceIntensity = other.subsurfaceIntensity;
28
50
  }
29
51
  /** true if vertex normal attribute presents */ get vertexNormal() {
30
52
  return this.featureUsed(PBRMetallicRoughnessMaterial.FEATURE_VERTEX_NORMAL);
@@ -38,6 +60,64 @@ import { RENDER_PASS_TYPE_LIGHT, MaterialVaryingFlags } from '../values.js';
38
60
  set vertexTangent(val) {
39
61
  this.useFeature(PBRMetallicRoughnessMaterial.FEATURE_VERTEX_TANGENT, !!val);
40
62
  }
63
+ /** true if subsurface scattering is enabled */ get subsurfaceScattering() {
64
+ return this.featureUsed(PBRMetallicRoughnessMaterial.FEATURE_SUBSURFACE_SCATTERING);
65
+ }
66
+ set subsurfaceScattering(val) {
67
+ this.useFeature(PBRMetallicRoughnessMaterial.FEATURE_SUBSURFACE_SCATTERING, !!val);
68
+ }
69
+ /** subsurface scattering color tint */ get subsurfaceColor() {
70
+ return this._subsurfaceColor;
71
+ }
72
+ set subsurfaceColor(val) {
73
+ if (!val.equalsTo(this._subsurfaceColor)) {
74
+ this._subsurfaceColor.set(val);
75
+ this.uniformChanged();
76
+ }
77
+ }
78
+ /** wrap factor for the scattering profile */ get subsurfaceScale() {
79
+ return this._subsurfaceScale;
80
+ }
81
+ set subsurfaceScale(val) {
82
+ if (val !== this._subsurfaceScale) {
83
+ this._subsurfaceScale = val;
84
+ this.uniformChanged();
85
+ }
86
+ }
87
+ /** profile exponent for the scattering profile */ get subsurfacePower() {
88
+ return this._subsurfacePower;
89
+ }
90
+ set subsurfacePower(val) {
91
+ if (val !== this._subsurfacePower) {
92
+ this._subsurfacePower = val;
93
+ this.uniformChanged();
94
+ }
95
+ }
96
+ /** final intensity of scattering contribution */ get subsurfaceIntensity() {
97
+ return this._subsurfaceIntensity;
98
+ }
99
+ set subsurfaceIntensity(val) {
100
+ if (val !== this._subsurfaceIntensity) {
101
+ this._subsurfaceIntensity = val;
102
+ this.uniformChanged();
103
+ }
104
+ }
105
+ getSubsurfaceColor(scope) {
106
+ const instancing = !!(this.drawContext.materialFlags & MaterialVaryingFlags.INSTANCING);
107
+ return instancing ? scope.$inputs.zSubsurfaceColor : scope.zSubsurfaceColor;
108
+ }
109
+ getSubsurfaceScale(scope) {
110
+ const instancing = !!(this.drawContext.materialFlags & MaterialVaryingFlags.INSTANCING);
111
+ return instancing ? scope.$inputs.zSubsurfaceScale : scope.zSubsurfaceScale;
112
+ }
113
+ getSubsurfacePower(scope) {
114
+ const instancing = !!(this.drawContext.materialFlags & MaterialVaryingFlags.INSTANCING);
115
+ return instancing ? scope.$inputs.zSubsurfacePower : scope.zSubsurfacePower;
116
+ }
117
+ getSubsurfaceIntensity(scope) {
118
+ const instancing = !!(this.drawContext.materialFlags & MaterialVaryingFlags.INSTANCING);
119
+ return instancing ? scope.$inputs.zSubsurfaceIntensity : scope.zSubsurfaceIntensity;
120
+ }
41
121
  vertexShader(scope) {
42
122
  super.vertexShader(scope);
43
123
  const pb = scope.$builder;
@@ -63,6 +143,12 @@ import { RENDER_PASS_TYPE_LIGHT, MaterialVaryingFlags } from '../values.js';
63
143
  fragmentShader(scope) {
64
144
  super.fragmentShader(scope);
65
145
  const pb = scope.$builder;
146
+ if (this.subsurfaceScattering && this.needFragmentColor() && this.drawContext.renderPass.type === RENDER_PASS_TYPE_LIGHT) {
147
+ scope.zSubsurfaceColor = pb.vec3().uniform(2);
148
+ scope.zSubsurfaceScale = pb.float().uniform(2);
149
+ scope.zSubsurfacePower = pb.float().uniform(2);
150
+ scope.zSubsurfaceIntensity = pb.float().uniform(2);
151
+ }
66
152
  if (this.needFragmentColor()) {
67
153
  scope.$l.albedo = this.calculateAlbedoColor(scope);
68
154
  if (this.vertexColor) {
@@ -74,6 +160,15 @@ import { RENDER_PASS_TYPE_LIGHT, MaterialVaryingFlags } from '../values.js';
74
160
  if (this.drawContext.materialFlags & MaterialVaryingFlags.SSR_STORE_ROUGHNESS) {
75
161
  scope.$l.outRoughness = pb.vec4();
76
162
  scope.$l.litColor = this.PBRLight(scope, scope.$inputs.worldPos, scope.normalInfo.normal, scope.viewVec, scope.albedo, scope.normalInfo.TBN, scope.outRoughness);
163
+ if (this.subsurfaceScattering) {
164
+ scope.$l.NoV = pb.clamp(pb.dot(scope.normalInfo.normal, scope.viewVec), 0, 1);
165
+ scope.$l.wrapNdotV = pb.clamp(pb.div(pb.add(pb.sub(1, scope.NoV), this.getSubsurfaceScale(scope)), pb.add(1, this.getSubsurfaceScale(scope))), 0, 1);
166
+ scope.$l.sssFactor = pb.mul(pb.pow(scope.wrapNdotV, this.getSubsurfacePower(scope)), this.getSubsurfaceIntensity(scope));
167
+ if (this.subsurfaceTexture) {
168
+ scope.sssFactor = pb.mul(scope.sssFactor, this.sampleSubsurfaceTexture(scope).r);
169
+ }
170
+ scope.litColor = pb.add(scope.litColor, pb.mul(scope.albedo.rgb, this.getSubsurfaceColor(scope), scope.sssFactor));
171
+ }
77
172
  /*
78
173
  scope.outRoughness = pb.vec4(
79
174
  pb.add(pb.mul(scope.normalInfo.normal, 0.5), pb.vec3(0.5)),
@@ -82,6 +177,15 @@ import { RENDER_PASS_TYPE_LIGHT, MaterialVaryingFlags } from '../values.js';
82
177
  */ this.outputFragmentColor(scope, scope.$inputs.worldPos, pb.vec4(scope.litColor, scope.albedo.a), scope.outRoughness, pb.vec4(pb.add(pb.mul(scope.normalInfo.normal, 0.5), pb.vec3(0.5)), 1));
83
178
  } else {
84
179
  scope.$l.litColor = this.PBRLight(scope, scope.$inputs.worldPos, scope.normalInfo.normal, scope.viewVec, scope.albedo, scope.normalInfo.TBN);
180
+ if (this.subsurfaceScattering) {
181
+ scope.$l.NoV = pb.clamp(pb.dot(scope.normalInfo.normal, scope.viewVec), 0, 1);
182
+ scope.$l.wrapNdotV = pb.clamp(pb.div(pb.add(pb.sub(1, scope.NoV), this.getSubsurfaceScale(scope)), pb.add(1, this.getSubsurfaceScale(scope))), 0, 1);
183
+ scope.$l.sssFactor = pb.mul(pb.pow(scope.wrapNdotV, this.getSubsurfacePower(scope)), this.getSubsurfaceIntensity(scope));
184
+ if (this.subsurfaceTexture) {
185
+ scope.sssFactor = pb.mul(scope.sssFactor, this.sampleSubsurfaceTexture(scope).r);
186
+ }
187
+ scope.litColor = pb.add(scope.litColor, pb.mul(scope.albedo.rgb, this.getSubsurfaceColor(scope), scope.sssFactor));
188
+ }
85
189
  this.outputFragmentColor(scope, scope.$inputs.worldPos, pb.vec4(scope.litColor, scope.albedo.a));
86
190
  }
87
191
  } else {
@@ -91,6 +195,15 @@ import { RENDER_PASS_TYPE_LIGHT, MaterialVaryingFlags } from '../values.js';
91
195
  this.outputFragmentColor(scope, scope.$inputs.worldPos, null);
92
196
  }
93
197
  }
198
+ applyUniformValues(bindGroup, ctx, pass) {
199
+ super.applyUniformValues(bindGroup, ctx, pass);
200
+ if (this.subsurfaceScattering && this.needFragmentColor(ctx) && ctx.renderPass.type === RENDER_PASS_TYPE_LIGHT && !(ctx.materialFlags & MaterialVaryingFlags.INSTANCING)) {
201
+ bindGroup.setValue('zSubsurfaceColor', this._subsurfaceColor);
202
+ bindGroup.setValue('zSubsurfaceScale', this._subsurfaceScale);
203
+ bindGroup.setValue('zSubsurfacePower', this._subsurfacePower);
204
+ bindGroup.setValue('zSubsurfaceIntensity', this._subsurfaceIntensity);
205
+ }
206
+ }
94
207
  }
95
208
 
96
209
  export { PBRMetallicRoughnessMaterial };