@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
@@ -0,0 +1,510 @@
1
+ import { drawFullscreenQuad } from './fullscreenquad.js';
2
+ import { fetchSampler } from '../utility/misc.js';
3
+ import { getGGXLUT } from '../utility/textures/ggxlut.js';
4
+ import { decodeNormalizedFloatFromRGBA } from '../shaders/misc.js';
5
+ import { fresnelSchlick, distributionGGX, visGGX } from '../shaders/pbr.js';
6
+ import { MAX_CLUSTERED_LIGHTS, LIGHT_TYPE_POINT, LIGHT_TYPE_SPOT, LIGHT_TYPE_RECT } from '../values.js';
7
+
8
+ /**
9
+ * Deferred lighting pass scaffold.
10
+ *
11
+ * Stage-1 implementation simply resolves GBuffer color to the lighting target.
12
+ * Follow-up will evaluate clustered lights using compact material attributes.
13
+ * @internal
14
+ */ class DeferredLightPass {
15
+ static _programs = {};
16
+ static _bindGroups = {};
17
+ render(ctx, gbufferColor, gbufferRoughness, gbufferNormal, gbufferExtra) {
18
+ if (!ctx.clusteredLight?.lightBuffer || !ctx.clusteredLight.lightIndexTexture || !ctx.linearDepthTexture) {
19
+ return;
20
+ }
21
+ const device = ctx.device;
22
+ const hasEnvLight = !!ctx.env?.light?.envLight;
23
+ const hasEnvRadiance = !!ctx.env?.light?.envLight?.hasRadiance();
24
+ const hasEnvIrradiance = !!ctx.env?.light?.envLight?.hasIrradiance();
25
+ const envHash = ctx.env?.light?.envLight ? ctx.env.light.getHash() : 'none';
26
+ const hash = `${device.type}:${envHash}:clustered:env:${hasEnvLight ? 1 : 0}:rad:${hasEnvRadiance ? 1 : 0}:irr:${hasEnvIrradiance ? 1 : 0}`;
27
+ let program = DeferredLightPass._programs[hash];
28
+ if (!program) {
29
+ const isWebGL = device.type === 'webgl';
30
+ const builtProgram = device.buildRenderProgram({
31
+ label: 'DeferredLightPass',
32
+ vertex (pb) {
33
+ this.$inputs.pos = pb.vec2().attrib('position');
34
+ this.$outputs.uv = pb.vec2();
35
+ pb.main(function() {
36
+ this.$builtins.position = pb.vec4(this.$inputs.pos, 1, 1);
37
+ this.$outputs.uv = pb.add(pb.mul(this.$inputs.pos.xy, 0.5), pb.vec2(0.5));
38
+ if (device.type === 'webgpu') {
39
+ this.$builtins.position.y = pb.neg(this.$builtins.position.y);
40
+ }
41
+ });
42
+ },
43
+ fragment (pb) {
44
+ this.gbufferColorTex = pb.tex2D().uniform(0);
45
+ this.gbufferRoughnessTex = pb.tex2D().uniform(0);
46
+ this.gbufferNormalTex = pb.tex2D().uniform(0);
47
+ this.gbufferExtraTex = pb.tex2D().uniform(0);
48
+ this.linearDepthTex = pb.tex2D().uniform(0);
49
+ this.zGGXLut = pb.tex2D().uniform(0);
50
+ this.lightIndexTex = (isWebGL ? pb.tex2D() : pb.utex2D()).uniform(0);
51
+ this.zLightBuffer = pb.vec4[(MAX_CLUSTERED_LIGHTS + 1) * 4]().uniformBuffer(0);
52
+ this.clusterParams = pb.vec4().uniform(0);
53
+ this.countParams = pb.ivec4().uniform(0);
54
+ this.lightIndexTexSize = pb.ivec2().uniform(0);
55
+ this.cameraPos = pb.vec3().uniform(0);
56
+ this.cameraRight = pb.vec3().uniform(0);
57
+ this.cameraUp = pb.vec3().uniform(0);
58
+ this.cameraForward = pb.vec3().uniform(0);
59
+ this.cameraProj = pb.vec2().uniform(0); // x: tanHalfFovy, y: aspect
60
+ this.cameraNearFar = pb.vec2().uniform(0);
61
+ this.sunDir = pb.vec3().uniform(0);
62
+ this.sunColorIntensity = pb.vec4().uniform(0);
63
+ this.showGBuffer = pb.int().uniform(0);
64
+ this.gbufferViewMode = pb.int().uniform(0);
65
+ this.showCluster = pb.int().uniform(0);
66
+ this.showShadowTerm = pb.int().uniform(0);
67
+ this.showSpecTerm = pb.int().uniform(0);
68
+ if (hasEnvLight) {
69
+ this.envLightStrength = pb.float().uniform(0);
70
+ ctx.env.light.envLight.initShaderBindings(pb);
71
+ }
72
+ this.$outputs.color = pb.vec4();
73
+ pb.func('zGetClusterIndex', [
74
+ pb.float('linearDepth')
75
+ ], function() {
76
+ this.$l.zTile = pb.int(pb.max(pb.add(pb.mul(pb.log2(pb.max(this.linearDepth, 1e-4)), this.clusterParams.z), this.clusterParams.w), 0));
77
+ this.zTile = pb.min(this.zTile, pb.sub(this.countParams.z, 1));
78
+ this.$l.f = pb.vec2(this.$builtins.fragCoord.x, pb.sub(this.clusterParams.y, pb.add(this.$builtins.fragCoord.y, 1)));
79
+ this.$l.xyTile = pb.ivec2(pb.div(this.f, pb.div(this.clusterParams.xy, pb.vec2(this.countParams.xy))));
80
+ this.xyTile = pb.clamp(this.xyTile, pb.ivec2(0), pb.sub(this.countParams.xy, 1));
81
+ this.$return(pb.add(this.xyTile.x, pb.mul(this.xyTile.y, this.countParams.x), pb.mul(this.zTile, this.countParams.x, this.countParams.y)));
82
+ });
83
+ pb.func('zGetLinearDepth', [], function() {
84
+ this.$l.depthSample = pb.textureSample(this.linearDepthTex, this.$inputs.uv);
85
+ if (isWebGL) {
86
+ this.$return(decodeNormalizedFloatFromRGBA(this, this.depthSample));
87
+ } else {
88
+ this.$return(this.depthSample.r);
89
+ }
90
+ });
91
+ pb.func('zDecodeWebGLLightIndex', [
92
+ pb.float('packed'),
93
+ pb.int('slot')
94
+ ], function() {
95
+ this.$if(pb.equal(this.slot, 0), function() {
96
+ this.$return(pb.int(pb.div(this.packed, 256)));
97
+ });
98
+ this.$return(pb.int(pb.mod(this.packed, 256)));
99
+ });
100
+ pb.func('zPointAtten', [
101
+ pb.float('dist'),
102
+ pb.float('range')
103
+ ], function() {
104
+ this.$l.falloff = pb.max(0, pb.sub(1, pb.div(this.dist, pb.max(this.range, 1e-4))));
105
+ this.$return(pb.mul(this.falloff, this.falloff));
106
+ });
107
+ pb.func('zSpotAtten', [
108
+ pb.vec3('worldPos'),
109
+ pb.vec4('posRange'),
110
+ pb.vec4('dirCutoff'),
111
+ pb.float('dist')
112
+ ], function() {
113
+ this.$l.base = this.zPointAtten(this.dist, this.posRange.w);
114
+ this.$l.spotFactor = pb.dot(pb.normalize(pb.sub(this.worldPos, this.posRange.xyz)), this.dirCutoff.xyz);
115
+ this.spotFactor = pb.smoothStep(this.dirCutoff.w, pb.mix(this.dirCutoff.w, 1, 0.5), this.spotFactor);
116
+ this.$return(pb.mul(this.base, this.spotFactor));
117
+ });
118
+ pb.func('zAccumulatePunctualLight', [
119
+ pb.vec3('baseColor'),
120
+ pb.float('metallic'),
121
+ pb.float('roughness'),
122
+ pb.float('specularStrength'),
123
+ pb.vec3('n'),
124
+ pb.vec3('viewDir'),
125
+ pb.float('NoV'),
126
+ pb.vec3('f0'),
127
+ pb.vec3('lightColor'),
128
+ pb.vec3('L'),
129
+ pb.float('atten'),
130
+ pb.float('diffScale'),
131
+ pb.float('specScale'),
132
+ pb.float('sourceRadiusFactor'),
133
+ pb.vec3('outDiffuse').inout(),
134
+ pb.vec3('outSpecular').inout()
135
+ ], function() {
136
+ this.$l.pointNoL = pb.clamp(pb.dot(this.n, this.L), 0, 1);
137
+ this.$if(pb.greaterThan(this.pointNoL, 1e-5), function() {
138
+ this.$l.H = pb.normalize(pb.add(this.viewDir, this.L));
139
+ this.$l.NoH = pb.clamp(pb.dot(this.n, this.H), 0, 1);
140
+ this.$l.VoH = pb.clamp(pb.dot(this.viewDir, this.H), 0, 1);
141
+ this.$l.F = fresnelSchlick(this, this.VoH, this.f0, pb.vec3(1));
142
+ this.$l.specularRoughness = pb.clamp(pb.add(this.roughness, this.sourceRadiusFactor), 0, 1);
143
+ this.$l.alphaRoughness = pb.mul(this.specularRoughness, this.specularRoughness);
144
+ this.$l.D = distributionGGX(this, this.NoH, this.alphaRoughness);
145
+ this.$l.V = visGGX(this, this.NoV, this.pointNoL, this.alphaRoughness);
146
+ this.$l.punctualColor = pb.mul(this.lightColor, this.atten, this.pointNoL);
147
+ this.$l.diffuseBRDF = pb.mul(pb.sub(pb.vec3(1), this.F), pb.div(pb.mul(this.baseColor, pb.sub(1, this.metallic)), Math.PI));
148
+ this.outDiffuse = pb.add(this.outDiffuse, pb.mul(this.punctualColor, pb.max(this.diffuseBRDF, pb.vec3(0)), this.diffScale));
149
+ this.outSpecular = pb.add(this.outSpecular, pb.mul(this.punctualColor, this.D, this.V, this.F, this.specScale));
150
+ });
151
+ });
152
+ pb.func('zAccumulateRectLight', [
153
+ pb.vec3('worldPos'),
154
+ pb.vec3('baseColor'),
155
+ pb.float('metallic'),
156
+ pb.float('roughness'),
157
+ pb.float('specularStrength'),
158
+ pb.vec3('n'),
159
+ pb.vec3('viewDir'),
160
+ pb.float('NoV'),
161
+ pb.vec3('f0'),
162
+ pb.vec4('posRange'),
163
+ pb.vec4('axisX'),
164
+ pb.vec4('axisY'),
165
+ pb.vec4('colorIntensity'),
166
+ pb.vec3('outDiffuse').inout(),
167
+ pb.vec3('outSpecular').inout()
168
+ ], function() {
169
+ this.$l.center = this.posRange.xyz;
170
+ this.$l.range = this.posRange.w;
171
+ this.$l.ax = this.axisX.xyz;
172
+ this.$l.ay = this.axisY.xyz;
173
+ this.$l.halfWidth = pb.length(this.ax);
174
+ this.$l.halfHeight = pb.length(this.ay);
175
+ this.$l.area = pb.mul(this.halfWidth, this.halfHeight, 4);
176
+ this.$l.lightNormal = pb.neg(pb.normalize(pb.cross(this.ax, this.ay)));
177
+ this.$if(pb.greaterThan(this.area, 0), function() {
178
+ this.$l.baseRectColor = pb.mul(this.colorIntensity.rgb, this.colorIntensity.a, this.area, 0.25);
179
+ this.$l.samplePos = pb.vec3();
180
+ this.$l.Lvec = pb.vec3();
181
+ this.$l.L = pb.vec3();
182
+ this.$l.dist = pb.float();
183
+ this.$l.invDist2 = pb.float();
184
+ this.$l.NoL = pb.float();
185
+ this.$l.NoL_light = pb.float();
186
+ this.$l.falloff = pb.float();
187
+ this.$l.lightSampleColor = pb.vec3();
188
+ const sample = (u, v)=>{
189
+ this.samplePos = pb.add(this.center, pb.add(pb.mul(this.ax, pb.sub(pb.mul(u, 2), 1)), pb.mul(this.ay, pb.sub(pb.mul(v, 2), 1))));
190
+ this.Lvec = pb.sub(this.samplePos, this.worldPos);
191
+ this.dist = pb.length(this.Lvec);
192
+ this.invDist2 = pb.div(1, pb.max(pb.mul(this.dist, this.dist), 0.0001));
193
+ this.L = pb.normalize(this.Lvec);
194
+ this.NoL = pb.clamp(pb.dot(this.n, this.L), 0, 1);
195
+ this.NoL_light = pb.clamp(pb.dot(this.lightNormal, pb.neg(this.L)), 0, 1);
196
+ this.$if(pb.greaterThan(pb.mul(this.NoL, this.NoL_light), 1e-5), function() {
197
+ this.falloff = pb.float(1);
198
+ this.$if(pb.greaterThan(this.range, 0), function() {
199
+ this.falloff = pb.max(0, pb.sub(1, pb.div(this.dist, this.range)));
200
+ this.falloff = pb.mul(this.falloff, this.falloff);
201
+ });
202
+ this.lightSampleColor = pb.mul(this.baseRectColor, this.invDist2, this.NoL_light);
203
+ this.zAccumulatePunctualLight(this.baseColor, this.metallic, this.roughness, this.specularStrength, this.n, this.viewDir, this.NoV, this.f0, this.lightSampleColor, this.L, this.falloff, 1, 1, 0, this.outDiffuse, this.outSpecular);
204
+ });
205
+ };
206
+ sample(0.25, 0.25);
207
+ sample(0.75, 0.25);
208
+ sample(0.25, 0.75);
209
+ sample(0.75, 0.75);
210
+ });
211
+ });
212
+ pb.main(function() {
213
+ this.$l.base = pb.textureSample(this.gbufferColorTex, this.$inputs.uv);
214
+ this.$l.rm = pb.textureSample(this.gbufferRoughnessTex, this.$inputs.uv);
215
+ this.$l.extra = pb.textureSample(this.gbufferExtraTex, this.$inputs.uv);
216
+ this.$l.litFlag = pb.float(pb.greaterThan(this.extra.a, 0.5));
217
+ this.$l.n = pb.normalize(pb.sub(pb.mul(pb.textureSample(this.gbufferNormalTex, this.$inputs.uv).xyz, 2), pb.vec3(1)));
218
+ this.$l.metallic = pb.clamp(this.rm.r, 0, 1);
219
+ this.$l.occlusion = pb.clamp(this.rm.g, 0, 1);
220
+ this.$l.specularStrength = pb.clamp(this.rm.b, 0, 1);
221
+ this.$l.roughness = pb.clamp(this.rm.a, 0.045, 1);
222
+ this.$l.ndc = pb.sub(pb.mul(this.$inputs.uv, 2), pb.vec2(1));
223
+ this.$l.xScale = pb.mul(this.cameraProj.x, this.cameraProj.y);
224
+ this.$l.yScale = this.cameraProj.x;
225
+ this.$l.camRayDir = pb.normalize(pb.add(this.cameraForward, pb.mul(this.cameraRight, pb.mul(this.ndc.x, this.xScale)), pb.mul(this.cameraUp, pb.mul(this.ndc.y, this.yScale))));
226
+ this.$l.linearDepthNormalized = this.zGetLinearDepth();
227
+ this.$l.linearDepth = pb.mul(pb.clamp(this.linearDepthNormalized, 0, 1), this.cameraNearFar.y);
228
+ this.$l.rayScale = pb.max(pb.dot(this.camRayDir, this.cameraForward), 1e-4);
229
+ this.$l.worldPos = pb.add(this.cameraPos, pb.mul(this.camRayDir, pb.div(this.linearDepth, this.rayScale)));
230
+ this.$l.viewDir = pb.neg(this.camRayDir);
231
+ this.$l.sunL = pb.normalize(this.sunDir);
232
+ this.$l.sunColor = pb.mul(this.sunColorIntensity.rgb, this.sunColorIntensity.a);
233
+ this.$l.NoL = pb.clamp(pb.dot(this.n, this.sunL), 0, 1);
234
+ this.$l.NoV = pb.clamp(pb.dot(this.n, this.viewDir), 0, 1);
235
+ this.$l.f0 = pb.mix(pb.mul(pb.vec3(0.04), this.specularStrength), this.base.rgb, this.metallic);
236
+ this.$l.fresnelNoV = pb.add(this.f0, pb.mul(pb.sub(pb.vec3(1), this.f0), pb.pow(pb.sub(1, this.NoV), 5)));
237
+ this.$l.kd = pb.mul(pb.sub(pb.vec3(1), this.fresnelNoV), pb.sub(1, this.metallic));
238
+ this.$l.sunDiffuse = pb.vec3(0);
239
+ this.$l.sunSpecular = pb.vec3(0);
240
+ this.$if(pb.greaterThan(this.NoL, 1e-5), function() {
241
+ this.$l.H = pb.normalize(pb.add(this.viewDir, this.sunL));
242
+ this.$l.NoH = pb.clamp(pb.dot(this.n, this.H), 0, 1);
243
+ this.$l.VoH = pb.clamp(pb.dot(this.viewDir, this.H), 0, 1);
244
+ this.$l.F = fresnelSchlick(this, this.VoH, this.f0, pb.vec3(1));
245
+ this.$l.alphaRoughness = pb.mul(this.roughness, this.roughness);
246
+ this.$l.D = distributionGGX(this, this.NoH, this.alphaRoughness);
247
+ this.$l.V = visGGX(this, this.NoV, this.NoL, this.alphaRoughness);
248
+ this.$l.sunPunctualColor = pb.mul(this.sunColor, this.NoL);
249
+ this.$l.diffuseBRDF = pb.mul(pb.sub(pb.vec3(1), this.F), pb.div(pb.mul(this.base.rgb, pb.sub(1, this.metallic)), Math.PI));
250
+ this.sunDiffuse = pb.mul(this.sunPunctualColor, pb.max(this.diffuseBRDF, pb.vec3(0)));
251
+ this.sunSpecular = pb.mul(this.sunPunctualColor, this.D, this.V, this.F);
252
+ });
253
+ this.$l.diffuse = this.sunDiffuse;
254
+ this.$l.specular = this.sunSpecular;
255
+ this.$l.clusterLightCount = pb.int(0);
256
+ this.$l.clusterIndex = this.zGetClusterIndex(this.linearDepth);
257
+ if (isWebGL) {
258
+ this.$l.texCoordX = pb.div(pb.add(pb.mod(pb.float(this.clusterIndex), pb.float(this.lightIndexTexSize.x)), 0.5), pb.float(this.lightIndexTexSize.x));
259
+ this.$l.texCoordY = pb.div(pb.add(pb.float(pb.div(this.clusterIndex, this.lightIndexTexSize.x)), 0.5), pb.float(this.lightIndexTexSize.y));
260
+ this.$l.samp = pb.textureSample(this.lightIndexTex, pb.vec2(this.texCoordX, this.texCoordY));
261
+ this.$for(pb.int('i'), 0, 4, function() {
262
+ this.$l.packed = this.samp.at(this.i);
263
+ this.$for(pb.int('k'), 0, 2, function() {
264
+ this.$l.lightIndex = this.zDecodeWebGLLightIndex(this.packed, this.k);
265
+ this.$if(pb.greaterThan(this.lightIndex, 0), function() {
266
+ this.clusterLightCount = pb.add(this.clusterLightCount, 1);
267
+ this.$l.positionRange = this.zLightBuffer.at(pb.mul(this.lightIndex, 4));
268
+ this.$l.directionCutoff = this.zLightBuffer.at(pb.add(pb.mul(this.lightIndex, 4), 1));
269
+ this.$l.diffuseIntensity = this.zLightBuffer.at(pb.add(pb.mul(this.lightIndex, 4), 2));
270
+ this.$l.extra = this.zLightBuffer.at(pb.add(pb.mul(this.lightIndex, 4), 3));
271
+ this.$l.lightType = pb.int(this.extra.w);
272
+ this.$if(pb.or(pb.equal(this.lightType, LIGHT_TYPE_POINT), pb.equal(this.lightType, LIGHT_TYPE_SPOT)), function() {
273
+ this.$l.toLight = pb.sub(this.positionRange.xyz, this.worldPos);
274
+ this.$l.dist = pb.length(this.toLight);
275
+ this.$l.L = pb.div(this.toLight, pb.max(this.dist, 1e-4));
276
+ this.$l.atten = this.zPointAtten(this.dist, this.positionRange.w);
277
+ this.$if(pb.equal(this.lightType, LIGHT_TYPE_SPOT), function() {
278
+ this.atten = this.zSpotAtten(this.worldPos, this.positionRange, this.directionCutoff, this.dist);
279
+ });
280
+ this.$if(pb.greaterThan(this.atten, 1e-5), function() {
281
+ this.$l.lightColor = pb.mul(this.diffuseIntensity.rgb, this.diffuseIntensity.a);
282
+ this.$l.diffScale = this.$choice(pb.equal(this.lightType, LIGHT_TYPE_POINT), this.extra.x, pb.float(1));
283
+ this.$l.specScale = this.$choice(pb.equal(this.lightType, LIGHT_TYPE_POINT), this.extra.y, pb.float(1));
284
+ this.$l.sourceRadiusFactor = this.$choice(pb.equal(this.lightType, LIGHT_TYPE_POINT), pb.div(this.extra.z, pb.max(this.dist, 1e-4)), pb.float(0));
285
+ this.zAccumulatePunctualLight(this.base.rgb, this.metallic, this.roughness, this.specularStrength, this.n, this.viewDir, this.NoV, this.f0, this.lightColor, this.L, this.atten, this.diffScale, this.specScale, this.sourceRadiusFactor, this.diffuse, this.specular);
286
+ });
287
+ });
288
+ this.$if(pb.equal(this.lightType, LIGHT_TYPE_RECT), function() {
289
+ this.zAccumulateRectLight(this.worldPos, this.base.rgb, this.metallic, this.roughness, this.specularStrength, this.n, this.viewDir, this.NoV, this.f0, this.positionRange, this.directionCutoff, this.extra, this.diffuseIntensity, this.diffuse, this.specular);
290
+ });
291
+ });
292
+ });
293
+ });
294
+ } else {
295
+ this.$l.texCoordX = pb.mod(this.clusterIndex, this.lightIndexTexSize.x);
296
+ this.$l.texCoordY = pb.div(this.clusterIndex, this.lightIndexTexSize.x);
297
+ this.$l.samp = pb.textureLoad(this.lightIndexTex, pb.ivec2(this.texCoordX, this.texCoordY), 0);
298
+ this.$for(pb.uint('i'), 0, 4, function() {
299
+ this.$for(pb.uint('k'), 0, 4, function() {
300
+ this.$l.lightIndex = pb.compAnd(pb.sar(this.samp.at(this.i), pb.mul(this.k, 8)), 0xff);
301
+ this.$if(pb.greaterThan(this.lightIndex, 0), function() {
302
+ this.clusterLightCount = pb.add(this.clusterLightCount, 1);
303
+ this.$l.positionRange = this.zLightBuffer.at(pb.mul(this.lightIndex, 4));
304
+ this.$l.directionCutoff = this.zLightBuffer.at(pb.add(pb.mul(this.lightIndex, 4), 1));
305
+ this.$l.diffuseIntensity = this.zLightBuffer.at(pb.add(pb.mul(this.lightIndex, 4), 2));
306
+ this.$l.extra = this.zLightBuffer.at(pb.add(pb.mul(this.lightIndex, 4), 3));
307
+ this.$l.lightType = pb.int(this.extra.w);
308
+ this.$if(pb.or(pb.equal(this.lightType, LIGHT_TYPE_POINT), pb.equal(this.lightType, LIGHT_TYPE_SPOT)), function() {
309
+ this.$l.toLight = pb.sub(this.positionRange.xyz, this.worldPos);
310
+ this.$l.dist = pb.length(this.toLight);
311
+ this.$l.L = pb.div(this.toLight, pb.max(this.dist, 1e-4));
312
+ this.$l.atten = this.zPointAtten(this.dist, this.positionRange.w);
313
+ this.$if(pb.equal(this.lightType, LIGHT_TYPE_SPOT), function() {
314
+ this.atten = this.zSpotAtten(this.worldPos, this.positionRange, this.directionCutoff, this.dist);
315
+ });
316
+ this.$if(pb.greaterThan(this.atten, 1e-5), function() {
317
+ this.$l.lightColor = pb.mul(this.diffuseIntensity.rgb, this.diffuseIntensity.a);
318
+ this.$l.diffScale = this.$choice(pb.equal(this.lightType, LIGHT_TYPE_POINT), this.extra.x, pb.float(1));
319
+ this.$l.specScale = this.$choice(pb.equal(this.lightType, LIGHT_TYPE_POINT), this.extra.y, pb.float(1));
320
+ this.$l.sourceRadiusFactor = this.$choice(pb.equal(this.lightType, LIGHT_TYPE_POINT), pb.div(this.extra.z, pb.max(this.dist, 1e-4)), pb.float(0));
321
+ this.zAccumulatePunctualLight(this.base.rgb, this.metallic, this.roughness, this.specularStrength, this.n, this.viewDir, this.NoV, this.f0, this.lightColor, this.L, this.atten, this.diffScale, this.specScale, this.sourceRadiusFactor, this.diffuse, this.specular);
322
+ });
323
+ });
324
+ this.$if(pb.equal(this.lightType, LIGHT_TYPE_RECT), function() {
325
+ this.zAccumulateRectLight(this.worldPos, this.base.rgb, this.metallic, this.roughness, this.specularStrength, this.n, this.viewDir, this.NoV, this.f0, this.positionRange, this.directionCutoff, this.extra, this.diffuseIntensity, this.diffuse, this.specular);
326
+ });
327
+ });
328
+ });
329
+ });
330
+ }
331
+ this.$l.finalColor = pb.add(pb.mul(pb.add(this.diffuse, this.specular), this.litFlag), this.extra.rgb);
332
+ if (hasEnvIrradiance || hasEnvRadiance) {
333
+ this.$l.ggxLutSample = pb.clamp(pb.textureSampleLevel(this.zGGXLut, pb.clamp(pb.vec2(this.NoV, this.roughness), pb.vec2(0), pb.vec2(1)), 0), pb.vec4(0), pb.vec4(1));
334
+ this.$l.f_ab = this.ggxLutSample.rg;
335
+ this.$l.FssEss = pb.add(pb.mul(this.fresnelNoV, this.f_ab.x), pb.vec3(this.f_ab.y));
336
+ this.$l.Ems = pb.sub(1, pb.add(this.f_ab.x, this.f_ab.y));
337
+ this.$l.F_avg = pb.add(this.f0, pb.div(pb.sub(pb.vec3(1), this.f0), 21));
338
+ this.$l.FmsEms = pb.div(pb.mul(this.FssEss, this.F_avg, this.Ems), pb.max(pb.sub(pb.vec3(1), pb.mul(this.F_avg, this.Ems)), pb.vec3(1e-4)));
339
+ }
340
+ if (hasEnvIrradiance) {
341
+ this.$l.envIrr = ctx.env.light.envLight.getIrradiance(this, this.n).rgb;
342
+ this.finalColor = pb.add(this.finalColor, pb.mul(pb.add(this.kd, this.FmsEms), this.base.rgb, this.envIrr, this.envLightStrength, this.occlusion, 1 / Math.PI));
343
+ }
344
+ if (hasEnvRadiance) {
345
+ this.$l.reflectVec = pb.reflect(pb.neg(this.viewDir), this.n);
346
+ this.$l.envRad = ctx.env.light.envLight.getRadiance(this, this.reflectVec, this.roughness).rgb;
347
+ this.finalColor = pb.add(this.finalColor, pb.mul(this.envRad, this.FssEss, this.envLightStrength, this.occlusion));
348
+ }
349
+ // Deferred direct shadowing is aligned in follow-up pass; keep a stable debug channel now.
350
+ this.$l.shadowTerm = pb.float(1);
351
+ this.$l.debugColor = pb.max(this.finalColor, pb.vec3(0));
352
+ this.$if(pb.notEqual(this.showGBuffer, 0), function() {
353
+ this.$if(pb.equal(this.gbufferViewMode, 1), function() {
354
+ this.debugColor = pb.vec3(pb.clamp(this.linearDepthNormalized, 0, 1));
355
+ }).$elseif(pb.equal(this.gbufferViewMode, 2), function() {
356
+ this.debugColor = pb.vec3(this.metallic);
357
+ }).$elseif(pb.equal(this.gbufferViewMode, 3), function() {
358
+ this.debugColor = pb.vec3(this.roughness);
359
+ }).$elseif(pb.equal(this.gbufferViewMode, 4), function() {
360
+ this.$l.rawN = pb.sub(pb.mul(pb.textureSample(this.gbufferNormalTex, this.$inputs.uv).xyz, 2), pb.vec3(1));
361
+ this.debugColor = pb.vec3(pb.clamp(pb.length(this.rawN), 0, 1));
362
+ }).$else(function() {
363
+ // composite
364
+ this.$if(pb.lessThan(this.$inputs.uv.x, 0.5), function() {
365
+ this.$if(pb.lessThan(this.$inputs.uv.y, 0.5), function() {
366
+ this.debugColor = this.base.rgb;
367
+ }).$else(function() {
368
+ this.debugColor = this.rm.rgb;
369
+ });
370
+ }).$else(function() {
371
+ this.$if(pb.lessThan(this.$inputs.uv.y, 0.5), function() {
372
+ this.debugColor = pb.add(pb.mul(this.n, 0.5), pb.vec3(0.5));
373
+ }).$else(function() {
374
+ this.debugColor = pb.vec3(this.roughness);
375
+ });
376
+ });
377
+ });
378
+ }).$elseif(pb.notEqual(this.showCluster, 0), function() {
379
+ this.$l.clusterT = pb.clamp(pb.div(pb.float(this.clusterLightCount), 16), 0, 1);
380
+ this.debugColor = pb.vec3(this.clusterT, pb.mul(this.clusterT, this.clusterT), pb.sub(1, this.clusterT));
381
+ }).$elseif(pb.notEqual(this.showShadowTerm, 0), function() {
382
+ this.debugColor = pb.vec3(this.shadowTerm);
383
+ }).$elseif(pb.notEqual(this.showSpecTerm, 0), function() {
384
+ this.debugColor = pb.max(this.specular, pb.vec3(0));
385
+ });
386
+ this.$outputs.color = pb.vec4(this.debugColor, this.base.a);
387
+ });
388
+ }
389
+ });
390
+ if (!builtProgram) {
391
+ return;
392
+ }
393
+ program = builtProgram;
394
+ program.name = '@DeferredLightPass';
395
+ DeferredLightPass._programs[hash] = program;
396
+ }
397
+ let bindGroup = DeferredLightPass._bindGroups[hash];
398
+ if (!bindGroup) {
399
+ bindGroup = device.createBindGroup(program.bindGroupLayouts[0]);
400
+ DeferredLightPass._bindGroups[hash] = bindGroup;
401
+ }
402
+ bindGroup.setTexture('gbufferColorTex', gbufferColor, fetchSampler('clamp_nearest_nomip'));
403
+ bindGroup.setTexture('gbufferRoughnessTex', gbufferRoughness, fetchSampler('clamp_nearest_nomip'));
404
+ bindGroup.setTexture('gbufferNormalTex', gbufferNormal, fetchSampler('clamp_nearest_nomip'));
405
+ bindGroup.setTexture('gbufferExtraTex', gbufferExtra, fetchSampler('clamp_nearest_nomip'));
406
+ bindGroup.setTexture('linearDepthTex', ctx.linearDepthTexture, fetchSampler('clamp_nearest_nomip'));
407
+ bindGroup.setTexture('zGGXLut', getGGXLUT(1024), fetchSampler('clamp_nearest_nomip'));
408
+ bindGroup.setTexture('lightIndexTex', ctx.clusteredLight.lightIndexTexture);
409
+ bindGroup.setBuffer('zLightBuffer', ctx.clusteredLight.lightBuffer);
410
+ bindGroup.setValue('clusterParams', ctx.clusteredLight.clusterParam);
411
+ bindGroup.setValue('countParams', ctx.clusteredLight.countParam);
412
+ bindGroup.setValue('lightIndexTexSize', new Int32Array([
413
+ ctx.clusteredLight.lightIndexTexture.width,
414
+ ctx.clusteredLight.lightIndexTexture.height
415
+ ]));
416
+ const sunDirSrc = ctx.sunLight ? ctx.sunLight.directionAndCutoff.xyz().scaleBy(-1) : {
417
+ x: 0,
418
+ y: 0,
419
+ z: 1
420
+ };
421
+ const sunShadowed = !!(ctx.sunLight && ctx.shadowMapInfo?.has(ctx.sunLight));
422
+ const sunColorIntensitySrc = ctx.sunLight ? sunShadowed ? {
423
+ x: 0,
424
+ y: 0,
425
+ z: 0,
426
+ w: 0
427
+ } : ctx.sunLight.diffuseAndIntensity : {
428
+ x: 1,
429
+ y: 1,
430
+ z: 1,
431
+ w: 0
432
+ };
433
+ const cameraRight = ctx.camera.worldMatrix.getRow(0).xyz().inplaceNormalize();
434
+ const cameraUp = ctx.camera.worldMatrix.getRow(1).xyz().inplaceNormalize();
435
+ const cameraForward = ctx.camera.worldMatrix.getRow(2).xyz().inplaceNormalize().scaleBy(-1);
436
+ const cameraPos = ctx.camera.getWorldPosition();
437
+ bindGroup.setValue('sunDir', new Float32Array([
438
+ sunDirSrc.x,
439
+ sunDirSrc.y,
440
+ sunDirSrc.z
441
+ ]));
442
+ bindGroup.setValue('sunColorIntensity', new Float32Array([
443
+ sunColorIntensitySrc.x,
444
+ sunColorIntensitySrc.y,
445
+ sunColorIntensitySrc.z,
446
+ sunColorIntensitySrc.w
447
+ ]));
448
+ bindGroup.setValue('cameraRight', new Float32Array([
449
+ cameraRight.x,
450
+ cameraRight.y,
451
+ cameraRight.z
452
+ ]));
453
+ bindGroup.setValue('cameraUp', new Float32Array([
454
+ cameraUp.x,
455
+ cameraUp.y,
456
+ cameraUp.z
457
+ ]));
458
+ bindGroup.setValue('cameraForward', new Float32Array([
459
+ cameraForward.x,
460
+ cameraForward.y,
461
+ cameraForward.z
462
+ ]));
463
+ bindGroup.setValue('cameraPos', new Float32Array([
464
+ cameraPos.x,
465
+ cameraPos.y,
466
+ cameraPos.z
467
+ ]));
468
+ bindGroup.setValue('cameraProj', new Float32Array([
469
+ ctx.camera.getTanHalfFovy(),
470
+ ctx.camera.getAspect()
471
+ ]));
472
+ bindGroup.setValue('cameraNearFar', new Float32Array([
473
+ ctx.camera.getNearPlane(),
474
+ ctx.camera.getFarPlane()
475
+ ]));
476
+ let gbufferViewMode = 0;
477
+ switch(ctx.camera.deferredGBufferView){
478
+ case 'depth':
479
+ gbufferViewMode = 1;
480
+ break;
481
+ case 'metallic':
482
+ gbufferViewMode = 2;
483
+ break;
484
+ case 'roughness':
485
+ gbufferViewMode = 3;
486
+ break;
487
+ case 'normal-length':
488
+ gbufferViewMode = 4;
489
+ break;
490
+ default:
491
+ gbufferViewMode = 0;
492
+ break;
493
+ }
494
+ bindGroup.setValue('showGBuffer', ctx.camera.deferredShowGBuffer ? 1 : 0);
495
+ bindGroup.setValue('gbufferViewMode', gbufferViewMode);
496
+ bindGroup.setValue('showCluster', ctx.camera.deferredShowCluster ? 1 : 0);
497
+ bindGroup.setValue('showShadowTerm', ctx.camera.deferredShowShadowTerm ? 1 : 0);
498
+ bindGroup.setValue('showSpecTerm', ctx.camera.deferredShowSpecTerm ? 1 : 0);
499
+ if (ctx.env?.light?.envLight) {
500
+ bindGroup.setValue('envLightStrength', ctx.env.light.strength ?? 0);
501
+ ctx.env.light.envLight.updateBindGroup(bindGroup);
502
+ }
503
+ device.setProgram(program);
504
+ device.setBindGroup(0, bindGroup);
505
+ drawFullscreenQuad();
506
+ }
507
+ }
508
+
509
+ export { DeferredLightPass };
510
+ //# sourceMappingURL=deferredlightpass.js.map