@zephyr3d/scene 0.9.19 → 0.9.21

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 (95) hide show
  1. package/dist/animation/joint_dynamics/convex_collider.js +320 -0
  2. package/dist/animation/joint_dynamics/convex_collider.js.map +1 -0
  3. package/dist/asset/assetmanager.js +1 -0
  4. package/dist/asset/assetmanager.js.map +1 -1
  5. package/dist/camera/camera.js +39 -0
  6. package/dist/camera/camera.js.map +1 -1
  7. package/dist/index.d.ts +190 -4
  8. package/dist/index.js +2 -1
  9. package/dist/index.js.map +1 -1
  10. package/dist/material/meshmaterial.js +2 -2
  11. package/dist/material/meshmaterial.js.map +1 -1
  12. package/dist/material/mixins/lit.js +10 -0
  13. package/dist/material/mixins/lit.js.map +1 -1
  14. package/dist/material/shader/helper.js +117 -2
  15. package/dist/material/shader/helper.js.map +1 -1
  16. package/dist/posteffect/skinsss.js +10 -10
  17. package/dist/posteffect/skinsss.js.map +1 -1
  18. package/dist/posteffect/ssr.js +13 -13
  19. package/dist/posteffect/ssr.js.map +1 -1
  20. package/dist/posteffect/sss.js +8 -7
  21. package/dist/posteffect/sss.js.map +1 -1
  22. package/dist/posteffect/tonemap.js +5 -5
  23. package/dist/posteffect/tonemap.js.map +1 -1
  24. package/dist/render/abuffer_oit.js +5 -0
  25. package/dist/render/abuffer_oit.js.map +1 -1
  26. package/dist/render/cluster_light.js +52 -8
  27. package/dist/render/cluster_light.js.map +1 -1
  28. package/dist/render/dualdepthpeeling_oit.js +331 -0
  29. package/dist/render/dualdepthpeeling_oit.js.map +1 -0
  30. package/dist/render/lightpass.js +29 -8
  31. package/dist/render/lightpass.js.map +1 -1
  32. package/dist/render/renderer.js +3 -0
  33. package/dist/render/renderer.js.map +1 -1
  34. package/dist/render/rendergraph/blackboard.js +40 -39
  35. package/dist/render/rendergraph/blackboard.js.map +1 -1
  36. package/dist/render/rendergraph/device_pool_allocator.js +10 -1
  37. package/dist/render/rendergraph/device_pool_allocator.js.map +1 -1
  38. package/dist/render/rendergraph/forward_plus_builder.js +75 -4
  39. package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
  40. package/dist/render/rendergraph/types.js.map +1 -1
  41. package/dist/render/renderpass.js +12 -2
  42. package/dist/render/renderpass.js.map +1 -1
  43. package/dist/render/shadow_mask_pass.js +297 -0
  44. package/dist/render/shadow_mask_pass.js.map +1 -0
  45. package/dist/render/weightedblended_oit.js +5 -0
  46. package/dist/render/weightedblended_oit.js.map +1 -1
  47. package/dist/scene/basesprite.js +1 -0
  48. package/dist/scene/basesprite.js.map +1 -1
  49. package/dist/scene/batchgroup.js +1 -0
  50. package/dist/scene/batchgroup.js.map +1 -1
  51. package/dist/scene/environment.js +1 -0
  52. package/dist/scene/environment.js.map +1 -1
  53. package/dist/scene/msdftext.js +1 -0
  54. package/dist/scene/msdftext.js.map +1 -1
  55. package/dist/scene/msdftextsprite.js +1 -0
  56. package/dist/scene/msdftextsprite.js.map +1 -1
  57. package/dist/scene/particlesys.js +1 -0
  58. package/dist/scene/particlesys.js.map +1 -1
  59. package/dist/scene/scene.js +1 -0
  60. package/dist/scene/scene.js.map +1 -1
  61. package/dist/scene/terrain-cm/grass.js +1 -0
  62. package/dist/scene/terrain-cm/grass.js.map +1 -1
  63. package/dist/scene/terrain-cm/terrain-cm.js +1 -0
  64. package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
  65. package/dist/scene/water.js +1 -0
  66. package/dist/scene/water.js.map +1 -1
  67. package/dist/utility/serialization/manager.js +1 -0
  68. package/dist/utility/serialization/manager.js.map +1 -1
  69. package/dist/utility/serialization/scene/animation.js +1 -0
  70. package/dist/utility/serialization/scene/animation.js.map +1 -1
  71. package/dist/utility/serialization/scene/batch.js +1 -0
  72. package/dist/utility/serialization/scene/batch.js.map +1 -1
  73. package/dist/utility/serialization/scene/camera.js +35 -2
  74. package/dist/utility/serialization/scene/camera.js.map +1 -1
  75. package/dist/utility/serialization/scene/light.js +1 -0
  76. package/dist/utility/serialization/scene/light.js.map +1 -1
  77. package/dist/utility/serialization/scene/mesh.js +1 -0
  78. package/dist/utility/serialization/scene/mesh.js.map +1 -1
  79. package/dist/utility/serialization/scene/node.js +1 -0
  80. package/dist/utility/serialization/scene/node.js.map +1 -1
  81. package/dist/utility/serialization/scene/particle.js +1 -0
  82. package/dist/utility/serialization/scene/particle.js.map +1 -1
  83. package/dist/utility/serialization/scene/primitive.js +1 -0
  84. package/dist/utility/serialization/scene/primitive.js.map +1 -1
  85. package/dist/utility/serialization/scene/sprite.js +1 -0
  86. package/dist/utility/serialization/scene/sprite.js.map +1 -1
  87. package/dist/utility/serialization/scene/terrain.js +1 -0
  88. package/dist/utility/serialization/scene/terrain.js.map +1 -1
  89. package/dist/utility/serialization/scene/text.js +1 -0
  90. package/dist/utility/serialization/scene/text.js.map +1 -1
  91. package/dist/utility/serialization/scene/water.js +1 -0
  92. package/dist/utility/serialization/scene/water.js.map +1 -1
  93. package/dist/values.js +11 -1
  94. package/dist/values.js.map +1 -1
  95. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"forward_plus_builder.js","sources":["../../../src/render/rendergraph/forward_plus_builder.ts"],"sourcesContent":["import type { Nullable } from '@zephyr3d/base';\r\nimport { Vector4 } from '@zephyr3d/base';\r\nimport type {\r\n BindGroup,\r\n ColorState,\r\n FrameBuffer,\r\n GPUProgram,\r\n Texture2D,\r\n TextureFormat\r\n} from '@zephyr3d/device';\r\nimport type { DrawContext } from '../drawable';\r\nimport {\r\n RenderQueue,\r\n type RenderItemList,\r\n type RenderItemListInfo,\r\n type RenderQueueItem\r\n} from '../render_queue';\r\nimport type { PunctualLight, Scene } from '../../scene';\r\nimport type { Camera } from '../../camera';\r\nimport { LightPass } from '../lightpass';\r\nimport { ShadowMapPass } from '../shadowmap_pass';\r\nimport { DepthPass } from '../depthpass';\r\nimport { ClusteredLight } from '../cluster_light';\r\nimport { buildHiZ } from '../hzb';\r\nimport { CopyBlitter } from '../../blitter';\r\nimport { fetchSampler } from '../../utility/misc';\r\nimport { MaterialVaryingFlags } from '../../values';\r\nimport { AbstractPostEffect, PostEffectLayer } from '../../posteffect/posteffect';\r\nimport { RenderGraph } from './rendergraph';\r\nimport { RenderGraphExecutor } from './executor';\r\nimport { DevicePoolAllocator } from './device_pool_allocator';\r\nimport { HistoryResourceManager } from './history_resource_manager';\r\nimport { RGHistoryResources } from './history_resources';\r\nimport { RGBlackboard, FrameResources } from './blackboard';\r\nimport type { RGExecuteContext, RGHandle } from './types';\r\nimport { renderObjectColors } from '../gpu_picking';\r\nimport type { Primitive } from '../primitive';\r\nimport { BoxShape } from '../../shapes';\r\n\r\n// ─── Shared Pass Instances ──────────────────────────────────────────\r\n\r\nconst _scenePass = new LightPass();\r\nconst _depthPass = new DepthPass();\r\nconst _shadowMapPass = new ShadowMapPass();\r\nconst _clusters: ClusteredLight[] = [];\r\nconst _devicePoolAllocator = new DevicePoolAllocator();\r\nlet _backDepthColorState: Nullable<ColorState> = null;\r\nlet _frontDepthColorState: Nullable<ColorState> = null;\r\nconst SURFACE_MRT_FLAGS =\r\n MaterialVaryingFlags.SSR_STORE_ROUGHNESS |\r\n MaterialVaryingFlags.SSS_STORE_PROFILE |\r\n MaterialVaryingFlags.SSS_STORE_DIFFUSE |\r\n MaterialVaryingFlags.SSS_STORE_NORMAL |\r\n MaterialVaryingFlags.SSS_STORE_TRANSMISSION |\r\n MaterialVaryingFlags.SKIN_SSS_STORE;\r\n\r\nfunction getClusteredLight(): ClusteredLight {\r\n return _clusters.length > 0 ? _clusters.pop()! : new ClusteredLight();\r\n}\r\nfunction freeClusteredLight(cl: ClusteredLight): void {\r\n _clusters.push(cl);\r\n}\r\n\r\nfunction getCoreMaterial(material: unknown): unknown {\r\n return (material as { coreMaterial?: unknown } | null | undefined)?.coreMaterial ?? material ?? null;\r\n}\r\n\r\nfunction hasSSSMaterialCore(material: unknown): boolean {\r\n return !!(getCoreMaterial(material) as { subsurfaceProfile?: unknown } | null)?.subsurfaceProfile;\r\n}\r\n\r\nfunction hasSkinSSSMaterialCore(material: unknown): boolean {\r\n return !!(getCoreMaterial(material) as { skinSSS?: unknown } | null)?.skinSSS;\r\n}\r\n\r\nfunction renderQueueHasActiveSSS(renderQueue: RenderQueue): boolean {\r\n const itemList = renderQueue.itemList;\r\n if (!itemList) {\r\n return false;\r\n }\r\n const lists = [...itemList.opaque.lit, ...itemList.opaque.unlit];\r\n for (const list of lists) {\r\n for (const material of list.materialList) {\r\n if (hasSSSMaterialCore(material)) {\r\n return true;\r\n }\r\n }\r\n }\r\n return false;\r\n}\r\n\r\nfunction renderQueueHasActiveSkinSSS(renderQueue: RenderQueue): boolean {\r\n const itemList = renderQueue.itemList;\r\n if (!itemList) {\r\n return false;\r\n }\r\n const lists = [...itemList.opaque.lit, ...itemList.opaque.unlit];\r\n for (const list of lists) {\r\n for (const material of list.materialList) {\r\n if (hasSkinSSSMaterialCore(material)) {\r\n return true;\r\n }\r\n }\r\n }\r\n return false;\r\n}\r\n\r\nfunction filterActualSSSItemList(items: RenderQueueItem[]): RenderQueueItem[] {\r\n return items.filter((item) => hasSSSMaterialCore(item.drawable.getMaterial?.()));\r\n}\r\n\r\nfunction filterActualSSSMaterialList(materialList: Set<any>): Set<any> {\r\n const filtered = new Set<any>();\r\n materialList.forEach((mat) => {\r\n if (hasSSSMaterialCore(mat)) {\r\n filtered.add(mat);\r\n }\r\n });\r\n return filtered;\r\n}\r\n\r\nfunction cloneActualSSSListInfo(source: RenderItemListInfo, _targetQueue: RenderQueue): RenderItemListInfo {\r\n return {\r\n itemList: filterActualSSSItemList(source.itemList),\r\n skinItemList: filterActualSSSItemList(source.skinItemList),\r\n morphItemList: filterActualSSSItemList(source.morphItemList),\r\n skinAndMorphItemList: filterActualSSSItemList(source.skinAndMorphItemList),\r\n instanceItemList: filterActualSSSItemList(source.instanceItemList),\r\n materialList: filterActualSSSMaterialList(source.materialList),\r\n instanceList: {},\r\n renderQueue: source.renderQueue\r\n };\r\n}\r\n\r\nfunction cloneActualSSSBundle(\r\n source: RenderItemList['opaque'],\r\n targetQueue: RenderQueue\r\n): RenderItemList['opaque'] {\r\n return {\r\n lit: source.lit.map((info) => cloneActualSSSListInfo(info, targetQueue)),\r\n unlit: source.unlit.map((info) => cloneActualSSSListInfo(info, targetQueue))\r\n };\r\n}\r\n\r\nfunction hasAnyActualSSSItems(renderItems: RenderItemListInfo[]): boolean {\r\n return renderItems.some(\r\n (info) =>\r\n info.itemList.length > 0 ||\r\n info.skinItemList.length > 0 ||\r\n info.morphItemList.length > 0 ||\r\n info.skinAndMorphItemList.length > 0 ||\r\n info.instanceItemList.length > 0\r\n );\r\n}\r\n\r\nfunction createActualSSSRenderQueue(renderQueue: RenderQueue): RenderQueue | null {\r\n const itemList = renderQueue.itemList;\r\n if (!itemList) {\r\n return null;\r\n }\r\n const queue = new RenderQueue(_scenePass);\r\n const sssOpaque = cloneActualSSSBundle(itemList.opaque, queue);\r\n if (!hasAnyActualSSSItems([...sssOpaque.lit, ...sssOpaque.unlit])) {\r\n queue.dispose();\r\n return null;\r\n }\r\n const emptyBundle = { lit: [], unlit: [] };\r\n const target = queue as unknown as {\r\n _itemList: RenderItemList;\r\n _shadowedLightList: PunctualLight[];\r\n _unshadowedLightList: PunctualLight[];\r\n _sunLight: typeof renderQueue.sunLight;\r\n _primaryDirectionalLight: typeof renderQueue.primaryDirectionalLight;\r\n _primaryTransmissionLight: typeof renderQueue.primaryTransmissionLight;\r\n _needSceneColor: boolean;\r\n _needSceneDepth: boolean;\r\n _needSceneColorWithDepth: boolean;\r\n _drawTransparent: boolean;\r\n };\r\n target._itemList = {\r\n opaque: sssOpaque,\r\n transmission: emptyBundle,\r\n transparent: emptyBundle,\r\n transmission_trans: emptyBundle\r\n };\r\n target._shadowedLightList = renderQueue.shadowedLights;\r\n target._unshadowedLightList = renderQueue.unshadowedLights;\r\n target._sunLight = renderQueue.sunLight;\r\n target._primaryDirectionalLight = renderQueue.primaryDirectionalLight;\r\n target._primaryTransmissionLight = renderQueue.primaryTransmissionLight;\r\n target._needSceneColor = false;\r\n target._needSceneDepth = false;\r\n target._needSceneColorWithDepth = false;\r\n target._drawTransparent = false;\r\n return queue;\r\n}\r\n\r\nfunction getSurfaceTextureFormat(ctx: DrawContext): TextureFormat {\r\n const caps = ctx.device.getDeviceCaps?.();\r\n return caps?.textureCaps.supportHalfFloatColorBuffer ? 'rgba16f' : 'rgba8unorm';\r\n}\r\n\r\nfunction getTextureFormatBytes(ctx: DrawContext, format: TextureFormat): number {\r\n return ctx.device.getDeviceCaps().textureCaps.getTextureFormatInfo(format).size;\r\n}\r\n\r\nfunction shouldStoreSSSDiffuse(ctx: DrawContext): boolean {\r\n return ctx.camera.sssStrength > 0 && ctx.camera.sssBlurScale > 0;\r\n}\r\n\r\nfunction shouldStoreSSSTransmission(ctx: DrawContext): boolean {\r\n return ctx.camera.sssStrength > 0 && ctx.camera.sssTransmissionStrength > 0;\r\n}\r\n\r\nfunction getSSSLightingTextureFormat(\r\n ctx: DrawContext,\r\n attachmentCount: number,\r\n includeSSRSurfaceMRT: boolean\r\n): TextureFormat {\r\n const colorFormat = ctx.colorFormat!;\r\n if (!includeSSRSurfaceMRT || attachmentCount === 0) {\r\n return colorFormat;\r\n }\r\n const caps = ctx.device.getDeviceCaps();\r\n // The SSR roughness/normal MRT textures use the glossy surface format; they\r\n // are graph textures now, so derive the format directly instead of reading\r\n // the (not yet resolved) DrawContext fields.\r\n const surfaceFormat = getSurfaceTextureFormat(ctx);\r\n const colorBytes =\r\n getTextureFormatBytes(ctx, colorFormat) +\r\n getTextureFormatBytes(ctx, surfaceFormat) +\r\n getTextureFormatBytes(ctx, surfaceFormat);\r\n const fullPrecisionBytes = colorBytes + getTextureFormatBytes(ctx, colorFormat) * attachmentCount;\r\n if (fullPrecisionBytes <= caps.framebufferCaps.maxColorAttachmentBytesPerSample) {\r\n return colorFormat;\r\n }\r\n return 'rgba8unorm';\r\n}\r\n\r\nfunction getFullMipLevelCount(width: number, height: number): number {\r\n return Math.max(1, Math.floor(Math.log2(Math.max(1, width, height))) + 1);\r\n}\r\n\r\nfunction hasSurfaceMRT(ctx: DrawContext): boolean {\r\n return !!(ctx.materialFlags & SURFACE_MRT_FLAGS);\r\n}\r\n\r\nfunction getLightPassColorAttachments(\r\n ctx: DrawContext,\r\n colorAttachment: TextureFormat | Texture2D\r\n): TextureFormat | Texture2D | Array<TextureFormat | Texture2D> {\r\n const attachments: Array<TextureFormat | Texture2D> = [colorAttachment];\r\n if (ctx.materialFlags & MaterialVaryingFlags.SSR_STORE_ROUGHNESS) {\r\n attachments.push(ctx.SSRRoughnessTexture!, ctx.SSRNormalTexture!);\r\n } else if (ctx.materialFlags & MaterialVaryingFlags.SSS_STORE_NORMAL) {\r\n attachments.push(ctx.SSRNormalTexture!);\r\n }\r\n if (ctx.materialFlags & MaterialVaryingFlags.SSS_STORE_PROFILE) {\r\n attachments.push(ctx.SSSProfileTexture!, ctx.SSSParamTexture!);\r\n }\r\n if (ctx.materialFlags & MaterialVaryingFlags.SSS_STORE_DIFFUSE) {\r\n attachments.push(ctx.SSSDiffuseTexture!);\r\n }\r\n if (ctx.materialFlags & MaterialVaryingFlags.SSS_STORE_TRANSMISSION) {\r\n attachments.push(ctx.SSSTransmissionTexture!);\r\n }\r\n if (ctx.materialFlags & MaterialVaryingFlags.SKIN_SSS_STORE) {\r\n attachments.push(ctx.SkinSSSTexture!);\r\n }\r\n return attachments.length === 1 ? attachments[0] : attachments;\r\n}\r\n\r\n// ─── Pipeline Options ───────────────────────────────────────────────\r\n\r\n/**\r\n * Options controlling which features are enabled in the forward+ pipeline.\r\n *\r\n * Derived from camera settings and device capabilities each frame.\r\n *\r\n * @public\r\n */\r\nexport interface ForwardPlusOptions {\r\n /** Enable depth prepass (always true for now). */\r\n depthPrepass: boolean;\r\n /** Enable motion vectors (requires TAA or motionBlur). */\r\n motionVectors: boolean;\r\n /** Enable Hi-Z pyramid (for SSR ray tracing). */\r\n hiZ: boolean;\r\n /** Enable screen-space reflections. */\r\n ssr: boolean;\r\n /** Whether to compute SSR thickness. */\r\n ssrCalcThickness: boolean;\r\n /** Whether GPU picking is requested this frame. */\r\n gpuPicking: boolean;\r\n /** Whether transmission/refraction materials are present. */\r\n needSceneColor: boolean;\r\n /** Whether scene-color-dependent materials also require scene depth. */\r\n needSceneColorWithDepth: boolean;\r\n /** Whether SSR needs transmission depth before the main light pass. */\r\n needsTransmissionDepthForSSR: boolean;\r\n /** Enable screen-space subsurface scattering. */\r\n sss: boolean;\r\n /** Enable the stylized skin-specific SSS pass. */\r\n skinSSS: boolean;\r\n}\r\n\r\n/**\r\n * Derive pipeline options from the current scene/camera state.\r\n * @internal\r\n */\r\nexport function deriveForwardPlusOptions(\r\n scene: Scene,\r\n camera: Camera,\r\n deviceType: string,\r\n renderQueue: RenderQueue\r\n): ForwardPlusOptions {\r\n const ssr = camera.SSR && scene.env.light.envLight && scene.env.light.envLight.hasRadiance();\r\n const sss = camera.SSS && renderQueueHasActiveSSS(renderQueue);\r\n const skinSSS = camera.skinSSS && renderQueueHasActiveSkinSSS(renderQueue);\r\n const needSceneColor = renderQueue.needSceneColor();\r\n const needSceneColorWithDepth = renderQueue.needSceneColorWithDepth();\r\n return {\r\n depthPrepass: true,\r\n motionVectors:\r\n deviceType !== 'webgl' && (camera.TAA || camera.motionBlur || (!!ssr && camera.ssrTemporal)),\r\n hiZ: camera.HiZ && deviceType !== 'webgl',\r\n ssr: !!ssr,\r\n ssrCalcThickness: !!ssr && camera.ssrCalcThickness,\r\n gpuPicking: !!camera.getPickResultResolveFunc(),\r\n needSceneColor,\r\n needSceneColorWithDepth,\r\n needsTransmissionDepthForSSR: !!ssr && needSceneColor && !needSceneColorWithDepth,\r\n sss: !!sss,\r\n skinSSS: !!skinSSS\r\n };\r\n}\r\n\r\n// ─── Shared Frame State ─────────────────────────────────────────────\r\n\r\n/**\r\n * Mutable state shared between pass execute callbacks within a single frame.\r\n *\r\n * This replaces the monolithic DrawContext mutation pattern with an explicit\r\n * object that graph passes can read from and write to.\r\n *\r\n * @internal\r\n */\r\nexport interface FrameState {\r\n ctx: DrawContext;\r\n renderQueue: RenderQueue;\r\n depthFramebuffer: Nullable<FrameBuffer>;\r\n sunLightColor: Nullable<any>;\r\n options: ForwardPlusOptions;\r\n renderQueueDisposed: boolean;\r\n clusteredLightReleased: boolean;\r\n sunLightRestored: boolean;\r\n}\r\n\r\ninterface ForwardPlusGraphBuildResult {\r\n backbuffer: RGHandle;\r\n frame: FrameState;\r\n}\r\n\r\ninterface HistoryReadBinding {\r\n name: string;\r\n handle: RGHandle;\r\n}\r\n\r\ninterface SSSProfilePassResult {\r\n profileHandle: RGHandle;\r\n paramHandle: RGHandle;\r\n normalHandle?: RGHandle;\r\n framebufferHandle: RGHandle;\r\n}\r\n\r\n// ─── Forward+ Graph Builder ─────────────────────────────────────────\r\n\r\n/**\r\n * Constructs a render graph representing the forward+ pipeline.\r\n *\r\n * Each step in the existing `SceneRenderer._renderScene` becomes a graph pass.\r\n * Execute callbacks delegate to the existing rendering code, sharing a mutable\r\n * `FrameState`.\r\n *\r\n * @param graph - The render graph to populate.\r\n * @param ctx - The draw context for this frame.\r\n * @param renderQueue - The culled render queue.\r\n * @param options - Pipeline feature toggles.\r\n * @returns The backbuffer handle (graph output).\r\n *\r\n * @public\r\n */\r\nexport function buildForwardPlusGraph(\r\n graph: RenderGraph,\r\n ctx: DrawContext,\r\n renderQueue: RenderQueue,\r\n options: ForwardPlusOptions\r\n): RGHandle {\r\n return buildForwardPlusGraphInternal(graph, ctx, renderQueue, options).backbuffer;\r\n}\r\n\r\nfunction buildForwardPlusGraphInternal(\r\n graph: RenderGraph,\r\n ctx: DrawContext,\r\n renderQueue: RenderQueue,\r\n options: ForwardPlusOptions\r\n): ForwardPlusGraphBuildResult {\r\n const backbuffer = graph.importTexture('backbuffer');\r\n ctx.SSS = !!options.sss;\r\n ctx.SkinSSSTexture = null;\r\n\r\n // Named registry of shared frame resources (consumed by post effect setup)\r\n const blackboard = new RGBlackboard();\r\n\r\n // Shared mutable frame state\r\n const frame: FrameState = {\r\n ctx,\r\n renderQueue,\r\n depthFramebuffer: null,\r\n sunLightColor: null,\r\n options,\r\n renderQueueDisposed: false,\r\n clusteredLightReleased: false,\r\n sunLightRestored: false\r\n };\r\n\r\n // ── 1. Sky Update ─────────────────────────────────────────────────\r\n let orderToken = graph.addPass('SkyUpdate', (builder) => {\r\n const done = builder.createToken('SkyUpdateDone');\r\n builder.sideEffect();\r\n builder.setExecute(() => {\r\n frame.sunLightColor = ctx.scene.env.sky.update(ctx);\r\n });\r\n return done;\r\n });\r\n\r\n // ── 2. Clustered Light Setup ──────────────────────────────────────\r\n orderToken = graph.addPass('ClusterLights', (builder) => {\r\n builder.read(orderToken);\r\n const done = builder.createToken('ClusterLightsDone');\r\n builder.sideEffect();\r\n builder.setExecute(() => {\r\n ctx.clusteredLight = getClusteredLight();\r\n ctx.clusteredLight.calculateLightIndex(ctx.camera, renderQueue);\r\n });\r\n return done;\r\n });\r\n\r\n // ── 3. GPU Picking (optional, sideEffect) ─────────────────────────\r\n if (options.gpuPicking) {\r\n orderToken = graph.addPass('GPUPicking', (builder) => {\r\n builder.read(orderToken);\r\n const done = builder.createToken('GPUPickingDone');\r\n builder.sideEffect();\r\n builder.setExecute(() => {\r\n const pickResolveFunc = ctx.camera.getPickResultResolveFunc();\r\n if (pickResolveFunc) {\r\n renderObjectColors(ctx, pickResolveFunc, renderQueue);\r\n }\r\n });\r\n return done;\r\n });\r\n }\r\n\r\n // ── 4. Shadow Maps ────────────────────────────────────────────────\r\n // Shadow maps are managed internally by lights, mark as side effect\r\n if (renderQueue.shadowedLights.length > 0) {\r\n orderToken = graph.addPass('ShadowMaps', (builder) => {\r\n builder.read(orderToken);\r\n const done = builder.createToken('ShadowMapsDone');\r\n builder.sideEffect();\r\n builder.setExecute(() => {\r\n renderShadowMaps(ctx, renderQueue.shadowedLights);\r\n });\r\n return done;\r\n });\r\n }\r\n\r\n // ── 5. Depth Prepass ──────────────────────────────────────────────\r\n // Declare transient depth and motion vector textures\r\n const depthPassResult = graph.addPass('DepthPrepass', (builder) => {\r\n builder.read(orderToken);\r\n const format: TextureFormat =\r\n ctx.device.type === 'webgl'\r\n ? ctx.SSRCalcThickness\r\n ? 'rgba16f'\r\n : 'rgba8unorm'\r\n : ctx.SSRCalcThickness\r\n ? 'rg32f'\r\n : 'r32f';\r\n const mvFormat: TextureFormat = 'rgba16f';\r\n\r\n const depthHandle = builder.createTexture({ format, label: 'linearDepth' });\r\n const motionVectorHandle = options.motionVectors\r\n ? builder.createTexture({ format: mvFormat, label: 'motionVector' })\r\n : undefined;\r\n const finalDepthAttachment = ctx.finalFramebuffer?.getDepthAttachment();\r\n const externalDepthAttachment = finalDepthAttachment?.isTexture2D()\r\n ? (finalDepthAttachment as Texture2D)\r\n : null;\r\n const graphDepthAttachmentHandle = externalDepthAttachment\r\n ? undefined\r\n : builder.createTexture({ format: ctx.depthFormat, label: 'sceneDepth' });\r\n const depthAttachmentOrFormat = externalDepthAttachment ?? graphDepthAttachmentHandle ?? ctx.depthFormat;\r\n const depthFramebufferHandle = builder.createFramebuffer({\r\n label: 'DepthPrepassFramebuffer',\r\n width: ctx.renderWidth,\r\n height: ctx.renderHeight,\r\n colorAttachments: motionVectorHandle ? [depthHandle, motionVectorHandle] : depthHandle,\r\n depthAttachment: depthAttachmentOrFormat,\r\n ignoreDepthStencil: false\r\n });\r\n const skyMotionVectorFramebufferHandle = motionVectorHandle\r\n ? builder.createFramebuffer({\r\n label: 'SkyMotionVectorFramebuffer',\r\n width: ctx.renderWidth,\r\n height: ctx.renderHeight,\r\n colorAttachments: motionVectorHandle,\r\n depthAttachment: depthAttachmentOrFormat\r\n })\r\n : undefined;\r\n\r\n builder.addSubpass('SceneDepth', (rgCtx) => {\r\n const depthFramebuffer = rgCtx.getFramebuffer<FrameBuffer>(depthFramebufferHandle);\r\n frame.depthFramebuffer = renderSceneDepth(frame, depthFramebuffer, rgCtx, undefined, undefined, false);\r\n });\r\n if (skyMotionVectorFramebufferHandle) {\r\n builder.addSubpass('SkyMotionVectors', (rgCtx) => {\r\n renderSkyMotionVectors(ctx, rgCtx, skyMotionVectorFramebufferHandle);\r\n });\r\n }\r\n\r\n return {\r\n depthHandle,\r\n motionVectorHandle,\r\n graphDepthAttachmentHandle,\r\n externalDepthAttachment,\r\n depthFramebufferHandle\r\n };\r\n });\r\n\r\n let depthHandle = depthPassResult.depthHandle;\r\n const motionVectorHandle = depthPassResult.motionVectorHandle;\r\n blackboard.set(FrameResources.LinearDepth, depthHandle);\r\n if (motionVectorHandle) {\r\n blackboard.set(FrameResources.MotionVector, motionVectorHandle);\r\n }\r\n if (depthPassResult.graphDepthAttachmentHandle) {\r\n blackboard.set(FrameResources.SceneDepthAttachment, depthPassResult.graphDepthAttachmentHandle);\r\n }\r\n const renderDepthAttachment =\r\n depthPassResult.graphDepthAttachmentHandle ?? depthPassResult.externalDepthAttachment ?? null;\r\n // Rendering the scene directly into the final framebuffer is only possible\r\n // when no opaque-layer effect is enabled: those effects must sample the\r\n // opaque scene color as a texture and may require surface MRT attachments\r\n // (SSR roughness / SSS / SkinSSS), which the single-color final framebuffer\r\n // cannot carry. The legacy compositor.begin() used to redirect rendering to\r\n // a temporal MRT framebuffer in that case; the graph path uses the regular\r\n // scene color texture pipeline instead.\r\n const opaqueLayerHasEffects = !!ctx.compositor?.layerHasEnabledEffect(PostEffectLayer.opaque);\r\n const useFinalFramebufferAsIntermediate =\r\n !!depthPassResult.externalDepthAttachment &&\r\n depthPassResult.externalDepthAttachment === ctx.finalFramebuffer?.getDepthAttachment() &&\r\n !opaqueLayerHasEffects;\r\n\r\n let preLightTransmissionDepthToken: RGHandle | undefined;\r\n if (options.needsTransmissionDepthForSSR) {\r\n const transmissionDepthResult = graph.addPass('TransmissionDepthForSSR', (builder) => {\r\n builder.read(depthHandle);\r\n builder.read(depthPassResult.depthFramebufferHandle);\r\n // This pass renders transmission geometry into the prepass linear-depth\r\n // texture: model the mutation as a write so later readers order against\r\n // it through data flow instead of relying on the token alone.\r\n const depthOut = builder.write(depthHandle);\r\n const done = builder.createToken('TransmissionDepthForSSRDone');\r\n builder.sideEffect();\r\n builder.setExecute((rgCtx) => {\r\n renderTransmissionDepthPass(frame, rgCtx);\r\n });\r\n return { done, depthOut };\r\n });\r\n preLightTransmissionDepthToken = transmissionDepthResult.done;\r\n depthHandle = transmissionDepthResult.depthOut;\r\n // Re-register so blackboard consumers read the post-transmission version.\r\n blackboard.set(FrameResources.LinearDepth, depthHandle);\r\n }\r\n\r\n // ── 6. Hi-Z (optional) ───────────────────────────────────────────\r\n let hiZHandle: RGHandle | undefined;\r\n if (options.hiZ) {\r\n graph.addPass('HiZ', (builder) => {\r\n builder.read(depthHandle!);\r\n builder.read(depthPassResult.depthFramebufferHandle);\r\n if (preLightTransmissionDepthToken) {\r\n builder.read(preLightTransmissionDepthToken);\r\n }\r\n hiZHandle = builder.createTexture({\r\n format: 'rg32f',\r\n label: 'hiZ',\r\n mipLevels: getFullMipLevelCount(ctx.renderWidth, ctx.renderHeight)\r\n });\r\n const hiZFramebufferHandle = builder.createFramebuffer({\r\n label: 'HiZFramebuffer',\r\n colorAttachments: hiZHandle,\r\n depthAttachment: null\r\n });\r\n builder.setExecute((rgCtx) => {\r\n const ctx = frame.ctx;\r\n // Use the depth texture from the framebuffer (which contains the RenderGraph texture)\r\n const depthTex = frame.depthFramebuffer?.getDepthAttachment() as Texture2D;\r\n if (depthTex) {\r\n // Get the HiZ texture allocated by the executor\r\n const hiZTex = rgCtx.getTexture<Texture2D>(hiZHandle!);\r\n const HiZFrameBuffer = rgCtx.getFramebuffer<FrameBuffer>(hiZFramebufferHandle);\r\n buildHiZ(depthTex, HiZFrameBuffer);\r\n ctx.HiZTexture = hiZTex;\r\n }\r\n });\r\n });\r\n if (hiZHandle) {\r\n blackboard.set(FrameResources.HiZ, hiZHandle);\r\n }\r\n }\r\n\r\n // ── 7. Main Light Pass ────────────────────────────────────────────\r\n const historyManager = ctx.camera?.getHistoryResourceManager?.() ?? null;\r\n const lightHistoryReadBindings: HistoryReadBinding[] = [];\r\n const historySize = { width: ctx.renderWidth, height: ctx.renderHeight };\r\n if (historyManager && options.ssr && ctx.camera?.ssrTemporal && options.motionVectors) {\r\n const reflectHistoryHandle = historyManager.importPreviousIfCompatible(\r\n graph,\r\n RGHistoryResources.SSR_REFLECT,\r\n {\r\n format: 'rgba16f',\r\n sizeMode: 'absolute',\r\n width: ctx.renderWidth,\r\n height: ctx.renderHeight\r\n },\r\n historySize\r\n );\r\n const motionVectorHistoryHandle = historyManager.importPreviousIfCompatible(\r\n graph,\r\n RGHistoryResources.SSR_MOTION_VECTOR,\r\n {\r\n format: 'rgba16f',\r\n sizeMode: 'absolute',\r\n width: ctx.renderWidth,\r\n height: ctx.renderHeight\r\n },\r\n historySize\r\n );\r\n if (reflectHistoryHandle && motionVectorHistoryHandle) {\r\n lightHistoryReadBindings.push(\r\n { name: RGHistoryResources.SSR_REFLECT, handle: reflectHistoryHandle },\r\n { name: RGHistoryResources.SSR_MOTION_VECTOR, handle: motionVectorHistoryHandle }\r\n );\r\n }\r\n }\r\n // Note: TAA history import/commit is handled by TAA.setup() (self-describing).\r\n\r\n let sssProfileResult: SSSProfilePassResult | undefined;\r\n if (options.sss) {\r\n sssProfileResult = graph.addPass('SSSProfile', (builder) => {\r\n builder.read(depthHandle);\r\n builder.read(depthPassResult.depthFramebufferHandle);\r\n if (preLightTransmissionDepthToken) {\r\n builder.read(preLightTransmissionDepthToken);\r\n }\r\n const profileHandle = builder.createTexture({ format: 'rgba16f', label: 'sssProfile' });\r\n const paramHandle = builder.createTexture({ format: 'rgba8unorm', label: 'sssParam' });\r\n const normalHandle = options.ssr\r\n ? undefined\r\n : builder.createTexture({ format: getSurfaceTextureFormat(ctx), label: 'sssNormal' });\r\n const colorAttachments = normalHandle\r\n ? [ctx.colorFormat!, normalHandle, profileHandle, paramHandle]\r\n : [ctx.colorFormat!, profileHandle, paramHandle];\r\n const framebufferHandle = builder.createFramebuffer({\r\n label: 'SSSProfileFramebuffer',\r\n width: ctx.renderWidth,\r\n height: ctx.renderHeight,\r\n colorAttachments,\r\n depthAttachment: renderDepthAttachment,\r\n ignoreDepthStencil: false\r\n });\r\n\r\n builder.setExecute((rgCtx) => {\r\n renderForwardSSSProfile(\r\n frame,\r\n rgCtx.getFramebuffer<FrameBuffer>(framebufferHandle),\r\n rgCtx.getTexture<Texture2D>(profileHandle),\r\n rgCtx.getTexture<Texture2D>(paramHandle),\r\n normalHandle ? rgCtx.getTexture<Texture2D>(normalHandle) : null\r\n );\r\n });\r\n\r\n return {\r\n profileHandle,\r\n paramHandle,\r\n normalHandle,\r\n framebufferHandle\r\n };\r\n });\r\n }\r\n\r\n // 7b. Scene color grab: renders the full scene (no transmission) into a copy\r\n // texture that transmission/refraction materials sample as background.\r\n // Extracted from the former monolithic light pass.\r\n let grabResult: { copyHandle: RGHandle; copyFramebufferHandle?: RGHandle } | undefined;\r\n if (options.needSceneColor) {\r\n grabResult = graph.addPass('SceneColorGrab', (builder) => {\r\n builder.read(depthHandle);\r\n builder.read(depthPassResult.depthFramebufferHandle);\r\n if (preLightTransmissionDepthToken) {\r\n builder.read(preLightTransmissionDepthToken);\r\n }\r\n const copyHandle = builder.createTexture({\r\n format: ctx.colorFormat!,\r\n label: 'sceneColorCopy'\r\n });\r\n // SSR may pre-insert transmission depth before LightPass for Hi-Z. In that\r\n // case the refraction scene-color copy needs an isolated depth buffer so\r\n // transmission surfaces do not occlude the background they sample.\r\n const copyFramebufferHandle = !options.needsTransmissionDepthForSSR\r\n ? builder.createFramebuffer({\r\n label: 'SceneColorCopyFramebuffer',\r\n width: ctx.renderWidth,\r\n height: ctx.renderHeight,\r\n colorAttachments: copyHandle,\r\n depthAttachment: renderDepthAttachment,\r\n ignoreDepthStencil: false\r\n })\r\n : undefined;\r\n builder.setExecute((rgCtx) => {\r\n renderSceneColorGrab(frame, rgCtx, copyHandle, copyFramebufferHandle);\r\n });\r\n return { copyHandle, copyFramebufferHandle };\r\n });\r\n }\r\n\r\n const lightPassResult = graph.addPass('LightPass', (builder) => {\r\n builder.read(depthHandle);\r\n builder.read(depthPassResult.depthFramebufferHandle);\r\n if (preLightTransmissionDepthToken) {\r\n builder.read(preLightTransmissionDepthToken);\r\n }\r\n if (hiZHandle) {\r\n builder.read(hiZHandle);\r\n }\r\n for (const binding of lightHistoryReadBindings) {\r\n builder.read(binding.handle);\r\n }\r\n\r\n // Scene color: in final-framebuffer-as-intermediate mode the scene is\r\n // physically rendered into the final framebuffer, so declare the\r\n // backbuffer write — the graph sees the real data flow and no keep-alive\r\n // reads are needed downstream. Otherwise render into a graph texture.\r\n const sceneColorHandle = useFinalFramebufferAsIntermediate\r\n ? builder.write(backbuffer)\r\n : builder.createTexture({\r\n format: ctx.colorFormat!,\r\n label: 'sceneColor'\r\n });\r\n\r\n // Transmission/refraction background produced by the SceneColorGrab pass\r\n const sceneColorCopyHandle = grabResult?.copyHandle;\r\n if (sceneColorCopyHandle) {\r\n builder.read(sceneColorCopyHandle);\r\n }\r\n if (sssProfileResult) {\r\n builder.read(sssProfileResult.profileHandle);\r\n builder.read(sssProfileResult.paramHandle);\r\n if (sssProfileResult.normalHandle) {\r\n builder.read(sssProfileResult.normalHandle);\r\n }\r\n }\r\n const includeSSRSurfaceMRT = !!options.ssr;\r\n // SSR glossy-surface MRT outputs (roughness + world normal) are graph\r\n // textures owned by this pass; effects reach them through the blackboard\r\n // handles (or the ctx fields resolved below during execution).\r\n const ssrRoughnessHandle = includeSSRSurfaceMRT\r\n ? builder.createTexture({ format: getSurfaceTextureFormat(ctx), label: 'ssrRoughness' })\r\n : undefined;\r\n const ssrNormalHandle = includeSSRSurfaceMRT\r\n ? builder.createTexture({ format: getSurfaceTextureFormat(ctx), label: 'ssrNormal' })\r\n : undefined;\r\n const writeSSSDiffuse = options.sss && shouldStoreSSSDiffuse(ctx);\r\n let writeSSSTransmission = options.sss && shouldStoreSSSTransmission(ctx);\r\n if (\r\n writeSSSDiffuse &&\r\n writeSSSTransmission &&\r\n includeSSRSurfaceMRT &&\r\n getSSSLightingTextureFormat(ctx, 2, includeSSRSurfaceMRT) !== ctx.colorFormat\r\n ) {\r\n writeSSSTransmission = false;\r\n }\r\n const writeSkinSSS = options.skinSSS;\r\n const sssLightingAttachmentCount =\r\n (writeSSSDiffuse ? 1 : 0) + (writeSSSTransmission ? 1 : 0) + (writeSkinSSS ? 1 : 0);\r\n const sssLightingFormat = getSSSLightingTextureFormat(\r\n ctx,\r\n sssLightingAttachmentCount,\r\n includeSSRSurfaceMRT\r\n );\r\n const sssDiffuseHandle = writeSSSDiffuse\r\n ? builder.createTexture({ format: sssLightingFormat, label: 'sssDiffuse' })\r\n : undefined;\r\n const sssTransmissionHandle = writeSSSTransmission\r\n ? builder.createTexture({ format: sssLightingFormat, label: 'sssTransmission' })\r\n : undefined;\r\n const skinSSSHandle = writeSkinSSS\r\n ? builder.createTexture({ format: sssLightingFormat, label: 'skinSSS' })\r\n : undefined;\r\n const sceneColorFramebufferHandle = useFinalFramebufferAsIntermediate\r\n ? undefined\r\n : builder.createFramebuffer({\r\n label: 'SceneColorFramebuffer',\r\n width: ctx.renderWidth,\r\n height: ctx.renderHeight,\r\n colorAttachments: sceneColorHandle,\r\n depthAttachment: renderDepthAttachment\r\n });\r\n\r\n builder.setExecute((rgCtx) => {\r\n const sceneColorTex = rgCtx.getTexture<Texture2D>(sceneColorHandle);\r\n const sceneColorCopyTex = sceneColorCopyHandle\r\n ? rgCtx.getTexture<Texture2D>(sceneColorCopyHandle)\r\n : null;\r\n // Resolve MRT products into the DrawContext bridge fields that scene\r\n // rendering and apply()-based effects still read.\r\n ctx.SSRRoughnessTexture = ssrRoughnessHandle ? rgCtx.getTexture<Texture2D>(ssrRoughnessHandle) : null;\r\n ctx.SSRNormalTexture = ssrNormalHandle ? rgCtx.getTexture<Texture2D>(ssrNormalHandle) : null;\r\n if (sssProfileResult) {\r\n ctx.SSSProfileTexture = rgCtx.getTexture<Texture2D>(sssProfileResult.profileHandle);\r\n ctx.SSSParamTexture = rgCtx.getTexture<Texture2D>(sssProfileResult.paramHandle);\r\n if (sssProfileResult.normalHandle) {\r\n ctx.SSRNormalTexture = rgCtx.getTexture<Texture2D>(sssProfileResult.normalHandle);\r\n }\r\n }\r\n ctx.SSSDiffuseTexture = sssDiffuseHandle ? rgCtx.getTexture<Texture2D>(sssDiffuseHandle) : null;\r\n ctx.SSSTransmissionTexture = sssTransmissionHandle\r\n ? rgCtx.getTexture<Texture2D>(sssTransmissionHandle)\r\n : null;\r\n ctx.SkinSSSTexture = skinSSSHandle ? rgCtx.getTexture<Texture2D>(skinSSSHandle) : null;\r\n const renderLightPass = () =>\r\n renderOpaqueScenePass(frame, sceneColorTex, sceneColorCopyTex, rgCtx, sceneColorFramebufferHandle);\r\n if (historyManager && lightHistoryReadBindings.length > 0) {\r\n historyManager.beginReadScope(\r\n lightHistoryReadBindings.map((binding) => ({\r\n name: binding.name,\r\n texture: rgCtx.getTexture<Texture2D>(binding.handle)\r\n }))\r\n );\r\n try {\r\n renderLightPass();\r\n } finally {\r\n historyManager.endReadScope();\r\n }\r\n } else {\r\n renderLightPass();\r\n }\r\n });\r\n\r\n return {\r\n sceneColorHandle,\r\n sceneColorCopyHandle,\r\n sceneColorFramebufferHandle,\r\n ssrRoughnessHandle,\r\n ssrNormalHandle,\r\n sssDiffuseHandle,\r\n sssTransmissionHandle,\r\n skinSSSHandle\r\n };\r\n });\r\n // Register the LightPass MRT products so effects can look them up by name.\r\n if (lightPassResult.ssrRoughnessHandle) {\r\n blackboard.set(FrameResources.SSRRoughness, lightPassResult.ssrRoughnessHandle);\r\n }\r\n if (lightPassResult.ssrNormalHandle) {\r\n blackboard.set(FrameResources.SSRNormal, lightPassResult.ssrNormalHandle);\r\n } else if (sssProfileResult?.normalHandle) {\r\n blackboard.set(FrameResources.SSRNormal, sssProfileResult.normalHandle);\r\n }\r\n if (lightPassResult.sssDiffuseHandle) {\r\n blackboard.set(FrameResources.SSSDiffuse, lightPassResult.sssDiffuseHandle);\r\n }\r\n if (lightPassResult.sssTransmissionHandle) {\r\n blackboard.set(FrameResources.SSSTransmission, lightPassResult.sssTransmissionHandle);\r\n }\r\n if (lightPassResult.skinSSSHandle) {\r\n blackboard.set(FrameResources.SkinSSS, lightPassResult.skinSSSHandle);\r\n }\r\n\r\n // 7d. Opaque-layer post effects (SAO/SSR/SSS/SkinSSS). They read the opaque\r\n // scene color and must complete before transparent geometry renders on top\r\n // of their output. Never direct-write: the chain output becomes the\r\n // transparent pass's render target. In final-framebuffer-as-intermediate\r\n // mode the scene color handle is the LightPass's backbuffer write version,\r\n // so the data flow is real either way — no keep-alive reads needed.\r\n const opaqueChainInput = lightPassResult.sceneColorHandle;\r\n // Data dependencies for every effect pass: frame textures the effects sample\r\n // through DrawContext fields (linear depth, HiZ, scene color copy, SSS MRT\r\n // outputs) rather than through declared require* hooks.\r\n const opaqueChainDeps: RGHandle[] = [depthHandle];\r\n if (hiZHandle) {\r\n opaqueChainDeps.push(hiZHandle);\r\n }\r\n if (lightPassResult.sceneColorFramebufferHandle) {\r\n opaqueChainDeps.push(lightPassResult.sceneColorFramebufferHandle);\r\n }\r\n if (grabResult) {\r\n opaqueChainDeps.push(grabResult.copyHandle);\r\n }\r\n if (sssProfileResult) {\r\n opaqueChainDeps.push(sssProfileResult.profileHandle, sssProfileResult.paramHandle);\r\n if (sssProfileResult.normalHandle) {\r\n opaqueChainDeps.push(sssProfileResult.normalHandle);\r\n }\r\n }\r\n for (const handle of [\r\n lightPassResult.ssrRoughnessHandle,\r\n lightPassResult.ssrNormalHandle,\r\n lightPassResult.sssDiffuseHandle,\r\n lightPassResult.sssTransmissionHandle,\r\n lightPassResult.skinSSSHandle\r\n ]) {\r\n if (handle) {\r\n opaqueChainDeps.push(handle);\r\n }\r\n }\r\n const opaqueChainResult = ctx.compositor\r\n ? ctx.compositor.buildLayer({\r\n graph,\r\n ctx,\r\n layer: PostEffectLayer.opaque,\r\n blackboard,\r\n input: opaqueChainInput,\r\n finalOutput: null,\r\n sceneDepthAttachment: renderDepthAttachment,\r\n dependencies: opaqueChainDeps,\r\n historyReads: lightHistoryReadBindings,\r\n history: historyManager\r\n })\r\n : { color: opaqueChainInput, wroteFinal: false };\r\n const opaqueChainRan = opaqueChainResult.color !== opaqueChainInput;\r\n\r\n // 7e. Transparent scene geometry (transmission/transparent lists + OIT).\r\n // Renders on top of the opaque-chain output; graph-wise an in-place write\r\n // producing a new version of the current scene color.\r\n const sceneColorHandle = graph.addPass('TransparentPass', (builder) => {\r\n builder.read(depthHandle);\r\n builder.read(depthPassResult.depthFramebufferHandle);\r\n if (hiZHandle) {\r\n // Transparent-phase materials may ray-march HiZ (e.g. water SSR)\r\n builder.read(hiZHandle);\r\n }\r\n if (lightPassResult.sceneColorFramebufferHandle) {\r\n builder.read(lightPassResult.sceneColorFramebufferHandle);\r\n }\r\n if (lightPassResult.sceneColorCopyHandle) {\r\n builder.read(lightPassResult.sceneColorCopyHandle);\r\n }\r\n builder.read(opaqueChainResult.color);\r\n const out = builder.write(opaqueChainResult.color);\r\n builder.setExecute((rgCtx) => {\r\n renderTransparentScenePass(\r\n frame,\r\n rgCtx,\r\n opaqueChainRan ? opaqueChainResult.color : null,\r\n lightPassResult.sceneColorFramebufferHandle\r\n );\r\n });\r\n return out;\r\n });\r\n blackboard.set(FrameResources.SceneColor, sceneColorHandle);\r\n if (lightPassResult.sceneColorCopyHandle) {\r\n blackboard.set(FrameResources.SceneColorCopy, lightPassResult.sceneColorCopyHandle);\r\n }\r\n if (sssProfileResult) {\r\n blackboard.set(FrameResources.SSSProfile, sssProfileResult.profileHandle);\r\n blackboard.set(FrameResources.SSSParam, sssProfileResult.paramHandle);\r\n }\r\n\r\n // 8. Post effect chains + transmission depth.\r\n //\r\n // Chain input: the TransparentPass output version — the authoritative scene\r\n // color regardless of whether it physically lives in a texture or in the\r\n // backbuffer (final framebuffer used as intermediate, no opaque effects).\r\n const chainInput = sceneColorHandle;\r\n // When the scene color still physically resides in the final framebuffer,\r\n // the Present blit must be skipped if no effect moved it to a texture.\r\n // (Opaque-layer effects disable final-as-intermediate mode, so the scene\r\n // color is backbuffer-resident whenever that mode is active.)\r\n const backbufferResidentHandle = useFinalFramebufferAsIntermediate ? sceneColorHandle : null;\r\n // No extra chain dependencies: the effect chains link to the scene color\r\n // through their inputs, and per-effect texture needs are declared via the\r\n // require* hooks in AbstractPostEffect.setup().\r\n const chainDependencies: RGHandle[] = [];\r\n const finalOutput = { handle: backbuffer, isScreen: !ctx.finalFramebuffer };\r\n const endLayerHasEffects = !!ctx.compositor?.layerHasEnabledEffect(PostEffectLayer.end);\r\n\r\n // 8a. Transparent-layer effects (bloom, tonemap, FXAA, ...). They run right\r\n // after the light pass and must sample the pre-transmission linear depth, so\r\n // they carry no transmissionDepthToken dependency; TransmissionDepth is\r\n // instead ordered after this chain (see 8b).\r\n const transparentChainResult = ctx.compositor\r\n ? ctx.compositor.buildLayer({\r\n graph,\r\n ctx,\r\n layer: PostEffectLayer.transparent,\r\n blackboard,\r\n input: chainInput,\r\n finalOutput: endLayerHasEffects ? null : finalOutput,\r\n inputResidesInFinalTarget: !!backbufferResidentHandle,\r\n sceneDepthAttachment: renderDepthAttachment,\r\n dependencies: chainDependencies,\r\n history: historyManager\r\n })\r\n : { color: chainInput, wroteFinal: false };\r\n\r\n // 8b. Transmission depth pass (optional). Mutates the linear depth texture;\r\n // the mutation is modeled as a graph write: the WAR hazard orders this pass\r\n // after every pre-transmission depth reader (the transparent-layer chain),\r\n // and re-registering the post-write version in the blackboard gives\r\n // end-layer effects (TAA) a real data dependency on the transmission depth.\r\n let transmissionDepthToken: RGHandle | undefined;\r\n if (options.needSceneColor && !options.needsTransmissionDepthForSSR) {\r\n const transmissionDepthResult = graph.addPass('TransmissionDepth', (builder) => {\r\n builder.read(sceneColorHandle);\r\n if (transparentChainResult.color !== sceneColorHandle) {\r\n builder.read(transparentChainResult.color);\r\n }\r\n builder.read(depthHandle);\r\n builder.read(depthPassResult.depthFramebufferHandle);\r\n const depthOut = builder.write(depthHandle);\r\n const done = builder.createToken('TransmissionDepthDone');\r\n builder.sideEffect();\r\n builder.setExecute((rgCtx) => {\r\n renderTransmissionDepthPass(frame, rgCtx);\r\n });\r\n return { done, depthOut };\r\n });\r\n transmissionDepthToken = transmissionDepthResult.done;\r\n depthHandle = transmissionDepthResult.depthOut;\r\n // The transparent-layer chain above read the pre-transmission version;\r\n // everything built from here on (end-layer chain) reads this one.\r\n blackboard.set(FrameResources.LinearDepth, depthHandle);\r\n }\r\n\r\n // 9. End-layer effects (TAA). Ordered after TransmissionDepth.\r\n const endChainDependencies = transmissionDepthToken\r\n ? [...chainDependencies, transmissionDepthToken]\r\n : chainDependencies;\r\n const chainResult = ctx.compositor\r\n ? ctx.compositor.buildLayer({\r\n graph,\r\n ctx,\r\n layer: PostEffectLayer.end,\r\n blackboard,\r\n input: transparentChainResult.color,\r\n finalOutput,\r\n // Still backbuffer-resident if the transparent-layer chain ran no effect\r\n inputResidesInFinalTarget: !!backbufferResidentHandle && transparentChainResult.color === chainInput,\r\n sceneDepthAttachment: renderDepthAttachment,\r\n dependencies: endChainDependencies,\r\n history: historyManager\r\n })\r\n : { color: transparentChainResult.color, wroteFinal: false };\r\n const finalWroteFinal = chainResult.wroteFinal || transparentChainResult.wroteFinal;\r\n\r\n // 10. Present + frame cleanup.\r\n let presentedBackbuffer: RGHandle;\r\n if (finalWroteFinal) {\r\n // The last effect wrote the final target directly; only cleanup remains.\r\n presentedBackbuffer = chainResult.color;\r\n graph.addPass('FrameCleanup', (builder) => {\r\n builder.read(presentedBackbuffer);\r\n for (const dep of endChainDependencies) {\r\n builder.read(dep);\r\n }\r\n builder.sideEffect();\r\n builder.setExecute(() => {\r\n finishFrame(frame);\r\n });\r\n });\r\n } else {\r\n presentedBackbuffer = graph.addPass('Present', (builder) => {\r\n builder.read(chainResult.color);\r\n for (const dep of endChainDependencies) {\r\n builder.read(dep);\r\n }\r\n const outputBackbuffer = builder.write(backbuffer);\r\n // Skip the blit when the chain output already lives in the final target\r\n // (final framebuffer used as intermediate and no end-layer effect ran).\r\n const needsBlit = chainResult.color !== backbufferResidentHandle;\r\n builder.setExecute((rgCtx) => {\r\n const sourceTex = needsBlit ? rgCtx.getTexture<Texture2D>(chainResult.color) : null;\r\n if (sourceTex) {\r\n const blitter = new CopyBlitter();\r\n blitter.srgbOut = !ctx.finalFramebuffer;\r\n blitter.blit(sourceTex, ctx.finalFramebuffer ?? null, fetchSampler('clamp_nearest_nomip'));\r\n }\r\n finishFrame(frame);\r\n });\r\n return outputBackbuffer;\r\n });\r\n }\r\n\r\n return { backbuffer: presentedBackbuffer, frame };\r\n}\r\n\r\n// ─── Pass Implementation Helpers ────────────────────────────────────\r\n// These wrap the existing SceneRenderer static methods, adapted to work\r\n// with the FrameState pattern. They contain the same logic as the\r\n// original methods but read/write through FrameState.\r\n\r\n/** @internal */\r\nfunction renderShadowMaps(ctx: DrawContext, lights: PunctualLight[]): void {\r\n ctx.renderPass = _shadowMapPass;\r\n ctx.device.pushDeviceStates();\r\n try {\r\n for (const light of lights) {\r\n light.shadow.render(ctx, _shadowMapPass);\r\n }\r\n } finally {\r\n ctx.device.popDeviceStates();\r\n }\r\n}\r\n\r\nfunction renderForwardSSSProfile(\r\n frame: FrameState,\r\n profileFramebuffer: FrameBuffer,\r\n profileTexture: Texture2D,\r\n paramTexture: Texture2D,\r\n normalTexture: Nullable<Texture2D>\r\n): void {\r\n const { ctx, renderQueue } = frame;\r\n if (!ctx.SSS || !ctx.depthTexture) {\r\n return;\r\n }\r\n const sssRenderQueue = createActualSSSRenderQueue(renderQueue);\r\n if (!sssRenderQueue) {\r\n return;\r\n }\r\n\r\n const device = ctx.device;\r\n const savedMaterialFlags = ctx.materialFlags;\r\n const savedCompositor = ctx.compositor;\r\n const savedTransmission = _scenePass.transmission;\r\n const savedRenderOpaque = _scenePass.renderOpaque;\r\n const savedRenderTransparent = _scenePass.renderTransparent;\r\n const savedClearColor = _scenePass.clearColor;\r\n const savedClearDepth = _scenePass.clearDepth;\r\n const savedClearStencil = _scenePass.clearStencil;\r\n const savedCommandBufferReuse = ctx.camera.commandBufferReuse;\r\n const savedProfileTexture = ctx.SSSProfileTexture;\r\n const savedParamTexture = ctx.SSSParamTexture;\r\n const savedNormalTexture = ctx.SSRNormalTexture;\r\n\r\n let profileFlags = MaterialVaryingFlags.SSS_STORE_PROFILE;\r\n if (normalTexture) {\r\n profileFlags |= MaterialVaryingFlags.SSS_STORE_NORMAL;\r\n }\r\n\r\n device.pushDeviceStates();\r\n try {\r\n device.setFramebuffer(profileFramebuffer);\r\n ctx.SSSProfileTexture = profileTexture;\r\n ctx.SSSParamTexture = paramTexture;\r\n ctx.SSRNormalTexture = normalTexture;\r\n ctx.compositor = null;\r\n ctx.camera.commandBufferReuse = false;\r\n ctx.materialFlags =\r\n (ctx.materialFlags &\r\n ~(\r\n MaterialVaryingFlags.SSR_STORE_ROUGHNESS |\r\n MaterialVaryingFlags.SSS_STORE_PROFILE |\r\n MaterialVaryingFlags.SSS_STORE_NORMAL |\r\n MaterialVaryingFlags.SSS_STORE_DIFFUSE |\r\n MaterialVaryingFlags.SSS_STORE_TRANSMISSION |\r\n MaterialVaryingFlags.SKIN_SSS_STORE\r\n )) |\r\n profileFlags;\r\n _scenePass.transmission = false;\r\n _scenePass.renderOpaque = true;\r\n _scenePass.renderTransparent = false;\r\n _scenePass.clearColor = Vector4.zero();\r\n _scenePass.clearDepth = null;\r\n _scenePass.clearStencil = null;\r\n _scenePass.render(ctx, null, null, sssRenderQueue);\r\n } finally {\r\n _scenePass.clearColor = savedClearColor;\r\n _scenePass.clearDepth = savedClearDepth;\r\n _scenePass.clearStencil = savedClearStencil;\r\n _scenePass.renderTransparent = savedRenderTransparent;\r\n _scenePass.renderOpaque = savedRenderOpaque;\r\n _scenePass.transmission = savedTransmission;\r\n ctx.camera.commandBufferReuse = savedCommandBufferReuse;\r\n ctx.materialFlags = savedMaterialFlags;\r\n ctx.compositor = savedCompositor;\r\n ctx.SSSProfileTexture = savedProfileTexture;\r\n ctx.SSSParamTexture = savedParamTexture;\r\n ctx.SSRNormalTexture = savedNormalTexture;\r\n device.popDeviceStates();\r\n sssRenderQueue.dispose();\r\n }\r\n}\r\n\r\nfunction releaseIntermediateFramebuffer(frame: FrameState): void {\r\n // Device state is contained within each pass now (LightPass/TransparentPass\r\n // push/pop their own framebuffer bindings); only the context field remains.\r\n frame.ctx.intermediateFramebuffer = null;\r\n}\r\n\r\nfunction releaseDepthFramebuffer(frame: FrameState): void {\r\n frame.depthFramebuffer = null;\r\n}\r\n\r\nfunction disposeRenderQueue(frame: FrameState): void {\r\n if (!frame.renderQueueDisposed) {\r\n frame.renderQueue.dispose();\r\n frame.renderQueueDisposed = true;\r\n }\r\n}\r\n\r\nfunction releaseClusteredLight(frame: FrameState): void {\r\n if (!frame.clusteredLightReleased && frame.ctx.clusteredLight) {\r\n freeClusteredLight(frame.ctx.clusteredLight);\r\n frame.ctx.clusteredLight = undefined;\r\n frame.clusteredLightReleased = true;\r\n }\r\n}\r\n\r\nfunction restoreSunLight(frame: FrameState): void {\r\n if (!frame.sunLightRestored && frame.sunLightColor && frame.ctx.sunLight) {\r\n frame.ctx.sunLight.color = frame.sunLightColor;\r\n frame.sunLightRestored = true;\r\n }\r\n}\r\n\r\nfunction cleanupFrame(frame: FrameState): void {\r\n releaseIntermediateFramebuffer(frame);\r\n releaseDepthFramebuffer(frame);\r\n releaseClusteredLight(frame);\r\n disposeRenderQueue(frame);\r\n restoreSunLight(frame);\r\n}\r\n\r\n/** @internal */\r\nfunction renderSceneDepth(\r\n frame: FrameState,\r\n existingDepthFb: Nullable<FrameBuffer>,\r\n rgCtx: RGExecuteContext,\r\n depthTex?: Texture2D,\r\n motionVectorTex?: Nullable<Texture2D>,\r\n transmissionOverride?: boolean\r\n): FrameBuffer {\r\n const ctx = frame.ctx;\r\n const renderQueue = frame.renderQueue;\r\n const transmission = transmissionOverride ?? !!existingDepthFb;\r\n let depthFramebuffer = existingDepthFb;\r\n\r\n if (!depthFramebuffer) {\r\n // Use RenderGraph-allocated textures if provided\r\n if (depthTex) {\r\n const colorAttachments = motionVectorTex ? [depthTex, motionVectorTex] : depthTex;\r\n const depthAttachment = ctx.finalFramebuffer?.getDepthAttachment();\r\n const depthTexOrFormat = depthAttachment?.isTexture2D() ? depthAttachment : ctx.depthFormat;\r\n\r\n depthFramebuffer = rgCtx.createFramebuffer<FrameBuffer>({\r\n width: depthTex.width,\r\n height: depthTex.height,\r\n colorAttachments,\r\n depthAttachment: depthTexOrFormat,\r\n ignoreDepthStencil: false\r\n });\r\n } else {\r\n // Allocate through RenderGraph so framebuffer lifetime is owned by the executor.\r\n const format: TextureFormat =\r\n ctx.device.type === 'webgl'\r\n ? ctx.SSRCalcThickness\r\n ? 'rgba16f'\r\n : 'rgba8unorm'\r\n : ctx.SSRCalcThickness\r\n ? 'rg32f'\r\n : 'r32f';\r\n const mvFormat: TextureFormat = 'rgba16f';\r\n if (!ctx.finalFramebuffer) {\r\n depthFramebuffer = rgCtx.createFramebuffer<FrameBuffer>({\r\n width: ctx.renderWidth,\r\n height: ctx.renderHeight,\r\n colorAttachments: ctx.motionVectors ? [format, mvFormat] : format,\r\n depthAttachment: ctx.depthFormat,\r\n ignoreDepthStencil: false\r\n });\r\n } else {\r\n const originDepth = ctx.finalFramebuffer?.getDepthAttachment();\r\n if (originDepth?.isTexture2D()) {\r\n depthFramebuffer = rgCtx.createFramebuffer<FrameBuffer>({\r\n width: originDepth.width,\r\n height: originDepth.height,\r\n colorAttachments: ctx.motionVectors ? [format, mvFormat] : format,\r\n depthAttachment: originDepth,\r\n ignoreDepthStencil: false\r\n });\r\n } else {\r\n depthFramebuffer = rgCtx.createFramebuffer<FrameBuffer>({\r\n width: ctx.renderWidth,\r\n height: ctx.renderHeight,\r\n colorAttachments: ctx.motionVectors ? [format, mvFormat] : format,\r\n depthAttachment: ctx.depthFormat,\r\n ignoreDepthStencil: false\r\n });\r\n }\r\n }\r\n }\r\n }\r\n\r\n if (!transmission) {\r\n frame.depthFramebuffer = depthFramebuffer!;\r\n }\r\n\r\n ctx.device.pushDeviceStates();\r\n try {\r\n ctx.device.setFramebuffer(depthFramebuffer!);\r\n _depthPass.encodeDepth = depthFramebuffer!.getColorAttachments()[0].format === 'rgba8unorm';\r\n _depthPass.clearColor = transmission\r\n ? null\r\n : _depthPass.encodeDepth\r\n ? new Vector4(0, 0, 0, 1)\r\n : new Vector4(1, 1, 1, 1);\r\n _depthPass.clearDepth = transmission ? null : 1;\r\n _depthPass.clearStencil = null;\r\n _depthPass.transmission = transmission;\r\n\r\n if (ctx.SSRCalcThickness && !transmission) {\r\n if (!_backDepthColorState) {\r\n _backDepthColorState = ctx.device.createColorState().setColorMask(false, true, false, false);\r\n }\r\n if (!_frontDepthColorState) {\r\n _frontDepthColorState = ctx.device.createColorState().setColorMask(true, false, false, false);\r\n }\r\n ctx.forceColorState = _backDepthColorState;\r\n ctx.forceCullMode = 'front';\r\n _depthPass.renderBackface = true;\r\n _depthPass.transmission = false;\r\n _depthPass.render(ctx, null, null, renderQueue);\r\n _depthPass.clearColor = null;\r\n _depthPass.renderBackface = false;\r\n ctx.forceColorState = _frontDepthColorState;\r\n ctx.forceCullMode = null;\r\n }\r\n _depthPass.render(ctx, null, null, renderQueue);\r\n } finally {\r\n ctx.forceColorState = null;\r\n ctx.forceCullMode = null;\r\n _depthPass.renderBackface = false;\r\n ctx.device.popDeviceStates();\r\n }\r\n\r\n if (!transmission) {\r\n ctx.motionVectorTexture = ctx.motionVectors\r\n ? (depthFramebuffer!.getColorAttachments()[1] as Texture2D)\r\n : null;\r\n ctx.linearDepthTexture = depthFramebuffer!.getColorAttachments()[0] as Texture2D;\r\n ctx.depthTexture = depthFramebuffer!.getDepthAttachment() as Texture2D;\r\n ctx.depthPrepassAttachment = ctx.depthTexture;\r\n // HiZ is now built in the dedicated HiZ pass\r\n }\r\n return depthFramebuffer!;\r\n}\r\n\r\n// ─── Sky Motion Vector State ────────────────────────────────────────\r\n\r\nlet _skyMVProgram: Nullable<GPUProgram> = null;\r\nlet _skyMVBindGroup: Nullable<BindGroup> = null;\r\nlet _skyMVBox: Nullable<Primitive> = null;\r\n\r\n/** @internal */\r\nfunction renderSkyMotionVectors(\r\n ctx: DrawContext,\r\n rgCtx: RGExecuteContext,\r\n framebufferHandle?: RGHandle\r\n): void {\r\n if (!ctx.motionVectorTexture) {\r\n return;\r\n }\r\n\r\n const device = ctx.device;\r\n const fb = framebufferHandle\r\n ? rgCtx.getFramebuffer<FrameBuffer>(framebufferHandle)\r\n : rgCtx.createFramebuffer<FrameBuffer>({\r\n colorAttachments: ctx.motionVectorTexture,\r\n depthAttachment: ctx.depthTexture\r\n });\r\n\r\n if (!_skyMVProgram) {\r\n _skyMVProgram = device.buildRenderProgram({\r\n vertex(pb) {\r\n this.$inputs.pos = pb.vec3().attrib('position');\r\n this.VPMatrix = pb.mat4().uniform(0);\r\n this.prevVPMatrix = pb.mat4().uniform(0);\r\n this.cameraPos = pb.vec3().uniform(0);\r\n this.prevCameraPos = pb.vec3().uniform(0);\r\n pb.main(function () {\r\n this.$l.worldPos = pb.add(this.$inputs.pos, this.cameraPos);\r\n this.$l.prevWorldPos = pb.add(this.$inputs.pos, this.prevCameraPos);\r\n this.$l.clipPos = pb.mul(this.VPMatrix, pb.vec4(this.worldPos, 1));\r\n this.$l.prevClipPos = pb.mul(this.prevVPMatrix, pb.vec4(this.prevWorldPos, 1));\r\n this.clipPos.z = this.clipPos.w;\r\n this.$builtins.position = this.clipPos;\r\n this.$outputs.currentPos = this.clipPos;\r\n this.$outputs.prevPos = this.prevClipPos;\r\n });\r\n },\r\n fragment(pb) {\r\n this.$outputs.color = pb.vec4();\r\n pb.main(function () {\r\n this.$l.motionVector = pb.mul(\r\n pb.sub(\r\n pb.div(this.$inputs.currentPos.xy, this.$inputs.currentPos.w),\r\n pb.div(this.$inputs.prevPos.xy, this.$inputs.prevPos.w)\r\n ),\r\n 0.5\r\n );\r\n this.$outputs.color = pb.vec4(this.motionVector, 0, 1);\r\n });\r\n }\r\n })!;\r\n _skyMVProgram.name = '@TAA_SkyMotionVector';\r\n }\r\n\r\n if (!_skyMVBindGroup) {\r\n _skyMVBindGroup = device.createBindGroup(_skyMVProgram.bindGroupLayouts[0]);\r\n }\r\n\r\n if (!_skyMVBox) {\r\n _skyMVBox = new BoxShape({ size: 2, needNormal: false, needUV: false });\r\n }\r\n\r\n _skyMVBindGroup.setValue('VPMatrix', ctx.camera.viewProjectionMatrix);\r\n _skyMVBindGroup.setValue('prevVPMatrix', ctx.camera.prevVPMatrix!);\r\n _skyMVBindGroup.setValue('cameraPos', ctx.camera.getWorldPosition());\r\n _skyMVBindGroup.setValue('prevCameraPos', ctx.camera.prevPosition!);\r\n\r\n device.pushDeviceStates();\r\n device.setProgram(_skyMVProgram);\r\n device.setBindGroup(0, _skyMVBindGroup);\r\n device.setRenderStates(AbstractPostEffect.getDefaultRenderState(ctx, 'le'));\r\n device.setFramebuffer(fb);\r\n _skyMVBox.draw();\r\n device.popDeviceStates();\r\n}\r\n\r\nfunction blitToCurrentColorAttachment(ctx: DrawContext, source: Texture2D): void {\r\n const framebuffer = ctx.device.getFramebuffer();\r\n const destination = framebuffer?.getColorAttachment<Texture2D>(0) ?? null;\r\n new CopyBlitter().blit(source, destination, fetchSampler('clamp_nearest_nomip'));\r\n}\r\n\r\n/**\r\n * Renders the full scene (no transmission) into the scene-color copy texture\r\n * used as refraction background. Runs as its own graph pass before LightPass.\r\n * @internal\r\n */\r\nfunction renderSceneColorGrab(\r\n frame: FrameState,\r\n rgCtx: RGExecuteContext,\r\n copyHandle: RGHandle,\r\n copyFramebufferHandle?: RGHandle\r\n): void {\r\n const { ctx, renderQueue } = frame;\r\n const device = ctx.device;\r\n const depthTex = frame.depthFramebuffer?.getDepthAttachment() as Texture2D;\r\n const copyTex = rgCtx.getTexture<Texture2D>(copyHandle);\r\n const compositor = ctx.compositor;\r\n ctx.compositor = null;\r\n const isolateSceneColorDepth = frame.options.needsTransmissionDepthForSSR;\r\n const savedDepthPrepassAttachment = ctx.depthPrepassAttachment;\r\n const savedMaterialFlags = ctx.materialFlags;\r\n\r\n // MRT store flags never apply to the background copy\r\n const sceneColorMaterialFlags = ctx.materialFlags & ~SURFACE_MRT_FLAGS;\r\n const sceneColorFramebuffer = copyFramebufferHandle\r\n ? rgCtx.getFramebuffer<FrameBuffer>(copyFramebufferHandle)\r\n : rgCtx.createFramebuffer<FrameBuffer>({\r\n width: copyTex.width,\r\n height: copyTex.height,\r\n colorAttachments: copyTex,\r\n depthAttachment: isolateSceneColorDepth ? ctx.depthFormat : depthTex,\r\n ignoreDepthStencil: false\r\n });\r\n let sceneColorStatePushed = false;\r\n try {\r\n device.pushDeviceStates();\r\n sceneColorStatePushed = true;\r\n device.setFramebuffer(sceneColorFramebuffer);\r\n _scenePass.transmission = false;\r\n if (isolateSceneColorDepth) {\r\n ctx.depthPrepassAttachment = undefined;\r\n _scenePass.clearDepth = 1;\r\n _scenePass.clearStencil = 0;\r\n } else {\r\n _scenePass.clearDepth = depthTex ? null : 1;\r\n _scenePass.clearStencil = depthTex ? null : 0;\r\n }\r\n ctx.materialFlags = sceneColorMaterialFlags;\r\n _scenePass.render(ctx, null, null, renderQueue);\r\n } finally {\r\n ctx.materialFlags = savedMaterialFlags;\r\n if (isolateSceneColorDepth) {\r\n ctx.depthPrepassAttachment = savedDepthPrepassAttachment;\r\n }\r\n if (sceneColorStatePushed) {\r\n device.popDeviceStates();\r\n }\r\n ctx.compositor = compositor;\r\n }\r\n}\r\n\r\n/** @internal */\r\nfunction renderOpaqueScenePass(\r\n frame: FrameState,\r\n sceneColorTex: Texture2D,\r\n sceneColorCopyTex: Nullable<Texture2D>,\r\n rgCtx: RGExecuteContext,\r\n sceneColorFramebufferHandle?: RGHandle\r\n): void {\r\n const { ctx, renderQueue } = frame;\r\n\r\n // Use RenderGraph-allocated scene color texture\r\n const depthTex = frame.depthFramebuffer?.getDepthAttachment() as Texture2D;\r\n\r\n ctx.materialFlags &= ~(\r\n MaterialVaryingFlags.SSR_STORE_ROUGHNESS |\r\n MaterialVaryingFlags.SSS_STORE_PROFILE |\r\n MaterialVaryingFlags.SSS_STORE_DIFFUSE |\r\n MaterialVaryingFlags.SSS_STORE_NORMAL |\r\n MaterialVaryingFlags.SSS_STORE_TRANSMISSION |\r\n MaterialVaryingFlags.SKIN_SSS_STORE\r\n );\r\n\r\n if (ctx.SSR) {\r\n ctx.materialFlags |= MaterialVaryingFlags.SSR_STORE_ROUGHNESS;\r\n }\r\n if (ctx.SSS) {\r\n if (ctx.SSSDiffuseTexture) {\r\n ctx.materialFlags |= MaterialVaryingFlags.SSS_STORE_DIFFUSE;\r\n }\r\n if (ctx.SSSTransmissionTexture) {\r\n ctx.materialFlags |= MaterialVaryingFlags.SSS_STORE_TRANSMISSION;\r\n }\r\n }\r\n if (ctx.SkinSSSTexture) {\r\n ctx.materialFlags |= MaterialVaryingFlags.SKIN_SSS_STORE;\r\n }\r\n\r\n // The graph scene color framebuffer takes priority: it is absent only when\r\n // the graph was built in final-framebuffer-as-intermediate mode (external\r\n // depth shared with the final framebuffer AND no opaque-layer effects).\r\n // Checking the shared depth first would wrongly route the MRT/opaque-effect\r\n // case into the single-color final framebuffer.\r\n if (sceneColorFramebufferHandle && !hasSurfaceMRT(ctx)) {\r\n ctx.intermediateFramebuffer = rgCtx.getFramebuffer<FrameBuffer>(sceneColorFramebufferHandle);\r\n } else if (!sceneColorFramebufferHandle && depthTex === ctx.finalFramebuffer?.getDepthAttachment()) {\r\n ctx.intermediateFramebuffer = ctx.finalFramebuffer;\r\n } else {\r\n ctx.intermediateFramebuffer = rgCtx.createFramebuffer<FrameBuffer>({\r\n width: sceneColorTex.width,\r\n height: sceneColorTex.height,\r\n colorAttachments: getLightPassColorAttachments(ctx, sceneColorTex),\r\n depthAttachment: depthTex\r\n });\r\n }\r\n\r\n // The scene target is bound explicitly and the device state is restored at\r\n // the end of this pass: graph passes never communicate through leftover\r\n // device state. TransparentPass re-binds the same target (or the opaque\r\n // chain output) explicitly.\r\n ctx.device.pushDeviceStates();\r\n try {\r\n // setFramebuffer() no-ops when the target is unchanged, so reset the\r\n // viewport/scissor explicitly to cover that case.\r\n ctx.device.setFramebuffer(ctx.intermediateFramebuffer);\r\n ctx.device.setViewport(null);\r\n ctx.device.setScissor(null);\r\n\r\n _scenePass.transmission = false;\r\n _scenePass.clearDepth = depthTex ? null : 1;\r\n _scenePass.clearStencil = depthTex ? null : 0;\r\n\r\n if (renderQueue.needSceneColor() && sceneColorCopyTex) {\r\n // Background copy was produced by the SceneColorGrab pass; seed the main\r\n // color attachment with it and render only transmission/transparent on top.\r\n ctx.sceneColorTexture = sceneColorCopyTex;\r\n blitToCurrentColorAttachment(ctx, ctx.sceneColorTexture);\r\n if (hasSurfaceMRT(ctx)) {\r\n // The background copy carries no surface MRT attachments, so opaque\r\n // geometry exists only there without roughness/normal (and SSS\r\n // lighting) data. Re-render the opaque lists into the MRT scene\r\n // target: early-z against the prepass depth keeps this cheap, and the\r\n // color output matches the blitted copy on opaque pixels while the\r\n // MRT attachments receive the surface data SSR/SSS require.\r\n _scenePass.clearColor = null;\r\n _scenePass.clearDepth = null;\r\n _scenePass.clearStencil = null;\r\n _scenePass.renderOpaque = true;\r\n _scenePass.renderTransparent = false;\r\n _scenePass.render(ctx, null, null, renderQueue);\r\n }\r\n _scenePass.transmission = true;\r\n _scenePass.clearColor = null;\r\n _scenePass.clearDepth = null;\r\n _scenePass.clearStencil = null;\r\n }\r\n _scenePass.renderOpaque = true;\r\n _scenePass.renderTransparent = false;\r\n _scenePass.render(ctx, null, null, renderQueue);\r\n _scenePass.renderTransparent = true;\r\n } finally {\r\n ctx.device.popDeviceStates();\r\n }\r\n}\r\n\r\n/**\r\n * Renders the transmission/transparent geometry lists (including OIT) on top\r\n * of the opaque result. The target framebuffer is always bound explicitly:\r\n * the opaque chain output when opaque-layer effects ran, otherwise the same\r\n * scene target the light pass rendered into. OIT implementations composite\r\n * into the currently bound framebuffer, which this pass guarantees.\r\n * @internal\r\n */\r\nfunction renderTransparentScenePass(\r\n frame: FrameState,\r\n rgCtx: RGExecuteContext,\r\n opaqueChainOutput: Nullable<RGHandle>,\r\n sceneColorFramebufferHandle?: RGHandle\r\n): void {\r\n const { ctx, renderQueue } = frame;\r\n const device = ctx.device;\r\n let framebuffer: Nullable<FrameBuffer>;\r\n if (opaqueChainOutput) {\r\n // Opaque-layer effects redirected the scene color into their chain output;\r\n // transparent geometry renders on top of it with the scene depth attached.\r\n const chainTex = rgCtx.getTexture<Texture2D>(opaqueChainOutput);\r\n const depthTex = frame.depthFramebuffer?.getDepthAttachment() as Texture2D;\r\n framebuffer = rgCtx.createFramebuffer<FrameBuffer>({\r\n width: chainTex.width,\r\n height: chainTex.height,\r\n colorAttachments: chainTex,\r\n depthAttachment: depthTex\r\n });\r\n // The chain output is single-color: surface MRT stores no longer apply.\r\n ctx.materialFlags &= ~SURFACE_MRT_FLAGS;\r\n } else if (sceneColorFramebufferHandle) {\r\n // No opaque-layer effect ran (thus no surface MRT either): continue in the\r\n // graph scene color framebuffer the light pass rendered into.\r\n framebuffer = rgCtx.getFramebuffer<FrameBuffer>(sceneColorFramebufferHandle);\r\n } else {\r\n // Final framebuffer used as scene intermediate.\r\n framebuffer = ctx.finalFramebuffer;\r\n }\r\n device.pushDeviceStates();\r\n try {\r\n // setFramebuffer() no-ops when the target is unchanged, so reset the\r\n // viewport/scissor explicitly to cover that case.\r\n device.setFramebuffer(framebuffer);\r\n device.setViewport(null);\r\n device.setScissor(null);\r\n // _scenePass.transmission carries over from the opaque phase (true when the\r\n // scene color copy seeded the background, false otherwise). Never clear:\r\n // the opaque result is already in the target.\r\n _scenePass.clearColor = null;\r\n _scenePass.clearDepth = null;\r\n _scenePass.clearStencil = null;\r\n _scenePass.renderOpaque = false;\r\n _scenePass.renderTransparent = true;\r\n try {\r\n _scenePass.render(ctx, null, null, renderQueue);\r\n } finally {\r\n _scenePass.renderOpaque = true;\r\n }\r\n } finally {\r\n device.popDeviceStates();\r\n }\r\n}\r\n\r\n/** @internal */\r\nfunction renderTransmissionDepthPass(frame: FrameState, rgCtx: RGExecuteContext): void {\r\n renderSceneDepth(frame, frame.depthFramebuffer, rgCtx);\r\n}\r\n\r\n/**\r\n * Frame-tail housekeeping shared by the Present and FrameCleanup passes.\r\n *\r\n * The end-layer post effect chain and the final blit are graph passes now\r\n * (see buildForwardPlusGraphInternal step 9/10); this only releases per-frame\r\n * state. The compositor's scene ping-pong is flushed back to the intermediate\r\n * framebuffer by compositor.end() at the tail of the light pass.\r\n *\r\n * @internal\r\n */\r\nfunction finishFrame(frame: FrameState): void {\r\n const { ctx } = frame;\r\n\r\n disposeRenderQueue(frame);\r\n ctx.materialFlags &= ~MaterialVaryingFlags.SSR_STORE_ROUGHNESS;\r\n ctx.materialFlags &= ~MaterialVaryingFlags.SSS_STORE_PROFILE;\r\n ctx.materialFlags &= ~MaterialVaryingFlags.SSS_STORE_DIFFUSE;\r\n ctx.materialFlags &= ~MaterialVaryingFlags.SSS_STORE_NORMAL;\r\n ctx.materialFlags &= ~MaterialVaryingFlags.SSS_STORE_TRANSMISSION;\r\n ctx.materialFlags &= ~MaterialVaryingFlags.SKIN_SSS_STORE;\r\n\r\n releaseIntermediateFramebuffer(frame);\r\n releaseDepthFramebuffer(frame);\r\n releaseClusteredLight(frame);\r\n restoreSunLight(frame);\r\n}\r\n\r\n// ─── Convenience: Execute Full Pipeline ─────────────────────────────\r\n\r\n/**\r\n * Build, compile, and execute the forward+ pipeline as a render graph.\r\n *\r\n * This is the drop-in replacement for `SceneRenderer._renderScene`.\r\n *\r\n * @param ctx - The draw context for this frame.\r\n * @public\r\n */\r\nexport function executeForwardPlusGraph(ctx: DrawContext): void {\r\n const device = ctx.device;\r\n const graph = new RenderGraph();\r\n let renderQueue: RenderQueue | null = null;\r\n let frame: FrameState | null = null;\r\n let executor: RenderGraphExecutor<Texture2D, FrameBuffer> | null = null;\r\n let historyManager: HistoryResourceManager<Texture2D> | null = null;\r\n let historyFrameStarted = false;\r\n\r\n try {\r\n // Cull scene first (needed to derive options)\r\n renderQueue = _scenePass.cullScene(ctx, ctx.camera);\r\n\r\n const options = deriveForwardPlusOptions(ctx.scene, ctx.camera, device.type, renderQueue);\r\n ctx.SSS = options.sss;\r\n\r\n // Ensure the camera has a history resource manager for temporal effects (TAA, motion blur)\r\n historyManager = ctx.camera.getHistoryResourceManager();\r\n if (!historyManager) {\r\n historyManager = new HistoryResourceManager<Texture2D>(_devicePoolAllocator);\r\n ctx.camera.setHistoryResourceManager(historyManager);\r\n }\r\n historyManager.beginFrame();\r\n historyFrameStarted = true;\r\n\r\n const buildResult = buildForwardPlusGraphInternal(graph, ctx, renderQueue, options);\r\n frame = buildResult.frame;\r\n\r\n const compiled = graph.compile([buildResult.backbuffer]);\r\n\r\n // Use RenderGraphExecutor for automatic resource management\r\n executor = new RenderGraphExecutor(_devicePoolAllocator, ctx.renderWidth, ctx.renderHeight);\r\n\r\n // Register imported backbuffer (if using finalFramebuffer)\r\n if (ctx.finalFramebuffer) {\r\n const backbufferTex = ctx.finalFramebuffer.getColorAttachments()[0] as Texture2D;\r\n executor.setImportedTexture(buildResult.backbuffer, backbufferTex);\r\n }\r\n historyManager.bindImportedTextures(executor);\r\n\r\n executor.execute(compiled);\r\n historyManager.commitFrame();\r\n } finally {\r\n if (historyFrameStarted) {\r\n historyManager?.discardFrame();\r\n }\r\n if (frame) {\r\n cleanupFrame(frame);\r\n } else {\r\n renderQueue?.dispose();\r\n }\r\n executor?.reset();\r\n }\r\n}\r\n"],"names":["_scenePass","LightPass","_depthPass","DepthPass","_shadowMapPass","ShadowMapPass","_clusters","_devicePoolAllocator","DevicePoolAllocator","_backDepthColorState","_frontDepthColorState","SURFACE_MRT_FLAGS","MaterialVaryingFlags","SSR_STORE_ROUGHNESS","SSS_STORE_PROFILE","SSS_STORE_DIFFUSE","SSS_STORE_NORMAL","SSS_STORE_TRANSMISSION","SKIN_SSS_STORE","getClusteredLight","length","pop","ClusteredLight","freeClusteredLight","cl","push","getCoreMaterial","material","coreMaterial","hasSSSMaterialCore","subsurfaceProfile","hasSkinSSSMaterialCore","skinSSS","renderQueueHasActiveSSS","renderQueue","itemList","lists","opaque","lit","unlit","list","materialList","renderQueueHasActiveSkinSSS","filterActualSSSItemList","items","filter","item","drawable","getMaterial","filterActualSSSMaterialList","filtered","Set","forEach","mat","add","cloneActualSSSListInfo","source","_targetQueue","skinItemList","morphItemList","skinAndMorphItemList","instanceItemList","instanceList","cloneActualSSSBundle","targetQueue","map","info","hasAnyActualSSSItems","renderItems","some","createActualSSSRenderQueue","queue","RenderQueue","sssOpaque","dispose","emptyBundle","target","_itemList","transmission","transparent","transmission_trans","_shadowedLightList","shadowedLights","_unshadowedLightList","unshadowedLights","_sunLight","sunLight","_primaryDirectionalLight","primaryDirectionalLight","_primaryTransmissionLight","primaryTransmissionLight","_needSceneColor","_needSceneDepth","_needSceneColorWithDepth","_drawTransparent","getSurfaceTextureFormat","ctx","caps","device","getDeviceCaps","textureCaps","supportHalfFloatColorBuffer","getTextureFormatBytes","format","getTextureFormatInfo","size","shouldStoreSSSDiffuse","camera","sssStrength","sssBlurScale","shouldStoreSSSTransmission","sssTransmissionStrength","getSSSLightingTextureFormat","attachmentCount","includeSSRSurfaceMRT","colorFormat","surfaceFormat","colorBytes","fullPrecisionBytes","framebufferCaps","maxColorAttachmentBytesPerSample","getFullMipLevelCount","width","height","Math","max","floor","log2","hasSurfaceMRT","materialFlags","getLightPassColorAttachments","colorAttachment","attachments","SSRRoughnessTexture","SSRNormalTexture","SSSProfileTexture","SSSParamTexture","SSSDiffuseTexture","SSSTransmissionTexture","SkinSSSTexture","deriveForwardPlusOptions","scene","deviceType","ssr","SSR","env","light","envLight","hasRadiance","sss","SSS","needSceneColor","needSceneColorWithDepth","depthPrepass","motionVectors","TAA","motionBlur","ssrTemporal","hiZ","HiZ","ssrCalcThickness","gpuPicking","getPickResultResolveFunc","needsTransmissionDepthForSSR","buildForwardPlusGraph","graph","options","buildForwardPlusGraphInternal","backbuffer","importTexture","blackboard","RGBlackboard","frame","depthFramebuffer","sunLightColor","renderQueueDisposed","clusteredLightReleased","sunLightRestored","orderToken","addPass","builder","done","createToken","sideEffect","setExecute","sky","update","read","clusteredLight","calculateLightIndex","pickResolveFunc","renderObjectColors","renderShadowMaps","depthPassResult","type","SSRCalcThickness","mvFormat","depthHandle","createTexture","label","motionVectorHandle","undefined","finalDepthAttachment","finalFramebuffer","getDepthAttachment","externalDepthAttachment","isTexture2D","graphDepthAttachmentHandle","depthFormat","depthAttachmentOrFormat","depthFramebufferHandle","createFramebuffer","renderWidth","renderHeight","colorAttachments","depthAttachment","ignoreDepthStencil","skyMotionVectorFramebufferHandle","addSubpass","rgCtx","getFramebuffer","renderSceneDepth","renderSkyMotionVectors","set","FrameResources","LinearDepth","MotionVector","SceneDepthAttachment","renderDepthAttachment","opaqueLayerHasEffects","compositor","layerHasEnabledEffect","PostEffectLayer","useFinalFramebufferAsIntermediate","preLightTransmissionDepthToken","transmissionDepthResult","depthOut","write","renderTransmissionDepthPass","hiZHandle","mipLevels","hiZFramebufferHandle","depthTex","hiZTex","getTexture","HiZFrameBuffer","buildHiZ","HiZTexture","historyManager","getHistoryResourceManager","lightHistoryReadBindings","historySize","reflectHistoryHandle","importPreviousIfCompatible","RGHistoryResources","SSR_REFLECT","sizeMode","motionVectorHistoryHandle","SSR_MOTION_VECTOR","name","handle","sssProfileResult","profileHandle","paramHandle","normalHandle","framebufferHandle","renderForwardSSSProfile","grabResult","copyHandle","copyFramebufferHandle","renderSceneColorGrab","lightPassResult","binding","sceneColorHandle","sceneColorCopyHandle","ssrRoughnessHandle","ssrNormalHandle","writeSSSDiffuse","writeSSSTransmission","writeSkinSSS","sssLightingAttachmentCount","sssLightingFormat","sssDiffuseHandle","sssTransmissionHandle","skinSSSHandle","sceneColorFramebufferHandle","sceneColorTex","sceneColorCopyTex","renderLightPass","renderOpaqueScenePass","beginReadScope","texture","endReadScope","SSRRoughness","SSRNormal","SSSDiffuse","SSSTransmission","SkinSSS","opaqueChainInput","opaqueChainDeps","opaqueChainResult","buildLayer","layer","input","finalOutput","sceneDepthAttachment","dependencies","historyReads","history","color","wroteFinal","opaqueChainRan","out","renderTransparentScenePass","SceneColor","SceneColorCopy","SSSProfile","SSSParam","chainInput","backbufferResidentHandle","chainDependencies","isScreen","endLayerHasEffects","end","transparentChainResult","inputResidesInFinalTarget","transmissionDepthToken","endChainDependencies","chainResult","finalWroteFinal","presentedBackbuffer","dep","finishFrame","outputBackbuffer","needsBlit","sourceTex","blitter","CopyBlitter","srgbOut","blit","fetchSampler","lights","renderPass","pushDeviceStates","shadow","render","popDeviceStates","profileFramebuffer","profileTexture","paramTexture","normalTexture","depthTexture","sssRenderQueue","savedMaterialFlags","savedCompositor","savedTransmission","savedRenderOpaque","renderOpaque","savedRenderTransparent","renderTransparent","savedClearColor","clearColor","savedClearDepth","clearDepth","savedClearStencil","clearStencil","savedCommandBufferReuse","commandBufferReuse","savedProfileTexture","savedParamTexture","savedNormalTexture","profileFlags","setFramebuffer","Vector4","zero","releaseIntermediateFramebuffer","intermediateFramebuffer","releaseDepthFramebuffer","disposeRenderQueue","releaseClusteredLight","restoreSunLight","cleanupFrame","existingDepthFb","motionVectorTex","transmissionOverride","originDepth","encodeDepth","getColorAttachments","createColorState","setColorMask","forceColorState","forceCullMode","renderBackface","motionVectorTexture","linearDepthTexture","depthPrepassAttachment","_skyMVProgram","_skyMVBindGroup","_skyMVBox","fb","buildRenderProgram","vertex","pb","$inputs","pos","vec3","attrib","VPMatrix","mat4","uniform","prevVPMatrix","cameraPos","prevCameraPos","main","$l","worldPos","prevWorldPos","clipPos","mul","vec4","prevClipPos","z","w","$builtins","position","$outputs","currentPos","prevPos","fragment","motionVector","sub","div","xy","createBindGroup","bindGroupLayouts","BoxShape","needNormal","needUV","setValue","viewProjectionMatrix","getWorldPosition","prevPosition","setProgram","setBindGroup","setRenderStates","AbstractPostEffect","getDefaultRenderState","draw","blitToCurrentColorAttachment","framebuffer","destination","getColorAttachment","copyTex","isolateSceneColorDepth","savedDepthPrepassAttachment","sceneColorMaterialFlags","sceneColorFramebuffer","sceneColorStatePushed","setViewport","setScissor","sceneColorTexture","opaqueChainOutput","chainTex","executeForwardPlusGraph","RenderGraph","executor","historyFrameStarted","cullScene","HistoryResourceManager","setHistoryResourceManager","beginFrame","buildResult","compiled","compile","RenderGraphExecutor","backbufferTex","setImportedTexture","bindImportedTextures","execute","commitFrame","discardFrame","reset"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA;AAEA,MAAMA,aAAa,IAAIC,SAAAA,EAAAA;AACvB,MAAMC,aAAa,IAAIC,SAAAA,EAAAA;AACvB,MAAMC,iBAAiB,IAAIC,aAAAA,EAAAA;AAC3B,MAAMC,YAA8B,EAAE;AACtC,MAAMC,uBAAuB,IAAIC,mBAAAA,EAAAA;AACjC,IAAIC,oBAA6C,GAAA,IAAA;AACjD,IAAIC,qBAA8C,GAAA,IAAA;AAClD,MAAMC,oBACJC,oBAAqBC,CAAAA,mBAAmB,GACxCD,oBAAAA,CAAqBE,iBAAiB,GACtCF,oBAAAA,CAAqBG,iBAAiB,GACtCH,qBAAqBI,gBAAgB,GACrCJ,qBAAqBK,sBAAsB,GAC3CL,qBAAqBM,cAAc;AAErC,SAASC,iBAAAA,GAAAA;AACP,IAAA,OAAOb,UAAUc,MAAM,GAAG,IAAId,SAAUe,CAAAA,GAAG,KAAM,IAAIC,cAAAA,EAAAA;AACvD;AACA,SAASC,mBAAmBC,EAAkB,EAAA;AAC5ClB,IAAAA,SAAAA,CAAUmB,IAAI,CAACD,EAAAA,CAAAA;AACjB;AAEA,SAASE,gBAAgBC,QAAiB,EAAA;IACxC,OAAQA,QAA4DC,EAAAA,YAAAA,IAAgBD,QAAY,IAAA,IAAA;AAClG;AAEA,SAASE,mBAAmBF,QAAiB,EAAA;IAC3C,OAAO,CAAC,CAAED,eAAA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AI2G,gBAAgB,EAAE;AACxB,YAAA,MAAMgR,gBAAgB3X,GAAI2G,CAAAA,gBAAgB,CAACwL,mBAAmB,EAAE,CAAC,CAAE,CAAA;AACnE8E,YAAAA,QAAAA,CAASW,kBAAkB,CAACL,WAAY/S,CAAAA,UAAU,EAAEmT,aAAAA,CAAAA;AACtD;AACAnO,QAAAA,cAAAA,CAAeqO,oBAAoB,CAACZ,QAAAA,CAAAA;AAEpCA,QAAAA,QAAAA,CAASa,OAAO,CAACN,QAAAA,CAAAA;AACjBhO,QAAAA,cAAAA,CAAeuO,WAAW,EAAA;KAClB,QAAA;AACR,QAAA,IAAIb,mBAAqB,EAAA;YACvB1N,cAAgBwO,EAAAA,YAAAA,EAAAA;AAClB;AACA,QAAA,IAAIpT,KAAO,EAAA;YACTiN,YAAajN,CAAAA,KAAAA,CAAAA;SACR,MAAA;YACL1I,WAAawC,EAAAA,OAAAA,EAAAA;AACf;QACAuY,QAAUgB,EAAAA,KAAAA,EAAAA;AACZ;AACF;;;;"}
1
+ {"version":3,"file":"forward_plus_builder.js","sources":["../../../src/render/rendergraph/forward_plus_builder.ts"],"sourcesContent":["import type { Nullable } from '@zephyr3d/base';\r\nimport { Vector4 } from '@zephyr3d/base';\r\nimport type {\r\n BindGroup,\r\n ColorState,\r\n FrameBuffer,\r\n GPUProgram,\r\n Texture2D,\r\n Texture2DArray,\r\n TextureFormat\r\n} from '@zephyr3d/device';\r\nimport type { DrawContext } from '../drawable';\r\nimport {\r\n RenderQueue,\r\n type RenderItemList,\r\n type RenderItemListInfo,\r\n type RenderQueueItem\r\n} from '../render_queue';\r\nimport type { PunctualLight, Scene } from '../../scene';\r\nimport type { Camera } from '../../camera';\r\nimport { LightPass } from '../lightpass';\r\nimport { ShadowMapPass } from '../shadowmap_pass';\r\nimport { DepthPass } from '../depthpass';\r\nimport { ClusteredLight } from '../cluster_light';\r\nimport { ShadowMaskRenderer } from '../shadow_mask_pass';\r\nimport { buildHiZ } from '../hzb';\r\nimport { CopyBlitter } from '../../blitter';\r\nimport { fetchSampler } from '../../utility/misc';\r\nimport { MaterialVaryingFlags } from '../../values';\r\nimport { AbstractPostEffect, PostEffectLayer } from '../../posteffect/posteffect';\r\nimport { RenderGraph } from './rendergraph';\r\nimport { RenderGraphExecutor } from './executor';\r\nimport { DevicePoolAllocator } from './device_pool_allocator';\r\nimport { HistoryResourceManager } from './history_resource_manager';\r\nimport { RGHistoryResources } from './history_resources';\r\nimport { RGBlackboard, FrameResources } from './blackboard';\r\nimport type { RGExecuteContext, RGHandle } from './types';\r\nimport { renderObjectColors } from '../gpu_picking';\r\nimport type { Primitive } from '../primitive';\r\nimport { BoxShape } from '../../shapes';\r\n\r\n// ─── Shared Pass Instances ──────────────────────────────────────────\r\n\r\nconst _scenePass = new LightPass();\r\nconst _depthPass = new DepthPass();\r\nconst _shadowMapPass = new ShadowMapPass();\r\nconst _clusters: ClusteredLight[] = [];\r\nconst _shadowMaskRenderer = new ShadowMaskRenderer();\r\nconst _devicePoolAllocator = new DevicePoolAllocator();\r\nlet _backDepthColorState: Nullable<ColorState> = null;\r\nlet _frontDepthColorState: Nullable<ColorState> = null;\r\nconst SURFACE_MRT_FLAGS =\r\n MaterialVaryingFlags.SSR_STORE_ROUGHNESS |\r\n MaterialVaryingFlags.SSS_STORE_PROFILE |\r\n MaterialVaryingFlags.SSS_STORE_DIFFUSE |\r\n MaterialVaryingFlags.SSS_STORE_NORMAL |\r\n MaterialVaryingFlags.SSS_STORE_TRANSMISSION |\r\n MaterialVaryingFlags.SKIN_SSS_STORE;\r\n\r\nfunction getClusteredLight(): ClusteredLight {\r\n return _clusters.length > 0 ? _clusters.pop()! : new ClusteredLight();\r\n}\r\nfunction freeClusteredLight(cl: ClusteredLight): void {\r\n _clusters.push(cl);\r\n}\r\n\r\nfunction getCoreMaterial(material: unknown): unknown {\r\n return (material as { coreMaterial?: unknown } | null | undefined)?.coreMaterial ?? material ?? null;\r\n}\r\n\r\nfunction hasSSSMaterialCore(material: unknown): boolean {\r\n return !!(getCoreMaterial(material) as { subsurfaceProfile?: unknown } | null)?.subsurfaceProfile;\r\n}\r\n\r\nfunction hasSkinSSSMaterialCore(material: unknown): boolean {\r\n return !!(getCoreMaterial(material) as { skinSSS?: unknown } | null)?.skinSSS;\r\n}\r\n\r\nfunction renderQueueHasActiveSSS(renderQueue: RenderQueue): boolean {\r\n const itemList = renderQueue.itemList;\r\n if (!itemList) {\r\n return false;\r\n }\r\n const lists = [...itemList.opaque.lit, ...itemList.opaque.unlit];\r\n for (const list of lists) {\r\n for (const material of list.materialList) {\r\n if (hasSSSMaterialCore(material)) {\r\n return true;\r\n }\r\n }\r\n }\r\n return false;\r\n}\r\n\r\nfunction renderQueueHasActiveSkinSSS(renderQueue: RenderQueue): boolean {\r\n const itemList = renderQueue.itemList;\r\n if (!itemList) {\r\n return false;\r\n }\r\n const lists = [...itemList.opaque.lit, ...itemList.opaque.unlit];\r\n for (const list of lists) {\r\n for (const material of list.materialList) {\r\n if (hasSkinSSSMaterialCore(material)) {\r\n return true;\r\n }\r\n }\r\n }\r\n return false;\r\n}\r\n\r\nfunction filterActualSSSItemList(items: RenderQueueItem[]): RenderQueueItem[] {\r\n return items.filter((item) => hasSSSMaterialCore(item.drawable.getMaterial?.()));\r\n}\r\n\r\nfunction filterActualSSSMaterialList(materialList: Set<any>): Set<any> {\r\n const filtered = new Set<any>();\r\n materialList.forEach((mat) => {\r\n if (hasSSSMaterialCore(mat)) {\r\n filtered.add(mat);\r\n }\r\n });\r\n return filtered;\r\n}\r\n\r\nfunction cloneActualSSSListInfo(source: RenderItemListInfo, _targetQueue: RenderQueue): RenderItemListInfo {\r\n return {\r\n itemList: filterActualSSSItemList(source.itemList),\r\n skinItemList: filterActualSSSItemList(source.skinItemList),\r\n morphItemList: filterActualSSSItemList(source.morphItemList),\r\n skinAndMorphItemList: filterActualSSSItemList(source.skinAndMorphItemList),\r\n instanceItemList: filterActualSSSItemList(source.instanceItemList),\r\n materialList: filterActualSSSMaterialList(source.materialList),\r\n instanceList: {},\r\n renderQueue: source.renderQueue\r\n };\r\n}\r\n\r\nfunction cloneActualSSSBundle(\r\n source: RenderItemList['opaque'],\r\n targetQueue: RenderQueue\r\n): RenderItemList['opaque'] {\r\n return {\r\n lit: source.lit.map((info) => cloneActualSSSListInfo(info, targetQueue)),\r\n unlit: source.unlit.map((info) => cloneActualSSSListInfo(info, targetQueue))\r\n };\r\n}\r\n\r\nfunction hasAnyActualSSSItems(renderItems: RenderItemListInfo[]): boolean {\r\n return renderItems.some(\r\n (info) =>\r\n info.itemList.length > 0 ||\r\n info.skinItemList.length > 0 ||\r\n info.morphItemList.length > 0 ||\r\n info.skinAndMorphItemList.length > 0 ||\r\n info.instanceItemList.length > 0\r\n );\r\n}\r\n\r\nfunction createActualSSSRenderQueue(renderQueue: RenderQueue): RenderQueue | null {\r\n const itemList = renderQueue.itemList;\r\n if (!itemList) {\r\n return null;\r\n }\r\n const queue = new RenderQueue(_scenePass);\r\n const sssOpaque = cloneActualSSSBundle(itemList.opaque, queue);\r\n if (!hasAnyActualSSSItems([...sssOpaque.lit, ...sssOpaque.unlit])) {\r\n queue.dispose();\r\n return null;\r\n }\r\n const emptyBundle = { lit: [], unlit: [] };\r\n const target = queue as unknown as {\r\n _itemList: RenderItemList;\r\n _shadowedLightList: PunctualLight[];\r\n _unshadowedLightList: PunctualLight[];\r\n _sunLight: typeof renderQueue.sunLight;\r\n _primaryDirectionalLight: typeof renderQueue.primaryDirectionalLight;\r\n _primaryTransmissionLight: typeof renderQueue.primaryTransmissionLight;\r\n _needSceneColor: boolean;\r\n _needSceneDepth: boolean;\r\n _needSceneColorWithDepth: boolean;\r\n _drawTransparent: boolean;\r\n };\r\n target._itemList = {\r\n opaque: sssOpaque,\r\n transmission: emptyBundle,\r\n transparent: emptyBundle,\r\n transmission_trans: emptyBundle\r\n };\r\n target._shadowedLightList = renderQueue.shadowedLights;\r\n target._unshadowedLightList = renderQueue.unshadowedLights;\r\n target._sunLight = renderQueue.sunLight;\r\n target._primaryDirectionalLight = renderQueue.primaryDirectionalLight;\r\n target._primaryTransmissionLight = renderQueue.primaryTransmissionLight;\r\n target._needSceneColor = false;\r\n target._needSceneDepth = false;\r\n target._needSceneColorWithDepth = false;\r\n target._drawTransparent = false;\r\n return queue;\r\n}\r\n\r\nfunction getSurfaceTextureFormat(ctx: DrawContext): TextureFormat {\r\n const caps = ctx.device.getDeviceCaps?.();\r\n return caps?.textureCaps.supportHalfFloatColorBuffer ? 'rgba16f' : 'rgba8unorm';\r\n}\r\n\r\nfunction getTextureFormatBytes(ctx: DrawContext, format: TextureFormat): number {\r\n return ctx.device.getDeviceCaps().textureCaps.getTextureFormatInfo(format).size;\r\n}\r\n\r\nfunction shouldStoreSSSDiffuse(ctx: DrawContext): boolean {\r\n return ctx.camera.sssStrength > 0 && ctx.camera.sssBlurScale > 0;\r\n}\r\n\r\nfunction shouldStoreSSSTransmission(ctx: DrawContext): boolean {\r\n return ctx.camera.sssStrength > 0 && ctx.camera.sssTransmissionStrength > 0;\r\n}\r\n\r\nfunction getSSSLightingTextureFormat(\r\n ctx: DrawContext,\r\n attachmentCount: number,\r\n includeSSRSurfaceMRT: boolean\r\n): TextureFormat {\r\n const colorFormat = ctx.colorFormat!;\r\n if (!includeSSRSurfaceMRT || attachmentCount === 0) {\r\n return colorFormat;\r\n }\r\n const caps = ctx.device.getDeviceCaps();\r\n // The SSR roughness/normal MRT textures use the glossy surface format; they\r\n // are graph textures now, so derive the format directly instead of reading\r\n // the (not yet resolved) DrawContext fields.\r\n const surfaceFormat = getSurfaceTextureFormat(ctx);\r\n const colorBytes =\r\n getTextureFormatBytes(ctx, colorFormat) +\r\n getTextureFormatBytes(ctx, surfaceFormat) +\r\n getTextureFormatBytes(ctx, surfaceFormat);\r\n const fullPrecisionBytes = colorBytes + getTextureFormatBytes(ctx, colorFormat) * attachmentCount;\r\n if (fullPrecisionBytes <= caps.framebufferCaps.maxColorAttachmentBytesPerSample) {\r\n return colorFormat;\r\n }\r\n return 'rgba8unorm';\r\n}\r\n\r\nfunction getFullMipLevelCount(width: number, height: number): number {\r\n return Math.max(1, Math.floor(Math.log2(Math.max(1, width, height))) + 1);\r\n}\r\n\r\nfunction hasSurfaceMRT(ctx: DrawContext): boolean {\r\n return !!(ctx.materialFlags & SURFACE_MRT_FLAGS);\r\n}\r\n\r\nfunction getLightPassColorAttachments(\r\n ctx: DrawContext,\r\n colorAttachment: TextureFormat | Texture2D\r\n): TextureFormat | Texture2D | Array<TextureFormat | Texture2D> {\r\n const attachments: Array<TextureFormat | Texture2D> = [colorAttachment];\r\n if (ctx.materialFlags & MaterialVaryingFlags.SSR_STORE_ROUGHNESS) {\r\n attachments.push(ctx.SSRRoughnessTexture!, ctx.SSRNormalTexture!);\r\n } else if (ctx.materialFlags & MaterialVaryingFlags.SSS_STORE_NORMAL) {\r\n attachments.push(ctx.SSRNormalTexture!);\r\n }\r\n if (ctx.materialFlags & MaterialVaryingFlags.SSS_STORE_PROFILE) {\r\n attachments.push(ctx.SSSProfileTexture!, ctx.SSSParamTexture!);\r\n }\r\n if (ctx.materialFlags & MaterialVaryingFlags.SSS_STORE_DIFFUSE) {\r\n attachments.push(ctx.SSSDiffuseTexture!);\r\n }\r\n if (ctx.materialFlags & MaterialVaryingFlags.SSS_STORE_TRANSMISSION) {\r\n attachments.push(ctx.SSSTransmissionTexture!);\r\n }\r\n if (ctx.materialFlags & MaterialVaryingFlags.SKIN_SSS_STORE) {\r\n attachments.push(ctx.SkinSSSTexture!);\r\n }\r\n return attachments.length === 1 ? attachments[0] : attachments;\r\n}\r\n\r\n// ─── Pipeline Options ───────────────────────────────────────────────\r\n\r\n/**\r\n * Options controlling which features are enabled in the forward+ pipeline.\r\n *\r\n * Derived from camera settings and device capabilities each frame.\r\n *\r\n * @public\r\n */\r\nexport interface ForwardPlusOptions {\r\n /** Enable depth prepass (always true for now). */\r\n depthPrepass: boolean;\r\n /** Enable motion vectors (requires TAA or motionBlur). */\r\n motionVectors: boolean;\r\n /** Enable Hi-Z pyramid (for SSR ray tracing). */\r\n hiZ: boolean;\r\n /** Enable screen-space reflections. */\r\n ssr: boolean;\r\n /** Whether to compute SSR thickness. */\r\n ssrCalcThickness: boolean;\r\n /** Whether GPU picking is requested this frame. */\r\n gpuPicking: boolean;\r\n /** Whether transmission/refraction materials are present. */\r\n needSceneColor: boolean;\r\n /** Whether scene-color-dependent materials also require scene depth. */\r\n needSceneColorWithDepth: boolean;\r\n /** Whether SSR needs transmission depth before the main light pass. */\r\n needsTransmissionDepthForSSR: boolean;\r\n /** Enable screen-space subsurface scattering. */\r\n sss: boolean;\r\n /** Enable the stylized skin-specific SSS pass. */\r\n skinSSS: boolean;\r\n}\r\n\r\n/**\r\n * Derive pipeline options from the current scene/camera state.\r\n * @internal\r\n */\r\nexport function deriveForwardPlusOptions(\r\n scene: Scene,\r\n camera: Camera,\r\n deviceType: string,\r\n renderQueue: RenderQueue\r\n): ForwardPlusOptions {\r\n const ssr = camera.SSR && scene.env.light.envLight && scene.env.light.envLight.hasRadiance();\r\n const sss = camera.SSS && renderQueueHasActiveSSS(renderQueue);\r\n const skinSSS = camera.skinSSS && renderQueueHasActiveSkinSSS(renderQueue);\r\n const needSceneColor = renderQueue.needSceneColor();\r\n const needSceneColorWithDepth = renderQueue.needSceneColorWithDepth();\r\n return {\r\n depthPrepass: true,\r\n motionVectors:\r\n deviceType !== 'webgl' && (camera.TAA || camera.motionBlur || (!!ssr && camera.ssrTemporal)),\r\n hiZ: camera.HiZ && deviceType !== 'webgl',\r\n ssr: !!ssr,\r\n ssrCalcThickness: !!ssr && camera.ssrCalcThickness,\r\n gpuPicking: !!camera.getPickResultResolveFunc(),\r\n needSceneColor,\r\n needSceneColorWithDepth,\r\n needsTransmissionDepthForSSR: !!ssr && needSceneColor && !needSceneColorWithDepth,\r\n sss: !!sss,\r\n skinSSS: !!skinSSS\r\n };\r\n}\r\n\r\n// ─── Shared Frame State ─────────────────────────────────────────────\r\n\r\n/**\r\n * Mutable state shared between pass execute callbacks within a single frame.\r\n *\r\n * This replaces the monolithic DrawContext mutation pattern with an explicit\r\n * object that graph passes can read from and write to.\r\n *\r\n * @internal\r\n */\r\nexport interface FrameState {\r\n ctx: DrawContext;\r\n renderQueue: RenderQueue;\r\n depthFramebuffer: Nullable<FrameBuffer>;\r\n sunLightColor: Nullable<any>;\r\n options: ForwardPlusOptions;\r\n renderQueueDisposed: boolean;\r\n clusteredLightReleased: boolean;\r\n sunLightRestored: boolean;\r\n}\r\n\r\ninterface ForwardPlusGraphBuildResult {\r\n backbuffer: RGHandle;\r\n frame: FrameState;\r\n}\r\n\r\ninterface HistoryReadBinding {\r\n name: string;\r\n handle: RGHandle;\r\n}\r\n\r\ninterface SSSProfilePassResult {\r\n profileHandle: RGHandle;\r\n paramHandle: RGHandle;\r\n normalHandle?: RGHandle;\r\n framebufferHandle: RGHandle;\r\n}\r\n\r\n// ─── Forward+ Graph Builder ─────────────────────────────────────────\r\n\r\n/**\r\n * Constructs a render graph representing the forward+ pipeline.\r\n *\r\n * Each step in the existing `SceneRenderer._renderScene` becomes a graph pass.\r\n * Execute callbacks delegate to the existing rendering code, sharing a mutable\r\n * `FrameState`.\r\n *\r\n * @param graph - The render graph to populate.\r\n * @param ctx - The draw context for this frame.\r\n * @param renderQueue - The culled render queue.\r\n * @param options - Pipeline feature toggles.\r\n * @returns The backbuffer handle (graph output).\r\n *\r\n * @public\r\n */\r\nexport function buildForwardPlusGraph(\r\n graph: RenderGraph,\r\n ctx: DrawContext,\r\n renderQueue: RenderQueue,\r\n options: ForwardPlusOptions\r\n): RGHandle {\r\n return buildForwardPlusGraphInternal(graph, ctx, renderQueue, options).backbuffer;\r\n}\r\n\r\nfunction buildForwardPlusGraphInternal(\r\n graph: RenderGraph,\r\n ctx: DrawContext,\r\n renderQueue: RenderQueue,\r\n options: ForwardPlusOptions\r\n): ForwardPlusGraphBuildResult {\r\n const backbuffer = graph.importTexture('backbuffer');\r\n ctx.SSS = !!options.sss;\r\n ctx.SkinSSSTexture = null;\r\n\r\n // Named registry of shared frame resources (consumed by post effect setup)\r\n const blackboard = new RGBlackboard();\r\n\r\n // Shared mutable frame state\r\n const frame: FrameState = {\r\n ctx,\r\n renderQueue,\r\n depthFramebuffer: null,\r\n sunLightColor: null,\r\n options,\r\n renderQueueDisposed: false,\r\n clusteredLightReleased: false,\r\n sunLightRestored: false\r\n };\r\n\r\n // ── 1. Sky Update ─────────────────────────────────────────────────\r\n let orderToken = graph.addPass('SkyUpdate', (builder) => {\r\n const done = builder.createToken('SkyUpdateDone');\r\n builder.sideEffect();\r\n builder.setExecute(() => {\r\n frame.sunLightColor = ctx.scene.env.sky.update(ctx);\r\n });\r\n return done;\r\n });\r\n\r\n // ── 2. Clustered Light Setup ──────────────────────────────────────\r\n orderToken = graph.addPass('ClusterLights', (builder) => {\r\n builder.read(orderToken);\r\n const done = builder.createToken('ClusterLightsDone');\r\n builder.sideEffect();\r\n builder.setExecute(() => {\r\n ctx.clusteredLight = getClusteredLight();\r\n ctx.clusteredLight.calculateLightIndex(ctx.camera, renderQueue);\r\n });\r\n return done;\r\n });\r\n\r\n // ── 3. GPU Picking (optional, sideEffect) ─────────────────────────\r\n if (options.gpuPicking) {\r\n orderToken = graph.addPass('GPUPicking', (builder) => {\r\n builder.read(orderToken);\r\n const done = builder.createToken('GPUPickingDone');\r\n builder.sideEffect();\r\n builder.setExecute(() => {\r\n const pickResolveFunc = ctx.camera.getPickResultResolveFunc();\r\n if (pickResolveFunc) {\r\n renderObjectColors(ctx, pickResolveFunc, renderQueue);\r\n }\r\n });\r\n return done;\r\n });\r\n }\r\n\r\n // ── 4. Shadow Maps ────────────────────────────────────────────────\r\n // Shadow maps are managed internally by lights, mark as side effect\r\n if (renderQueue.shadowedLights.length > 0) {\r\n orderToken = graph.addPass('ShadowMaps', (builder) => {\r\n builder.read(orderToken);\r\n const done = builder.createToken('ShadowMapsDone');\r\n builder.sideEffect();\r\n builder.setExecute(() => {\r\n renderShadowMaps(ctx, renderQueue.shadowedLights);\r\n });\r\n return done;\r\n });\r\n }\r\n\r\n // ── 5. Depth Prepass ──────────────────────────────────────────────\r\n // Declare transient depth and motion vector textures\r\n const depthPassResult = graph.addPass('DepthPrepass', (builder) => {\r\n builder.read(orderToken);\r\n const format: TextureFormat =\r\n ctx.device.type === 'webgl'\r\n ? ctx.SSRCalcThickness\r\n ? 'rgba16f'\r\n : 'rgba8unorm'\r\n : ctx.SSRCalcThickness\r\n ? 'rg32f'\r\n : 'r32f';\r\n const mvFormat: TextureFormat = 'rgba16f';\r\n\r\n const depthHandle = builder.createTexture({ format, label: 'linearDepth' });\r\n const motionVectorHandle = options.motionVectors\r\n ? builder.createTexture({ format: mvFormat, label: 'motionVector' })\r\n : undefined;\r\n const finalDepthAttachment = ctx.finalFramebuffer?.getDepthAttachment();\r\n const externalDepthAttachment = finalDepthAttachment?.isTexture2D()\r\n ? (finalDepthAttachment as Texture2D)\r\n : null;\r\n const graphDepthAttachmentHandle = externalDepthAttachment\r\n ? undefined\r\n : builder.createTexture({ format: ctx.depthFormat, label: 'sceneDepth' });\r\n const depthAttachmentOrFormat = externalDepthAttachment ?? graphDepthAttachmentHandle ?? ctx.depthFormat;\r\n const depthFramebufferHandle = builder.createFramebuffer({\r\n label: 'DepthPrepassFramebuffer',\r\n width: ctx.renderWidth,\r\n height: ctx.renderHeight,\r\n colorAttachments: motionVectorHandle ? [depthHandle, motionVectorHandle] : depthHandle,\r\n depthAttachment: depthAttachmentOrFormat,\r\n ignoreDepthStencil: false\r\n });\r\n const skyMotionVectorFramebufferHandle = motionVectorHandle\r\n ? builder.createFramebuffer({\r\n label: 'SkyMotionVectorFramebuffer',\r\n width: ctx.renderWidth,\r\n height: ctx.renderHeight,\r\n colorAttachments: motionVectorHandle,\r\n depthAttachment: depthAttachmentOrFormat\r\n })\r\n : undefined;\r\n\r\n builder.addSubpass('SceneDepth', (rgCtx) => {\r\n const depthFramebuffer = rgCtx.getFramebuffer<FrameBuffer>(depthFramebufferHandle);\r\n frame.depthFramebuffer = renderSceneDepth(frame, depthFramebuffer, rgCtx, undefined, undefined, false);\r\n });\r\n if (skyMotionVectorFramebufferHandle) {\r\n builder.addSubpass('SkyMotionVectors', (rgCtx) => {\r\n renderSkyMotionVectors(ctx, rgCtx, skyMotionVectorFramebufferHandle);\r\n });\r\n }\r\n\r\n return {\r\n depthHandle,\r\n motionVectorHandle,\r\n graphDepthAttachmentHandle,\r\n externalDepthAttachment,\r\n depthFramebufferHandle\r\n };\r\n });\r\n\r\n let depthHandle = depthPassResult.depthHandle;\r\n const motionVectorHandle = depthPassResult.motionVectorHandle;\r\n blackboard.set(FrameResources.LinearDepth, depthHandle);\r\n if (motionVectorHandle) {\r\n blackboard.set(FrameResources.MotionVector, motionVectorHandle);\r\n }\r\n if (depthPassResult.graphDepthAttachmentHandle) {\r\n blackboard.set(FrameResources.SceneDepthAttachment, depthPassResult.graphDepthAttachmentHandle);\r\n }\r\n\r\n // ── Screen-space shadow mask ────────────────────────────────────────────\r\n // When active, render each shadow-casting light's visibility into an RGBA8\r\n // texture array (4 lights per layer). The clustered LightPass samples this\r\n // mask instead of each shadowed light running its own additive pass. The\r\n // layer/channel order is locked to ClusteredLight.getVisibleLights: shadow\r\n // lights fill clustered buffer indices 1..N in renderQueue.shadowedLights\r\n // order, and ordinal s = index-1 maps to layer s>>2, channel s&3.\r\n let shadowMaskHandle: RGHandle | null = null;\r\n // Reset any mask carried over from a previous frame; the pass below re-sets it\r\n // during execution only when the mask is actually produced.\r\n ctx.shadowMaskTexture = null;\r\n // Gate on build-time state only: renderQueue.shadowedLights is available now,\r\n // whereas ctx.shadowMapInfo is populated later by the ShadowMaps pass execute\r\n // (which runs before this pass thanks to the orderToken chain), so it must not\r\n // be part of the pass-creation condition.\r\n const useShadowMask = ctx.screenSpaceShadowMask && renderQueue.shadowedLights.length > 0;\r\n if (useShadowMask) {\r\n const numShadowLights = renderQueue.shadowedLights.length;\r\n const numLayers = ShadowMaskRenderer.getLayerCount(numShadowLights);\r\n const maskPassResult = graph.addPass('ShadowMaskPass', (builder) => {\r\n // Freeze the current linear-depth handle at build time. `depthHandle` is a\r\n // mutable `let` that a later TransmissionDepth pass reassigns to a new\r\n // version ('linearDepth@TransmissionDepth'); if the execute closure below\r\n // captured it by reference it would read a handle this pass never declared,\r\n // tripping RenderGraphExecutor's access assertion. The shadow mask is built\r\n // from the opaque prepass depth, so the pre-transmission version is correct.\r\n const maskDepthHandle = depthHandle;\r\n builder.read(maskDepthHandle);\r\n builder.read(depthPassResult.depthFramebufferHandle);\r\n // createTexture already registers this pass as the resource producer, so\r\n // downstream passes read this handle directly (same pattern as HiZ). The\r\n // per-layer framebuffers are created inside execute (rgCtx.createFramebuffer),\r\n // which the graph cannot see; the createTexture producer edge is what keeps\r\n // the resource alive and ordered before the LightPass reader.\r\n const maskHandle = builder.createTexture({\r\n format: 'rgba8unorm',\r\n label: 'shadowMask',\r\n arrayLayers: numLayers\r\n });\r\n builder.setExecute((rgCtx) => {\r\n const depthTex = rgCtx.getTexture<Texture2D>(maskDepthHandle);\r\n const maskTex = rgCtx.getTexture<Texture2DArray>(maskHandle);\r\n _shadowMaskRenderer.render(ctx, depthTex, renderQueue.shadowedLights, (layer) =>\r\n rgCtx.createFramebuffer<FrameBuffer>({\r\n width: maskTex.width,\r\n height: maskTex.height,\r\n colorAttachments: maskTex,\r\n depthAttachment: null,\r\n attachmentLayer: layer\r\n })\r\n );\r\n ctx.shadowMaskTexture = maskTex;\r\n });\r\n return { maskHandle };\r\n });\r\n shadowMaskHandle = maskPassResult.maskHandle;\r\n blackboard.set(FrameResources.ShadowMask, shadowMaskHandle);\r\n }\r\n const renderDepthAttachment =\r\n depthPassResult.graphDepthAttachmentHandle ?? depthPassResult.externalDepthAttachment ?? null;\r\n // Rendering the scene directly into the final framebuffer is only possible\r\n // when no opaque-layer effect is enabled: those effects must sample the\r\n // opaque scene color as a texture and may require surface MRT attachments\r\n // (SSR roughness / SSS / SkinSSS), which the single-color final framebuffer\r\n // cannot carry. The legacy compositor.begin() used to redirect rendering to\r\n // a temporal MRT framebuffer in that case; the graph path uses the regular\r\n // scene color texture pipeline instead.\r\n const opaqueLayerHasEffects = !!ctx.compositor?.layerHasEnabledEffect(PostEffectLayer.opaque);\r\n const useFinalFramebufferAsIntermediate =\r\n !!depthPassResult.externalDepthAttachment &&\r\n depthPassResult.externalDepthAttachment === ctx.finalFramebuffer?.getDepthAttachment() &&\r\n !opaqueLayerHasEffects;\r\n\r\n let preLightTransmissionDepthToken: RGHandle | undefined;\r\n if (options.needsTransmissionDepthForSSR) {\r\n const transmissionDepthResult = graph.addPass('TransmissionDepthForSSR', (builder) => {\r\n builder.read(depthHandle);\r\n builder.read(depthPassResult.depthFramebufferHandle);\r\n // This pass renders transmission geometry into the prepass linear-depth\r\n // texture: model the mutation as a write so later readers order against\r\n // it through data flow instead of relying on the token alone.\r\n const depthOut = builder.write(depthHandle);\r\n const done = builder.createToken('TransmissionDepthForSSRDone');\r\n builder.sideEffect();\r\n builder.setExecute((rgCtx) => {\r\n renderTransmissionDepthPass(frame, rgCtx);\r\n });\r\n return { done, depthOut };\r\n });\r\n preLightTransmissionDepthToken = transmissionDepthResult.done;\r\n depthHandle = transmissionDepthResult.depthOut;\r\n // Re-register so blackboard consumers read the post-transmission version.\r\n blackboard.set(FrameResources.LinearDepth, depthHandle);\r\n }\r\n\r\n // ── 6. Hi-Z (optional) ───────────────────────────────────────────\r\n let hiZHandle: RGHandle | undefined;\r\n if (options.hiZ) {\r\n graph.addPass('HiZ', (builder) => {\r\n builder.read(depthHandle!);\r\n builder.read(depthPassResult.depthFramebufferHandle);\r\n if (preLightTransmissionDepthToken) {\r\n builder.read(preLightTransmissionDepthToken);\r\n }\r\n hiZHandle = builder.createTexture({\r\n format: 'rg32f',\r\n label: 'hiZ',\r\n mipLevels: getFullMipLevelCount(ctx.renderWidth, ctx.renderHeight)\r\n });\r\n const hiZFramebufferHandle = builder.createFramebuffer({\r\n label: 'HiZFramebuffer',\r\n colorAttachments: hiZHandle,\r\n depthAttachment: null\r\n });\r\n builder.setExecute((rgCtx) => {\r\n const ctx = frame.ctx;\r\n // Use the depth texture from the framebuffer (which contains the RenderGraph texture)\r\n const depthTex = frame.depthFramebuffer?.getDepthAttachment() as Texture2D;\r\n if (depthTex) {\r\n // Get the HiZ texture allocated by the executor\r\n const hiZTex = rgCtx.getTexture<Texture2D>(hiZHandle!);\r\n const HiZFrameBuffer = rgCtx.getFramebuffer<FrameBuffer>(hiZFramebufferHandle);\r\n buildHiZ(depthTex, HiZFrameBuffer);\r\n ctx.HiZTexture = hiZTex;\r\n }\r\n });\r\n });\r\n if (hiZHandle) {\r\n blackboard.set(FrameResources.HiZ, hiZHandle);\r\n }\r\n }\r\n\r\n // ── 7. Main Light Pass ────────────────────────────────────────────\r\n const historyManager = ctx.camera?.getHistoryResourceManager?.() ?? null;\r\n const lightHistoryReadBindings: HistoryReadBinding[] = [];\r\n const historySize = { width: ctx.renderWidth, height: ctx.renderHeight };\r\n if (historyManager && options.ssr && ctx.camera?.ssrTemporal && options.motionVectors) {\r\n const reflectHistoryHandle = historyManager.importPreviousIfCompatible(\r\n graph,\r\n RGHistoryResources.SSR_REFLECT,\r\n {\r\n format: 'rgba16f',\r\n sizeMode: 'absolute',\r\n width: ctx.renderWidth,\r\n height: ctx.renderHeight\r\n },\r\n historySize\r\n );\r\n const motionVectorHistoryHandle = historyManager.importPreviousIfCompatible(\r\n graph,\r\n RGHistoryResources.SSR_MOTION_VECTOR,\r\n {\r\n format: 'rgba16f',\r\n sizeMode: 'absolute',\r\n width: ctx.renderWidth,\r\n height: ctx.renderHeight\r\n },\r\n historySize\r\n );\r\n if (reflectHistoryHandle && motionVectorHistoryHandle) {\r\n lightHistoryReadBindings.push(\r\n { name: RGHistoryResources.SSR_REFLECT, handle: reflectHistoryHandle },\r\n { name: RGHistoryResources.SSR_MOTION_VECTOR, handle: motionVectorHistoryHandle }\r\n );\r\n }\r\n }\r\n // Note: TAA history import/commit is handled by TAA.setup() (self-describing).\r\n\r\n let sssProfileResult: SSSProfilePassResult | undefined;\r\n if (options.sss) {\r\n sssProfileResult = graph.addPass('SSSProfile', (builder) => {\r\n builder.read(depthHandle);\r\n builder.read(depthPassResult.depthFramebufferHandle);\r\n if (preLightTransmissionDepthToken) {\r\n builder.read(preLightTransmissionDepthToken);\r\n }\r\n const profileHandle = builder.createTexture({ format: 'rgba16f', label: 'sssProfile' });\r\n const paramHandle = builder.createTexture({ format: 'rgba8unorm', label: 'sssParam' });\r\n const normalHandle = options.ssr\r\n ? undefined\r\n : builder.createTexture({ format: getSurfaceTextureFormat(ctx), label: 'sssNormal' });\r\n const colorAttachments = normalHandle\r\n ? [ctx.colorFormat!, normalHandle, profileHandle, paramHandle]\r\n : [ctx.colorFormat!, profileHandle, paramHandle];\r\n const framebufferHandle = builder.createFramebuffer({\r\n label: 'SSSProfileFramebuffer',\r\n width: ctx.renderWidth,\r\n height: ctx.renderHeight,\r\n colorAttachments,\r\n depthAttachment: renderDepthAttachment,\r\n ignoreDepthStencil: false\r\n });\r\n\r\n builder.setExecute((rgCtx) => {\r\n renderForwardSSSProfile(\r\n frame,\r\n rgCtx.getFramebuffer<FrameBuffer>(framebufferHandle),\r\n rgCtx.getTexture<Texture2D>(profileHandle),\r\n rgCtx.getTexture<Texture2D>(paramHandle),\r\n normalHandle ? rgCtx.getTexture<Texture2D>(normalHandle) : null\r\n );\r\n });\r\n\r\n return {\r\n profileHandle,\r\n paramHandle,\r\n normalHandle,\r\n framebufferHandle\r\n };\r\n });\r\n }\r\n\r\n // 7b. Scene color grab: renders the full scene (no transmission) into a copy\r\n // texture that transmission/refraction materials sample as background.\r\n // Extracted from the former monolithic light pass.\r\n let grabResult: { copyHandle: RGHandle; copyFramebufferHandle?: RGHandle } | undefined;\r\n if (options.needSceneColor) {\r\n grabResult = graph.addPass('SceneColorGrab', (builder) => {\r\n builder.read(depthHandle);\r\n builder.read(depthPassResult.depthFramebufferHandle);\r\n if (preLightTransmissionDepthToken) {\r\n builder.read(preLightTransmissionDepthToken);\r\n }\r\n const copyHandle = builder.createTexture({\r\n format: ctx.colorFormat!,\r\n label: 'sceneColorCopy'\r\n });\r\n // SSR may pre-insert transmission depth before LightPass for Hi-Z. In that\r\n // case the refraction scene-color copy needs an isolated depth buffer so\r\n // transmission surfaces do not occlude the background they sample.\r\n const copyFramebufferHandle = !options.needsTransmissionDepthForSSR\r\n ? builder.createFramebuffer({\r\n label: 'SceneColorCopyFramebuffer',\r\n width: ctx.renderWidth,\r\n height: ctx.renderHeight,\r\n colorAttachments: copyHandle,\r\n depthAttachment: renderDepthAttachment,\r\n ignoreDepthStencil: false\r\n })\r\n : undefined;\r\n builder.setExecute((rgCtx) => {\r\n renderSceneColorGrab(frame, rgCtx, copyHandle, copyFramebufferHandle);\r\n });\r\n return { copyHandle, copyFramebufferHandle };\r\n });\r\n }\r\n\r\n const lightPassResult = graph.addPass('LightPass', (builder) => {\r\n builder.read(depthHandle);\r\n builder.read(depthPassResult.depthFramebufferHandle);\r\n if (shadowMaskHandle) {\r\n builder.read(shadowMaskHandle);\r\n }\r\n if (preLightTransmissionDepthToken) {\r\n builder.read(preLightTransmissionDepthToken);\r\n }\r\n if (hiZHandle) {\r\n builder.read(hiZHandle);\r\n }\r\n for (const binding of lightHistoryReadBindings) {\r\n builder.read(binding.handle);\r\n }\r\n\r\n // Scene color: in final-framebuffer-as-intermediate mode the scene is\r\n // physically rendered into the final framebuffer, so declare the\r\n // backbuffer write — the graph sees the real data flow and no keep-alive\r\n // reads are needed downstream. Otherwise render into a graph texture.\r\n const sceneColorHandle = useFinalFramebufferAsIntermediate\r\n ? builder.write(backbuffer)\r\n : builder.createTexture({\r\n format: ctx.colorFormat!,\r\n label: 'sceneColor'\r\n });\r\n\r\n // Transmission/refraction background produced by the SceneColorGrab pass\r\n const sceneColorCopyHandle = grabResult?.copyHandle;\r\n if (sceneColorCopyHandle) {\r\n builder.read(sceneColorCopyHandle);\r\n }\r\n if (sssProfileResult) {\r\n builder.read(sssProfileResult.profileHandle);\r\n builder.read(sssProfileResult.paramHandle);\r\n if (sssProfileResult.normalHandle) {\r\n builder.read(sssProfileResult.normalHandle);\r\n }\r\n }\r\n const includeSSRSurfaceMRT = !!options.ssr;\r\n // SSR glossy-surface MRT outputs (roughness + world normal) are graph\r\n // textures owned by this pass; effects reach them through the blackboard\r\n // handles (or the ctx fields resolved below during execution).\r\n const ssrRoughnessHandle = includeSSRSurfaceMRT\r\n ? builder.createTexture({ format: getSurfaceTextureFormat(ctx), label: 'ssrRoughness' })\r\n : undefined;\r\n const ssrNormalHandle = includeSSRSurfaceMRT\r\n ? builder.createTexture({ format: getSurfaceTextureFormat(ctx), label: 'ssrNormal' })\r\n : undefined;\r\n const writeSSSDiffuse = options.sss && shouldStoreSSSDiffuse(ctx);\r\n let writeSSSTransmission = options.sss && shouldStoreSSSTransmission(ctx);\r\n if (\r\n writeSSSDiffuse &&\r\n writeSSSTransmission &&\r\n includeSSRSurfaceMRT &&\r\n getSSSLightingTextureFormat(ctx, 2, includeSSRSurfaceMRT) !== ctx.colorFormat\r\n ) {\r\n writeSSSTransmission = false;\r\n }\r\n const writeSkinSSS = options.skinSSS;\r\n const sssLightingAttachmentCount =\r\n (writeSSSDiffuse ? 1 : 0) + (writeSSSTransmission ? 1 : 0) + (writeSkinSSS ? 1 : 0);\r\n const sssLightingFormat = getSSSLightingTextureFormat(\r\n ctx,\r\n sssLightingAttachmentCount,\r\n includeSSRSurfaceMRT\r\n );\r\n const sssDiffuseHandle = writeSSSDiffuse\r\n ? builder.createTexture({ format: sssLightingFormat, label: 'sssDiffuse' })\r\n : undefined;\r\n const sssTransmissionHandle = writeSSSTransmission\r\n ? builder.createTexture({ format: sssLightingFormat, label: 'sssTransmission' })\r\n : undefined;\r\n const skinSSSHandle = writeSkinSSS\r\n ? builder.createTexture({ format: sssLightingFormat, label: 'skinSSS' })\r\n : undefined;\r\n const sceneColorFramebufferHandle = useFinalFramebufferAsIntermediate\r\n ? undefined\r\n : builder.createFramebuffer({\r\n label: 'SceneColorFramebuffer',\r\n width: ctx.renderWidth,\r\n height: ctx.renderHeight,\r\n colorAttachments: sceneColorHandle,\r\n depthAttachment: renderDepthAttachment\r\n });\r\n\r\n builder.setExecute((rgCtx) => {\r\n const sceneColorTex = rgCtx.getTexture<Texture2D>(sceneColorHandle);\r\n const sceneColorCopyTex = sceneColorCopyHandle\r\n ? rgCtx.getTexture<Texture2D>(sceneColorCopyHandle)\r\n : null;\r\n // Resolve MRT products into the DrawContext bridge fields that scene\r\n // rendering and apply()-based effects still read.\r\n ctx.SSRRoughnessTexture = ssrRoughnessHandle ? rgCtx.getTexture<Texture2D>(ssrRoughnessHandle) : null;\r\n ctx.SSRNormalTexture = ssrNormalHandle ? rgCtx.getTexture<Texture2D>(ssrNormalHandle) : null;\r\n if (sssProfileResult) {\r\n ctx.SSSProfileTexture = rgCtx.getTexture<Texture2D>(sssProfileResult.profileHandle);\r\n ctx.SSSParamTexture = rgCtx.getTexture<Texture2D>(sssProfileResult.paramHandle);\r\n if (sssProfileResult.normalHandle) {\r\n ctx.SSRNormalTexture = rgCtx.getTexture<Texture2D>(sssProfileResult.normalHandle);\r\n }\r\n }\r\n ctx.SSSDiffuseTexture = sssDiffuseHandle ? rgCtx.getTexture<Texture2D>(sssDiffuseHandle) : null;\r\n ctx.SSSTransmissionTexture = sssTransmissionHandle\r\n ? rgCtx.getTexture<Texture2D>(sssTransmissionHandle)\r\n : null;\r\n ctx.SkinSSSTexture = skinSSSHandle ? rgCtx.getTexture<Texture2D>(skinSSSHandle) : null;\r\n const renderLightPass = () =>\r\n renderOpaqueScenePass(frame, sceneColorTex, sceneColorCopyTex, rgCtx, sceneColorFramebufferHandle);\r\n if (historyManager && lightHistoryReadBindings.length > 0) {\r\n historyManager.beginReadScope(\r\n lightHistoryReadBindings.map((binding) => ({\r\n name: binding.name,\r\n texture: rgCtx.getTexture<Texture2D>(binding.handle)\r\n }))\r\n );\r\n try {\r\n renderLightPass();\r\n } finally {\r\n historyManager.endReadScope();\r\n }\r\n } else {\r\n renderLightPass();\r\n }\r\n });\r\n\r\n return {\r\n sceneColorHandle,\r\n sceneColorCopyHandle,\r\n sceneColorFramebufferHandle,\r\n ssrRoughnessHandle,\r\n ssrNormalHandle,\r\n sssDiffuseHandle,\r\n sssTransmissionHandle,\r\n skinSSSHandle\r\n };\r\n });\r\n // Register the LightPass MRT products so effects can look them up by name.\r\n if (lightPassResult.ssrRoughnessHandle) {\r\n blackboard.set(FrameResources.SSRRoughness, lightPassResult.ssrRoughnessHandle);\r\n }\r\n if (lightPassResult.ssrNormalHandle) {\r\n blackboard.set(FrameResources.SSRNormal, lightPassResult.ssrNormalHandle);\r\n } else if (sssProfileResult?.normalHandle) {\r\n blackboard.set(FrameResources.SSRNormal, sssProfileResult.normalHandle);\r\n }\r\n if (lightPassResult.sssDiffuseHandle) {\r\n blackboard.set(FrameResources.SSSDiffuse, lightPassResult.sssDiffuseHandle);\r\n }\r\n if (lightPassResult.sssTransmissionHandle) {\r\n blackboard.set(FrameResources.SSSTransmission, lightPassResult.sssTransmissionHandle);\r\n }\r\n if (lightPassResult.skinSSSHandle) {\r\n blackboard.set(FrameResources.SkinSSS, lightPassResult.skinSSSHandle);\r\n }\r\n\r\n // 7d. Opaque-layer post effects (SAO/SSR/SSS/SkinSSS). They read the opaque\r\n // scene color and must complete before transparent geometry renders on top\r\n // of their output. Never direct-write: the chain output becomes the\r\n // transparent pass's render target. In final-framebuffer-as-intermediate\r\n // mode the scene color handle is the LightPass's backbuffer write version,\r\n // so the data flow is real either way — no keep-alive reads needed.\r\n const opaqueChainInput = lightPassResult.sceneColorHandle;\r\n // Data dependencies for every effect pass: frame textures the effects sample\r\n // through DrawContext fields (linear depth, HiZ, scene color copy, SSS MRT\r\n // outputs) rather than through declared require* hooks.\r\n const opaqueChainDeps: RGHandle[] = [depthHandle];\r\n if (hiZHandle) {\r\n opaqueChainDeps.push(hiZHandle);\r\n }\r\n if (lightPassResult.sceneColorFramebufferHandle) {\r\n opaqueChainDeps.push(lightPassResult.sceneColorFramebufferHandle);\r\n }\r\n if (grabResult) {\r\n opaqueChainDeps.push(grabResult.copyHandle);\r\n }\r\n if (sssProfileResult) {\r\n opaqueChainDeps.push(sssProfileResult.profileHandle, sssProfileResult.paramHandle);\r\n if (sssProfileResult.normalHandle) {\r\n opaqueChainDeps.push(sssProfileResult.normalHandle);\r\n }\r\n }\r\n for (const handle of [\r\n lightPassResult.ssrRoughnessHandle,\r\n lightPassResult.ssrNormalHandle,\r\n lightPassResult.sssDiffuseHandle,\r\n lightPassResult.sssTransmissionHandle,\r\n lightPassResult.skinSSSHandle\r\n ]) {\r\n if (handle) {\r\n opaqueChainDeps.push(handle);\r\n }\r\n }\r\n const opaqueChainResult = ctx.compositor\r\n ? ctx.compositor.buildLayer({\r\n graph,\r\n ctx,\r\n layer: PostEffectLayer.opaque,\r\n blackboard,\r\n input: opaqueChainInput,\r\n finalOutput: null,\r\n sceneDepthAttachment: renderDepthAttachment,\r\n dependencies: opaqueChainDeps,\r\n historyReads: lightHistoryReadBindings,\r\n history: historyManager\r\n })\r\n : { color: opaqueChainInput, wroteFinal: false };\r\n const opaqueChainRan = opaqueChainResult.color !== opaqueChainInput;\r\n\r\n // 7e. Transparent scene geometry (transmission/transparent lists + OIT).\r\n // Renders on top of the opaque-chain output; graph-wise an in-place write\r\n // producing a new version of the current scene color.\r\n const sceneColorHandle = graph.addPass('TransparentPass', (builder) => {\r\n builder.read(depthHandle);\r\n builder.read(depthPassResult.depthFramebufferHandle);\r\n if (hiZHandle) {\r\n // Transparent-phase materials may ray-march HiZ (e.g. water SSR)\r\n builder.read(hiZHandle);\r\n }\r\n if (lightPassResult.sceneColorFramebufferHandle) {\r\n builder.read(lightPassResult.sceneColorFramebufferHandle);\r\n }\r\n if (lightPassResult.sceneColorCopyHandle) {\r\n builder.read(lightPassResult.sceneColorCopyHandle);\r\n }\r\n builder.read(opaqueChainResult.color);\r\n const out = builder.write(opaqueChainResult.color);\r\n builder.setExecute((rgCtx) => {\r\n renderTransparentScenePass(\r\n frame,\r\n rgCtx,\r\n opaqueChainRan ? opaqueChainResult.color : null,\r\n lightPassResult.sceneColorFramebufferHandle\r\n );\r\n });\r\n return out;\r\n });\r\n blackboard.set(FrameResources.SceneColor, sceneColorHandle);\r\n if (lightPassResult.sceneColorCopyHandle) {\r\n blackboard.set(FrameResources.SceneColorCopy, lightPassResult.sceneColorCopyHandle);\r\n }\r\n if (sssProfileResult) {\r\n blackboard.set(FrameResources.SSSProfile, sssProfileResult.profileHandle);\r\n blackboard.set(FrameResources.SSSParam, sssProfileResult.paramHandle);\r\n }\r\n\r\n // 8. Post effect chains + transmission depth.\r\n //\r\n // Chain input: the TransparentPass output version — the authoritative scene\r\n // color regardless of whether it physically lives in a texture or in the\r\n // backbuffer (final framebuffer used as intermediate, no opaque effects).\r\n const chainInput = sceneColorHandle;\r\n // When the scene color still physically resides in the final framebuffer,\r\n // the Present blit must be skipped if no effect moved it to a texture.\r\n // (Opaque-layer effects disable final-as-intermediate mode, so the scene\r\n // color is backbuffer-resident whenever that mode is active.)\r\n const backbufferResidentHandle = useFinalFramebufferAsIntermediate ? sceneColorHandle : null;\r\n // No extra chain dependencies: the effect chains link to the scene color\r\n // through their inputs, and per-effect texture needs are declared via the\r\n // require* hooks in AbstractPostEffect.setup().\r\n const chainDependencies: RGHandle[] = [];\r\n const finalOutput = { handle: backbuffer, isScreen: !ctx.finalFramebuffer };\r\n const endLayerHasEffects = !!ctx.compositor?.layerHasEnabledEffect(PostEffectLayer.end);\r\n\r\n // 8a. Transparent-layer effects (bloom, tonemap, FXAA, ...). They run right\r\n // after the light pass and must sample the pre-transmission linear depth, so\r\n // they carry no transmissionDepthToken dependency; TransmissionDepth is\r\n // instead ordered after this chain (see 8b).\r\n const transparentChainResult = ctx.compositor\r\n ? ctx.compositor.buildLayer({\r\n graph,\r\n ctx,\r\n layer: PostEffectLayer.transparent,\r\n blackboard,\r\n input: chainInput,\r\n finalOutput: endLayerHasEffects ? null : finalOutput,\r\n inputResidesInFinalTarget: !!backbufferResidentHandle,\r\n sceneDepthAttachment: renderDepthAttachment,\r\n dependencies: chainDependencies,\r\n history: historyManager\r\n })\r\n : { color: chainInput, wroteFinal: false };\r\n\r\n // 8b. Transmission depth pass (optional). Mutates the linear depth texture;\r\n // the mutation is modeled as a graph write: the WAR hazard orders this pass\r\n // after every pre-transmission depth reader (the transparent-layer chain),\r\n // and re-registering the post-write version in the blackboard gives\r\n // end-layer effects (TAA) a real data dependency on the transmission depth.\r\n let transmissionDepthToken: RGHandle | undefined;\r\n if (options.needSceneColor && !options.needsTransmissionDepthForSSR) {\r\n const transmissionDepthResult = graph.addPass('TransmissionDepth', (builder) => {\r\n builder.read(sceneColorHandle);\r\n if (transparentChainResult.color !== sceneColorHandle) {\r\n builder.read(transparentChainResult.color);\r\n }\r\n builder.read(depthHandle);\r\n builder.read(depthPassResult.depthFramebufferHandle);\r\n const depthOut = builder.write(depthHandle);\r\n const done = builder.createToken('TransmissionDepthDone');\r\n builder.sideEffect();\r\n builder.setExecute((rgCtx) => {\r\n renderTransmissionDepthPass(frame, rgCtx);\r\n });\r\n return { done, depthOut };\r\n });\r\n transmissionDepthToken = transmissionDepthResult.done;\r\n depthHandle = transmissionDepthResult.depthOut;\r\n // The transparent-layer chain above read the pre-transmission version;\r\n // everything built from here on (end-layer chain) reads this one.\r\n blackboard.set(FrameResources.LinearDepth, depthHandle);\r\n }\r\n\r\n // 9. End-layer effects (TAA). Ordered after TransmissionDepth.\r\n const endChainDependencies = transmissionDepthToken\r\n ? [...chainDependencies, transmissionDepthToken]\r\n : chainDependencies;\r\n const chainResult = ctx.compositor\r\n ? ctx.compositor.buildLayer({\r\n graph,\r\n ctx,\r\n layer: PostEffectLayer.end,\r\n blackboard,\r\n input: transparentChainResult.color,\r\n finalOutput,\r\n // Still backbuffer-resident if the transparent-layer chain ran no effect\r\n inputResidesInFinalTarget: !!backbufferResidentHandle && transparentChainResult.color === chainInput,\r\n sceneDepthAttachment: renderDepthAttachment,\r\n dependencies: endChainDependencies,\r\n history: historyManager\r\n })\r\n : { color: transparentChainResult.color, wroteFinal: false };\r\n const finalWroteFinal = chainResult.wroteFinal || transparentChainResult.wroteFinal;\r\n\r\n // 10. Present + frame cleanup.\r\n let presentedBackbuffer: RGHandle;\r\n if (finalWroteFinal) {\r\n // The last effect wrote the final target directly; only cleanup remains.\r\n presentedBackbuffer = chainResult.color;\r\n graph.addPass('FrameCleanup', (builder) => {\r\n builder.read(presentedBackbuffer);\r\n for (const dep of endChainDependencies) {\r\n builder.read(dep);\r\n }\r\n builder.sideEffect();\r\n builder.setExecute(() => {\r\n finishFrame(frame);\r\n });\r\n });\r\n } else {\r\n presentedBackbuffer = graph.addPass('Present', (builder) => {\r\n builder.read(chainResult.color);\r\n for (const dep of endChainDependencies) {\r\n builder.read(dep);\r\n }\r\n const outputBackbuffer = builder.write(backbuffer);\r\n // Skip the blit when the chain output already lives in the final target\r\n // (final framebuffer used as intermediate and no end-layer effect ran).\r\n const needsBlit = chainResult.color !== backbufferResidentHandle;\r\n builder.setExecute((rgCtx) => {\r\n const sourceTex = needsBlit ? rgCtx.getTexture<Texture2D>(chainResult.color) : null;\r\n if (sourceTex) {\r\n const blitter = new CopyBlitter();\r\n blitter.srgbOut = !ctx.finalFramebuffer;\r\n blitter.blit(sourceTex, ctx.finalFramebuffer ?? null, fetchSampler('clamp_nearest_nomip'));\r\n }\r\n finishFrame(frame);\r\n });\r\n return outputBackbuffer;\r\n });\r\n }\r\n\r\n return { backbuffer: presentedBackbuffer, frame };\r\n}\r\n\r\n// ─── Pass Implementation Helpers ────────────────────────────────────\r\n// These wrap the existing SceneRenderer static methods, adapted to work\r\n// with the FrameState pattern. They contain the same logic as the\r\n// original methods but read/write through FrameState.\r\n\r\n/** @internal */\r\nfunction renderShadowMaps(ctx: DrawContext, lights: PunctualLight[]): void {\r\n ctx.renderPass = _shadowMapPass;\r\n ctx.device.pushDeviceStates();\r\n try {\r\n for (const light of lights) {\r\n light.shadow.render(ctx, _shadowMapPass);\r\n }\r\n } finally {\r\n ctx.device.popDeviceStates();\r\n }\r\n}\r\n\r\nfunction renderForwardSSSProfile(\r\n frame: FrameState,\r\n profileFramebuffer: FrameBuffer,\r\n profileTexture: Texture2D,\r\n paramTexture: Texture2D,\r\n normalTexture: Nullable<Texture2D>\r\n): void {\r\n const { ctx, renderQueue } = frame;\r\n if (!ctx.SSS || !ctx.depthTexture) {\r\n return;\r\n }\r\n const sssRenderQueue = createActualSSSRenderQueue(renderQueue);\r\n if (!sssRenderQueue) {\r\n return;\r\n }\r\n\r\n const device = ctx.device;\r\n const savedMaterialFlags = ctx.materialFlags;\r\n const savedCompositor = ctx.compositor;\r\n const savedTransmission = _scenePass.transmission;\r\n const savedRenderOpaque = _scenePass.renderOpaque;\r\n const savedRenderTransparent = _scenePass.renderTransparent;\r\n const savedClearColor = _scenePass.clearColor;\r\n const savedClearDepth = _scenePass.clearDepth;\r\n const savedClearStencil = _scenePass.clearStencil;\r\n const savedCommandBufferReuse = ctx.camera.commandBufferReuse;\r\n const savedProfileTexture = ctx.SSSProfileTexture;\r\n const savedParamTexture = ctx.SSSParamTexture;\r\n const savedNormalTexture = ctx.SSRNormalTexture;\r\n\r\n let profileFlags = MaterialVaryingFlags.SSS_STORE_PROFILE;\r\n if (normalTexture) {\r\n profileFlags |= MaterialVaryingFlags.SSS_STORE_NORMAL;\r\n }\r\n\r\n device.pushDeviceStates();\r\n try {\r\n device.setFramebuffer(profileFramebuffer);\r\n ctx.SSSProfileTexture = profileTexture;\r\n ctx.SSSParamTexture = paramTexture;\r\n ctx.SSRNormalTexture = normalTexture;\r\n ctx.compositor = null;\r\n ctx.camera.commandBufferReuse = false;\r\n ctx.materialFlags =\r\n (ctx.materialFlags &\r\n ~(\r\n MaterialVaryingFlags.SSR_STORE_ROUGHNESS |\r\n MaterialVaryingFlags.SSS_STORE_PROFILE |\r\n MaterialVaryingFlags.SSS_STORE_NORMAL |\r\n MaterialVaryingFlags.SSS_STORE_DIFFUSE |\r\n MaterialVaryingFlags.SSS_STORE_TRANSMISSION |\r\n MaterialVaryingFlags.SKIN_SSS_STORE\r\n )) |\r\n profileFlags;\r\n _scenePass.transmission = false;\r\n _scenePass.renderOpaque = true;\r\n _scenePass.renderTransparent = false;\r\n _scenePass.clearColor = Vector4.zero();\r\n _scenePass.clearDepth = null;\r\n _scenePass.clearStencil = null;\r\n _scenePass.render(ctx, null, null, sssRenderQueue);\r\n } finally {\r\n _scenePass.clearColor = savedClearColor;\r\n _scenePass.clearDepth = savedClearDepth;\r\n _scenePass.clearStencil = savedClearStencil;\r\n _scenePass.renderTransparent = savedRenderTransparent;\r\n _scenePass.renderOpaque = savedRenderOpaque;\r\n _scenePass.transmission = savedTransmission;\r\n ctx.camera.commandBufferReuse = savedCommandBufferReuse;\r\n ctx.materialFlags = savedMaterialFlags;\r\n ctx.compositor = savedCompositor;\r\n ctx.SSSProfileTexture = savedProfileTexture;\r\n ctx.SSSParamTexture = savedParamTexture;\r\n ctx.SSRNormalTexture = savedNormalTexture;\r\n device.popDeviceStates();\r\n sssRenderQueue.dispose();\r\n }\r\n}\r\n\r\nfunction releaseIntermediateFramebuffer(frame: FrameState): void {\r\n // Device state is contained within each pass now (LightPass/TransparentPass\r\n // push/pop their own framebuffer bindings); only the context field remains.\r\n frame.ctx.intermediateFramebuffer = null;\r\n}\r\n\r\nfunction releaseDepthFramebuffer(frame: FrameState): void {\r\n frame.depthFramebuffer = null;\r\n}\r\n\r\nfunction disposeRenderQueue(frame: FrameState): void {\r\n if (!frame.renderQueueDisposed) {\r\n frame.renderQueue.dispose();\r\n frame.renderQueueDisposed = true;\r\n }\r\n}\r\n\r\nfunction releaseClusteredLight(frame: FrameState): void {\r\n if (!frame.clusteredLightReleased && frame.ctx.clusteredLight) {\r\n freeClusteredLight(frame.ctx.clusteredLight);\r\n frame.ctx.clusteredLight = undefined;\r\n frame.clusteredLightReleased = true;\r\n }\r\n}\r\n\r\nfunction restoreSunLight(frame: FrameState): void {\r\n if (!frame.sunLightRestored && frame.sunLightColor && frame.ctx.sunLight) {\r\n frame.ctx.sunLight.color = frame.sunLightColor;\r\n frame.sunLightRestored = true;\r\n }\r\n}\r\n\r\nfunction cleanupFrame(frame: FrameState): void {\r\n releaseIntermediateFramebuffer(frame);\r\n releaseDepthFramebuffer(frame);\r\n releaseClusteredLight(frame);\r\n disposeRenderQueue(frame);\r\n restoreSunLight(frame);\r\n}\r\n\r\n/** @internal */\r\nfunction renderSceneDepth(\r\n frame: FrameState,\r\n existingDepthFb: Nullable<FrameBuffer>,\r\n rgCtx: RGExecuteContext,\r\n depthTex?: Texture2D,\r\n motionVectorTex?: Nullable<Texture2D>,\r\n transmissionOverride?: boolean\r\n): FrameBuffer {\r\n const ctx = frame.ctx;\r\n const renderQueue = frame.renderQueue;\r\n const transmission = transmissionOverride ?? !!existingDepthFb;\r\n let depthFramebuffer = existingDepthFb;\r\n\r\n if (!depthFramebuffer) {\r\n // Use RenderGraph-allocated textures if provided\r\n if (depthTex) {\r\n const colorAttachments = motionVectorTex ? [depthTex, motionVectorTex] : depthTex;\r\n const depthAttachment = ctx.finalFramebuffer?.getDepthAttachment();\r\n const depthTexOrFormat = depthAttachment?.isTexture2D() ? depthAttachment : ctx.depthFormat;\r\n\r\n depthFramebuffer = rgCtx.createFramebuffer<FrameBuffer>({\r\n width: depthTex.width,\r\n height: depthTex.height,\r\n colorAttachments,\r\n depthAttachment: depthTexOrFormat,\r\n ignoreDepthStencil: false\r\n });\r\n } else {\r\n // Allocate through RenderGraph so framebuffer lifetime is owned by the executor.\r\n const format: TextureFormat =\r\n ctx.device.type === 'webgl'\r\n ? ctx.SSRCalcThickness\r\n ? 'rgba16f'\r\n : 'rgba8unorm'\r\n : ctx.SSRCalcThickness\r\n ? 'rg32f'\r\n : 'r32f';\r\n const mvFormat: TextureFormat = 'rgba16f';\r\n if (!ctx.finalFramebuffer) {\r\n depthFramebuffer = rgCtx.createFramebuffer<FrameBuffer>({\r\n width: ctx.renderWidth,\r\n height: ctx.renderHeight,\r\n colorAttachments: ctx.motionVectors ? [format, mvFormat] : format,\r\n depthAttachment: ctx.depthFormat,\r\n ignoreDepthStencil: false\r\n });\r\n } else {\r\n const originDepth = ctx.finalFramebuffer?.getDepthAttachment();\r\n if (originDepth?.isTexture2D()) {\r\n depthFramebuffer = rgCtx.createFramebuffer<FrameBuffer>({\r\n width: originDepth.width,\r\n height: originDepth.height,\r\n colorAttachments: ctx.motionVectors ? [format, mvFormat] : format,\r\n depthAttachment: originDepth,\r\n ignoreDepthStencil: false\r\n });\r\n } else {\r\n depthFramebuffer = rgCtx.createFramebuffer<FrameBuffer>({\r\n width: ctx.renderWidth,\r\n height: ctx.renderHeight,\r\n colorAttachments: ctx.motionVectors ? [format, mvFormat] : format,\r\n depthAttachment: ctx.depthFormat,\r\n ignoreDepthStencil: false\r\n });\r\n }\r\n }\r\n }\r\n }\r\n\r\n if (!transmission) {\r\n frame.depthFramebuffer = depthFramebuffer!;\r\n }\r\n\r\n ctx.device.pushDeviceStates();\r\n try {\r\n ctx.device.setFramebuffer(depthFramebuffer!);\r\n _depthPass.encodeDepth = depthFramebuffer!.getColorAttachments()[0].format === 'rgba8unorm';\r\n _depthPass.clearColor = transmission\r\n ? null\r\n : _depthPass.encodeDepth\r\n ? new Vector4(0, 0, 0, 1)\r\n : new Vector4(1, 1, 1, 1);\r\n _depthPass.clearDepth = transmission ? null : 1;\r\n _depthPass.clearStencil = null;\r\n _depthPass.transmission = transmission;\r\n\r\n if (ctx.SSRCalcThickness && !transmission) {\r\n if (!_backDepthColorState) {\r\n _backDepthColorState = ctx.device.createColorState().setColorMask(false, true, false, false);\r\n }\r\n if (!_frontDepthColorState) {\r\n _frontDepthColorState = ctx.device.createColorState().setColorMask(true, false, false, false);\r\n }\r\n ctx.forceColorState = _backDepthColorState;\r\n ctx.forceCullMode = 'front';\r\n _depthPass.renderBackface = true;\r\n _depthPass.transmission = false;\r\n _depthPass.render(ctx, null, null, renderQueue);\r\n _depthPass.clearColor = null;\r\n _depthPass.renderBackface = false;\r\n ctx.forceColorState = _frontDepthColorState;\r\n ctx.forceCullMode = null;\r\n }\r\n _depthPass.render(ctx, null, null, renderQueue);\r\n } finally {\r\n ctx.forceColorState = null;\r\n ctx.forceCullMode = null;\r\n _depthPass.renderBackface = false;\r\n ctx.device.popDeviceStates();\r\n }\r\n\r\n if (!transmission) {\r\n ctx.motionVectorTexture = ctx.motionVectors\r\n ? (depthFramebuffer!.getColorAttachments()[1] as Texture2D)\r\n : null;\r\n ctx.linearDepthTexture = depthFramebuffer!.getColorAttachments()[0] as Texture2D;\r\n ctx.depthTexture = depthFramebuffer!.getDepthAttachment() as Texture2D;\r\n ctx.depthPrepassAttachment = ctx.depthTexture;\r\n // HiZ is now built in the dedicated HiZ pass\r\n }\r\n return depthFramebuffer!;\r\n}\r\n\r\n// ─── Sky Motion Vector State ────────────────────────────────────────\r\n\r\nlet _skyMVProgram: Nullable<GPUProgram> = null;\r\nlet _skyMVBindGroup: Nullable<BindGroup> = null;\r\nlet _skyMVBox: Nullable<Primitive> = null;\r\n\r\n/** @internal */\r\nfunction renderSkyMotionVectors(\r\n ctx: DrawContext,\r\n rgCtx: RGExecuteContext,\r\n framebufferHandle?: RGHandle\r\n): void {\r\n if (!ctx.motionVectorTexture) {\r\n return;\r\n }\r\n\r\n const device = ctx.device;\r\n const fb = framebufferHandle\r\n ? rgCtx.getFramebuffer<FrameBuffer>(framebufferHandle)\r\n : rgCtx.createFramebuffer<FrameBuffer>({\r\n colorAttachments: ctx.motionVectorTexture,\r\n depthAttachment: ctx.depthTexture\r\n });\r\n\r\n if (!_skyMVProgram) {\r\n _skyMVProgram = device.buildRenderProgram({\r\n vertex(pb) {\r\n this.$inputs.pos = pb.vec3().attrib('position');\r\n this.VPMatrix = pb.mat4().uniform(0);\r\n this.prevVPMatrix = pb.mat4().uniform(0);\r\n this.cameraPos = pb.vec3().uniform(0);\r\n this.prevCameraPos = pb.vec3().uniform(0);\r\n pb.main(function () {\r\n this.$l.worldPos = pb.add(this.$inputs.pos, this.cameraPos);\r\n this.$l.prevWorldPos = pb.add(this.$inputs.pos, this.prevCameraPos);\r\n this.$l.clipPos = pb.mul(this.VPMatrix, pb.vec4(this.worldPos, 1));\r\n this.$l.prevClipPos = pb.mul(this.prevVPMatrix, pb.vec4(this.prevWorldPos, 1));\r\n this.clipPos.z = this.clipPos.w;\r\n this.$builtins.position = this.clipPos;\r\n this.$outputs.currentPos = this.clipPos;\r\n this.$outputs.prevPos = this.prevClipPos;\r\n });\r\n },\r\n fragment(pb) {\r\n this.$outputs.color = pb.vec4();\r\n pb.main(function () {\r\n this.$l.motionVector = pb.mul(\r\n pb.sub(\r\n pb.div(this.$inputs.currentPos.xy, this.$inputs.currentPos.w),\r\n pb.div(this.$inputs.prevPos.xy, this.$inputs.prevPos.w)\r\n ),\r\n 0.5\r\n );\r\n this.$outputs.color = pb.vec4(this.motionVector, 0, 1);\r\n });\r\n }\r\n })!;\r\n _skyMVProgram.name = '@TAA_SkyMotionVector';\r\n }\r\n\r\n if (!_skyMVBindGroup) {\r\n _skyMVBindGroup = device.createBindGroup(_skyMVProgram.bindGroupLayouts[0]);\r\n }\r\n\r\n if (!_skyMVBox) {\r\n _skyMVBox = new BoxShape({ size: 2, needNormal: false, needUV: false });\r\n }\r\n\r\n _skyMVBindGroup.setValue('VPMatrix', ctx.camera.viewProjectionMatrix);\r\n _skyMVBindGroup.setValue('prevVPMatrix', ctx.camera.prevVPMatrix!);\r\n _skyMVBindGroup.setValue('cameraPos', ctx.camera.getWorldPosition());\r\n _skyMVBindGroup.setValue('prevCameraPos', ctx.camera.prevPosition!);\r\n\r\n device.pushDeviceStates();\r\n device.setProgram(_skyMVProgram);\r\n device.setBindGroup(0, _skyMVBindGroup);\r\n device.setRenderStates(AbstractPostEffect.getDefaultRenderState(ctx, 'le'));\r\n device.setFramebuffer(fb);\r\n _skyMVBox.draw();\r\n device.popDeviceStates();\r\n}\r\n\r\nfunction blitToCurrentColorAttachment(ctx: DrawContext, source: Texture2D): void {\r\n const framebuffer = ctx.device.getFramebuffer();\r\n const destination = framebuffer?.getColorAttachment<Texture2D>(0) ?? null;\r\n new CopyBlitter().blit(source, destination, fetchSampler('clamp_nearest_nomip'));\r\n}\r\n\r\n/**\r\n * Renders the full scene (no transmission) into the scene-color copy texture\r\n * used as refraction background. Runs as its own graph pass before LightPass.\r\n * @internal\r\n */\r\nfunction renderSceneColorGrab(\r\n frame: FrameState,\r\n rgCtx: RGExecuteContext,\r\n copyHandle: RGHandle,\r\n copyFramebufferHandle?: RGHandle\r\n): void {\r\n const { ctx, renderQueue } = frame;\r\n const device = ctx.device;\r\n const depthTex = frame.depthFramebuffer?.getDepthAttachment() as Texture2D;\r\n const copyTex = rgCtx.getTexture<Texture2D>(copyHandle);\r\n const compositor = ctx.compositor;\r\n ctx.compositor = null;\r\n const isolateSceneColorDepth = frame.options.needsTransmissionDepthForSSR;\r\n const savedDepthPrepassAttachment = ctx.depthPrepassAttachment;\r\n const savedMaterialFlags = ctx.materialFlags;\r\n\r\n // MRT store flags never apply to the background copy\r\n const sceneColorMaterialFlags = ctx.materialFlags & ~SURFACE_MRT_FLAGS;\r\n const sceneColorFramebuffer = copyFramebufferHandle\r\n ? rgCtx.getFramebuffer<FrameBuffer>(copyFramebufferHandle)\r\n : rgCtx.createFramebuffer<FrameBuffer>({\r\n width: copyTex.width,\r\n height: copyTex.height,\r\n colorAttachments: copyTex,\r\n depthAttachment: isolateSceneColorDepth ? ctx.depthFormat : depthTex,\r\n ignoreDepthStencil: false\r\n });\r\n let sceneColorStatePushed = false;\r\n try {\r\n device.pushDeviceStates();\r\n sceneColorStatePushed = true;\r\n device.setFramebuffer(sceneColorFramebuffer);\r\n _scenePass.transmission = false;\r\n if (isolateSceneColorDepth) {\r\n ctx.depthPrepassAttachment = undefined;\r\n _scenePass.clearDepth = 1;\r\n _scenePass.clearStencil = 0;\r\n } else {\r\n _scenePass.clearDepth = depthTex ? null : 1;\r\n _scenePass.clearStencil = depthTex ? null : 0;\r\n }\r\n ctx.materialFlags = sceneColorMaterialFlags;\r\n _scenePass.render(ctx, null, null, renderQueue);\r\n } finally {\r\n ctx.materialFlags = savedMaterialFlags;\r\n if (isolateSceneColorDepth) {\r\n ctx.depthPrepassAttachment = savedDepthPrepassAttachment;\r\n }\r\n if (sceneColorStatePushed) {\r\n device.popDeviceStates();\r\n }\r\n ctx.compositor = compositor;\r\n }\r\n}\r\n\r\n/** @internal */\r\nfunction renderOpaqueScenePass(\r\n frame: FrameState,\r\n sceneColorTex: Texture2D,\r\n sceneColorCopyTex: Nullable<Texture2D>,\r\n rgCtx: RGExecuteContext,\r\n sceneColorFramebufferHandle?: RGHandle\r\n): void {\r\n const { ctx, renderQueue } = frame;\r\n\r\n // Use RenderGraph-allocated scene color texture\r\n const depthTex = frame.depthFramebuffer?.getDepthAttachment() as Texture2D;\r\n\r\n ctx.materialFlags &= ~(\r\n MaterialVaryingFlags.SSR_STORE_ROUGHNESS |\r\n MaterialVaryingFlags.SSS_STORE_PROFILE |\r\n MaterialVaryingFlags.SSS_STORE_DIFFUSE |\r\n MaterialVaryingFlags.SSS_STORE_NORMAL |\r\n MaterialVaryingFlags.SSS_STORE_TRANSMISSION |\r\n MaterialVaryingFlags.SKIN_SSS_STORE\r\n );\r\n\r\n if (ctx.SSR) {\r\n ctx.materialFlags |= MaterialVaryingFlags.SSR_STORE_ROUGHNESS;\r\n }\r\n if (ctx.SSS) {\r\n if (ctx.SSSDiffuseTexture) {\r\n ctx.materialFlags |= MaterialVaryingFlags.SSS_STORE_DIFFUSE;\r\n }\r\n if (ctx.SSSTransmissionTexture) {\r\n ctx.materialFlags |= MaterialVaryingFlags.SSS_STORE_TRANSMISSION;\r\n }\r\n }\r\n if (ctx.SkinSSSTexture) {\r\n ctx.materialFlags |= MaterialVaryingFlags.SKIN_SSS_STORE;\r\n }\r\n\r\n // The graph scene color framebuffer takes priority: it is absent only when\r\n // the graph was built in final-framebuffer-as-intermediate mode (external\r\n // depth shared with the final framebuffer AND no opaque-layer effects).\r\n // Checking the shared depth first would wrongly route the MRT/opaque-effect\r\n // case into the single-color final framebuffer.\r\n if (sceneColorFramebufferHandle && !hasSurfaceMRT(ctx)) {\r\n ctx.intermediateFramebuffer = rgCtx.getFramebuffer<FrameBuffer>(sceneColorFramebufferHandle);\r\n } else if (!sceneColorFramebufferHandle && depthTex === ctx.finalFramebuffer?.getDepthAttachment()) {\r\n ctx.intermediateFramebuffer = ctx.finalFramebuffer;\r\n } else {\r\n ctx.intermediateFramebuffer = rgCtx.createFramebuffer<FrameBuffer>({\r\n width: sceneColorTex.width,\r\n height: sceneColorTex.height,\r\n colorAttachments: getLightPassColorAttachments(ctx, sceneColorTex),\r\n depthAttachment: depthTex\r\n });\r\n }\r\n\r\n // The scene target is bound explicitly and the device state is restored at\r\n // the end of this pass: graph passes never communicate through leftover\r\n // device state. TransparentPass re-binds the same target (or the opaque\r\n // chain output) explicitly.\r\n ctx.device.pushDeviceStates();\r\n try {\r\n // setFramebuffer() no-ops when the target is unchanged, so reset the\r\n // viewport/scissor explicitly to cover that case.\r\n ctx.device.setFramebuffer(ctx.intermediateFramebuffer);\r\n ctx.device.setViewport(null);\r\n ctx.device.setScissor(null);\r\n\r\n _scenePass.transmission = false;\r\n _scenePass.clearDepth = depthTex ? null : 1;\r\n _scenePass.clearStencil = depthTex ? null : 0;\r\n\r\n if (renderQueue.needSceneColor() && sceneColorCopyTex) {\r\n // Background copy was produced by the SceneColorGrab pass; seed the main\r\n // color attachment with it and render only transmission/transparent on top.\r\n ctx.sceneColorTexture = sceneColorCopyTex;\r\n blitToCurrentColorAttachment(ctx, ctx.sceneColorTexture);\r\n if (hasSurfaceMRT(ctx)) {\r\n // The background copy carries no surface MRT attachments, so opaque\r\n // geometry exists only there without roughness/normal (and SSS\r\n // lighting) data. Re-render the opaque lists into the MRT scene\r\n // target: early-z against the prepass depth keeps this cheap, and the\r\n // color output matches the blitted copy on opaque pixels while the\r\n // MRT attachments receive the surface data SSR/SSS require.\r\n _scenePass.clearColor = null;\r\n _scenePass.clearDepth = null;\r\n _scenePass.clearStencil = null;\r\n _scenePass.renderOpaque = true;\r\n _scenePass.renderTransparent = false;\r\n _scenePass.render(ctx, null, null, renderQueue);\r\n }\r\n _scenePass.transmission = true;\r\n _scenePass.clearColor = null;\r\n _scenePass.clearDepth = null;\r\n _scenePass.clearStencil = null;\r\n }\r\n _scenePass.renderOpaque = true;\r\n _scenePass.renderTransparent = false;\r\n _scenePass.render(ctx, null, null, renderQueue);\r\n } finally {\r\n // Restore the shared _scenePass flags so no state leaks to the next pass:\r\n // the transparent pass sets transmission/renderOpaque/renderTransparent\r\n // itself rather than inheriting whatever this pass happened to leave.\r\n _scenePass.renderTransparent = true;\r\n _scenePass.transmission = false;\r\n ctx.device.popDeviceStates();\r\n }\r\n}\r\n\r\n/**\r\n * Renders the transmission/transparent geometry lists (including OIT) on top\r\n * of the opaque result. The target framebuffer is always bound explicitly:\r\n * the opaque chain output when opaque-layer effects ran, otherwise the same\r\n * scene target the light pass rendered into. OIT implementations composite\r\n * into the currently bound framebuffer, which this pass guarantees.\r\n * @internal\r\n */\r\nfunction renderTransparentScenePass(\r\n frame: FrameState,\r\n rgCtx: RGExecuteContext,\r\n opaqueChainOutput: Nullable<RGHandle>,\r\n sceneColorFramebufferHandle?: RGHandle\r\n): void {\r\n const { ctx, renderQueue } = frame;\r\n const device = ctx.device;\r\n let framebuffer: Nullable<FrameBuffer>;\r\n if (opaqueChainOutput) {\r\n // Opaque-layer effects redirected the scene color into their chain output;\r\n // transparent geometry renders on top of it with the scene depth attached.\r\n const chainTex = rgCtx.getTexture<Texture2D>(opaqueChainOutput);\r\n const depthTex = frame.depthFramebuffer?.getDepthAttachment() as Texture2D;\r\n framebuffer = rgCtx.createFramebuffer<FrameBuffer>({\r\n width: chainTex.width,\r\n height: chainTex.height,\r\n colorAttachments: chainTex,\r\n depthAttachment: depthTex\r\n });\r\n // The chain output is single-color: surface MRT stores no longer apply.\r\n ctx.materialFlags &= ~SURFACE_MRT_FLAGS;\r\n } else if (sceneColorFramebufferHandle) {\r\n // No opaque-layer effect ran (thus no surface MRT either): continue in the\r\n // graph scene color framebuffer the light pass rendered into.\r\n framebuffer = rgCtx.getFramebuffer<FrameBuffer>(sceneColorFramebufferHandle);\r\n } else {\r\n // Final framebuffer used as scene intermediate.\r\n framebuffer = ctx.finalFramebuffer;\r\n }\r\n device.pushDeviceStates();\r\n try {\r\n // setFramebuffer() no-ops when the target is unchanged, so reset the\r\n // viewport/scissor explicitly to cover that case.\r\n device.setFramebuffer(framebuffer);\r\n device.setViewport(null);\r\n device.setScissor(null);\r\n // Derive transmission mode from the same single source of truth the opaque\r\n // pass used (renderQueue.needSceneColor()) instead of inheriting leftover\r\n // _scenePass state. When scene color is needed the opaque pass seeded the\r\n // refraction background and drew the transmission-opaque list, so here we\r\n // draw transmission_trans + transparent; otherwise just the transparent\r\n // list. Never clear: the opaque result is already in the target.\r\n _scenePass.transmission = renderQueue.needSceneColor();\r\n _scenePass.clearColor = null;\r\n _scenePass.clearDepth = null;\r\n _scenePass.clearStencil = null;\r\n _scenePass.renderOpaque = false;\r\n _scenePass.renderTransparent = true;\r\n try {\r\n _scenePass.render(ctx, null, null, renderQueue);\r\n } finally {\r\n _scenePass.renderOpaque = true;\r\n }\r\n } finally {\r\n device.popDeviceStates();\r\n }\r\n}\r\n\r\n/** @internal */\r\nfunction renderTransmissionDepthPass(frame: FrameState, rgCtx: RGExecuteContext): void {\r\n renderSceneDepth(frame, frame.depthFramebuffer, rgCtx);\r\n}\r\n\r\n/**\r\n * Frame-tail housekeeping shared by the Present and FrameCleanup passes.\r\n *\r\n * The end-layer post effect chain and the final blit are graph passes now\r\n * (see buildForwardPlusGraphInternal step 9/10); this only releases per-frame\r\n * state. The compositor's scene ping-pong is flushed back to the intermediate\r\n * framebuffer by compositor.end() at the tail of the light pass.\r\n *\r\n * @internal\r\n */\r\nfunction finishFrame(frame: FrameState): void {\r\n const { ctx } = frame;\r\n\r\n disposeRenderQueue(frame);\r\n ctx.materialFlags &= ~MaterialVaryingFlags.SSR_STORE_ROUGHNESS;\r\n ctx.materialFlags &= ~MaterialVaryingFlags.SSS_STORE_PROFILE;\r\n ctx.materialFlags &= ~MaterialVaryingFlags.SSS_STORE_DIFFUSE;\r\n ctx.materialFlags &= ~MaterialVaryingFlags.SSS_STORE_NORMAL;\r\n ctx.materialFlags &= ~MaterialVaryingFlags.SSS_STORE_TRANSMISSION;\r\n ctx.materialFlags &= ~MaterialVaryingFlags.SKIN_SSS_STORE;\r\n\r\n releaseIntermediateFramebuffer(frame);\r\n releaseDepthFramebuffer(frame);\r\n releaseClusteredLight(frame);\r\n restoreSunLight(frame);\r\n}\r\n\r\n// ─── Convenience: Execute Full Pipeline ─────────────────────────────\r\n\r\n/**\r\n * Build, compile, and execute the forward+ pipeline as a render graph.\r\n *\r\n * This is the drop-in replacement for `SceneRenderer._renderScene`.\r\n *\r\n * @param ctx - The draw context for this frame.\r\n * @public\r\n */\r\nexport function executeForwardPlusGraph(ctx: DrawContext): void {\r\n const device = ctx.device;\r\n const graph = new RenderGraph();\r\n let renderQueue: RenderQueue | null = null;\r\n let frame: FrameState | null = null;\r\n let executor: RenderGraphExecutor<Texture2D, FrameBuffer> | null = null;\r\n let historyManager: HistoryResourceManager<Texture2D> | null = null;\r\n let historyFrameStarted = false;\r\n\r\n try {\r\n // Cull scene first (needed to derive options)\r\n renderQueue = _scenePass.cullScene(ctx, ctx.camera);\r\n\r\n const options = deriveForwardPlusOptions(ctx.scene, ctx.camera, device.type, renderQueue);\r\n ctx.SSS = options.sss;\r\n\r\n // Ensure the camera has a history resource manager for temporal effects (TAA, motion blur)\r\n historyManager = ctx.camera.getHistoryResourceManager();\r\n if (!historyManager) {\r\n historyManager = new HistoryResourceManager<Texture2D>(_devicePoolAllocator);\r\n ctx.camera.setHistoryResourceManager(historyManager);\r\n }\r\n historyManager.beginFrame();\r\n historyFrameStarted = true;\r\n\r\n const buildResult = buildForwardPlusGraphInternal(graph, ctx, renderQueue, options);\r\n frame = buildResult.frame;\r\n\r\n const compiled = graph.compile([buildResult.backbuffer]);\r\n\r\n // Use RenderGraphExecutor for automatic resource management\r\n executor = new RenderGraphExecutor(_devicePoolAllocator, ctx.renderWidth, ctx.renderHeight);\r\n\r\n // Register imported backbuffer (if using finalFramebuffer)\r\n if (ctx.finalFramebuffer) {\r\n const backbufferTex = ctx.finalFramebuffer.getColorAttachments()[0] as Texture2D;\r\n executor.setImportedTexture(buildResult.backbuffer, backbufferTex);\r\n }\r\n historyManager.bindImportedTextures(executor);\r\n\r\n executor.execute(compiled);\r\n historyManager.commitFrame();\r\n } finally {\r\n if (historyFrameStarted) {\r\n historyManager?.discardFrame();\r\n }\r\n if (frame) {\r\n cleanupFrame(frame);\r\n } else {\r\n renderQueue?.dispose();\r\n }\r\n executor?.reset();\r\n }\r\n}\r\n"],"names":["_scenePass","LightPass","_depthPass","DepthPass","_shadowMapPass","ShadowMapPass","_clusters","_shadowMaskRenderer","ShadowMaskRenderer","_devicePoolAllocator","DevicePoolAllocator","_backDepthColorState","_frontDepthColorState","SURFACE_MRT_FLAGS","MaterialVaryingFlags","SSR_STORE_ROUGHNESS","SSS_STORE_PROFILE","SSS_STORE_DIFFUSE","SSS_STORE_NORMAL","SSS_STORE_TRANSMISSION","SKIN_SSS_STORE","getClusteredLight","length","pop","ClusteredLight","freeClusteredLight","cl","push","getCoreMaterial","material","coreMaterial","hasSSSMaterialCore","subsurfaceProfile","hasSkinSSSMaterialCore","skinSSS","renderQueueHasActiveSSS","renderQueue","itemList","lists","opaque","lit","unlit","list","materialList","renderQueueHasActiveSkinSSS","filterActualSSSItemList","items","filter","item","drawable","getMaterial","filterActualSSSMaterialList","filtered","Set","forEach","mat","add","cloneActualSSSListInfo","source","_targetQueue","skinItemList","morphItemList","skinAndMorphItemList","instanceItemList","instanceList","cloneActualSSSBundle","targetQueue","map","info","hasAnyActualSSSItems","renderItems","some","createActualSSSRenderQueue","queue","RenderQueue","sssOpaque","dispose","emptyBundle","target","_itemList","transmission","transparent","transmission_trans","_shadowedLightList","shadowedLights","_unshadowedLightList","unshadowedLights","_sunLight","sunLight","_primaryDirectionalLight","primaryDirectionalLight","_primaryTransmissionLight","primaryTransmissionLight","_needSceneColor","_needSceneDepth","_needSceneColorWithDepth","_drawTransparent","getSurfaceTextureFormat","ctx","caps","device","getDeviceCaps","textureCaps","supportHalfFloatColorBuffer","getTextureFormatBytes","format","getTextureFormatInfo","size","shouldStoreSSSDiffuse","camera","sssStrength","sssBlurScale","shouldStoreSSSTransmission","sssTransmissionStrength","getSSSLightingTextureFormat","attachmentCount","includeSSRSurfaceMRT","colorFormat","surfaceFormat","colorBytes","fullPrecisionBytes","framebufferCaps","maxColorAttachmentBytesPerSample","getFullMipLevelCount","width","height","Math","max","floor","log2","hasSurfaceMRT","materialFlags","getLightPassColorAttachments","colorAttachment","attachments","SSRRoughnessTexture","SSRNormalTexture","SSSProfileTexture","SSSParamTexture","SSSDiffuseTexture","SSSTransmissionTexture","SkinSSSTexture","deriveForwardPlusOptions","scene","deviceType","ssr","SSR","env","light","envLight","hasRadiance","sss","SSS","needSceneColor","needSceneColorWithDepth","depthPrepass","motionVectors","TAA","motionBlur","ssrTemporal","hiZ","HiZ","ssrCalcThickness","gpuPicking","getPickResultResolveFunc","needsTransmissionDepthForSSR","buildForwardPlusGraph","graph","options","buildForwardPlusGraphInternal","backbuffer","importTexture","blackboard","RGBlackboard","frame","depthFramebuffer","sunLightColor","renderQueueDisposed","clusteredLightReleased","sunLightRestored","orderToken","addPass","builder","done","createToken","sideEffect","setExecute","sky","update","read","clusteredLight","calculateLightIndex","pickResolveFunc","renderObjectColors","renderShadowMaps","depthPassResult","type","SSRCalcThickness","mvFormat","depthHandle","createTexture","label","motionVectorHandle","undefined","finalDepthAttachment","finalFramebuffer","getDepthAttachment","externalDepthAttachment","isTexture2D","graphDepthAttachmentHandle","depthFormat","depthAttachmentOrFormat","depthFramebufferHandle","createFramebuffer","renderWidth","renderHeight","colorAttachments","depthAttachment","ignoreDepthStencil","skyMotionVectorFramebufferHandle","addSubpass","rgCtx","getFramebuffer","renderSceneDepth","renderSkyMotionVectors","set","FrameResources","LinearDepth","MotionVector","SceneDepthAttachment","shadowMaskHandle","shadowMaskTexture","useShadowMask","screenSpaceShadowMask","numShadowLights","numLayers","getLayerCount","maskPassResult","maskDepthHandle","maskHandle","arrayLayers","depthTex","getTexture","maskTex","render","layer","attachmentLayer","ShadowMask","renderDepthAttachment","opaqueLayerHasEffects","compositor","layerHasEnabledEffect","PostEffectLayer","useFinalFramebufferAsIntermediate","preLightTransmissionDepthToken","transmissionDepthResult","depthOut","write","renderTransmissionDepthPass","hiZHandle","mipLevels","hiZFramebufferHandle","hiZTex","HiZFrameBuffer","buildHiZ","HiZTexture","historyManager","getHistoryResourceManager","lightHistoryReadBindings","historySize","reflectHistoryHandle","importPreviousIfCompatible","RGHistoryResources","SSR_REFLECT","sizeMode","motionVectorHistoryHandle","SSR_MOTION_VECTOR","name","handle","sssProfileResult","profileHandle","paramHandle","normalHandle","framebufferHandle","renderForwardSSSProfile","grabResult","copyHandle","copyFramebufferHandle","renderSceneColorGrab","lightPassResult","binding","sceneColorHandle","sceneColorCopyHandle","ssrRoughnessHandle","ssrNormalHandle","writeSSSDiffuse","writeSSSTransmission","writeSkinSSS","sssLightingAttachmentCount","sssLightingFormat","sssDiffuseHandle","sssTransmissionHandle","skinSSSHandle","sceneColorFramebufferHandle","sceneColorTex","sceneColorCopyTex","renderLightPass","renderOpaqueScenePass","beginReadScope","texture","endReadScope","SSRRoughness","SSRNormal","SSSDiffuse","SSSTransmission","SkinSSS","opaqueChainInput","opaqueChainDeps","opaqueChainResult","buildLayer","input","finalOutput","sceneDepthAttachment","dependencies","historyReads","history","color","wroteFinal","opaqueChainRan","out","renderTransparentScenePass","SceneColor","SceneColorCopy","SSSProfile","SSSParam","chainInput","backbufferResidentHandle","chainDependencies","isScreen","endLayerHasEffects","end","transparentChainResult","inputResidesInFinalTarget","transmissionDepthToken","endChainDependencies","chainResult","finalWroteFinal","presentedBackbuffer","dep","finishFrame","outputBackbuffer","needsBlit","sourceTex","blitter","CopyBlitter","srgbOut","blit","fetchSampler","lights","renderPass","pushDeviceStates","shadow","popDeviceStates","profileFramebuffer","profileTexture","paramTexture","normalTexture","depthTexture","sssRenderQueue","savedMaterialFlags","savedCompositor","savedTransmission","savedRenderOpaque","renderOpaque","savedRenderTransparent","renderTransparent","savedClearColor","clearColor","savedClearDepth","clearDepth","savedClearStencil","clearStencil","savedCommandBufferReuse","commandBufferReuse","savedProfileTexture","savedParamTexture","savedNormalTexture","profileFlags","setFramebuffer","Vector4","zero","releaseIntermediateFramebuffer","intermediateFramebuffer","releaseDepthFramebuffer","disposeRenderQueue","releaseClusteredLight","restoreSunLight","cleanupFrame","existingDepthFb","motionVectorTex","transmissionOverride","originDepth","encodeDepth","getColorAttachments","createColorState","setColorMask","forceColorState","forceCullMode","renderBackface","motionVectorTexture","linearDepthTexture","depthPrepassAttachment","_skyMVProgram","_skyMVBindGroup","_skyMVBox","fb","buildRenderProgram","vertex","pb","$inputs","pos","vec3","attrib","VPMatrix","mat4","uniform","prevVPMatrix","cameraPos","prevCameraPos","main","$l","worldPos","prevWorldPos","clipPos","mul","vec4","prevClipPos","z","w","$builtins","position","$outputs","currentPos","prevPos","fragment","motionVector","sub","div","xy","createBindGroup","bindGroupLayouts","BoxShape","needNormal","needUV","setValue","viewProjectionMatrix","getWorldPosition","prevPosition","setProgram","setBindGroup","setRenderStates","AbstractPostEffect","getDefaultRenderState","draw","blitToCurrentColorAttachment","framebuffer","destination","getColorAttachment","copyTex","isolateSceneColorDepth","savedDepthPrepassAttachment","sceneColorMaterialFlags","sceneColorFramebuffer","sceneColorStatePushed","setViewport","setScissor","sceneColorTexture","opaqueChainOutput","chainTex","executeForwardPlusGraph","RenderGraph","executor","historyFrameStarted","cullScene","HistoryResourceManager","setHistoryResourceManager","beginFrame","buildResult","compiled","compile","RenderGraphExecutor","backbufferTex","setImportedTexture","bindImportedTextures","execute","commitFrame","discardFrame","reset"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA;AAEA,MAAMA,aAAa,IAAIC,SAAAA,EAAAA;AACvB,MAAMC,aAAa,IAAIC,SAAAA,EAAAA;AACvB,MAAMC,iBAAiB,IAAIC,aAAAA,EAAAA;AAC3B,MAAMC,YAA8B,EAAE;AACtC,MAAMC,sBAAsB,IAAIC,kBAAAA,EAAAA;AAChC,MAAMC,uBAAuB,IAAIC,mBAAAA,EAAAA;AACjC,IAAIC,oBAA6C,GAAA,IAAA;AACjD,IAAIC,qBAA8C,GAAA,IAAA;AAClD,MAAMC,oBACJC,oBAAqBC,CAAAA,mBAAmB,GACxCD,oBAAAA,CAAqBE,iBAAiB,GACtCF,oBAAAA,CAAqBG,iBAAiB,GACtCH,qBAAqBI,gBAAgB,GACrCJ,qBAAqBK,sBAAsB,GAC3CL,qBAAqBM,cAAc;AAErC,SAASC,iBAAAA,GAAAA;AACP,IAAA,OAAOf,UAAUgB,MAAM,GAAG,IAAIhB,SAAUiB,CAAAA,GAAG,KAAM,IAAIC,cAAAA,EAAAA;AACvD;AACA,SAASC,mBAAmBC,EAAkB,EAAA;AAC5CpB,IAAAA,SAAAA,CAAUqB,IAAI,CAACD,EAAAA,CAAAA;AACjB;AAEA,SAASE,gBAAgBC,QAAiB,EAAA;IACxC,OAAQA,QAA4DC,EAAAA,YAAAA,IAAgBD,QAAY,IAAA,IAAA;AAClG;AAEA,SAASE,mBAAmBF,QAAiB,EAAA;IAC3C,OAAO,CAAC,CAAED,eAAAA,CAAgBC,QAAsDG,CAAAA,EAAAA,iBAAAA;AAClF;AAEA,SAASC,uBAAuBJ,QAAiB,EAAA;IAC/C,OAAO,CAAC,CAAED,eAAAA,CAAgBC,QAA4CK,CAAAA,EAAAA,OAAAA;AACxE;AAEA,SAASC,wBAAwBC,WAAwB,EAAA;IACvD,MAAMC,QAAAA,GAAWD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