@zephyr3d/scene 0.9.6 → 0.9.8

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 (205) hide show
  1. package/dist/animation/animationset.js +52 -55
  2. package/dist/animation/animationset.js.map +1 -1
  3. package/dist/animation/joint_dynamics/controller.js +92 -32
  4. package/dist/animation/joint_dynamics/controller.js.map +1 -1
  5. package/dist/animation/joint_dynamics/convex_collider.js +320 -0
  6. package/dist/animation/joint_dynamics/convex_collider.js.map +1 -0
  7. package/dist/animation/joint_dynamics/joint_dynamics_system.js +57 -19
  8. package/dist/animation/joint_dynamics/joint_dynamics_system.js.map +1 -1
  9. package/dist/animation/joint_dynamics/solver.js +71 -27
  10. package/dist/animation/joint_dynamics/solver.js.map +1 -1
  11. package/dist/animation/joint_dynamics_modifier.js +4 -3
  12. package/dist/animation/joint_dynamics_modifier.js.map +1 -1
  13. package/dist/animation/skeleton.js +7 -10
  14. package/dist/animation/skeleton.js.map +1 -1
  15. package/dist/app/engine.js +3 -9
  16. package/dist/app/engine.js.map +1 -1
  17. package/dist/app/scriptregistry.js +47 -16
  18. package/dist/app/scriptregistry.js.map +1 -1
  19. package/dist/asset/assetmanager.js +3 -1
  20. package/dist/asset/assetmanager.js.map +1 -1
  21. package/dist/asset/model.js +346 -7
  22. package/dist/asset/model.js.map +1 -1
  23. package/dist/avatar/wardrobe.js +7 -3
  24. package/dist/avatar/wardrobe.js.map +1 -1
  25. package/dist/camera/camera.js +240 -34
  26. package/dist/camera/camera.js.map +1 -1
  27. package/dist/index.d.ts +1350 -622
  28. package/dist/index.js +6 -11
  29. package/dist/index.js.map +1 -1
  30. package/dist/material/blinn.js +1 -1
  31. package/dist/material/blinn.js.map +1 -1
  32. package/dist/material/lambert.js +1 -1
  33. package/dist/material/lambert.js.map +1 -1
  34. package/dist/material/material.js +23 -1
  35. package/dist/material/material.js.map +1 -1
  36. package/dist/material/meshmaterial.js +178 -23
  37. package/dist/material/meshmaterial.js.map +1 -1
  38. package/dist/material/mixins/albedocolor.js +4 -4
  39. package/dist/material/mixins/albedocolor.js.map +1 -1
  40. package/dist/material/mixins/lightmodel/blinnphong.js +2 -1
  41. package/dist/material/mixins/lightmodel/blinnphong.js.map +1 -1
  42. package/dist/material/mixins/lightmodel/lambert.js +2 -1
  43. package/dist/material/mixins/lightmodel/lambert.js.map +1 -1
  44. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js +63 -16
  45. package/dist/material/mixins/lightmodel/pbrblueprintmixin.js.map +1 -1
  46. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js +100 -27
  47. package/dist/material/mixins/lightmodel/pbrmetallicroughness.js.map +1 -1
  48. package/dist/material/mixins/lightmodel/pbrspecularglossness.js +16 -6
  49. package/dist/material/mixins/lightmodel/pbrspecularglossness.js.map +1 -1
  50. package/dist/material/mixins/lit.js +1 -1
  51. package/dist/material/mixins/lit.js.map +1 -1
  52. package/dist/material/mixins/pbr/common.js +276 -65
  53. package/dist/material/mixins/pbr/common.js.map +1 -1
  54. package/dist/material/mixins/texture.js +3 -3
  55. package/dist/material/mixins/texture.js.map +1 -1
  56. package/dist/material/mixins/vertexcolor.js +2 -2
  57. package/dist/material/mixins/vertexcolor.js.map +1 -1
  58. package/dist/material/mtoon.js +574 -0
  59. package/dist/material/mtoon.js.map +1 -0
  60. package/dist/material/pbrblueprint.js +494 -331
  61. package/dist/material/pbrblueprint.js.map +1 -1
  62. package/dist/material/pbrmr.js +118 -100
  63. package/dist/material/pbrmr.js.map +1 -1
  64. package/dist/material/pbrsg.js +1 -1
  65. package/dist/material/pbrsg.js.map +1 -1
  66. package/dist/material/shader/helper.js +45 -15
  67. package/dist/material/shader/helper.js.map +1 -1
  68. package/dist/material/subsurfaceprofile.js +812 -0
  69. package/dist/material/subsurfaceprofile.js.map +1 -0
  70. package/dist/material/unlit.js +1 -1
  71. package/dist/material/unlit.js.map +1 -1
  72. package/dist/posteffect/compositor.js +46 -11
  73. package/dist/posteffect/compositor.js.map +1 -1
  74. package/dist/posteffect/ssr.js +413 -87
  75. package/dist/posteffect/ssr.js.map +1 -1
  76. package/dist/posteffect/sss.js +1053 -0
  77. package/dist/posteffect/sss.js.map +1 -0
  78. package/dist/posteffect/taa.js +61 -60
  79. package/dist/posteffect/taa.js.map +1 -1
  80. package/dist/render/abuffer_oit.js +63 -12
  81. package/dist/render/abuffer_oit.js.map +1 -1
  82. package/dist/render/cluster_light.js +6 -5
  83. package/dist/render/cluster_light.js.map +1 -1
  84. package/dist/render/drawable.js +1 -5
  85. package/dist/render/drawable.js.map +1 -1
  86. package/dist/render/drawable_mixin.js +2 -1
  87. package/dist/render/drawable_mixin.js.map +1 -1
  88. package/dist/render/fbm_wavegenerator.js +2 -1
  89. package/dist/render/fbm_wavegenerator.js.map +1 -1
  90. package/dist/render/gerstner_wavegenerator.js +2 -1
  91. package/dist/render/gerstner_wavegenerator.js.map +1 -1
  92. package/dist/render/globalbindgroup_allocator.js +2 -1
  93. package/dist/render/globalbindgroup_allocator.js.map +1 -1
  94. package/dist/render/lightpass.js +105 -18
  95. package/dist/render/lightpass.js.map +1 -1
  96. package/dist/render/render_queue.js +51 -8
  97. package/dist/render/render_queue.js.map +1 -1
  98. package/dist/render/renderer.js +73 -59
  99. package/dist/render/renderer.js.map +1 -1
  100. package/dist/render/rendergraph/device_pool_allocator.js +8 -0
  101. package/dist/render/rendergraph/device_pool_allocator.js.map +1 -1
  102. package/dist/render/rendergraph/forward_plus_builder.js +481 -95
  103. package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
  104. package/dist/render/rendergraph/history_resource_manager.js +55 -0
  105. package/dist/render/rendergraph/history_resource_manager.js.map +1 -1
  106. package/dist/render/rendergraph/history_resources.js +3 -1
  107. package/dist/render/rendergraph/history_resources.js.map +1 -1
  108. package/dist/render/rendergraph/types.js.map +1 -1
  109. package/dist/render/renderpass.js +10 -4
  110. package/dist/render/renderpass.js.map +1 -1
  111. package/dist/render/sky.js +31 -1
  112. package/dist/render/sky.js.map +1 -1
  113. package/dist/render/weightedblended_oit.js +23 -5
  114. package/dist/render/weightedblended_oit.js.map +1 -1
  115. package/dist/scene/basesprite.js +4 -2
  116. package/dist/scene/basesprite.js.map +1 -1
  117. package/dist/scene/batchgroup.js +3 -1
  118. package/dist/scene/batchgroup.js.map +1 -1
  119. package/dist/scene/environment.js +11 -1
  120. package/dist/scene/environment.js.map +1 -1
  121. package/dist/scene/light.js +21 -3
  122. package/dist/scene/light.js.map +1 -1
  123. package/dist/scene/mesh.js +29 -14
  124. package/dist/scene/mesh.js.map +1 -1
  125. package/dist/scene/meshdrawable.js +6 -0
  126. package/dist/scene/meshdrawable.js.map +1 -1
  127. package/dist/scene/msdftext.js +5 -2
  128. package/dist/scene/msdftext.js.map +1 -1
  129. package/dist/scene/msdftextsprite.js +5 -3
  130. package/dist/scene/msdftextsprite.js.map +1 -1
  131. package/dist/scene/particlesys.js +3 -1
  132. package/dist/scene/particlesys.js.map +1 -1
  133. package/dist/scene/scene.js +6 -5
  134. package/dist/scene/scene.js.map +1 -1
  135. package/dist/scene/terrain-cm/grass.js +4 -2
  136. package/dist/scene/terrain-cm/grass.js.map +1 -1
  137. package/dist/scene/terrain-cm/grassmaterial.js +2 -1
  138. package/dist/scene/terrain-cm/grassmaterial.js.map +1 -1
  139. package/dist/scene/terrain-cm/terrain-cm.js +4 -2
  140. package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
  141. package/dist/scene/water.js +4 -2
  142. package/dist/scene/water.js.map +1 -1
  143. package/dist/shaders/shadow.js +26 -393
  144. package/dist/shaders/shadow.js.map +1 -1
  145. package/dist/shadow/esm.js +112 -12
  146. package/dist/shadow/esm.js.map +1 -1
  147. package/dist/shadow/pcf_opt.js +2 -2
  148. package/dist/shadow/pcf_opt.js.map +1 -1
  149. package/dist/shadow/pcf_pd.js +19 -10
  150. package/dist/shadow/pcf_pd.js.map +1 -1
  151. package/dist/shadow/shader.js +58 -7
  152. package/dist/shadow/shader.js.map +1 -1
  153. package/dist/shadow/shadow_impl.js +6 -0
  154. package/dist/shadow/shadow_impl.js.map +1 -1
  155. package/dist/shadow/shadow_region.js +229 -0
  156. package/dist/shadow/shadow_region.js.map +1 -0
  157. package/dist/shadow/shadowmapper.js +67 -59
  158. package/dist/shadow/shadowmapper.js.map +1 -1
  159. package/dist/shadow/vsm.js +45 -19
  160. package/dist/shadow/vsm.js.map +1 -1
  161. package/dist/utility/blueprint/common/constants.js +8 -8
  162. package/dist/utility/blueprint/common/constants.js.map +1 -1
  163. package/dist/utility/blueprint/material/pbr.js +31 -4
  164. package/dist/utility/blueprint/material/pbr.js.map +1 -1
  165. package/dist/utility/blueprint/material/texture.js +1 -17
  166. package/dist/utility/blueprint/material/texture.js.map +1 -1
  167. package/dist/utility/serialization/manager.js +66 -98
  168. package/dist/utility/serialization/manager.js.map +1 -1
  169. package/dist/utility/serialization/scene/animation.js +5 -2
  170. package/dist/utility/serialization/scene/animation.js.map +1 -1
  171. package/dist/utility/serialization/scene/batch.js +4 -1
  172. package/dist/utility/serialization/scene/batch.js.map +1 -1
  173. package/dist/utility/serialization/scene/camera.js +249 -54
  174. package/dist/utility/serialization/scene/camera.js.map +1 -1
  175. package/dist/utility/serialization/scene/common.js +37 -1
  176. package/dist/utility/serialization/scene/common.js.map +1 -1
  177. package/dist/utility/serialization/scene/light.js +42 -3
  178. package/dist/utility/serialization/scene/light.js.map +1 -1
  179. package/dist/utility/serialization/scene/material.js +1112 -646
  180. package/dist/utility/serialization/scene/material.js.map +1 -1
  181. package/dist/utility/serialization/scene/mesh.js +7 -4
  182. package/dist/utility/serialization/scene/mesh.js.map +1 -1
  183. package/dist/utility/serialization/scene/node.js +31 -12
  184. package/dist/utility/serialization/scene/node.js.map +1 -1
  185. package/dist/utility/serialization/scene/particle.js +4 -1
  186. package/dist/utility/serialization/scene/particle.js.map +1 -1
  187. package/dist/utility/serialization/scene/primitive.js +3 -1
  188. package/dist/utility/serialization/scene/primitive.js.map +1 -1
  189. package/dist/utility/serialization/scene/scene.js +18 -0
  190. package/dist/utility/serialization/scene/scene.js.map +1 -1
  191. package/dist/utility/serialization/scene/sprite.js +6 -3
  192. package/dist/utility/serialization/scene/sprite.js.map +1 -1
  193. package/dist/utility/serialization/scene/terrain.js +5 -2
  194. package/dist/utility/serialization/scene/terrain.js.map +1 -1
  195. package/dist/utility/serialization/scene/text.js +3 -1
  196. package/dist/utility/serialization/scene/text.js.map +1 -1
  197. package/dist/utility/serialization/scene/water.js +4 -1
  198. package/dist/utility/serialization/scene/water.js.map +1 -1
  199. package/dist/utility/textures/ltcdata.js +6 -0
  200. package/dist/utility/textures/ltcdata.js.map +1 -0
  201. package/dist/utility/textures/ltclut.js +61 -0
  202. package/dist/utility/textures/ltclut.js.map +1 -0
  203. package/dist/values.js +9 -1
  204. package/dist/values.js.map +1 -1
  205. package/package.json +3 -3
@@ -1,4 +1,5 @@
1
1
  import { Vector4 } from '@zephyr3d/base';
2
+ import { RenderQueue } from '../render_queue.js';
2
3
  import { LightPass } from '../lightpass.js';
3
4
  import { ShadowMapPass } from '../shadowmap_pass.js';
4
5
  import { DepthPass } from '../depthpass.js';
@@ -32,47 +33,184 @@ const _clusters = [];
32
33
  const _devicePoolAllocator = new DevicePoolAllocator();
33
34
  let _backDepthColorState = null;
34
35
  let _frontDepthColorState = null;
36
+ const SURFACE_MRT_FLAGS = MaterialVaryingFlags.SSR_STORE_ROUGHNESS | MaterialVaryingFlags.SSS_STORE_PROFILE | MaterialVaryingFlags.SSS_STORE_DIFFUSE | MaterialVaryingFlags.SSS_STORE_NORMAL | MaterialVaryingFlags.SSS_STORE_TRANSMISSION;
35
37
  function getClusteredLight() {
36
38
  return _clusters.length > 0 ? _clusters.pop() : new ClusteredLight();
37
39
  }
38
40
  function freeClusteredLight(cl) {
39
41
  _clusters.push(cl);
40
42
  }
43
+ function getCoreMaterial(material) {
44
+ return material?.coreMaterial ?? material ?? null;
45
+ }
46
+ function hasSSSMaterialCore(material) {
47
+ return !!getCoreMaterial(material)?.subsurfaceProfile;
48
+ }
49
+ function renderQueueHasActiveSSS(renderQueue) {
50
+ const itemList = renderQueue.itemList;
51
+ if (!itemList) {
52
+ return false;
53
+ }
54
+ const lists = [
55
+ ...itemList.opaque.lit,
56
+ ...itemList.opaque.unlit
57
+ ];
58
+ for (const list of lists){
59
+ for (const material of list.materialList){
60
+ if (hasSSSMaterialCore(material)) {
61
+ return true;
62
+ }
63
+ }
64
+ }
65
+ return false;
66
+ }
67
+ function filterActualSSSItemList(items) {
68
+ return items.filter((item)=>hasSSSMaterialCore(item.drawable.getMaterial?.()));
69
+ }
70
+ function filterActualSSSMaterialList(materialList) {
71
+ const filtered = new Set();
72
+ materialList.forEach((mat)=>{
73
+ if (hasSSSMaterialCore(mat)) {
74
+ filtered.add(mat);
75
+ }
76
+ });
77
+ return filtered;
78
+ }
79
+ function cloneActualSSSListInfo(source, _targetQueue) {
80
+ return {
81
+ itemList: filterActualSSSItemList(source.itemList),
82
+ skinItemList: filterActualSSSItemList(source.skinItemList),
83
+ morphItemList: filterActualSSSItemList(source.morphItemList),
84
+ skinAndMorphItemList: filterActualSSSItemList(source.skinAndMorphItemList),
85
+ instanceItemList: filterActualSSSItemList(source.instanceItemList),
86
+ materialList: filterActualSSSMaterialList(source.materialList),
87
+ instanceList: {},
88
+ renderQueue: source.renderQueue
89
+ };
90
+ }
91
+ function cloneActualSSSBundle(source, targetQueue) {
92
+ return {
93
+ lit: source.lit.map((info)=>cloneActualSSSListInfo(info)),
94
+ unlit: source.unlit.map((info)=>cloneActualSSSListInfo(info))
95
+ };
96
+ }
97
+ function hasAnyActualSSSItems(renderItems) {
98
+ return renderItems.some((info)=>info.itemList.length > 0 || info.skinItemList.length > 0 || info.morphItemList.length > 0 || info.skinAndMorphItemList.length > 0 || info.instanceItemList.length > 0);
99
+ }
100
+ function createActualSSSRenderQueue(renderQueue) {
101
+ const itemList = renderQueue.itemList;
102
+ if (!itemList) {
103
+ return null;
104
+ }
105
+ const queue = new RenderQueue(_scenePass);
106
+ const sssOpaque = cloneActualSSSBundle(itemList.opaque);
107
+ if (!hasAnyActualSSSItems([
108
+ ...sssOpaque.lit,
109
+ ...sssOpaque.unlit
110
+ ])) {
111
+ queue.dispose();
112
+ return null;
113
+ }
114
+ const emptyBundle = {
115
+ lit: [],
116
+ unlit: []
117
+ };
118
+ const target = queue;
119
+ target._itemList = {
120
+ opaque: sssOpaque,
121
+ transmission: emptyBundle,
122
+ transparent: emptyBundle,
123
+ transmission_trans: emptyBundle
124
+ };
125
+ target._shadowedLightList = renderQueue.shadowedLights;
126
+ target._unshadowedLightList = renderQueue.unshadowedLights;
127
+ target._sunLight = renderQueue.sunLight;
128
+ target._primaryDirectionalLight = renderQueue.primaryDirectionalLight;
129
+ target._primaryTransmissionLight = renderQueue.primaryTransmissionLight;
130
+ target._needSceneColor = false;
131
+ target._needSceneDepth = false;
132
+ target._needSceneColorWithDepth = false;
133
+ target._drawTransparent = false;
134
+ return queue;
135
+ }
136
+ function getSurfaceTextureFormat(ctx) {
137
+ const caps = ctx.device.getDeviceCaps?.();
138
+ return caps?.textureCaps.supportHalfFloatColorBuffer ? 'rgba16f' : 'rgba8unorm';
139
+ }
140
+ function getTextureFormatBytes(ctx, format) {
141
+ return ctx.device.getDeviceCaps().textureCaps.getTextureFormatInfo(format).size;
142
+ }
143
+ function shouldStoreSSSDiffuse(ctx) {
144
+ return ctx.camera.sssStrength > 0 && ctx.camera.sssBlurScale > 0;
145
+ }
146
+ function shouldStoreSSSTransmission(ctx) {
147
+ return ctx.camera.sssStrength > 0 && ctx.camera.sssTransmissionStrength > 0;
148
+ }
149
+ function getSSSLightingTextureFormat(ctx, attachmentCount, includeSSRSurfaceMRT) {
150
+ const colorFormat = ctx.colorFormat;
151
+ if (!includeSSRSurfaceMRT || attachmentCount === 0) {
152
+ return colorFormat;
153
+ }
154
+ const caps = ctx.device.getDeviceCaps();
155
+ const roughnessFormat = ctx.SSRRoughnessTexture?.format ?? colorFormat;
156
+ const normalFormat = ctx.SSRNormalTexture?.format ?? colorFormat;
157
+ const colorBytes = getTextureFormatBytes(ctx, colorFormat) + getTextureFormatBytes(ctx, roughnessFormat) + getTextureFormatBytes(ctx, normalFormat);
158
+ const fullPrecisionBytes = colorBytes + getTextureFormatBytes(ctx, colorFormat) * attachmentCount;
159
+ if (fullPrecisionBytes <= caps.framebufferCaps.maxColorAttachmentBytesPerSample) {
160
+ return colorFormat;
161
+ }
162
+ return 'rgba8unorm';
163
+ }
164
+ function getFullMipLevelCount(width, height) {
165
+ return Math.max(1, Math.floor(Math.log2(Math.max(1, width, height))) + 1);
166
+ }
167
+ function hasSurfaceMRT(ctx) {
168
+ return !!(ctx.materialFlags & SURFACE_MRT_FLAGS);
169
+ }
170
+ function getLightPassColorAttachments(ctx, colorAttachment) {
171
+ const attachments = [
172
+ colorAttachment
173
+ ];
174
+ if (ctx.materialFlags & MaterialVaryingFlags.SSR_STORE_ROUGHNESS) {
175
+ attachments.push(ctx.SSRRoughnessTexture, ctx.SSRNormalTexture);
176
+ } else if (ctx.materialFlags & MaterialVaryingFlags.SSS_STORE_NORMAL) {
177
+ attachments.push(ctx.SSRNormalTexture);
178
+ }
179
+ if (ctx.materialFlags & MaterialVaryingFlags.SSS_STORE_PROFILE) {
180
+ attachments.push(ctx.SSSProfileTexture, ctx.SSSParamTexture);
181
+ }
182
+ if (ctx.materialFlags & MaterialVaryingFlags.SSS_STORE_DIFFUSE) {
183
+ attachments.push(ctx.SSSDiffuseTexture);
184
+ }
185
+ if (ctx.materialFlags & MaterialVaryingFlags.SSS_STORE_TRANSMISSION) {
186
+ attachments.push(ctx.SSSTransmissionTexture);
187
+ }
188
+ return attachments.length === 1 ? attachments[0] : attachments;
189
+ }
41
190
  /**
42
191
  * Derive pipeline options from the current scene/camera state.
43
192
  * @internal
44
193
  */ function deriveForwardPlusOptions(scene, camera, deviceType, renderQueue) {
45
194
  const ssr = camera.SSR && scene.env.light.envLight && scene.env.light.envLight.hasRadiance();
195
+ const sss = camera.SSS && renderQueueHasActiveSSS(renderQueue);
196
+ const needSceneColor = renderQueue.needSceneColor();
197
+ const needSceneColorWithDepth = renderQueue.needSceneColorWithDepth();
46
198
  return {
47
199
  depthPrepass: true,
48
- motionVectors: deviceType !== 'webgl' && (camera.TAA || camera.motionBlur),
200
+ motionVectors: deviceType !== 'webgl' && (camera.TAA || camera.motionBlur || !!ssr && camera.ssrTemporal),
49
201
  hiZ: camera.HiZ && deviceType !== 'webgl',
50
202
  ssr: !!ssr,
51
203
  ssrCalcThickness: !!ssr && camera.ssrCalcThickness,
52
204
  gpuPicking: !!camera.getPickResultResolveFunc(),
53
- needSceneColor: renderQueue.needSceneColor()
205
+ needSceneColor,
206
+ needSceneColorWithDepth,
207
+ needsTransmissionDepthForSSR: !!ssr && needSceneColor && !needSceneColorWithDepth,
208
+ sss: !!sss
54
209
  };
55
210
  }
56
- // ─── Forward+ Graph Builder ─────────────────────────────────────────
57
- /**
58
- * Constructs a render graph representing the forward+ pipeline.
59
- *
60
- * Each step in the existing `SceneRenderer._renderScene` becomes a graph pass.
61
- * Execute callbacks delegate to the existing rendering code, sharing a mutable
62
- * `FrameState`.
63
- *
64
- * @param graph - The render graph to populate.
65
- * @param ctx - The draw context for this frame.
66
- * @param renderQueue - The culled render queue.
67
- * @param options - Pipeline feature toggles.
68
- * @returns The backbuffer handle (graph output).
69
- *
70
- * @public
71
- */ function buildForwardPlusGraph(graph, ctx, renderQueue, options) {
72
- return buildForwardPlusGraphInternal(graph, ctx, renderQueue, options).backbuffer;
73
- }
74
211
  function buildForwardPlusGraphInternal(graph, ctx, renderQueue, options) {
75
212
  const backbuffer = graph.importTexture('backbuffer');
213
+ ctx.SSS = !!options.sss;
76
214
  // Shared mutable frame state
77
215
  const frame = {
78
216
  ctx,
@@ -192,16 +330,31 @@ function buildForwardPlusGraphInternal(graph, ctx, renderQueue, options) {
192
330
  const depthHandle = depthPassResult.depthHandle;
193
331
  const motionVectorHandle = depthPassResult.motionVectorHandle;
194
332
  const renderDepthAttachment = depthPassResult.graphDepthAttachmentHandle ?? depthPassResult.externalDepthAttachment ?? null;
333
+ let preLightTransmissionDepthToken;
334
+ if (options.needsTransmissionDepthForSSR) {
335
+ preLightTransmissionDepthToken = graph.addPass('TransmissionDepthForSSR', (builder)=>{
336
+ builder.read(depthPassResult.depthFramebufferHandle);
337
+ const done = builder.createToken('TransmissionDepthForSSRDone');
338
+ builder.sideEffect();
339
+ builder.setExecute((rgCtx)=>{
340
+ renderTransmissionDepthPass(frame, rgCtx);
341
+ });
342
+ return done;
343
+ });
344
+ }
195
345
  // ── 6. Hi-Z (optional) ───────────────────────────────────────────
196
346
  let hiZHandle;
197
347
  if (options.hiZ) {
198
348
  graph.addPass('HiZ', (builder)=>{
199
349
  builder.read(depthHandle);
200
350
  builder.read(depthPassResult.depthFramebufferHandle);
351
+ if (preLightTransmissionDepthToken) {
352
+ builder.read(preLightTransmissionDepthToken);
353
+ }
201
354
  hiZHandle = builder.createTexture({
202
355
  format: 'r32f',
203
356
  label: 'hiZ',
204
- mipLevels: 10
357
+ mipLevels: getFullMipLevelCount(ctx.renderWidth, ctx.renderHeight)
205
358
  });
206
359
  const hiZFramebufferHandle = builder.createFramebuffer({
207
360
  label: 'HiZFramebuffer',
@@ -223,12 +376,120 @@ function buildForwardPlusGraphInternal(graph, ctx, renderQueue, options) {
223
376
  });
224
377
  }
225
378
  // ── 7. Main Light Pass ────────────────────────────────────────────
379
+ const historyManager = ctx.camera?.getHistoryResourceManager?.() ?? null;
380
+ const lightHistoryReadBindings = [];
381
+ const compositeHistoryReadBindings = [];
382
+ const historySize = {
383
+ width: ctx.renderWidth,
384
+ height: ctx.renderHeight
385
+ };
386
+ if (historyManager && options.ssr && ctx.camera?.ssrTemporal && options.motionVectors) {
387
+ const reflectHistoryHandle = historyManager.importPreviousIfCompatible(graph, RGHistoryResources.SSR_REFLECT, {
388
+ format: 'rgba16f',
389
+ sizeMode: 'absolute',
390
+ width: ctx.renderWidth,
391
+ height: ctx.renderHeight
392
+ }, historySize);
393
+ const motionVectorHistoryHandle = historyManager.importPreviousIfCompatible(graph, RGHistoryResources.SSR_MOTION_VECTOR, {
394
+ format: 'rgba16f',
395
+ sizeMode: 'absolute',
396
+ width: ctx.renderWidth,
397
+ height: ctx.renderHeight
398
+ }, historySize);
399
+ if (reflectHistoryHandle && motionVectorHistoryHandle) {
400
+ lightHistoryReadBindings.push({
401
+ name: RGHistoryResources.SSR_REFLECT,
402
+ handle: reflectHistoryHandle
403
+ }, {
404
+ name: RGHistoryResources.SSR_MOTION_VECTOR,
405
+ handle: motionVectorHistoryHandle
406
+ });
407
+ }
408
+ }
409
+ if (historyManager && ctx.camera?.TAA && options.motionVectors) {
410
+ const colorHistoryHandle = historyManager.importPreviousIfCompatible(graph, RGHistoryResources.TAA_COLOR, {
411
+ format: ctx.colorFormat,
412
+ sizeMode: 'absolute',
413
+ width: ctx.renderWidth,
414
+ height: ctx.renderHeight
415
+ }, historySize);
416
+ const motionVectorHistoryHandle = historyManager.importPreviousIfCompatible(graph, RGHistoryResources.TAA_MOTION_VECTOR, {
417
+ format: 'rgba16f',
418
+ sizeMode: 'absolute',
419
+ width: ctx.renderWidth,
420
+ height: ctx.renderHeight
421
+ }, historySize);
422
+ if (colorHistoryHandle && motionVectorHistoryHandle) {
423
+ compositeHistoryReadBindings.push({
424
+ name: RGHistoryResources.TAA_COLOR,
425
+ handle: colorHistoryHandle
426
+ }, {
427
+ name: RGHistoryResources.TAA_MOTION_VECTOR,
428
+ handle: motionVectorHistoryHandle
429
+ });
430
+ }
431
+ }
432
+ let sssProfileResult;
433
+ if (options.sss) {
434
+ sssProfileResult = graph.addPass('SSSProfile', (builder)=>{
435
+ builder.read(depthHandle);
436
+ builder.read(depthPassResult.depthFramebufferHandle);
437
+ if (preLightTransmissionDepthToken) {
438
+ builder.read(preLightTransmissionDepthToken);
439
+ }
440
+ const profileHandle = builder.createTexture({
441
+ format: 'rgba16f',
442
+ label: 'sssProfile'
443
+ });
444
+ const paramHandle = builder.createTexture({
445
+ format: 'rgba8unorm',
446
+ label: 'sssParam'
447
+ });
448
+ const normalHandle = options.ssr ? undefined : builder.createTexture({
449
+ format: getSurfaceTextureFormat(ctx),
450
+ label: 'sssNormal'
451
+ });
452
+ const colorAttachments = normalHandle ? [
453
+ ctx.colorFormat,
454
+ normalHandle,
455
+ profileHandle,
456
+ paramHandle
457
+ ] : [
458
+ ctx.colorFormat,
459
+ profileHandle,
460
+ paramHandle
461
+ ];
462
+ const framebufferHandle = builder.createFramebuffer({
463
+ label: 'SSSProfileFramebuffer',
464
+ width: ctx.renderWidth,
465
+ height: ctx.renderHeight,
466
+ colorAttachments,
467
+ depthAttachment: renderDepthAttachment,
468
+ ignoreDepthStencil: false
469
+ });
470
+ builder.setExecute((rgCtx)=>{
471
+ renderForwardSSSProfile(frame, rgCtx.getFramebuffer(framebufferHandle), rgCtx.getTexture(profileHandle), rgCtx.getTexture(paramHandle), normalHandle ? rgCtx.getTexture(normalHandle) : null);
472
+ });
473
+ return {
474
+ profileHandle,
475
+ paramHandle,
476
+ normalHandle,
477
+ framebufferHandle
478
+ };
479
+ });
480
+ }
226
481
  const lightPassResult = graph.addPass('LightPass', (builder)=>{
227
482
  builder.read(depthHandle);
228
483
  builder.read(depthPassResult.depthFramebufferHandle);
484
+ if (preLightTransmissionDepthToken) {
485
+ builder.read(preLightTransmissionDepthToken);
486
+ }
229
487
  if (hiZHandle) {
230
488
  builder.read(hiZHandle);
231
489
  }
490
+ for (const binding of lightHistoryReadBindings){
491
+ builder.read(binding.handle);
492
+ }
232
493
  // Create scene color texture (intermediate render target)
233
494
  const sceneColorHandle = builder.createTexture({
234
495
  format: ctx.colorFormat,
@@ -242,6 +503,29 @@ function buildForwardPlusGraphInternal(graph, ctx, renderQueue, options) {
242
503
  label: 'sceneColorCopy'
243
504
  });
244
505
  }
506
+ if (sssProfileResult) {
507
+ builder.read(sssProfileResult.profileHandle);
508
+ builder.read(sssProfileResult.paramHandle);
509
+ if (sssProfileResult.normalHandle) {
510
+ builder.read(sssProfileResult.normalHandle);
511
+ }
512
+ }
513
+ const includeSSRSurfaceMRT = !!options.ssr;
514
+ const writeSSSDiffuse = options.sss && shouldStoreSSSDiffuse(ctx);
515
+ let writeSSSTransmission = options.sss && shouldStoreSSSTransmission(ctx);
516
+ if (writeSSSDiffuse && writeSSSTransmission && includeSSRSurfaceMRT && getSSSLightingTextureFormat(ctx, 2, includeSSRSurfaceMRT) !== ctx.colorFormat) {
517
+ writeSSSTransmission = false;
518
+ }
519
+ const sssLightingAttachmentCount = (writeSSSDiffuse ? 1 : 0) + (writeSSSTransmission ? 1 : 0);
520
+ const sssLightingFormat = getSSSLightingTextureFormat(ctx, sssLightingAttachmentCount, includeSSRSurfaceMRT);
521
+ const sssDiffuseHandle = writeSSSDiffuse ? builder.createTexture({
522
+ format: sssLightingFormat,
523
+ label: 'sssDiffuse'
524
+ }) : undefined;
525
+ const sssTransmissionHandle = writeSSSTransmission ? builder.createTexture({
526
+ format: sssLightingFormat,
527
+ label: 'sssTransmission'
528
+ }) : undefined;
245
529
  const useFinalFramebufferAsIntermediate = !!depthPassResult.externalDepthAttachment && depthPassResult.externalDepthAttachment === ctx.finalFramebuffer?.getDepthAttachment();
246
530
  const sceneColorFramebufferHandle = useFinalFramebufferAsIntermediate ? undefined : builder.createFramebuffer({
247
531
  label: 'SceneColorFramebuffer',
@@ -250,7 +534,10 @@ function buildForwardPlusGraphInternal(graph, ctx, renderQueue, options) {
250
534
  colorAttachments: sceneColorHandle,
251
535
  depthAttachment: renderDepthAttachment
252
536
  });
253
- const sceneColorCopyFramebufferHandle = sceneColorCopyHandle ? builder.createFramebuffer({
537
+ // SSR may pre-insert transmission depth before LightPass for Hi-Z. In that case the
538
+ // refraction scene-color copy needs an isolated depth buffer so transmission surfaces
539
+ // do not occlude the background color they are about to sample.
540
+ const sceneColorCopyFramebufferHandle = sceneColorCopyHandle && !options.needsTransmissionDepthForSSR ? builder.createFramebuffer({
254
541
  label: 'SceneColorCopyFramebuffer',
255
542
  width: ctx.renderWidth,
256
543
  height: ctx.renderHeight,
@@ -261,7 +548,29 @@ function buildForwardPlusGraphInternal(graph, ctx, renderQueue, options) {
261
548
  builder.setExecute((rgCtx)=>{
262
549
  const sceneColorTex = rgCtx.getTexture(sceneColorHandle);
263
550
  const sceneColorCopyTex = sceneColorCopyHandle ? rgCtx.getTexture(sceneColorCopyHandle) : null;
264
- renderMainLightPass(frame, sceneColorTex, sceneColorCopyTex, rgCtx, sceneColorFramebufferHandle, sceneColorCopyFramebufferHandle);
551
+ if (sssProfileResult) {
552
+ ctx.SSSProfileTexture = rgCtx.getTexture(sssProfileResult.profileHandle);
553
+ ctx.SSSParamTexture = rgCtx.getTexture(sssProfileResult.paramHandle);
554
+ if (sssProfileResult.normalHandle) {
555
+ ctx.SSRNormalTexture = rgCtx.getTexture(sssProfileResult.normalHandle);
556
+ }
557
+ }
558
+ ctx.SSSDiffuseTexture = sssDiffuseHandle ? rgCtx.getTexture(sssDiffuseHandle) : null;
559
+ ctx.SSSTransmissionTexture = sssTransmissionHandle ? rgCtx.getTexture(sssTransmissionHandle) : null;
560
+ const renderLightPass = ()=>renderMainLightPass(frame, sceneColorTex, sceneColorCopyTex, rgCtx, sceneColorFramebufferHandle, sceneColorCopyFramebufferHandle);
561
+ if (historyManager && lightHistoryReadBindings.length > 0) {
562
+ historyManager.beginReadScope(lightHistoryReadBindings.map((binding)=>({
563
+ name: binding.name,
564
+ texture: rgCtx.getTexture(binding.handle)
565
+ })));
566
+ try {
567
+ renderLightPass();
568
+ } finally{
569
+ historyManager.endReadScope();
570
+ }
571
+ } else {
572
+ renderLightPass();
573
+ }
265
574
  });
266
575
  return {
267
576
  sceneColorHandle,
@@ -270,38 +579,9 @@ function buildForwardPlusGraphInternal(graph, ctx, renderQueue, options) {
270
579
  };
271
580
  });
272
581
  const sceneColorHandle = lightPassResult.sceneColorHandle;
273
- const historyManager = ctx.camera?.getHistoryResourceManager?.() ?? null;
274
- const historyReadBindings = [];
275
- if (historyManager && ctx.camera?.TAA && options.motionVectors) {
276
- const historySize = {
277
- width: ctx.renderWidth,
278
- height: ctx.renderHeight
279
- };
280
- const colorHistoryHandle = historyManager.importPreviousIfCompatible(graph, RGHistoryResources.TAA_COLOR, {
281
- format: ctx.colorFormat,
282
- sizeMode: 'absolute',
283
- width: ctx.renderWidth,
284
- height: ctx.renderHeight
285
- }, historySize);
286
- const motionVectorHistoryHandle = historyManager.importPreviousIfCompatible(graph, RGHistoryResources.TAA_MOTION_VECTOR, {
287
- format: 'rgba16f',
288
- sizeMode: 'absolute',
289
- width: ctx.renderWidth,
290
- height: ctx.renderHeight
291
- }, historySize);
292
- if (colorHistoryHandle && motionVectorHistoryHandle) {
293
- historyReadBindings.push({
294
- name: RGHistoryResources.TAA_COLOR,
295
- handle: colorHistoryHandle
296
- }, {
297
- name: RGHistoryResources.TAA_MOTION_VECTOR,
298
- handle: motionVectorHistoryHandle
299
- });
300
- }
301
- }
302
582
  // 8. Transmission depth pass (optional)
303
583
  let transmissionDepthToken;
304
- if (options.needSceneColor) {
584
+ if (options.needSceneColor && !options.needsTransmissionDepthForSSR) {
305
585
  transmissionDepthToken = graph.addPass('TransmissionDepth', (builder)=>{
306
586
  builder.read(sceneColorHandle);
307
587
  builder.read(depthPassResult.depthFramebufferHandle);
@@ -329,13 +609,13 @@ function buildForwardPlusGraphInternal(graph, ctx, renderQueue, options) {
329
609
  if (transmissionDepthToken) {
330
610
  builder.read(transmissionDepthToken);
331
611
  }
332
- for (const binding of historyReadBindings){
612
+ for (const binding of compositeHistoryReadBindings){
333
613
  builder.read(binding.handle);
334
614
  }
335
615
  const outputBackbuffer = builder.write(backbuffer);
336
616
  builder.setExecute((rgCtx)=>{
337
- if (historyManager && historyReadBindings.length > 0) {
338
- historyManager.beginReadScope(historyReadBindings.map((binding)=>({
617
+ if (historyManager && compositeHistoryReadBindings.length > 0) {
618
+ historyManager.beginReadScope(compositeHistoryReadBindings.map((binding)=>({
339
619
  name: binding.name,
340
620
  texture: rgCtx.getTexture(binding.handle)
341
621
  })));
@@ -370,6 +650,65 @@ function buildForwardPlusGraphInternal(graph, ctx, renderQueue, options) {
370
650
  ctx.device.popDeviceStates();
371
651
  }
372
652
  }
653
+ function renderForwardSSSProfile(frame, profileFramebuffer, profileTexture, paramTexture, normalTexture) {
654
+ const { ctx, renderQueue } = frame;
655
+ if (!ctx.SSS || !ctx.depthTexture) {
656
+ return;
657
+ }
658
+ const sssRenderQueue = createActualSSSRenderQueue(renderQueue);
659
+ if (!sssRenderQueue) {
660
+ return;
661
+ }
662
+ const device = ctx.device;
663
+ const savedMaterialFlags = ctx.materialFlags;
664
+ const savedCompositor = ctx.compositor;
665
+ const savedTransmission = _scenePass.transmission;
666
+ const savedRenderOpaque = _scenePass.renderOpaque;
667
+ const savedRenderTransparent = _scenePass.renderTransparent;
668
+ const savedClearColor = _scenePass.clearColor;
669
+ const savedClearDepth = _scenePass.clearDepth;
670
+ const savedClearStencil = _scenePass.clearStencil;
671
+ const savedCommandBufferReuse = ctx.camera.commandBufferReuse;
672
+ const savedProfileTexture = ctx.SSSProfileTexture;
673
+ const savedParamTexture = ctx.SSSParamTexture;
674
+ const savedNormalTexture = ctx.SSRNormalTexture;
675
+ let profileFlags = MaterialVaryingFlags.SSS_STORE_PROFILE;
676
+ if (normalTexture) {
677
+ profileFlags |= MaterialVaryingFlags.SSS_STORE_NORMAL;
678
+ }
679
+ device.pushDeviceStates();
680
+ try {
681
+ device.setFramebuffer(profileFramebuffer);
682
+ ctx.SSSProfileTexture = profileTexture;
683
+ ctx.SSSParamTexture = paramTexture;
684
+ ctx.SSRNormalTexture = normalTexture;
685
+ ctx.compositor = null;
686
+ ctx.camera.commandBufferReuse = false;
687
+ ctx.materialFlags = ctx.materialFlags & ~(MaterialVaryingFlags.SSR_STORE_ROUGHNESS | MaterialVaryingFlags.SSS_STORE_PROFILE | MaterialVaryingFlags.SSS_STORE_NORMAL | MaterialVaryingFlags.SSS_STORE_DIFFUSE | MaterialVaryingFlags.SSS_STORE_TRANSMISSION) | profileFlags;
688
+ _scenePass.transmission = false;
689
+ _scenePass.renderOpaque = true;
690
+ _scenePass.renderTransparent = false;
691
+ _scenePass.clearColor = Vector4.zero();
692
+ _scenePass.clearDepth = null;
693
+ _scenePass.clearStencil = null;
694
+ _scenePass.render(ctx, null, null, sssRenderQueue);
695
+ } finally{
696
+ _scenePass.clearColor = savedClearColor;
697
+ _scenePass.clearDepth = savedClearDepth;
698
+ _scenePass.clearStencil = savedClearStencil;
699
+ _scenePass.renderTransparent = savedRenderTransparent;
700
+ _scenePass.renderOpaque = savedRenderOpaque;
701
+ _scenePass.transmission = savedTransmission;
702
+ ctx.camera.commandBufferReuse = savedCommandBufferReuse;
703
+ ctx.materialFlags = savedMaterialFlags;
704
+ ctx.compositor = savedCompositor;
705
+ ctx.SSSProfileTexture = savedProfileTexture;
706
+ ctx.SSSParamTexture = savedParamTexture;
707
+ ctx.SSRNormalTexture = savedNormalTexture;
708
+ device.popDeviceStates();
709
+ sssRenderQueue.dispose();
710
+ }
711
+ }
373
712
  function releaseIntermediateFramebuffer(frame) {
374
713
  const { ctx } = frame;
375
714
  if (frame.intermediateDeviceStatePushed) {
@@ -496,6 +835,7 @@ function cleanupFrame(frame) {
496
835
  ctx.motionVectorTexture = ctx.motionVectors ? depthFramebuffer.getColorAttachments()[1] : null;
497
836
  ctx.linearDepthTexture = depthFramebuffer.getColorAttachments()[0];
498
837
  ctx.depthTexture = depthFramebuffer.getDepthAttachment();
838
+ ctx.depthPrepassAttachment = ctx.depthTexture;
499
839
  // HiZ is now built in the dedicated HiZ pass
500
840
  }
501
841
  return depthFramebuffer;
@@ -564,20 +904,37 @@ let _skyMVBox = null;
564
904
  _skyMVBox.draw();
565
905
  device.popDeviceStates();
566
906
  }
907
+ function blitToCurrentColorAttachment(ctx, source) {
908
+ const framebuffer = ctx.device.getFramebuffer();
909
+ const destination = framebuffer?.getColorAttachment(0) ?? null;
910
+ new CopyBlitter().blit(source, destination, fetchSampler('clamp_nearest_nomip'));
911
+ }
567
912
  /** @internal */ function renderMainLightPass(frame, sceneColorTex, sceneColorCopyTex, rgCtx, sceneColorFramebufferHandle, sceneColorCopyFramebufferHandle) {
568
913
  const { ctx, renderQueue } = frame;
569
914
  const device = ctx.device;
570
915
  // Use RenderGraph-allocated scene color texture
571
916
  const depthTex = frame.depthFramebuffer?.getDepthAttachment();
917
+ ctx.materialFlags &= ~(MaterialVaryingFlags.SSR_STORE_ROUGHNESS | MaterialVaryingFlags.SSS_STORE_PROFILE | MaterialVaryingFlags.SSS_STORE_DIFFUSE | MaterialVaryingFlags.SSS_STORE_NORMAL | MaterialVaryingFlags.SSS_STORE_TRANSMISSION);
918
+ if (ctx.SSR) {
919
+ ctx.materialFlags |= MaterialVaryingFlags.SSR_STORE_ROUGHNESS;
920
+ }
921
+ if (ctx.SSS) {
922
+ if (ctx.SSSDiffuseTexture) {
923
+ ctx.materialFlags |= MaterialVaryingFlags.SSS_STORE_DIFFUSE;
924
+ }
925
+ if (ctx.SSSTransmissionTexture) {
926
+ ctx.materialFlags |= MaterialVaryingFlags.SSS_STORE_TRANSMISSION;
927
+ }
928
+ }
572
929
  if (depthTex === ctx.finalFramebuffer?.getDepthAttachment()) {
573
930
  ctx.intermediateFramebuffer = ctx.finalFramebuffer;
574
- } else if (sceneColorFramebufferHandle) {
931
+ } else if (sceneColorFramebufferHandle && !hasSurfaceMRT(ctx)) {
575
932
  ctx.intermediateFramebuffer = rgCtx.getFramebuffer(sceneColorFramebufferHandle);
576
933
  } else {
577
934
  ctx.intermediateFramebuffer = rgCtx.createFramebuffer({
578
935
  width: sceneColorTex.width,
579
936
  height: sceneColorTex.height,
580
- colorAttachments: sceneColorTex,
937
+ colorAttachments: getLightPassColorAttachments(ctx, sceneColorTex),
581
938
  depthAttachment: depthTex
582
939
  });
583
940
  }
@@ -592,23 +949,22 @@ let _skyMVBox = null;
592
949
  _scenePass.transmission = false;
593
950
  _scenePass.clearDepth = depthTex ? null : 1;
594
951
  _scenePass.clearStencil = depthTex ? null : 0;
595
- if (ctx.SSR && !renderQueue.needSceneColor()) {
596
- ctx.materialFlags |= MaterialVaryingFlags.SSR_STORE_ROUGHNESS;
597
- }
598
952
  ctx.compositor?.begin(ctx);
599
953
  if (renderQueue.needSceneColor() && sceneColorCopyTex) {
600
954
  const compositor = ctx.compositor;
601
955
  ctx.compositor = null;
956
+ const isolateSceneColorDepth = frame.options.needsTransmissionDepthForSSR;
957
+ const savedDepthPrepassAttachment = ctx.depthPrepassAttachment;
958
+ const savedClearDepth = _scenePass.clearDepth;
959
+ const savedClearStencil = _scenePass.clearStencil;
960
+ const savedMaterialFlags = ctx.materialFlags;
602
961
  // Use RenderGraph-allocated sceneColorCopy texture
603
- const sceneColorFramebuffer = sceneColorCopyFramebufferHandle && !(ctx.materialFlags & MaterialVaryingFlags.SSR_STORE_ROUGHNESS) ? rgCtx.getFramebuffer(sceneColorCopyFramebufferHandle) : rgCtx.createFramebuffer({
962
+ const sceneColorMaterialFlags = ctx.materialFlags & ~SURFACE_MRT_FLAGS;
963
+ const sceneColorFramebuffer = sceneColorCopyFramebufferHandle ? rgCtx.getFramebuffer(sceneColorCopyFramebufferHandle) : rgCtx.createFramebuffer({
604
964
  width: sceneColorCopyTex.width,
605
965
  height: sceneColorCopyTex.height,
606
- colorAttachments: ctx.materialFlags & MaterialVaryingFlags.SSR_STORE_ROUGHNESS ? [
607
- sceneColorCopyTex,
608
- device.getFramebuffer().getColorAttachments()[1],
609
- device.getFramebuffer().getColorAttachments()[2]
610
- ] : sceneColorCopyTex,
611
- depthAttachment: depthTex,
966
+ colorAttachments: sceneColorCopyTex,
967
+ depthAttachment: isolateSceneColorDepth ? ctx.depthFormat : depthTex,
612
968
  ignoreDepthStencil: false
613
969
  });
614
970
  let sceneColorStatePushed = false;
@@ -617,15 +973,27 @@ let _skyMVBox = null;
617
973
  sceneColorStatePushed = true;
618
974
  device.setFramebuffer(sceneColorFramebuffer);
619
975
  _scenePass.transmission = false;
976
+ if (isolateSceneColorDepth) {
977
+ ctx.depthPrepassAttachment = undefined;
978
+ _scenePass.clearDepth = 1;
979
+ _scenePass.clearStencil = 0;
980
+ }
981
+ ctx.materialFlags = sceneColorMaterialFlags;
620
982
  _scenePass.render(ctx, null, null, renderQueue);
621
983
  } finally{
984
+ ctx.materialFlags = savedMaterialFlags;
985
+ if (isolateSceneColorDepth) {
986
+ ctx.depthPrepassAttachment = savedDepthPrepassAttachment;
987
+ _scenePass.clearDepth = savedClearDepth;
988
+ _scenePass.clearStencil = savedClearStencil;
989
+ }
622
990
  if (sceneColorStatePushed) {
623
991
  device.popDeviceStates();
624
992
  }
625
993
  ctx.compositor = compositor;
626
994
  }
627
995
  ctx.sceneColorTexture = sceneColorCopyTex;
628
- new CopyBlitter().blit(ctx.sceneColorTexture, device.getFramebuffer() ?? null, fetchSampler('clamp_nearest_nomip'));
996
+ blitToCurrentColorAttachment(ctx, ctx.sceneColorTexture);
629
997
  _scenePass.transmission = true;
630
998
  _scenePass.clearColor = null;
631
999
  _scenePass.clearDepth = null;
@@ -642,6 +1010,10 @@ let _skyMVBox = null;
642
1010
  ctx.compositor?.end(ctx);
643
1011
  disposeRenderQueue(frame);
644
1012
  ctx.materialFlags &= ~MaterialVaryingFlags.SSR_STORE_ROUGHNESS;
1013
+ ctx.materialFlags &= ~MaterialVaryingFlags.SSS_STORE_PROFILE;
1014
+ ctx.materialFlags &= ~MaterialVaryingFlags.SSS_STORE_DIFFUSE;
1015
+ ctx.materialFlags &= ~MaterialVaryingFlags.SSS_STORE_NORMAL;
1016
+ ctx.materialFlags &= ~MaterialVaryingFlags.SSS_STORE_TRANSMISSION;
645
1017
  if (ctx.intermediateFramebuffer && ctx.intermediateFramebuffer !== ctx.finalFramebuffer) {
646
1018
  const blitter = new CopyBlitter();
647
1019
  blitter.srgbOut = !ctx.finalFramebuffer;
@@ -664,37 +1036,51 @@ let _skyMVBox = null;
664
1036
  */ function executeForwardPlusGraph(ctx) {
665
1037
  const device = ctx.device;
666
1038
  const graph = new RenderGraph();
667
- // Cull scene first (needed to derive options)
668
- const renderQueue = _scenePass.cullScene(ctx, ctx.camera);
669
- const options = deriveForwardPlusOptions(ctx.scene, ctx.camera, device.type, renderQueue);
670
- // Ensure the camera has a history resource manager for temporal effects (TAA, motion blur)
671
- let historyManager = ctx.camera.getHistoryResourceManager();
672
- if (!historyManager) {
673
- historyManager = new HistoryResourceManager(_devicePoolAllocator);
674
- ctx.camera.setHistoryResourceManager(historyManager);
675
- }
676
- historyManager.beginFrame();
677
- const { backbuffer, frame } = buildForwardPlusGraphInternal(graph, ctx, renderQueue, options);
678
- const compiled = graph.compile([
679
- backbuffer
680
- ]);
681
- // Use RenderGraphExecutor for automatic resource management
682
- const executor = new RenderGraphExecutor(_devicePoolAllocator, ctx.renderWidth, ctx.renderHeight);
683
- // Register imported backbuffer (if using finalFramebuffer)
684
- if (ctx.finalFramebuffer) {
685
- const backbufferTex = ctx.finalFramebuffer.getColorAttachments()[0];
686
- executor.setImportedTexture(backbuffer, backbufferTex);
687
- }
688
- historyManager.bindImportedTextures(executor);
1039
+ let renderQueue = null;
1040
+ let frame = null;
1041
+ let executor = null;
1042
+ let historyManager = null;
1043
+ let historyFrameStarted = false;
689
1044
  try {
1045
+ // Cull scene first (needed to derive options)
1046
+ renderQueue = _scenePass.cullScene(ctx, ctx.camera);
1047
+ const options = deriveForwardPlusOptions(ctx.scene, ctx.camera, device.type, renderQueue);
1048
+ ctx.SSS = options.sss;
1049
+ // Ensure the camera has a history resource manager for temporal effects (TAA, motion blur)
1050
+ historyManager = ctx.camera.getHistoryResourceManager();
1051
+ if (!historyManager) {
1052
+ historyManager = new HistoryResourceManager(_devicePoolAllocator);
1053
+ ctx.camera.setHistoryResourceManager(historyManager);
1054
+ }
1055
+ historyManager.beginFrame();
1056
+ historyFrameStarted = true;
1057
+ const buildResult = buildForwardPlusGraphInternal(graph, ctx, renderQueue, options);
1058
+ frame = buildResult.frame;
1059
+ const compiled = graph.compile([
1060
+ buildResult.backbuffer
1061
+ ]);
1062
+ // Use RenderGraphExecutor for automatic resource management
1063
+ executor = new RenderGraphExecutor(_devicePoolAllocator, ctx.renderWidth, ctx.renderHeight);
1064
+ // Register imported backbuffer (if using finalFramebuffer)
1065
+ if (ctx.finalFramebuffer) {
1066
+ const backbufferTex = ctx.finalFramebuffer.getColorAttachments()[0];
1067
+ executor.setImportedTexture(buildResult.backbuffer, backbufferTex);
1068
+ }
1069
+ historyManager.bindImportedTextures(executor);
690
1070
  executor.execute(compiled);
691
1071
  historyManager.commitFrame();
692
1072
  } finally{
693
- historyManager.discardFrame();
694
- cleanupFrame(frame);
695
- executor.reset();
1073
+ if (historyFrameStarted) {
1074
+ historyManager?.discardFrame();
1075
+ }
1076
+ if (frame) {
1077
+ cleanupFrame(frame);
1078
+ } else {
1079
+ renderQueue?.dispose();
1080
+ }
1081
+ executor?.reset();
696
1082
  }
697
1083
  }
698
1084
 
699
- export { buildForwardPlusGraph, deriveForwardPlusOptions, executeForwardPlusGraph };
1085
+ export { deriveForwardPlusOptions, executeForwardPlusGraph };
700
1086
  //# sourceMappingURL=forward_plus_builder.js.map