@woosh/meep-engine 3.10.0 → 3.11.0
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.
- package/README.md +168 -152
- package/package.json +1 -1
- package/src/REVIEW_2026_08_06.md +610 -610
- package/src/core/geom/3d/shape/ConvexHullShape3D.d.ts.map +1 -1
- package/src/core/geom/3d/shape/ConvexHullShape3D.js +28 -4
- package/src/engine/graphics/render/frame_graph/FrameGraph.d.ts +26 -0
- package/src/engine/graphics/render/frame_graph/FrameGraph.d.ts.map +1 -1
- package/src/engine/graphics/render/frame_graph/FrameGraph.js +47 -0
- package/src/engine/physics/ecs/PhysicsSystem.d.ts +0 -3
- package/src/engine/physics/ecs/PhysicsSystem.d.ts.map +1 -1
- package/src/engine/physics/ecs/PhysicsSystem.js +0 -3
- package/src/shade/device/ShadeGPUCommandContext.d.ts +21 -0
- package/src/shade/device/ShadeGPUCommandContext.d.ts.map +1 -1
- package/src/shade/device/ShadeGPUCommandContext.js +940 -749
- package/src/shade/device/timing/GPUTimerArray.d.ts +22 -4
- package/src/shade/device/timing/GPUTimerArray.d.ts.map +1 -1
- package/src/shade/device/timing/GPUTimerArray.js +88 -14
- package/src/shade/device/timing/GPU_PROFILER_PROPOSAL_2026_08_28.md +349 -98
- package/src/shade/device/timing/profile/GPUFrameRecorder.d.ts +93 -0
- package/src/shade/device/timing/profile/GPUFrameRecorder.d.ts.map +1 -0
- package/src/shade/device/timing/profile/GPUFrameRecorder.js +297 -0
- package/src/shade/device/timing/profile/GPUProfileCapture.d.ts +62 -0
- package/src/shade/device/timing/profile/GPUProfileCapture.d.ts.map +1 -0
- package/src/shade/device/timing/profile/GPUProfileCapture.js +77 -0
- package/src/shade/device/timing/profile/GPUProfileFrame.d.ts +73 -0
- package/src/shade/device/timing/profile/GPUProfileFrame.d.ts.map +1 -0
- package/src/shade/device/timing/profile/GPUProfileFrame.js +88 -0
- package/src/shade/device/timing/profile/GPUProfileLevel.d.ts +20 -0
- package/src/shade/device/timing/profile/GPUProfileLevel.d.ts.map +1 -0
- package/src/shade/device/timing/profile/GPUProfileLevel.js +50 -0
- package/src/shade/device/timing/profile/GPUProfileMeta.d.ts +63 -0
- package/src/shade/device/timing/profile/GPUProfileMeta.d.ts.map +1 -0
- package/src/shade/device/timing/profile/GPUProfileMeta.js +73 -0
- package/src/shade/device/timing/profile/GPUProfileSession.d.ts +173 -0
- package/src/shade/device/timing/profile/GPUProfileSession.d.ts.map +1 -0
- package/src/shade/device/timing/profile/GPUProfileSession.js +470 -0
- package/src/shade/device/timing/profile/GPUProfileSpan.d.ts +60 -0
- package/src/shade/device/timing/profile/GPUProfileSpan.d.ts.map +1 -0
- package/src/shade/device/timing/profile/GPUProfileSpan.js +65 -0
- package/src/shade/device/timing/profile/GPUProfileSpanKind.d.ts +19 -0
- package/src/shade/device/timing/profile/GPUProfileSpanKind.d.ts.map +1 -0
- package/src/shade/device/timing/profile/GPUProfileSpanKind.js +25 -0
- package/src/shade/device/timing/profile/GPUProfileTopology.d.ts +159 -0
- package/src/shade/device/timing/profile/GPUProfileTopology.d.ts.map +1 -0
- package/src/shade/device/timing/profile/GPUProfileTopology.js +202 -0
- package/src/shade/device/timing/profile/GPUProfileWork.d.ts +90 -0
- package/src/shade/device/timing/profile/GPUProfileWork.d.ts.map +1 -0
- package/src/shade/device/timing/profile/GPUProfileWork.js +115 -0
- package/src/shade/device/timing/profile/SGPTDefect.d.ts +43 -0
- package/src/shade/device/timing/profile/SGPTDefect.d.ts.map +1 -0
- package/src/shade/device/timing/profile/SGPTDefect.js +65 -0
- package/src/shade/device/timing/profile/SGPTHeader.d.ts +38 -0
- package/src/shade/device/timing/profile/SGPTHeader.d.ts.map +1 -0
- package/src/shade/device/timing/profile/SGPTHeader.js +46 -0
- package/src/shade/device/timing/profile/SGPTRecordRef.d.ts +37 -0
- package/src/shade/device/timing/profile/SGPTRecordRef.d.ts.map +1 -0
- package/src/shade/device/timing/profile/SGPTRecordRef.js +45 -0
- package/src/shade/device/timing/profile/SGPTWriteStream.d.ts +103 -0
- package/src/shade/device/timing/profile/SGPTWriteStream.d.ts.map +1 -0
- package/src/shade/device/timing/profile/SGPTWriteStream.js +287 -0
- package/src/shade/device/timing/profile/SGPT_DEFECT.d.ts +19 -0
- package/src/shade/device/timing/profile/SGPT_DEFECT.d.ts.map +1 -0
- package/src/shade/device/timing/profile/SGPT_DEFECT.js +26 -0
- package/src/shade/device/timing/profile/SGPT_FLAG.d.ts +8 -0
- package/src/shade/device/timing/profile/SGPT_FLAG.d.ts.map +1 -0
- package/src/shade/device/timing/profile/SGPT_FLAG.js +15 -0
- package/src/shade/device/timing/profile/SGPT_FORMAT.md +345 -0
- package/src/shade/device/timing/profile/SGPT_FORMAT_VERSION.d.ts +10 -0
- package/src/shade/device/timing/profile/SGPT_FORMAT_VERSION.d.ts.map +1 -0
- package/src/shade/device/timing/profile/SGPT_FORMAT_VERSION.js +9 -0
- package/src/shade/device/timing/profile/SGPT_FRAME_SLACK.d.ts +17 -0
- package/src/shade/device/timing/profile/SGPT_FRAME_SLACK.d.ts.map +1 -0
- package/src/shade/device/timing/profile/SGPT_FRAME_SLACK.js +16 -0
- package/src/shade/device/timing/profile/SGPT_HEADER_CHECKSUM_COVERAGE.d.ts +16 -0
- package/src/shade/device/timing/profile/SGPT_HEADER_CHECKSUM_COVERAGE.d.ts.map +1 -0
- package/src/shade/device/timing/profile/SGPT_HEADER_CHECKSUM_COVERAGE.js +15 -0
- package/src/shade/device/timing/profile/SGPT_HEADER_OFFSET.d.ts +15 -0
- package/src/shade/device/timing/profile/SGPT_HEADER_OFFSET.d.ts.map +1 -0
- package/src/shade/device/timing/profile/SGPT_HEADER_OFFSET.js +29 -0
- package/src/shade/device/timing/profile/SGPT_HEADER_SIZE.d.ts +7 -0
- package/src/shade/device/timing/profile/SGPT_HEADER_SIZE.d.ts.map +1 -0
- package/src/shade/device/timing/profile/SGPT_HEADER_SIZE.js +6 -0
- package/src/shade/device/timing/profile/SGPT_MAGIC.d.ts +7 -0
- package/src/shade/device/timing/profile/SGPT_MAGIC.d.ts.map +1 -0
- package/src/shade/device/timing/profile/SGPT_MAGIC.js +6 -0
- package/src/shade/device/timing/profile/SGPT_MIN_READER_VERSION.d.ts +16 -0
- package/src/shade/device/timing/profile/SGPT_MIN_READER_VERSION.d.ts.map +1 -0
- package/src/shade/device/timing/profile/SGPT_MIN_READER_VERSION.js +15 -0
- package/src/shade/device/timing/profile/SGPT_RECORD_HEADER_SIZE.d.ts +7 -0
- package/src/shade/device/timing/profile/SGPT_RECORD_HEADER_SIZE.d.ts.map +1 -0
- package/src/shade/device/timing/profile/SGPT_RECORD_HEADER_SIZE.js +6 -0
- package/src/shade/device/timing/profile/SGPT_RECORD_OFFSET.d.ts +13 -0
- package/src/shade/device/timing/profile/SGPT_RECORD_OFFSET.d.ts.map +1 -0
- package/src/shade/device/timing/profile/SGPT_RECORD_OFFSET.js +23 -0
- package/src/shade/device/timing/profile/SGPT_RECORD_SYNC.d.ts +12 -0
- package/src/shade/device/timing/profile/SGPT_RECORD_SYNC.d.ts.map +1 -0
- package/src/shade/device/timing/profile/SGPT_RECORD_SYNC.js +11 -0
- package/src/shade/device/timing/profile/SGPT_RECORD_TYPE.d.ts +18 -0
- package/src/shade/device/timing/profile/SGPT_RECORD_TYPE.d.ts.map +1 -0
- package/src/shade/device/timing/profile/SGPT_RECORD_TYPE.js +46 -0
- package/src/shade/device/timing/profile/frame_graph_extract_topology.d.ts +20 -0
- package/src/shade/device/timing/profile/frame_graph_extract_topology.d.ts.map +1 -0
- package/src/shade/device/timing/profile/frame_graph_extract_topology.js +174 -0
- package/src/shade/device/timing/profile/make_profiling_pass_encoder.d.ts +21 -0
- package/src/shade/device/timing/profile/make_profiling_pass_encoder.d.ts.map +1 -0
- package/src/shade/device/timing/profile/make_profiling_pass_encoder.js +114 -0
- package/src/shade/device/timing/profile/parse_workgroup_size.d.ts +20 -0
- package/src/shade/device/timing/profile/parse_workgroup_size.d.ts.map +1 -0
- package/src/shade/device/timing/profile/parse_workgroup_size.js +43 -0
- package/src/shade/device/timing/profile/sgpt_fourcc.d.ts +18 -0
- package/src/shade/device/timing/profile/sgpt_fourcc.d.ts.map +1 -0
- package/src/shade/device/timing/profile/sgpt_fourcc.js +34 -0
- package/src/shade/device/timing/profile/sgpt_frame_codec.d.ts +42 -0
- package/src/shade/device/timing/profile/sgpt_frame_codec.d.ts.map +1 -0
- package/src/shade/device/timing/profile/sgpt_frame_codec.js +172 -0
- package/src/shade/device/timing/profile/sgpt_meta_codec.d.ts +20 -0
- package/src/shade/device/timing/profile/sgpt_meta_codec.d.ts.map +1 -0
- package/src/shade/device/timing/profile/sgpt_meta_codec.js +65 -0
- package/src/shade/device/timing/profile/sgpt_read_capture.d.ts +19 -0
- package/src/shade/device/timing/profile/sgpt_read_capture.d.ts.map +1 -0
- package/src/shade/device/timing/profile/sgpt_read_capture.js +134 -0
- package/src/shade/device/timing/profile/sgpt_read_header.d.ts +22 -0
- package/src/shade/device/timing/profile/sgpt_read_header.d.ts.map +1 -0
- package/src/shade/device/timing/profile/sgpt_read_header.js +94 -0
- package/src/shade/device/timing/profile/sgpt_read_records.d.ts +27 -0
- package/src/shade/device/timing/profile/sgpt_read_records.d.ts.map +1 -0
- package/src/shade/device/timing/profile/sgpt_read_records.js +153 -0
- package/src/shade/device/timing/profile/sgpt_topology_codec.d.ts +54 -0
- package/src/shade/device/timing/profile/sgpt_topology_codec.d.ts.map +1 -0
- package/src/shade/device/timing/profile/sgpt_topology_codec.js +329 -0
- package/src/shade/device/timing/profile/sgpt_write_header.d.ts +22 -0
- package/src/shade/device/timing/profile/sgpt_write_header.d.ts.map +1 -0
- package/src/shade/device/timing/profile/sgpt_write_header.js +47 -0
- package/src/shade/device/timing/profile/sgpt_write_record.d.ts +23 -0
- package/src/shade/device/timing/profile/sgpt_write_record.d.ts.map +1 -0
- package/src/shade/device/timing/profile/sgpt_write_record.js +62 -0
- package/src/shade/renderer/Renderer.d.ts +21 -0
- package/src/shade/renderer/Renderer.d.ts.map +1 -1
- package/src/shade/renderer/Renderer.js +2513 -2455
- package/src/engine/save/GameStateLoader.d.ts +0 -49
- package/src/engine/save/GameStateLoader.d.ts.map +0 -1
- package/src/engine/save/GameStateLoader.js +0 -168
|
@@ -1,2455 +1,2513 @@
|
|
|
1
|
-
import { assert } from "../../core/assert.js";
|
|
2
|
-
import Signal from "../../core/events/signal/Signal.js";
|
|
3
|
-
import Vector2 from "../../core/geom/Vector2.js";
|
|
4
|
-
import { clamp } from "../../core/math/clamp.js";
|
|
5
|
-
import { remap } from "../../core/math/remap.js";
|
|
6
|
-
import { MetricCollection } from "../../engine/development/performance/MetricCollection.js";
|
|
7
|
-
import {
|
|
8
|
-
MetricCollectionConsoleMonitor
|
|
9
|
-
} from "../../engine/development/performance/monitor/MetricCollectionConsoleMonitor.js";
|
|
10
|
-
import { FrameGraph } from "../../engine/graphics/render/frame_graph/FrameGraph.js";
|
|
11
|
-
import { TextureDescriptor } from "../descriptor/texture/TextureDescriptor.js";
|
|
12
|
-
import { WebGPUExtensionType } from "../descriptor/WebGPUExtensionType.js";
|
|
13
|
-
import { ShadeDeviceFailure } from "../device/ShadeDeviceFailure.js";
|
|
14
|
-
import { ShadeGPUCommandContext } from "../device/ShadeGPUCommandContext.js";
|
|
15
|
-
import { CameraManager } from "./camera/CameraManager.js";
|
|
16
|
-
import { shader_background } from "./deferred/shader_background.js";
|
|
17
|
-
import { shader_composite_volumetrics } from "./deferred/shader_composite_volumetrics.js";
|
|
18
|
-
import { shader_deferred_main, shader_deferred_main_restir } from "./deferred/shader_deferred_main.js";
|
|
19
|
-
import { ReSTIRDI } from "./restir/di/ReSTIRDI.js";
|
|
20
|
-
import { shader_tonemap_HDR } from "./deferred/shader_tonemap_HDR.js";
|
|
21
|
-
import { shader_tonemap_LDR } from "./deferred/shader_tonemap_LDR.js";
|
|
22
|
-
import { G_BUFFER_MIP_LEVELS } from "./gbuffer/G_BUFFER_MIP_LEVELS.js";
|
|
23
|
-
import {
|
|
24
|
-
graph_rasterize_meshes_transparent_oit
|
|
25
|
-
} from "./rasterize/native/oit/graph_rasterize_meshes_transparent_oit.js";
|
|
26
|
-
import {
|
|
27
|
-
viz_rasterization_alpha_tested_pass_descriptor
|
|
28
|
-
} from "./rasterize/native/viz/viz_rasterization_alpha_tested_pass_descriptor.js";
|
|
29
|
-
import {
|
|
30
|
-
viz_rasterization_opaque_pass_descriptor
|
|
31
|
-
} from "./rasterize/native/viz/viz_rasterization_opaque_pass_descriptor.js";
|
|
32
|
-
import { RasterizationJob } from "./rasterize/RasterizationJob.js";
|
|
33
|
-
import { graph_rasterize_scene } from "./rasterize/standard/graph_rasterize_scene.js";
|
|
34
|
-
import { FrameContext } from "./extension/FrameContext.js";
|
|
35
|
-
import { FramePhase } from "./extension/FramePhase.js";
|
|
36
|
-
import { GBufferTextures } from "./extension/GBufferTextures.js";
|
|
37
|
-
import { PresentTarget } from "./extension/PresentTarget.js";
|
|
38
|
-
import { RenderExtensionRegistry } from "./extension/RenderExtensionRegistry.js";
|
|
39
|
-
import { SceneColor } from "./extension/SceneColor.js";
|
|
40
|
-
import { ViewTextures } from "./extension/ViewTextures.js";
|
|
41
|
-
import { shader_brick4_diffuse } from "./global_illumination/brick4/gpu/draw/shader_brick4_diffuse.js";
|
|
42
|
-
import {
|
|
43
|
-
shader_brick4_indirect_lighting
|
|
44
|
-
} from "./global_illumination/brick4/gpu/draw/shader_brick4_indirect_lighting.js";
|
|
45
|
-
import { shader_brick4_specular } from "./global_illumination/brick4/gpu/draw/shader_brick4_specular.js";
|
|
46
|
-
import { shader_diffuse_IBL } from "./global_illumination/ibl/shader_diffuse_IBL.js";
|
|
47
|
-
import { shader_specular_IBL } from "./global_illumination/ibl/shader_specular_IBL.js";
|
|
48
|
-
import { GPULightProbeVolumeRenderer } from "./global_illumination/lpv/bake/GPULightProbeVolumeRenderer.js";
|
|
49
|
-
import { shader_diffuse_LPV } from "./global_illumination/lpv/shader_diffuse_LPV.js";
|
|
50
|
-
import { shader_resolve_indirect_lighting } from "./global_illumination/shader_resolve_indirect_lighting.js";
|
|
51
|
-
import { GraphicsContext } from "./GraphicsContext.js";
|
|
52
|
-
import { graph_build_light_clusters } from "./light/cluster/graph_build_light_clusters.js";
|
|
53
|
-
import { AccumulatingPathTracer } from "./path_tracer/accumulating/AccumulatingPathTracer.js";
|
|
54
|
-
import { graph_postprocess_bloom } from "./postprocess/bloom/graph_postprocess_bloom.js";
|
|
55
|
-
import { shader_ffx_rcas } from "./postprocess/cas/shader_ffx_rcas.js";
|
|
56
|
-
import { GPUCameraExposureManager } from "./postprocess/eye/GPUCameraExposureManager.js";
|
|
57
|
-
import { NSS } from "./postprocess/nss/NSS.js";
|
|
58
|
-
import { PostProcess } from "./postprocess/PostProcess.js";
|
|
59
|
-
import { shader_depth_occlusion_clip } from "./postprocess/taa/shader_depth_occlusion_clip.js";
|
|
60
|
-
import { TAA } from "./postprocess/taa/TAA.js";
|
|
61
|
-
import { MotionBlur } from "./postprocess/motion_blur/MotionBlur.js";
|
|
62
|
-
import { DepthOfField } from "./postprocess/dof/raymarch/DepthOfField.js";
|
|
63
|
-
import { DepthOfFieldU } from "./postprocess/dof/gather/DepthOfFieldU.js";
|
|
64
|
-
import { graph_add_per_object_velocity } from "./postprocess/velocity/graph_add_per_object_velocity.js";
|
|
65
|
-
import { SceneManager } from "./scene/SceneManager.js";
|
|
66
|
-
import { ShadeIndirectLightingMode } from "./ShadeIndirectLightingMode.js";
|
|
67
|
-
import { ShadeUpscalerType } from "./ShadeUpscalerType.js";
|
|
68
|
-
import { graph_image_pass } from "./shader/graph/graph_image_pass.js";
|
|
69
|
-
import { graph_import_buffer } from "./shader/graph/graph_import_buffer.js";
|
|
70
|
-
import { graph_import_texture } from "./shader/graph/graph_import_texture.js";
|
|
71
|
-
import { CascadedSceneSDF } from "./shadow/sdf/cascade/CascadedSceneSDF.js";
|
|
72
|
-
import { STATIC_GRAPHICS_ENGINE_ASSETS } from "./STATIC_GRAPHICS_ENGINE_ASSETS.js";
|
|
73
|
-
import { shader_debug_velocity } from "./postprocess/velocity/shader_debug_velocity.js";
|
|
74
|
-
import { GPUTextureContext } from "./texture/GPUTextureContext.js";
|
|
75
|
-
import { RenderTarget } from "./texture/RenderTarget.js";
|
|
76
|
-
import { View } from "./view/View.js";
|
|
77
|
-
import { ViewManager } from "./view/ViewManager.js";
|
|
78
|
-
|
|
79
|
-
const METRICS = new MetricCollection();
|
|
80
|
-
METRICS.create({ name: 'frame_time' });
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Depth and G-buffer textures carry {@link G_BUFFER_MIP_LEVELS} mip levels.
|
|
84
|
-
* WebGPU's createTexture validation requires mipLevelCount <= floor(log2(max(w,h))) + 1,
|
|
85
|
-
* so the internal resolution must never drop below 2^(G_BUFFER_MIP_LEVELS - 1)
|
|
86
|
-
* or texture allocation will fail.
|
|
87
|
-
* @type {number}
|
|
88
|
-
*/
|
|
89
|
-
const INTERNAL_RESOLUTION_MIN = 1 << (G_BUFFER_MIP_LEVELS - 1);
|
|
90
|
-
|
|
91
|
-
MetricCollectionConsoleMonitor.from(METRICS);
|
|
92
|
-
|
|
93
|
-
export class Renderer {
|
|
94
|
-
/**
|
|
95
|
-
* Indexes current drawn frame
|
|
96
|
-
* @type {number}
|
|
97
|
-
*/
|
|
98
|
-
#frame_count = 0;
|
|
99
|
-
|
|
100
|
-
get frame_count() {
|
|
101
|
-
return this.#frame_count;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* @type {GPUCanvasContext}
|
|
106
|
-
*/
|
|
107
|
-
context;
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* The HTMLCanvasElement (or OffscreenCanvas) bound to this renderer.
|
|
111
|
-
* If `initialize()` was called without a `context`, this is the canvas
|
|
112
|
-
* the renderer created — append it to the DOM to display the output.
|
|
113
|
-
*
|
|
114
|
-
* @returns {HTMLCanvasElement|OffscreenCanvas|undefined}
|
|
115
|
-
*/
|
|
116
|
-
get canvas() {
|
|
117
|
-
return this.context?.canvas;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* @type {GPUDevice}
|
|
122
|
-
*/
|
|
123
|
-
device;
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* @type {GPUCameraExposureManager}
|
|
127
|
-
*/
|
|
128
|
-
#autoexposure;
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* @type {SceneManager}
|
|
132
|
-
*/
|
|
133
|
-
#scenes;
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Only use for read-access
|
|
137
|
-
* @returns {SceneManager}
|
|
138
|
-
*/
|
|
139
|
-
get scenes() {
|
|
140
|
-
return this.#scenes;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* @type {CameraManager}
|
|
145
|
-
*/
|
|
146
|
-
#cameras
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* @type {ViewManager}
|
|
150
|
-
*/
|
|
151
|
-
#views
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
set feature_shadows_enabled(v) {
|
|
155
|
-
assert.isBoolean(v, 'v');
|
|
156
|
-
this.#feature_shadows_enabled = v;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
get feature_shadows_enabled() {
|
|
160
|
-
return this.#feature_shadows_enabled;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Controls which indirect lighting technique is used for
|
|
165
|
-
* both deferred resolve and forward transparency passes.
|
|
166
|
-
* @type {ShadeIndirectLightingMode}
|
|
167
|
-
*/
|
|
168
|
-
indirect_lighting_mode = ShadeIndirectLightingMode.IBL;
|
|
169
|
-
|
|
170
|
-
feature_ssr_enabled = false;
|
|
171
|
-
feature_ssao_enabled = true;
|
|
172
|
-
/**
|
|
173
|
-
* ReSTIR DI — stochastic screen-bounded direct shadowing of local
|
|
174
|
-
* (point+spot) lights. When on, the deferred pass skips its froxel cluster
|
|
175
|
-
* loop and consumes the ReSTIR-resolved radiance instead.
|
|
176
|
-
*/
|
|
177
|
-
feature_restir_di_enabled = false;
|
|
178
|
-
/**
|
|
179
|
-
* Generate point-light shadows with the tetrahedral (4-face) path instead of the default
|
|
180
|
-
* cube (6-face) path. Both produce the same octahedral atlas encoding, so this is safe to
|
|
181
|
-
* flip at runtime and is meant for A/B comparison of the two generators. Pushed to the
|
|
182
|
-
* scene's shadow context each frame; see
|
|
183
|
-
* {@link GPUSceneShadowmapContext.use_tetrahedron_point_shadows}.
|
|
184
|
-
* @type {boolean}
|
|
185
|
-
*/
|
|
186
|
-
feature_tetrahedron_point_shadows = false;
|
|
187
|
-
feature_bloom_enabled = true;
|
|
188
|
-
feature_automatic_exposure_enabled = true;
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Virtual texture streaming (opt-in per material via
|
|
192
|
-
* {@link StandardShadeMaterial#vt_stack}). This flag is the system-wide
|
|
193
|
-
* kill switch: when off, the feedback pass and residency maintenance
|
|
194
|
-
* stop running — already-resident pages keep rendering, nothing new
|
|
195
|
-
* streams in. Costs nothing while no stack is registered.
|
|
196
|
-
* @type {boolean}
|
|
197
|
-
*/
|
|
198
|
-
feature_virtual_textures = true;
|
|
199
|
-
|
|
200
|
-
#feature_taa_enabled = true;
|
|
201
|
-
|
|
202
|
-
get feature_taa_enabled() {
|
|
203
|
-
return this.#feature_taa_enabled;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* While TAA is off nothing writes the history textures, but the frame counter that
|
|
208
|
-
* indexes them keeps advancing — re-enabling would blend with arbitrarily stale
|
|
209
|
-
* history of arbitrary parity. Reset temporal history on the transition.
|
|
210
|
-
* @param {boolean} v
|
|
211
|
-
*/
|
|
212
|
-
set feature_taa_enabled(v) {
|
|
213
|
-
if (this.#feature_taa_enabled === v) {
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
this.#feature_taa_enabled = v;
|
|
218
|
-
this.indicate_view_change();
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Jimenez 2014 reconstruction-filter motion blur, runs between
|
|
223
|
-
* TAA and sharpening on the HDR colour. Reads the velocity buffer
|
|
224
|
-
* the same way TAA does — per-pixel pixel-space deltas — and
|
|
225
|
-
* scatter-gathers along the dilated tile velocity. Off by default
|
|
226
|
-
* because the reconstruction pass is a few-ms-budget item and not
|
|
227
|
-
* every scene needs it.
|
|
228
|
-
*
|
|
229
|
-
* @type {boolean}
|
|
230
|
-
*/
|
|
231
|
-
feature_motion_blur_enabled = false;
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Motion-blur subsystem (Jimenez 2014 reconstruction filter). A
|
|
235
|
-
* self-contained manager — same pattern as {@link #autoexposure} /
|
|
236
|
-
* {@link #depth_of_field} — that owns the motion-blur parameters
|
|
237
|
-
* (currently just `strength`). Constructed in init.
|
|
238
|
-
* @type {MotionBlur}
|
|
239
|
-
*/
|
|
240
|
-
#motion_blur;
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* The motion-blur subsystem. Configure it via `renderer.motion_blur.*`
|
|
244
|
-
* (currently `strength`); toggle the effect with
|
|
245
|
-
* {@link feature_motion_blur_enabled}.
|
|
246
|
-
* @returns {MotionBlur}
|
|
247
|
-
*/
|
|
248
|
-
get motion_blur() { return this.#motion_blur; }
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Debug-only override: when true, the per-object velocity texture
|
|
252
|
-
* is drawn straight into the post-TAA color path so the screen
|
|
253
|
-
* shows the velocity buffer instead of the rendered image. Wired
|
|
254
|
-
* just before TAA — TAA then operates on the velocity texture,
|
|
255
|
-
* which is nonsense but cheap to set up. Default false.
|
|
256
|
-
*
|
|
257
|
-
* @type {boolean}
|
|
258
|
-
*/
|
|
259
|
-
feature_velocity_debug_view = false;
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* When true, {@link path_tracer} replaces the rasterized+shaded color for the frame. The
|
|
263
|
-
* traced result still goes through TAA and tone mapping like any other color.
|
|
264
|
-
*
|
|
265
|
-
* The path tracer accumulates across frames itself, one tile per call, and resets whenever the
|
|
266
|
-
* camera moves. TAA on top of that is two temporal filters fighting over the same image — turn
|
|
267
|
-
* `feature_taa_enabled` off while this is on.
|
|
268
|
-
*
|
|
269
|
-
* This is the traversal-heaviest consumer of the TLAS — it binds `scene_ctx.tlas.buffer`
|
|
270
|
-
* directly — which is what made it the check that the GPU TLAS build traces correctly, and what
|
|
271
|
-
* makes it the first place a regression in that tree would show. Default false: it is a
|
|
272
|
-
* prototype-grade path, not a shipping render mode.
|
|
273
|
-
*
|
|
274
|
-
* @type {boolean}
|
|
275
|
-
*/
|
|
276
|
-
feature_path_tracing_enabled = false;
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Screen-space ray-marched depth of field — the Tiny Glade model
|
|
280
|
-
* (Stachowiak, GPC 2024; see {@link DepthOfField}): aperture sub-rays
|
|
281
|
-
* marched through the half-res depth/CoC buffer with nearest-hit
|
|
282
|
-
* occlusion, plus tilt-shift. Runs on the resolved HDR colour after TAA
|
|
283
|
-
* (which resolves the march's sample noise) and before motion blur. Off
|
|
284
|
-
* by default — a half-res march is a few-ms item, only worth it for a
|
|
285
|
-
* deliberate shallow-focus / diorama look. Configure via `renderer.dof`.
|
|
286
|
-
*
|
|
287
|
-
* @type {boolean}
|
|
288
|
-
*/
|
|
289
|
-
feature_dof_enabled = false;
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* Depth-of-field subsystem (screen-space ray-marched). A self-contained
|
|
293
|
-
* manager — same pattern as {@link #autoexposure} — that owns all DoF
|
|
294
|
-
* parameters, focus state, and GPU buffers. Constructed in init.
|
|
295
|
-
* @type {DepthOfField}
|
|
296
|
-
*/
|
|
297
|
-
#depth_of_field;
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* The depth-of-field subsystem. Configure it via `renderer.dof.*`
|
|
301
|
-
* (`f_number`, `quality`, the `focus*` helpers, `applyPreset`, …);
|
|
302
|
-
* toggle the effect with {@link feature_dof_enabled}.
|
|
303
|
-
* @returns {DepthOfField}
|
|
304
|
-
*/
|
|
305
|
-
get dof() { return this.#depth_of_field; }
|
|
306
|
-
|
|
307
|
-
/**
|
|
308
|
-
* Which depth-of-field implementation runs when {@link feature_dof_enabled}
|
|
309
|
-
* is on. `"raymarch"` (default) is the screen-space ray-march
|
|
310
|
-
* ({@link DepthOfField}); `"unreal"` is the gather-based Diaphragm /
|
|
311
|
-
* Cinematic DoF ({@link DepthOfFieldU}) — half-res near/far gather with a
|
|
312
|
-
* foreground coverage bleed. Mutually exclusive by construction (only one
|
|
313
|
-
* runs at the single DoF call site).
|
|
314
|
-
* @type {"raymarch"|"unreal"}
|
|
315
|
-
*/
|
|
316
|
-
dof_algorithm = "raymarch";
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
* Unreal-style (Diaphragm / Cinematic) gather depth of field — a drop-in
|
|
320
|
-
* alternative to {@link #depth_of_field}, selected via {@link dof_algorithm}.
|
|
321
|
-
* Constructed in init.
|
|
322
|
-
* @type {DepthOfFieldU}
|
|
323
|
-
*/
|
|
324
|
-
#depth_of_field_unreal;
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
* The Unreal-style depth-of-field subsystem. Configure it via
|
|
328
|
-
* `renderer.dof_unreal.*` and select it with `renderer.dof_algorithm = "unreal"`.
|
|
329
|
-
* @returns {DepthOfFieldU}
|
|
330
|
-
*/
|
|
331
|
-
get dof_unreal() { return this.#depth_of_field_unreal; }
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* When true and {@link indirect_lighting_mode} is Brick4, run a single fused
|
|
335
|
-
* pass that produces the resolved indirect lighting directly (combining the
|
|
336
|
-
* brick4 diffuse, brick4 specular and indirect resolve passes). Trades a
|
|
337
|
-
* bit of cache pressure inside the pass for substantially less memory
|
|
338
|
-
* bandwidth: no intermediate rgba16float diffuse/specular targets, the
|
|
339
|
-
* g-buffer is read once, and a single brick4 probe pair is shared between
|
|
340
|
-
* the diffuse and specular evaluations.
|
|
341
|
-
*
|
|
342
|
-
* SSR is mutually exclusive with the fused path (it needs the standalone
|
|
343
|
-
* specular target as input), so when SSR is enabled the split path is used.
|
|
344
|
-
* @type {boolean}
|
|
345
|
-
*/
|
|
346
|
-
fused_indirect = true;
|
|
347
|
-
|
|
348
|
-
/**
|
|
349
|
-
* RCAS
|
|
350
|
-
* @type {boolean}
|
|
351
|
-
*/
|
|
352
|
-
feature_sharpening_enabled = true;
|
|
353
|
-
|
|
354
|
-
#feature_shadows_enabled = true;
|
|
355
|
-
#feature_enabled_transparencies = true;
|
|
356
|
-
|
|
357
|
-
/**
|
|
358
|
-
*
|
|
359
|
-
* @return {ViewManager}
|
|
360
|
-
*/
|
|
361
|
-
get views() {
|
|
362
|
-
return this.#views;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
/**
|
|
366
|
-
* @type {GraphicsContext}
|
|
367
|
-
*/
|
|
368
|
-
#graphics;
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
*
|
|
372
|
-
* @return {GraphicsContext}
|
|
373
|
-
*/
|
|
374
|
-
get graphics() {
|
|
375
|
-
return this.#graphics;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
/**
|
|
380
|
-
*
|
|
381
|
-
* @type {Signal<number>}
|
|
382
|
-
*/
|
|
383
|
-
/**
|
|
384
|
-
* Extensions an outside caller has put into the frame, by phase.
|
|
385
|
-
*
|
|
386
|
-
* @type {RenderExtensionRegistry}
|
|
387
|
-
*/
|
|
388
|
-
#extensions = new RenderExtensionRegistry();
|
|
389
|
-
|
|
390
|
-
/**
|
|
391
|
-
* Raised when there is no usable device — the browser has no WebGPU, the hardware is below the
|
|
392
|
-
* floor, or a working device was lost while running. Carries a {@link ShadeDeviceFailure}.
|
|
393
|
-
*
|
|
394
|
-
* The floor is deliberate and there are no fallbacks (D6/I-8), so telling the player plainly is
|
|
395
|
-
* the whole of what the engine owes here. Loss is not recovered from (R6): everything built on
|
|
396
|
-
* the device went with it, and the honest response is a message and a reload.
|
|
397
|
-
*
|
|
398
|
-
* @type {Signal<ShadeDeviceFailure>}
|
|
399
|
-
*/
|
|
400
|
-
onDeviceFailure = new Signal();
|
|
401
|
-
|
|
402
|
-
onFrameFinished = new Signal();
|
|
403
|
-
|
|
404
|
-
/**
|
|
405
|
-
* First argument is frame index, second is table of debug data
|
|
406
|
-
* @type {Signal<number, Object[]>}
|
|
407
|
-
*/
|
|
408
|
-
onFrameDebug = new Signal();
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
/**
|
|
412
|
-
* Fraction of the output resolution.
|
|
413
|
-
* Controls {@link #internal_resolution}.
|
|
414
|
-
* If this is set to 0.5 for example - internal resolution will be 50% of the output resolution.
|
|
415
|
-
* @type {number}
|
|
416
|
-
*/
|
|
417
|
-
#internal_resolution_scale = 1;
|
|
418
|
-
|
|
419
|
-
/**
|
|
420
|
-
*
|
|
421
|
-
* @type {boolean}
|
|
422
|
-
*/
|
|
423
|
-
#internal_resolution_needs_update = true;
|
|
424
|
-
|
|
425
|
-
/**
|
|
426
|
-
*
|
|
427
|
-
* @param {number} v
|
|
428
|
-
*/
|
|
429
|
-
set internal_resolution_scale(v) {
|
|
430
|
-
assert.isNumber(v, 'v');
|
|
431
|
-
assert.notNaN(v, 'v');
|
|
432
|
-
assert.greaterThan(v, 0);
|
|
433
|
-
assert.isFinite(v, 'v');
|
|
434
|
-
|
|
435
|
-
if (this.#internal_resolution_scale === v) {
|
|
436
|
-
// no change
|
|
437
|
-
return;
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
this.#internal_resolution_scale = v;
|
|
441
|
-
|
|
442
|
-
// schedule resolution recalculation
|
|
443
|
-
this.#internal_resolution_needs_update = true;
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
/**
|
|
447
|
-
*
|
|
448
|
-
* @returns {number}
|
|
449
|
-
*/
|
|
450
|
-
get internal_resolution_scale() {
|
|
451
|
-
return this.#internal_resolution_scale;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
/**
|
|
455
|
-
* This is the resolution that the rendering happens at before upscaling.
|
|
456
|
-
* Derived from input resolution via {@link internal_resolution_scale}
|
|
457
|
-
* @type {Vector2}
|
|
458
|
-
*/
|
|
459
|
-
#internal_resolution = new Vector2(1, 1);
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
/**
|
|
463
|
-
* Output viewport size
|
|
464
|
-
* @type {Vector2}
|
|
465
|
-
*/
|
|
466
|
-
#size = new Vector2(1, 1);
|
|
467
|
-
|
|
468
|
-
/**
|
|
469
|
-
* Output resolution.
|
|
470
|
-
* Equal to {@link size} * {@link pixel_ratio}
|
|
471
|
-
* Don't write directly
|
|
472
|
-
* @type {Vector2}
|
|
473
|
-
* @see {#size}
|
|
474
|
-
* @see {#pixel_ratio}
|
|
475
|
-
*/
|
|
476
|
-
#output_resolution = new Vector2(1, 1);
|
|
477
|
-
|
|
478
|
-
/**
|
|
479
|
-
*
|
|
480
|
-
* @returns {Vector2}
|
|
481
|
-
*/
|
|
482
|
-
get output_resolution() {
|
|
483
|
-
return this.#output_resolution.clone();
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
/**
|
|
487
|
-
* width/height
|
|
488
|
-
* Useful for camera projection setup
|
|
489
|
-
* @return {number}
|
|
490
|
-
*/
|
|
491
|
-
get aspect_ratio() {
|
|
492
|
-
return this.#internal_resolution.x / this.#internal_resolution.y;
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
/**
|
|
496
|
-
* TODO rework ping-ping buffer usage to release old buffer when no longer needed. Can reach much better resource utilization that way. Same for all other TAA-like techniques
|
|
497
|
-
* @type {GPUTextureContext[]}
|
|
498
|
-
*/
|
|
499
|
-
#textures_depth = new Array(2);
|
|
500
|
-
|
|
501
|
-
/**
|
|
502
|
-
*
|
|
503
|
-
* @returns {GPUTextureContext}
|
|
504
|
-
*/
|
|
505
|
-
get texture_depth_current() {
|
|
506
|
-
const tx = this.#textures_depth;
|
|
507
|
-
|
|
508
|
-
return tx[this.#frame_count % tx.length];
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
/**
|
|
512
|
-
*
|
|
513
|
-
* @returns {GPUTextureContext}
|
|
514
|
-
*/
|
|
515
|
-
get texture_depth_previous() {
|
|
516
|
-
const tx = this.#textures_depth;
|
|
517
|
-
|
|
518
|
-
return tx[(this.#frame_count - 1 + tx.length) % tx.length];
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
/**
|
|
522
|
-
*
|
|
523
|
-
* @type {GPUTextureContext[]}
|
|
524
|
-
*/
|
|
525
|
-
#textures_taa_history = new Array(2);
|
|
526
|
-
|
|
527
|
-
/**
|
|
528
|
-
*
|
|
529
|
-
* @returns {GPUTextureContext}
|
|
530
|
-
*/
|
|
531
|
-
#get_texture_taa_history(x) {
|
|
532
|
-
const tx = this.#textures_taa_history;
|
|
533
|
-
|
|
534
|
-
return tx[(this.#frame_count - x + tx.length) % tx.length];
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
/**
|
|
539
|
-
* @type {GPUTextureFormat}
|
|
540
|
-
*/
|
|
541
|
-
#presentation_format = "rgba8unorm";
|
|
542
|
-
|
|
543
|
-
/**
|
|
544
|
-
* How many pixels to draw per screen pixel.
|
|
545
|
-
* Typically, this is used to match physical screen resolution to virtual resolution.
|
|
546
|
-
* On the high pixel density displays, CSS pixels usually take up more than one screen pixel.
|
|
547
|
-
* @type {number}
|
|
548
|
-
*/
|
|
549
|
-
#pixel_ratio = window.devicePixelRatio;
|
|
550
|
-
|
|
551
|
-
/**
|
|
552
|
-
*
|
|
553
|
-
* @return {number}
|
|
554
|
-
*/
|
|
555
|
-
get pixel_ratio() {
|
|
556
|
-
return this.#pixel_ratio;
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
/**
|
|
560
|
-
*
|
|
561
|
-
* @param {number} ratio
|
|
562
|
-
*/
|
|
563
|
-
set pixel_ratio(ratio) {
|
|
564
|
-
assert.isNumber(ratio, 'ratio');
|
|
565
|
-
assert.notNaN(ratio, 'ratio');
|
|
566
|
-
assert.greaterThan(ratio, 0);
|
|
567
|
-
assert.isFinite(ratio, 'ratio');
|
|
568
|
-
|
|
569
|
-
if (ratio === this.#pixel_ratio) {
|
|
570
|
-
// no change
|
|
571
|
-
return;
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
this.#pixel_ratio = ratio;
|
|
575
|
-
|
|
576
|
-
this.#update_resolution();
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
/**
|
|
580
|
-
* How many future frames should be debugged
|
|
581
|
-
* @type {number}
|
|
582
|
-
*/
|
|
583
|
-
#debug_frame_count = 0;
|
|
584
|
-
|
|
585
|
-
/**
|
|
586
|
-
*
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
*
|
|
590
|
-
*
|
|
591
|
-
*
|
|
592
|
-
*
|
|
593
|
-
*
|
|
594
|
-
*
|
|
595
|
-
*
|
|
596
|
-
*
|
|
597
|
-
*
|
|
598
|
-
*
|
|
599
|
-
*
|
|
600
|
-
*
|
|
601
|
-
*
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
/**
|
|
608
|
-
*
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
*
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
*
|
|
619
|
-
*
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
*
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
/**
|
|
640
|
-
*
|
|
641
|
-
* @
|
|
642
|
-
*/
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
/**
|
|
662
|
-
*
|
|
663
|
-
*
|
|
664
|
-
*/
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
if (
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
graph,
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
*
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
*
|
|
946
|
-
*
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
*
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
//
|
|
989
|
-
//
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
*
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
*
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
this.#
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
if (
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
//
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
//
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
//
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
}
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
this
|
|
1228
|
-
|
|
1229
|
-
this.#
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
}));
|
|
1265
|
-
}
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
this
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
const
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
//
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
const
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
const
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
this.#
|
|
1474
|
-
}
|
|
1475
|
-
|
|
1476
|
-
/**
|
|
1477
|
-
*
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
*
|
|
1500
|
-
*/
|
|
1501
|
-
#
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
this.#
|
|
1507
|
-
}
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
if (this
|
|
1527
|
-
this.#
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
if (this
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
//
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
const
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
//
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
//
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
//
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
});
|
|
2268
|
-
}
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
}
|
|
2334
|
-
}
|
|
2335
|
-
|
|
2336
|
-
//
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
input_color:
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
}
|
|
1
|
+
import { assert } from "../../core/assert.js";
|
|
2
|
+
import Signal from "../../core/events/signal/Signal.js";
|
|
3
|
+
import Vector2 from "../../core/geom/Vector2.js";
|
|
4
|
+
import { clamp } from "../../core/math/clamp.js";
|
|
5
|
+
import { remap } from "../../core/math/remap.js";
|
|
6
|
+
import { MetricCollection } from "../../engine/development/performance/MetricCollection.js";
|
|
7
|
+
import {
|
|
8
|
+
MetricCollectionConsoleMonitor
|
|
9
|
+
} from "../../engine/development/performance/monitor/MetricCollectionConsoleMonitor.js";
|
|
10
|
+
import { FrameGraph } from "../../engine/graphics/render/frame_graph/FrameGraph.js";
|
|
11
|
+
import { TextureDescriptor } from "../descriptor/texture/TextureDescriptor.js";
|
|
12
|
+
import { WebGPUExtensionType } from "../descriptor/WebGPUExtensionType.js";
|
|
13
|
+
import { ShadeDeviceFailure } from "../device/ShadeDeviceFailure.js";
|
|
14
|
+
import { ShadeGPUCommandContext } from "../device/ShadeGPUCommandContext.js";
|
|
15
|
+
import { CameraManager } from "./camera/CameraManager.js";
|
|
16
|
+
import { shader_background } from "./deferred/shader_background.js";
|
|
17
|
+
import { shader_composite_volumetrics } from "./deferred/shader_composite_volumetrics.js";
|
|
18
|
+
import { shader_deferred_main, shader_deferred_main_restir } from "./deferred/shader_deferred_main.js";
|
|
19
|
+
import { ReSTIRDI } from "./restir/di/ReSTIRDI.js";
|
|
20
|
+
import { shader_tonemap_HDR } from "./deferred/shader_tonemap_HDR.js";
|
|
21
|
+
import { shader_tonemap_LDR } from "./deferred/shader_tonemap_LDR.js";
|
|
22
|
+
import { G_BUFFER_MIP_LEVELS } from "./gbuffer/G_BUFFER_MIP_LEVELS.js";
|
|
23
|
+
import {
|
|
24
|
+
graph_rasterize_meshes_transparent_oit
|
|
25
|
+
} from "./rasterize/native/oit/graph_rasterize_meshes_transparent_oit.js";
|
|
26
|
+
import {
|
|
27
|
+
viz_rasterization_alpha_tested_pass_descriptor
|
|
28
|
+
} from "./rasterize/native/viz/viz_rasterization_alpha_tested_pass_descriptor.js";
|
|
29
|
+
import {
|
|
30
|
+
viz_rasterization_opaque_pass_descriptor
|
|
31
|
+
} from "./rasterize/native/viz/viz_rasterization_opaque_pass_descriptor.js";
|
|
32
|
+
import { RasterizationJob } from "./rasterize/RasterizationJob.js";
|
|
33
|
+
import { graph_rasterize_scene } from "./rasterize/standard/graph_rasterize_scene.js";
|
|
34
|
+
import { FrameContext } from "./extension/FrameContext.js";
|
|
35
|
+
import { FramePhase } from "./extension/FramePhase.js";
|
|
36
|
+
import { GBufferTextures } from "./extension/GBufferTextures.js";
|
|
37
|
+
import { PresentTarget } from "./extension/PresentTarget.js";
|
|
38
|
+
import { RenderExtensionRegistry } from "./extension/RenderExtensionRegistry.js";
|
|
39
|
+
import { SceneColor } from "./extension/SceneColor.js";
|
|
40
|
+
import { ViewTextures } from "./extension/ViewTextures.js";
|
|
41
|
+
import { shader_brick4_diffuse } from "./global_illumination/brick4/gpu/draw/shader_brick4_diffuse.js";
|
|
42
|
+
import {
|
|
43
|
+
shader_brick4_indirect_lighting
|
|
44
|
+
} from "./global_illumination/brick4/gpu/draw/shader_brick4_indirect_lighting.js";
|
|
45
|
+
import { shader_brick4_specular } from "./global_illumination/brick4/gpu/draw/shader_brick4_specular.js";
|
|
46
|
+
import { shader_diffuse_IBL } from "./global_illumination/ibl/shader_diffuse_IBL.js";
|
|
47
|
+
import { shader_specular_IBL } from "./global_illumination/ibl/shader_specular_IBL.js";
|
|
48
|
+
import { GPULightProbeVolumeRenderer } from "./global_illumination/lpv/bake/GPULightProbeVolumeRenderer.js";
|
|
49
|
+
import { shader_diffuse_LPV } from "./global_illumination/lpv/shader_diffuse_LPV.js";
|
|
50
|
+
import { shader_resolve_indirect_lighting } from "./global_illumination/shader_resolve_indirect_lighting.js";
|
|
51
|
+
import { GraphicsContext } from "./GraphicsContext.js";
|
|
52
|
+
import { graph_build_light_clusters } from "./light/cluster/graph_build_light_clusters.js";
|
|
53
|
+
import { AccumulatingPathTracer } from "./path_tracer/accumulating/AccumulatingPathTracer.js";
|
|
54
|
+
import { graph_postprocess_bloom } from "./postprocess/bloom/graph_postprocess_bloom.js";
|
|
55
|
+
import { shader_ffx_rcas } from "./postprocess/cas/shader_ffx_rcas.js";
|
|
56
|
+
import { GPUCameraExposureManager } from "./postprocess/eye/GPUCameraExposureManager.js";
|
|
57
|
+
import { NSS } from "./postprocess/nss/NSS.js";
|
|
58
|
+
import { PostProcess } from "./postprocess/PostProcess.js";
|
|
59
|
+
import { shader_depth_occlusion_clip } from "./postprocess/taa/shader_depth_occlusion_clip.js";
|
|
60
|
+
import { TAA } from "./postprocess/taa/TAA.js";
|
|
61
|
+
import { MotionBlur } from "./postprocess/motion_blur/MotionBlur.js";
|
|
62
|
+
import { DepthOfField } from "./postprocess/dof/raymarch/DepthOfField.js";
|
|
63
|
+
import { DepthOfFieldU } from "./postprocess/dof/gather/DepthOfFieldU.js";
|
|
64
|
+
import { graph_add_per_object_velocity } from "./postprocess/velocity/graph_add_per_object_velocity.js";
|
|
65
|
+
import { SceneManager } from "./scene/SceneManager.js";
|
|
66
|
+
import { ShadeIndirectLightingMode } from "./ShadeIndirectLightingMode.js";
|
|
67
|
+
import { ShadeUpscalerType } from "./ShadeUpscalerType.js";
|
|
68
|
+
import { graph_image_pass } from "./shader/graph/graph_image_pass.js";
|
|
69
|
+
import { graph_import_buffer } from "./shader/graph/graph_import_buffer.js";
|
|
70
|
+
import { graph_import_texture } from "./shader/graph/graph_import_texture.js";
|
|
71
|
+
import { CascadedSceneSDF } from "./shadow/sdf/cascade/CascadedSceneSDF.js";
|
|
72
|
+
import { STATIC_GRAPHICS_ENGINE_ASSETS } from "./STATIC_GRAPHICS_ENGINE_ASSETS.js";
|
|
73
|
+
import { shader_debug_velocity } from "./postprocess/velocity/shader_debug_velocity.js";
|
|
74
|
+
import { GPUTextureContext } from "./texture/GPUTextureContext.js";
|
|
75
|
+
import { RenderTarget } from "./texture/RenderTarget.js";
|
|
76
|
+
import { View } from "./view/View.js";
|
|
77
|
+
import { ViewManager } from "./view/ViewManager.js";
|
|
78
|
+
|
|
79
|
+
const METRICS = new MetricCollection();
|
|
80
|
+
METRICS.create({ name: 'frame_time' });
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Depth and G-buffer textures carry {@link G_BUFFER_MIP_LEVELS} mip levels.
|
|
84
|
+
* WebGPU's createTexture validation requires mipLevelCount <= floor(log2(max(w,h))) + 1,
|
|
85
|
+
* so the internal resolution must never drop below 2^(G_BUFFER_MIP_LEVELS - 1)
|
|
86
|
+
* or texture allocation will fail.
|
|
87
|
+
* @type {number}
|
|
88
|
+
*/
|
|
89
|
+
const INTERNAL_RESOLUTION_MIN = 1 << (G_BUFFER_MIP_LEVELS - 1);
|
|
90
|
+
|
|
91
|
+
MetricCollectionConsoleMonitor.from(METRICS);
|
|
92
|
+
|
|
93
|
+
export class Renderer {
|
|
94
|
+
/**
|
|
95
|
+
* Indexes current drawn frame
|
|
96
|
+
* @type {number}
|
|
97
|
+
*/
|
|
98
|
+
#frame_count = 0;
|
|
99
|
+
|
|
100
|
+
get frame_count() {
|
|
101
|
+
return this.#frame_count;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @type {GPUCanvasContext}
|
|
106
|
+
*/
|
|
107
|
+
context;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* The HTMLCanvasElement (or OffscreenCanvas) bound to this renderer.
|
|
111
|
+
* If `initialize()` was called without a `context`, this is the canvas
|
|
112
|
+
* the renderer created — append it to the DOM to display the output.
|
|
113
|
+
*
|
|
114
|
+
* @returns {HTMLCanvasElement|OffscreenCanvas|undefined}
|
|
115
|
+
*/
|
|
116
|
+
get canvas() {
|
|
117
|
+
return this.context?.canvas;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @type {GPUDevice}
|
|
122
|
+
*/
|
|
123
|
+
device;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* @type {GPUCameraExposureManager}
|
|
127
|
+
*/
|
|
128
|
+
#autoexposure;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* @type {SceneManager}
|
|
132
|
+
*/
|
|
133
|
+
#scenes;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Only use for read-access
|
|
137
|
+
* @returns {SceneManager}
|
|
138
|
+
*/
|
|
139
|
+
get scenes() {
|
|
140
|
+
return this.#scenes;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* @type {CameraManager}
|
|
145
|
+
*/
|
|
146
|
+
#cameras
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* @type {ViewManager}
|
|
150
|
+
*/
|
|
151
|
+
#views
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
set feature_shadows_enabled(v) {
|
|
155
|
+
assert.isBoolean(v, 'v');
|
|
156
|
+
this.#feature_shadows_enabled = v;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
get feature_shadows_enabled() {
|
|
160
|
+
return this.#feature_shadows_enabled;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Controls which indirect lighting technique is used for
|
|
165
|
+
* both deferred resolve and forward transparency passes.
|
|
166
|
+
* @type {ShadeIndirectLightingMode}
|
|
167
|
+
*/
|
|
168
|
+
indirect_lighting_mode = ShadeIndirectLightingMode.IBL;
|
|
169
|
+
|
|
170
|
+
feature_ssr_enabled = false;
|
|
171
|
+
feature_ssao_enabled = true;
|
|
172
|
+
/**
|
|
173
|
+
* ReSTIR DI — stochastic screen-bounded direct shadowing of local
|
|
174
|
+
* (point+spot) lights. When on, the deferred pass skips its froxel cluster
|
|
175
|
+
* loop and consumes the ReSTIR-resolved radiance instead.
|
|
176
|
+
*/
|
|
177
|
+
feature_restir_di_enabled = false;
|
|
178
|
+
/**
|
|
179
|
+
* Generate point-light shadows with the tetrahedral (4-face) path instead of the default
|
|
180
|
+
* cube (6-face) path. Both produce the same octahedral atlas encoding, so this is safe to
|
|
181
|
+
* flip at runtime and is meant for A/B comparison of the two generators. Pushed to the
|
|
182
|
+
* scene's shadow context each frame; see
|
|
183
|
+
* {@link GPUSceneShadowmapContext.use_tetrahedron_point_shadows}.
|
|
184
|
+
* @type {boolean}
|
|
185
|
+
*/
|
|
186
|
+
feature_tetrahedron_point_shadows = false;
|
|
187
|
+
feature_bloom_enabled = true;
|
|
188
|
+
feature_automatic_exposure_enabled = true;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Virtual texture streaming (opt-in per material via
|
|
192
|
+
* {@link StandardShadeMaterial#vt_stack}). This flag is the system-wide
|
|
193
|
+
* kill switch: when off, the feedback pass and residency maintenance
|
|
194
|
+
* stop running — already-resident pages keep rendering, nothing new
|
|
195
|
+
* streams in. Costs nothing while no stack is registered.
|
|
196
|
+
* @type {boolean}
|
|
197
|
+
*/
|
|
198
|
+
feature_virtual_textures = true;
|
|
199
|
+
|
|
200
|
+
#feature_taa_enabled = true;
|
|
201
|
+
|
|
202
|
+
get feature_taa_enabled() {
|
|
203
|
+
return this.#feature_taa_enabled;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* While TAA is off nothing writes the history textures, but the frame counter that
|
|
208
|
+
* indexes them keeps advancing — re-enabling would blend with arbitrarily stale
|
|
209
|
+
* history of arbitrary parity. Reset temporal history on the transition.
|
|
210
|
+
* @param {boolean} v
|
|
211
|
+
*/
|
|
212
|
+
set feature_taa_enabled(v) {
|
|
213
|
+
if (this.#feature_taa_enabled === v) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
this.#feature_taa_enabled = v;
|
|
218
|
+
this.indicate_view_change();
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Jimenez 2014 reconstruction-filter motion blur, runs between
|
|
223
|
+
* TAA and sharpening on the HDR colour. Reads the velocity buffer
|
|
224
|
+
* the same way TAA does — per-pixel pixel-space deltas — and
|
|
225
|
+
* scatter-gathers along the dilated tile velocity. Off by default
|
|
226
|
+
* because the reconstruction pass is a few-ms-budget item and not
|
|
227
|
+
* every scene needs it.
|
|
228
|
+
*
|
|
229
|
+
* @type {boolean}
|
|
230
|
+
*/
|
|
231
|
+
feature_motion_blur_enabled = false;
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Motion-blur subsystem (Jimenez 2014 reconstruction filter). A
|
|
235
|
+
* self-contained manager — same pattern as {@link #autoexposure} /
|
|
236
|
+
* {@link #depth_of_field} — that owns the motion-blur parameters
|
|
237
|
+
* (currently just `strength`). Constructed in init.
|
|
238
|
+
* @type {MotionBlur}
|
|
239
|
+
*/
|
|
240
|
+
#motion_blur;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* The motion-blur subsystem. Configure it via `renderer.motion_blur.*`
|
|
244
|
+
* (currently `strength`); toggle the effect with
|
|
245
|
+
* {@link feature_motion_blur_enabled}.
|
|
246
|
+
* @returns {MotionBlur}
|
|
247
|
+
*/
|
|
248
|
+
get motion_blur() { return this.#motion_blur; }
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Debug-only override: when true, the per-object velocity texture
|
|
252
|
+
* is drawn straight into the post-TAA color path so the screen
|
|
253
|
+
* shows the velocity buffer instead of the rendered image. Wired
|
|
254
|
+
* just before TAA — TAA then operates on the velocity texture,
|
|
255
|
+
* which is nonsense but cheap to set up. Default false.
|
|
256
|
+
*
|
|
257
|
+
* @type {boolean}
|
|
258
|
+
*/
|
|
259
|
+
feature_velocity_debug_view = false;
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* When true, {@link path_tracer} replaces the rasterized+shaded color for the frame. The
|
|
263
|
+
* traced result still goes through TAA and tone mapping like any other color.
|
|
264
|
+
*
|
|
265
|
+
* The path tracer accumulates across frames itself, one tile per call, and resets whenever the
|
|
266
|
+
* camera moves. TAA on top of that is two temporal filters fighting over the same image — turn
|
|
267
|
+
* `feature_taa_enabled` off while this is on.
|
|
268
|
+
*
|
|
269
|
+
* This is the traversal-heaviest consumer of the TLAS — it binds `scene_ctx.tlas.buffer`
|
|
270
|
+
* directly — which is what made it the check that the GPU TLAS build traces correctly, and what
|
|
271
|
+
* makes it the first place a regression in that tree would show. Default false: it is a
|
|
272
|
+
* prototype-grade path, not a shipping render mode.
|
|
273
|
+
*
|
|
274
|
+
* @type {boolean}
|
|
275
|
+
*/
|
|
276
|
+
feature_path_tracing_enabled = false;
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Screen-space ray-marched depth of field — the Tiny Glade model
|
|
280
|
+
* (Stachowiak, GPC 2024; see {@link DepthOfField}): aperture sub-rays
|
|
281
|
+
* marched through the half-res depth/CoC buffer with nearest-hit
|
|
282
|
+
* occlusion, plus tilt-shift. Runs on the resolved HDR colour after TAA
|
|
283
|
+
* (which resolves the march's sample noise) and before motion blur. Off
|
|
284
|
+
* by default — a half-res march is a few-ms item, only worth it for a
|
|
285
|
+
* deliberate shallow-focus / diorama look. Configure via `renderer.dof`.
|
|
286
|
+
*
|
|
287
|
+
* @type {boolean}
|
|
288
|
+
*/
|
|
289
|
+
feature_dof_enabled = false;
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Depth-of-field subsystem (screen-space ray-marched). A self-contained
|
|
293
|
+
* manager — same pattern as {@link #autoexposure} — that owns all DoF
|
|
294
|
+
* parameters, focus state, and GPU buffers. Constructed in init.
|
|
295
|
+
* @type {DepthOfField}
|
|
296
|
+
*/
|
|
297
|
+
#depth_of_field;
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* The depth-of-field subsystem. Configure it via `renderer.dof.*`
|
|
301
|
+
* (`f_number`, `quality`, the `focus*` helpers, `applyPreset`, …);
|
|
302
|
+
* toggle the effect with {@link feature_dof_enabled}.
|
|
303
|
+
* @returns {DepthOfField}
|
|
304
|
+
*/
|
|
305
|
+
get dof() { return this.#depth_of_field; }
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Which depth-of-field implementation runs when {@link feature_dof_enabled}
|
|
309
|
+
* is on. `"raymarch"` (default) is the screen-space ray-march
|
|
310
|
+
* ({@link DepthOfField}); `"unreal"` is the gather-based Diaphragm /
|
|
311
|
+
* Cinematic DoF ({@link DepthOfFieldU}) — half-res near/far gather with a
|
|
312
|
+
* foreground coverage bleed. Mutually exclusive by construction (only one
|
|
313
|
+
* runs at the single DoF call site).
|
|
314
|
+
* @type {"raymarch"|"unreal"}
|
|
315
|
+
*/
|
|
316
|
+
dof_algorithm = "raymarch";
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Unreal-style (Diaphragm / Cinematic) gather depth of field — a drop-in
|
|
320
|
+
* alternative to {@link #depth_of_field}, selected via {@link dof_algorithm}.
|
|
321
|
+
* Constructed in init.
|
|
322
|
+
* @type {DepthOfFieldU}
|
|
323
|
+
*/
|
|
324
|
+
#depth_of_field_unreal;
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* The Unreal-style depth-of-field subsystem. Configure it via
|
|
328
|
+
* `renderer.dof_unreal.*` and select it with `renderer.dof_algorithm = "unreal"`.
|
|
329
|
+
* @returns {DepthOfFieldU}
|
|
330
|
+
*/
|
|
331
|
+
get dof_unreal() { return this.#depth_of_field_unreal; }
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* When true and {@link indirect_lighting_mode} is Brick4, run a single fused
|
|
335
|
+
* pass that produces the resolved indirect lighting directly (combining the
|
|
336
|
+
* brick4 diffuse, brick4 specular and indirect resolve passes). Trades a
|
|
337
|
+
* bit of cache pressure inside the pass for substantially less memory
|
|
338
|
+
* bandwidth: no intermediate rgba16float diffuse/specular targets, the
|
|
339
|
+
* g-buffer is read once, and a single brick4 probe pair is shared between
|
|
340
|
+
* the diffuse and specular evaluations.
|
|
341
|
+
*
|
|
342
|
+
* SSR is mutually exclusive with the fused path (it needs the standalone
|
|
343
|
+
* specular target as input), so when SSR is enabled the split path is used.
|
|
344
|
+
* @type {boolean}
|
|
345
|
+
*/
|
|
346
|
+
fused_indirect = true;
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* RCAS
|
|
350
|
+
* @type {boolean}
|
|
351
|
+
*/
|
|
352
|
+
feature_sharpening_enabled = true;
|
|
353
|
+
|
|
354
|
+
#feature_shadows_enabled = true;
|
|
355
|
+
#feature_enabled_transparencies = true;
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
*
|
|
359
|
+
* @return {ViewManager}
|
|
360
|
+
*/
|
|
361
|
+
get views() {
|
|
362
|
+
return this.#views;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* @type {GraphicsContext}
|
|
367
|
+
*/
|
|
368
|
+
#graphics;
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
*
|
|
372
|
+
* @return {GraphicsContext}
|
|
373
|
+
*/
|
|
374
|
+
get graphics() {
|
|
375
|
+
return this.#graphics;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
*
|
|
381
|
+
* @type {Signal<number>}
|
|
382
|
+
*/
|
|
383
|
+
/**
|
|
384
|
+
* Extensions an outside caller has put into the frame, by phase.
|
|
385
|
+
*
|
|
386
|
+
* @type {RenderExtensionRegistry}
|
|
387
|
+
*/
|
|
388
|
+
#extensions = new RenderExtensionRegistry();
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Raised when there is no usable device — the browser has no WebGPU, the hardware is below the
|
|
392
|
+
* floor, or a working device was lost while running. Carries a {@link ShadeDeviceFailure}.
|
|
393
|
+
*
|
|
394
|
+
* The floor is deliberate and there are no fallbacks (D6/I-8), so telling the player plainly is
|
|
395
|
+
* the whole of what the engine owes here. Loss is not recovered from (R6): everything built on
|
|
396
|
+
* the device went with it, and the honest response is a message and a reload.
|
|
397
|
+
*
|
|
398
|
+
* @type {Signal<ShadeDeviceFailure>}
|
|
399
|
+
*/
|
|
400
|
+
onDeviceFailure = new Signal();
|
|
401
|
+
|
|
402
|
+
onFrameFinished = new Signal();
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* First argument is frame index, second is table of debug data
|
|
406
|
+
* @type {Signal<number, Object[]>}
|
|
407
|
+
*/
|
|
408
|
+
onFrameDebug = new Signal();
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Fraction of the output resolution.
|
|
413
|
+
* Controls {@link #internal_resolution}.
|
|
414
|
+
* If this is set to 0.5 for example - internal resolution will be 50% of the output resolution.
|
|
415
|
+
* @type {number}
|
|
416
|
+
*/
|
|
417
|
+
#internal_resolution_scale = 1;
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
*
|
|
421
|
+
* @type {boolean}
|
|
422
|
+
*/
|
|
423
|
+
#internal_resolution_needs_update = true;
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
*
|
|
427
|
+
* @param {number} v
|
|
428
|
+
*/
|
|
429
|
+
set internal_resolution_scale(v) {
|
|
430
|
+
assert.isNumber(v, 'v');
|
|
431
|
+
assert.notNaN(v, 'v');
|
|
432
|
+
assert.greaterThan(v, 0);
|
|
433
|
+
assert.isFinite(v, 'v');
|
|
434
|
+
|
|
435
|
+
if (this.#internal_resolution_scale === v) {
|
|
436
|
+
// no change
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
this.#internal_resolution_scale = v;
|
|
441
|
+
|
|
442
|
+
// schedule resolution recalculation
|
|
443
|
+
this.#internal_resolution_needs_update = true;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
*
|
|
448
|
+
* @returns {number}
|
|
449
|
+
*/
|
|
450
|
+
get internal_resolution_scale() {
|
|
451
|
+
return this.#internal_resolution_scale;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* This is the resolution that the rendering happens at before upscaling.
|
|
456
|
+
* Derived from input resolution via {@link internal_resolution_scale}
|
|
457
|
+
* @type {Vector2}
|
|
458
|
+
*/
|
|
459
|
+
#internal_resolution = new Vector2(1, 1);
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Output viewport size
|
|
464
|
+
* @type {Vector2}
|
|
465
|
+
*/
|
|
466
|
+
#size = new Vector2(1, 1);
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Output resolution.
|
|
470
|
+
* Equal to {@link size} * {@link pixel_ratio}
|
|
471
|
+
* Don't write directly
|
|
472
|
+
* @type {Vector2}
|
|
473
|
+
* @see {#size}
|
|
474
|
+
* @see {#pixel_ratio}
|
|
475
|
+
*/
|
|
476
|
+
#output_resolution = new Vector2(1, 1);
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
*
|
|
480
|
+
* @returns {Vector2}
|
|
481
|
+
*/
|
|
482
|
+
get output_resolution() {
|
|
483
|
+
return this.#output_resolution.clone();
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* width/height
|
|
488
|
+
* Useful for camera projection setup
|
|
489
|
+
* @return {number}
|
|
490
|
+
*/
|
|
491
|
+
get aspect_ratio() {
|
|
492
|
+
return this.#internal_resolution.x / this.#internal_resolution.y;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* TODO rework ping-ping buffer usage to release old buffer when no longer needed. Can reach much better resource utilization that way. Same for all other TAA-like techniques
|
|
497
|
+
* @type {GPUTextureContext[]}
|
|
498
|
+
*/
|
|
499
|
+
#textures_depth = new Array(2);
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
*
|
|
503
|
+
* @returns {GPUTextureContext}
|
|
504
|
+
*/
|
|
505
|
+
get texture_depth_current() {
|
|
506
|
+
const tx = this.#textures_depth;
|
|
507
|
+
|
|
508
|
+
return tx[this.#frame_count % tx.length];
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
*
|
|
513
|
+
* @returns {GPUTextureContext}
|
|
514
|
+
*/
|
|
515
|
+
get texture_depth_previous() {
|
|
516
|
+
const tx = this.#textures_depth;
|
|
517
|
+
|
|
518
|
+
return tx[(this.#frame_count - 1 + tx.length) % tx.length];
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
*
|
|
523
|
+
* @type {GPUTextureContext[]}
|
|
524
|
+
*/
|
|
525
|
+
#textures_taa_history = new Array(2);
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
*
|
|
529
|
+
* @returns {GPUTextureContext}
|
|
530
|
+
*/
|
|
531
|
+
#get_texture_taa_history(x) {
|
|
532
|
+
const tx = this.#textures_taa_history;
|
|
533
|
+
|
|
534
|
+
return tx[(this.#frame_count - x + tx.length) % tx.length];
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* @type {GPUTextureFormat}
|
|
540
|
+
*/
|
|
541
|
+
#presentation_format = "rgba8unorm";
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* How many pixels to draw per screen pixel.
|
|
545
|
+
* Typically, this is used to match physical screen resolution to virtual resolution.
|
|
546
|
+
* On the high pixel density displays, CSS pixels usually take up more than one screen pixel.
|
|
547
|
+
* @type {number}
|
|
548
|
+
*/
|
|
549
|
+
#pixel_ratio = window.devicePixelRatio;
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
*
|
|
553
|
+
* @return {number}
|
|
554
|
+
*/
|
|
555
|
+
get pixel_ratio() {
|
|
556
|
+
return this.#pixel_ratio;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
*
|
|
561
|
+
* @param {number} ratio
|
|
562
|
+
*/
|
|
563
|
+
set pixel_ratio(ratio) {
|
|
564
|
+
assert.isNumber(ratio, 'ratio');
|
|
565
|
+
assert.notNaN(ratio, 'ratio');
|
|
566
|
+
assert.greaterThan(ratio, 0);
|
|
567
|
+
assert.isFinite(ratio, 'ratio');
|
|
568
|
+
|
|
569
|
+
if (ratio === this.#pixel_ratio) {
|
|
570
|
+
// no change
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
this.#pixel_ratio = ratio;
|
|
575
|
+
|
|
576
|
+
this.#update_resolution();
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* How many future frames should be debugged
|
|
581
|
+
* @type {number}
|
|
582
|
+
*/
|
|
583
|
+
#debug_frame_count = 0;
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* The profile recording to feed, or null.
|
|
587
|
+
*
|
|
588
|
+
* **Assign one; the renderer never makes one.** The profiler is a leaf nothing in the engine
|
|
589
|
+
* imports, so an application that does not mention it does not carry it — see
|
|
590
|
+
* {@link GPUProfileSession}. This field and the null checks around it are the whole
|
|
591
|
+
* integration.
|
|
592
|
+
*
|
|
593
|
+
* ```js
|
|
594
|
+
* const session = new GPUProfileSession({ level: GPUProfileLevel.TIMING });
|
|
595
|
+
*
|
|
596
|
+
* renderer.profile_session = session;
|
|
597
|
+
* session.start();
|
|
598
|
+
* // ... frames ...
|
|
599
|
+
* const bytes = session.stop();
|
|
600
|
+
* renderer.profile_session = null;
|
|
601
|
+
* ```
|
|
602
|
+
*
|
|
603
|
+
* @type {GPUProfileSession|null}
|
|
604
|
+
*/
|
|
605
|
+
profile_session = null;
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* Increase the number of future debug frames by X
|
|
609
|
+
*/
|
|
610
|
+
/**
|
|
611
|
+
* Record work into the frame at a named point in it.
|
|
612
|
+
*
|
|
613
|
+
* The extension is called once per frame, when its phase comes round, and is handed the
|
|
614
|
+
* {@link FrameContext} — the frame's graph and the typed records holding the handles that exist
|
|
615
|
+
* at that moment. It records with the `graph_*` helpers exactly as the built-in passes do, and
|
|
616
|
+
* everything it produces reaches the rest of the frame by publishing a handle into a record.
|
|
617
|
+
*
|
|
618
|
+
* Handles come from the records rather than from the renderer on purpose: the graph is what
|
|
619
|
+
* knows which resources a pass touched, and work recorded around it cannot be ordered or aliased
|
|
620
|
+
* correctly against the rest of the frame.
|
|
621
|
+
*
|
|
622
|
+
* @param {RenderExtension} extension
|
|
623
|
+
* @returns {RenderExtension} `extension`, for handing back to {@link remove_extension}
|
|
624
|
+
*/
|
|
625
|
+
add_extension(extension) {
|
|
626
|
+
return this.#extensions.add(extension);
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
/**
|
|
630
|
+
* Take an extension back out of the frame.
|
|
631
|
+
*
|
|
632
|
+
* @param {RenderExtension} extension
|
|
633
|
+
* @returns {boolean} whether it was registered
|
|
634
|
+
*/
|
|
635
|
+
remove_extension(extension) {
|
|
636
|
+
return this.#extensions.remove(extension);
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* @param {FramePhase} phase
|
|
641
|
+
* @returns {number} how many extensions are registered on `phase`
|
|
642
|
+
*/
|
|
643
|
+
extension_count(phase) {
|
|
644
|
+
return this.#extensions.count(phase);
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
|
|
648
|
+
add_debug_frame(count = 1) {
|
|
649
|
+
assert.isNonNegativeInteger(count, 'count');
|
|
650
|
+
|
|
651
|
+
this.#debug_frame_count += count;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
/**
|
|
655
|
+
*
|
|
656
|
+
* @type {Map<Scene, GPULightProbeVolumeRenderer>}
|
|
657
|
+
*/
|
|
658
|
+
#probe_bakers = new Map();
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
/**
|
|
662
|
+
*
|
|
663
|
+
* @type {Map<Scene, CascadedSceneSDF>}
|
|
664
|
+
*/
|
|
665
|
+
#scene_sdfs = new Map();
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
*
|
|
669
|
+
* @param {Scene} scene
|
|
670
|
+
* @return {CascadedSceneSDF}
|
|
671
|
+
*/
|
|
672
|
+
obtains_scene_sdf(scene) {
|
|
673
|
+
let sdf = this.#scene_sdfs.get(scene);
|
|
674
|
+
|
|
675
|
+
if (sdf === undefined) {
|
|
676
|
+
sdf = new CascadedSceneSDF(this.device);
|
|
677
|
+
this.#scene_sdfs.set(scene, sdf);
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
return sdf;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
/**
|
|
684
|
+
* Used to instruct renderer that either the scene or camera has changed significantly
|
|
685
|
+
* Primarily instructs resetting history on temporal accumulation
|
|
686
|
+
*/
|
|
687
|
+
indicate_view_change() {
|
|
688
|
+
this.#postprocess.reset_history();
|
|
689
|
+
|
|
690
|
+
if (this.#path_tracer !== undefined) {
|
|
691
|
+
this.#path_tracer.clear_history = true;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
this.#taa.reset_history = true;
|
|
695
|
+
|
|
696
|
+
if (this.#nss !== undefined) {
|
|
697
|
+
this.#nss.reset_history = true;
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* For internal and debug use only
|
|
703
|
+
* @param {Scene} scene
|
|
704
|
+
* @returns {GPULightProbeVolumeRenderer}
|
|
705
|
+
*/
|
|
706
|
+
getProbeRendererForScene(scene) {
|
|
707
|
+
|
|
708
|
+
const scene_ctx = this.#scenes.obtain(scene);
|
|
709
|
+
|
|
710
|
+
let baker = this.#probe_bakers.get(scene);
|
|
711
|
+
|
|
712
|
+
if (baker === undefined) {
|
|
713
|
+
baker = new GPULightProbeVolumeRenderer(this.#graphics, scene_ctx);
|
|
714
|
+
this.#probe_bakers.set(scene, baker);
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
return baker;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
/**
|
|
722
|
+
*
|
|
723
|
+
* @param {Scene} scene
|
|
724
|
+
*/
|
|
725
|
+
update_lpv(scene) {
|
|
726
|
+
|
|
727
|
+
//
|
|
728
|
+
// let baker = this.getProbeRendererForScene(scene);
|
|
729
|
+
//
|
|
730
|
+
// baker.autoSetRaysPerProbe(1);
|
|
731
|
+
// baker.bake();
|
|
732
|
+
|
|
733
|
+
const scene_ctx = this.#scenes.obtain(scene);
|
|
734
|
+
|
|
735
|
+
const graph = new FrameGraph("LPV");
|
|
736
|
+
|
|
737
|
+
const cmd = ShadeGPUCommandContext.create(this.graphics, 'LPV');
|
|
738
|
+
|
|
739
|
+
scene_ctx.light_probe_volume.atlas.graph_update({
|
|
740
|
+
graph,
|
|
741
|
+
scene: scene_ctx,
|
|
742
|
+
graphics: this.graphics,
|
|
743
|
+
update_ray_count: 100_000
|
|
744
|
+
});
|
|
745
|
+
|
|
746
|
+
cmd.encodeGraph(graph);
|
|
747
|
+
cmd.finish();
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
/**
|
|
751
|
+
* Compute deferred indirect specular and diffuse contributions
|
|
752
|
+
* based on the active indirect lighting mode.
|
|
753
|
+
*
|
|
754
|
+
* @param {object} params
|
|
755
|
+
* @param {FrameGraph} params.graph
|
|
756
|
+
* @param {GPUViewContext} params.view_ctx
|
|
757
|
+
* @param {GPUSceneContext} params.scene_ctx
|
|
758
|
+
* @param {number} params.bent_normals - graph resource ID
|
|
759
|
+
* @param {number} params.current_color_out - graph resource ID (scene color, needed for SSR)
|
|
760
|
+
* @param {number} params.gr_texture_depth_current
|
|
761
|
+
* @param {number} params.gr_texture_hzb
|
|
762
|
+
* @param {number} params.gr_texture_material_albedo_ao
|
|
763
|
+
* @param {number} params.gr_texture_pbr
|
|
764
|
+
* @param {number} params.gr_texture_normal
|
|
765
|
+
* @param {number} params.gr_texture_environment
|
|
766
|
+
* @param {number} params.gr_velocity
|
|
767
|
+
* @param {number} params.gr_occlusion_clip
|
|
768
|
+
* @param {number} params.gr_buffer_camera_current
|
|
769
|
+
* @param {number} params.gr_buffer_camera_previous
|
|
770
|
+
* @param {Vector2} params.resolution
|
|
771
|
+
* @returns {{indirect_specular: number, indirect_diffuse: number}}
|
|
772
|
+
*/
|
|
773
|
+
#graph_indirect_lighting({
|
|
774
|
+
graph,
|
|
775
|
+
view_ctx,
|
|
776
|
+
scene_ctx,
|
|
777
|
+
bent_normals,
|
|
778
|
+
current_color_out,
|
|
779
|
+
//
|
|
780
|
+
gr_texture_depth_current,
|
|
781
|
+
gr_texture_hzb,
|
|
782
|
+
gr_texture_material_albedo_ao,
|
|
783
|
+
gr_texture_pbr,
|
|
784
|
+
gr_texture_normal,
|
|
785
|
+
gr_texture_environment,
|
|
786
|
+
gr_velocity,
|
|
787
|
+
gr_occlusion_clip,
|
|
788
|
+
gr_buffer_camera_current,
|
|
789
|
+
gr_buffer_camera_previous,
|
|
790
|
+
resolution,
|
|
791
|
+
}) {
|
|
792
|
+
|
|
793
|
+
const mode = this.indirect_lighting_mode;
|
|
794
|
+
|
|
795
|
+
let indirect_specular = -1;
|
|
796
|
+
let indirect_diffuse = -1;
|
|
797
|
+
|
|
798
|
+
const lpv = scene_ctx.light_probe_volume;
|
|
799
|
+
|
|
800
|
+
//
|
|
801
|
+
// ── SPECULAR ────────────────────────────────────────────
|
|
802
|
+
//
|
|
803
|
+
|
|
804
|
+
// SSR replaces the specular IBL fallback when enabled.
|
|
805
|
+
// NOTE: SSR is currently not supported in Brick4 mode — this is a known
|
|
806
|
+
// limitation and will be addressed in a future update.
|
|
807
|
+
if (this.feature_ssr_enabled && mode !== ShadeIndirectLightingMode.Brick4) {
|
|
808
|
+
|
|
809
|
+
const ssr = this.#postprocess.ssr.graph_pass({
|
|
810
|
+
graph,
|
|
811
|
+
input_depth: gr_texture_depth_current,
|
|
812
|
+
input_hzb: gr_texture_hzb,
|
|
813
|
+
input_scene_color: current_color_out,
|
|
814
|
+
input_albedo: gr_texture_material_albedo_ao,
|
|
815
|
+
input_pbr: gr_texture_pbr,
|
|
816
|
+
input_normal: gr_texture_normal,
|
|
817
|
+
input_velocity: gr_velocity,
|
|
818
|
+
input_occlusion: gr_occlusion_clip,
|
|
819
|
+
input_environment: gr_texture_environment,
|
|
820
|
+
camera_current: gr_buffer_camera_current,
|
|
821
|
+
camera_previous: gr_buffer_camera_previous,
|
|
822
|
+
lpv: mode === ShadeIndirectLightingMode.LPV ? lpv : undefined,
|
|
823
|
+
resolution,
|
|
824
|
+
});
|
|
825
|
+
|
|
826
|
+
indirect_specular = ssr.denoised;
|
|
827
|
+
|
|
828
|
+
} else if (mode === ShadeIndirectLightingMode.Brick4) {
|
|
829
|
+
|
|
830
|
+
// Brick4 specular from volumetric lightmap
|
|
831
|
+
[indirect_specular] = graph_image_pass({
|
|
832
|
+
graph,
|
|
833
|
+
shader: shader_brick4_specular,
|
|
834
|
+
input_depth: gr_texture_depth_current,
|
|
835
|
+
inputs: {
|
|
836
|
+
tDepth: gr_texture_depth_current,
|
|
837
|
+
tNormals: gr_texture_normal,
|
|
838
|
+
tPBR: gr_texture_pbr,
|
|
839
|
+
tSTBN_vec2: STATIC_GRAPHICS_ENGINE_ASSETS.stbn_vec2,
|
|
840
|
+
camera: gr_buffer_camera_current,
|
|
841
|
+
view: view_ctx.uniform_buffer.buffer,
|
|
842
|
+
brick4: scene_ctx.volumetric_light_map.buffer,
|
|
843
|
+
},
|
|
844
|
+
output_resolution: view_ctx.resolution,
|
|
845
|
+
});
|
|
846
|
+
|
|
847
|
+
} else {
|
|
848
|
+
// IBL / LPV fallback — environment map specular
|
|
849
|
+
[indirect_specular] = graph_image_pass({
|
|
850
|
+
graph,
|
|
851
|
+
shader: shader_specular_IBL,
|
|
852
|
+
input_depth: gr_texture_depth_current,
|
|
853
|
+
inputs: {
|
|
854
|
+
tBentNormals: bent_normals,
|
|
855
|
+
tNormals: gr_texture_normal,
|
|
856
|
+
tDepth: gr_texture_depth_current,
|
|
857
|
+
tPBR: gr_texture_pbr,
|
|
858
|
+
tEnvironment: gr_texture_environment,
|
|
859
|
+
camera: gr_buffer_camera_current,
|
|
860
|
+
},
|
|
861
|
+
output_resolution: view_ctx.resolution,
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
//
|
|
866
|
+
// ── DIFFUSE ─────────────────────────────────────────────
|
|
867
|
+
//
|
|
868
|
+
|
|
869
|
+
switch (mode) {
|
|
870
|
+
|
|
871
|
+
case ShadeIndirectLightingMode.IBL:
|
|
872
|
+
// Environment map irradiance
|
|
873
|
+
[indirect_diffuse] = graph_image_pass({
|
|
874
|
+
graph,
|
|
875
|
+
shader: shader_diffuse_IBL,
|
|
876
|
+
input_depth: gr_texture_depth_current,
|
|
877
|
+
inputs: {
|
|
878
|
+
tBentNormals: bent_normals,
|
|
879
|
+
tGBufferAlbedo: gr_texture_material_albedo_ao,
|
|
880
|
+
tEnvironment: gr_texture_environment,
|
|
881
|
+
},
|
|
882
|
+
output_resolution: view_ctx.resolution,
|
|
883
|
+
});
|
|
884
|
+
break;
|
|
885
|
+
|
|
886
|
+
case ShadeIndirectLightingMode.Brick4:
|
|
887
|
+
// Brick4 diffuse from volumetric lightmap
|
|
888
|
+
[indirect_diffuse] = graph_image_pass({
|
|
889
|
+
graph,
|
|
890
|
+
shader: shader_brick4_diffuse,
|
|
891
|
+
input_depth: gr_texture_depth_current,
|
|
892
|
+
inputs: {
|
|
893
|
+
tDepth: gr_texture_depth_current,
|
|
894
|
+
tBentNormals: bent_normals,
|
|
895
|
+
tAlbedoAO: gr_texture_material_albedo_ao,
|
|
896
|
+
tSTBN_vec2: STATIC_GRAPHICS_ENGINE_ASSETS.stbn_vec2,
|
|
897
|
+
camera: gr_buffer_camera_current,
|
|
898
|
+
view: view_ctx.uniform_buffer.buffer,
|
|
899
|
+
brick4: scene_ctx.volumetric_light_map.buffer,
|
|
900
|
+
},
|
|
901
|
+
output_resolution: view_ctx.resolution,
|
|
902
|
+
});
|
|
903
|
+
break;
|
|
904
|
+
|
|
905
|
+
case ShadeIndirectLightingMode.LPV:
|
|
906
|
+
// Light Probe Volume diffuse
|
|
907
|
+
[indirect_diffuse] = graph_image_pass({
|
|
908
|
+
graph,
|
|
909
|
+
shader: shader_diffuse_LPV,
|
|
910
|
+
input_depth: gr_texture_depth_current,
|
|
911
|
+
inputs: {
|
|
912
|
+
camera: gr_buffer_camera_current,
|
|
913
|
+
tDepth: gr_texture_depth_current,
|
|
914
|
+
tBentNormals: bent_normals,
|
|
915
|
+
tGBufferAlbedo: gr_texture_material_albedo_ao,
|
|
916
|
+
//
|
|
917
|
+
lpv_atlas_radiance: lpv.atlas.texture_radiance,
|
|
918
|
+
lpv_atlas_depth: lpv.atlas.texture_depth,
|
|
919
|
+
//
|
|
920
|
+
lpv_lookup: lpv.buffer_mesh_bvh,
|
|
921
|
+
lpv_metadata: lpv.buffer_metadata,
|
|
922
|
+
lpv_mesh: lpv.buffer_mesh,
|
|
923
|
+
lpv_probes: lpv.buffer_probes,
|
|
924
|
+
},
|
|
925
|
+
output_resolution: view_ctx.resolution,
|
|
926
|
+
});
|
|
927
|
+
break;
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
return { indirect_specular, indirect_diffuse };
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
/**
|
|
934
|
+
* @type {PostProcess}
|
|
935
|
+
*/
|
|
936
|
+
#postprocess
|
|
937
|
+
|
|
938
|
+
/**
|
|
939
|
+
* @type {ReSTIRDI}
|
|
940
|
+
*/
|
|
941
|
+
#restir_di
|
|
942
|
+
|
|
943
|
+
/**
|
|
944
|
+
* ReSTIR DI subsystem — exposed for runtime tuning (e.g. GUI toggles like
|
|
945
|
+
* `use_screen_space_shadow`, `m_initial`).
|
|
946
|
+
* @returns {ReSTIRDI}
|
|
947
|
+
*/
|
|
948
|
+
get restir_di() {
|
|
949
|
+
return this.#restir_di;
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
/**
|
|
953
|
+
*
|
|
954
|
+
* @type {TAA}
|
|
955
|
+
*/
|
|
956
|
+
#taa = new TAA();
|
|
957
|
+
|
|
958
|
+
/**
|
|
959
|
+
* Lazily constructed in {@link initialize} once a graphics context is
|
|
960
|
+
* available — NSS owns persistent GPU textures, so it can't be a
|
|
961
|
+
* field initializer like {@link #taa}.
|
|
962
|
+
* @type {NSS | undefined}
|
|
963
|
+
*/
|
|
964
|
+
#nss
|
|
965
|
+
|
|
966
|
+
/**
|
|
967
|
+
* Selects which temporal-AA / upscaler runs at the temporal-resolve
|
|
968
|
+
* stage. Defaults to {@link ShadeUpscalerType.TAA}; assign
|
|
969
|
+
* {@link ShadeUpscalerType.NSS} to use the bundled neural upscaler
|
|
970
|
+
* (no extra setup — the NSS instance ships with placeholder weights).
|
|
971
|
+
* @type {ShadeUpscalerType}
|
|
972
|
+
*/
|
|
973
|
+
upscale_type = ShadeUpscalerType.TAA;
|
|
974
|
+
|
|
975
|
+
/**
|
|
976
|
+
* Public read access to the NSS instance. Lazily constructed on
|
|
977
|
+
* first access, which is also when the bundled weights blob is
|
|
978
|
+
* decoded — so the cost of selecting NSS is amortized to a single
|
|
979
|
+
* frame.
|
|
980
|
+
* @returns {NSS}
|
|
981
|
+
*/
|
|
982
|
+
get nss() {
|
|
983
|
+
if (this.#nss === undefined) {
|
|
984
|
+
assert.defined(this.#graphics, 'graphics context not yet initialized — call Renderer.initialize() first');
|
|
985
|
+
this.#nss = new NSS(this.#graphics);
|
|
986
|
+
|
|
987
|
+
// First-time setup: align the jitter sequence size with the
|
|
988
|
+
// current upscale ratio. Subsequent resolution changes are
|
|
989
|
+
// picked up by #update_internal_resolution.
|
|
990
|
+
const out_w = this.#output_resolution.x;
|
|
991
|
+
const in_w = this.#internal_resolution.x;
|
|
992
|
+
if (out_w > 0 && in_w > 0) {
|
|
993
|
+
const upscale_ratio = out_w / in_w;
|
|
994
|
+
this.#nss.jitter_sequence_size = NSS.recommended_jitter_sequence_size(upscale_ratio);
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
return this.#nss;
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
#device_lost = false;
|
|
1001
|
+
|
|
1002
|
+
/**
|
|
1003
|
+
* Handles event when GPUDevice is lost
|
|
1004
|
+
* @param {GPUDeviceLostInfo} info
|
|
1005
|
+
*/
|
|
1006
|
+
#handle_device_lost(info) {
|
|
1007
|
+
this.#device_lost = true;
|
|
1008
|
+
|
|
1009
|
+
if (info.reason === "destroyed") {
|
|
1010
|
+
// most likely renderer was destroyed, this is expected behavior
|
|
1011
|
+
// TODO check if renderer owns the device, if not, log a warning
|
|
1012
|
+
return;
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
console.error('GPUDevice lost', info);
|
|
1016
|
+
|
|
1017
|
+
// Everything the renderer built lives on the device that just went away, so there is
|
|
1018
|
+
// nothing to carry over and no attempt to (R6). Whoever is hosting this gets told, and a
|
|
1019
|
+
// reload is the way back.
|
|
1020
|
+
this.onDeviceFailure.send1(ShadeDeviceFailure.device_lost(info.message ?? info.reason ?? ""));
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
#hdr_supported = false;
|
|
1024
|
+
|
|
1025
|
+
/**
|
|
1026
|
+
* What's the peak brightness of the display?
|
|
1027
|
+
* Only valid for HDR.
|
|
1028
|
+
*
|
|
1029
|
+
* @type {number}
|
|
1030
|
+
*/
|
|
1031
|
+
#display_peak_brightness_nits = 1000;
|
|
1032
|
+
|
|
1033
|
+
#update_presentation_format() {
|
|
1034
|
+
|
|
1035
|
+
const format8bit = navigator.gpu.getPreferredCanvasFormat();
|
|
1036
|
+
|
|
1037
|
+
const format = this.#hdr_supported ? "rgba16float" : format8bit;
|
|
1038
|
+
|
|
1039
|
+
if (format === this.#presentation_format) {
|
|
1040
|
+
return;
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
this.#presentation_format = format;
|
|
1044
|
+
|
|
1045
|
+
this.#context_needs_update = true;
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
/**
|
|
1049
|
+
* Needs to be a lambda, because we use it as a listener.
|
|
1050
|
+
*/
|
|
1051
|
+
#update_hdr_support = () => {
|
|
1052
|
+
const isHDR = window.matchMedia("(dynamic-range: high)").matches;
|
|
1053
|
+
|
|
1054
|
+
const previous_value = this.#hdr_supported;
|
|
1055
|
+
|
|
1056
|
+
|
|
1057
|
+
this.#hdr_supported = isHDR;
|
|
1058
|
+
|
|
1059
|
+
if (isHDR) {
|
|
1060
|
+
// Currently, there is no way to interrogate this from the browser, so going with an assumption
|
|
1061
|
+
this.#display_peak_brightness_nits = 1000;
|
|
1062
|
+
} else {
|
|
1063
|
+
// Assume SDR nits
|
|
1064
|
+
this.#display_peak_brightness_nits = 80;
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
if (isHDR === previous_value) {
|
|
1068
|
+
// no change
|
|
1069
|
+
return;
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
console.log(`HDR support: ${isHDR ? 'enabled' : 'disabled'}`);
|
|
1073
|
+
|
|
1074
|
+
this.#update_presentation_format();
|
|
1075
|
+
|
|
1076
|
+
this.#context_needs_update = true;
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
/**
|
|
1080
|
+
*
|
|
1081
|
+
* @param {GPUCanvasContext} [context] Optional, if not provided - one will be created.
|
|
1082
|
+
* @param {GPUDevice} [device] Optional, if not provided - one will be created.
|
|
1083
|
+
* @param {number} [pixelRatio] Optiona, if not provided - will be taken from browser context
|
|
1084
|
+
*/
|
|
1085
|
+
async initialize({
|
|
1086
|
+
context,
|
|
1087
|
+
device,
|
|
1088
|
+
pixelRatio = window.devicePixelRatio,
|
|
1089
|
+
} = {}) {
|
|
1090
|
+
|
|
1091
|
+
if (!('gpu' in navigator)) {
|
|
1092
|
+
throw new Error('navigator.gpu not available — WebGPU disabled or unsupported');
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
this.#update_presentation_format();
|
|
1096
|
+
this.#update_hdr_support();
|
|
1097
|
+
|
|
1098
|
+
if (context === undefined) {
|
|
1099
|
+
const canvas = document.createElement('canvas');
|
|
1100
|
+
canvas.width = window.innerWidth;
|
|
1101
|
+
canvas.height = window.innerHeight;
|
|
1102
|
+
// Sensible default styling so a freshly-appended canvas covers
|
|
1103
|
+
// the viewport without depending on the host page's CSS reset.
|
|
1104
|
+
// Override `style` after `initialize()` returns if the host
|
|
1105
|
+
// page wants the canvas embedded somewhere else.
|
|
1106
|
+
canvas.style.cssText = 'position:fixed;inset:0;width:100vw;height:100vh;display:block';
|
|
1107
|
+
|
|
1108
|
+
context = canvas.getContext('webgpu');
|
|
1109
|
+
|
|
1110
|
+
if (context === null) {
|
|
1111
|
+
throw new Error('Failed to bind GPUCanvasContext');
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
if (device === undefined) {
|
|
1116
|
+
// no device present, let's create one
|
|
1117
|
+
|
|
1118
|
+
const gpu = navigator.gpu;
|
|
1119
|
+
|
|
1120
|
+
if (gpu === undefined) {
|
|
1121
|
+
throw ShadeDeviceFailure.webgpu_unavailable();
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
const adapter = await gpu.requestAdapter({
|
|
1125
|
+
powerPreference: "high-performance",
|
|
1126
|
+
});
|
|
1127
|
+
|
|
1128
|
+
if (adapter === null) {
|
|
1129
|
+
throw ShadeDeviceFailure.adapter_unavailable();
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
if (adapter.isFallbackAdapter) {
|
|
1133
|
+
// see https://www.w3.org/TR/webgpu/#dom-gpurequestadapteroptions-forcefallbackadapter
|
|
1134
|
+
// fallback device is typically a software implementation and is going to be slow as sin
|
|
1135
|
+
console.warn('GPU provided a fallback adapter (typically because no other appropriate adapter was available). Fallback adapter is typically a software implementation and will be slow.');
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
// log details of the adapter
|
|
1139
|
+
console.log(`GPU adapter is ${adapter.info.vendor}/${adapter.info.architecture}, device='${adapter.info.device}', description='${adapter.info.description}'`);
|
|
1140
|
+
|
|
1141
|
+
// console.warn(`Buffer size limit: ${number_format_by_thousands(adapter.limits.maxBufferSize)}`);
|
|
1142
|
+
//
|
|
1143
|
+
// console.warn('adapter limits:', adapter.limits);
|
|
1144
|
+
|
|
1145
|
+
const maxStorageBuffersPerShaderStage = adapter.limits.maxStorageBuffersPerShaderStage;
|
|
1146
|
+
|
|
1147
|
+
if (maxStorageBuffersPerShaderStage < 10) {
|
|
1148
|
+
throw ShadeDeviceFailure.below_floor(
|
|
1149
|
+
`requires at least 10 storage buffers per shader stage, adapter offers ${maxStorageBuffersPerShaderStage}`
|
|
1150
|
+
);
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
const requiredFeatures = [
|
|
1154
|
+
// required for indirect draw that's used extensively in Shade
|
|
1155
|
+
WebGPUExtensionType.IndirectFirstInstance,
|
|
1156
|
+
// required for OIT (might be unavailable)
|
|
1157
|
+
WebGPUExtensionType.Float32Blendable,
|
|
1158
|
+
];
|
|
1159
|
+
|
|
1160
|
+
// add features if they are available
|
|
1161
|
+
const optional_desired = [
|
|
1162
|
+
// Profiling only, and some browsers withhold it on hardware that is otherwise
|
|
1163
|
+
// fine — so it is taken when offered and the timers go quiet when it is not
|
|
1164
|
+
// (E7, sponsor 2026-08-16). Requiring it would refuse to start on those browsers
|
|
1165
|
+
// for the sake of a feature the game does not need to run.
|
|
1166
|
+
WebGPUExtensionType.TimestampQuery,
|
|
1167
|
+
WebGPUExtensionType.Subgroups,
|
|
1168
|
+
WebGPUExtensionType.TextureFormatsTier1,
|
|
1169
|
+
];
|
|
1170
|
+
|
|
1171
|
+
// valid required features
|
|
1172
|
+
for (const feature of requiredFeatures) {
|
|
1173
|
+
if (!adapter.features.has(feature)) {
|
|
1174
|
+
throw ShadeDeviceFailure.below_floor(`adapter does not support required feature '${feature}'`);
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
for (const feature of optional_desired) {
|
|
1179
|
+
if (adapter.features.has(feature)) {
|
|
1180
|
+
requiredFeatures.push(feature);
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
|
|
1185
|
+
device = await adapter.requestDevice({
|
|
1186
|
+
requiredLimits: {
|
|
1187
|
+
// required for large G-buffers
|
|
1188
|
+
maxColorAttachmentBytesPerSample: 32,
|
|
1189
|
+
|
|
1190
|
+
/*
|
|
1191
|
+
grab the largest buffer limit we can get, default limits are super-low
|
|
1192
|
+
*/
|
|
1193
|
+
maxBufferSize: adapter.limits.maxBufferSize,
|
|
1194
|
+
maxStorageBufferBindingSize: adapter.limits.maxStorageBufferBindingSize,
|
|
1195
|
+
|
|
1196
|
+
maxStorageBuffersPerShaderStage: 10,
|
|
1197
|
+
},
|
|
1198
|
+
requiredFeatures
|
|
1199
|
+
});
|
|
1200
|
+
|
|
1201
|
+
// NOTE: according to spec (as of 2025/09/19) - adapter can only be used to create one device, after which it becomes "consumed"
|
|
1202
|
+
// see https://www.w3.org/TR/webgpu/#adapters
|
|
1203
|
+
|
|
1204
|
+
// TODO obtained device might be "lost" if something goes wrong, would make sense to check for that
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
device.lost.then(info => {
|
|
1208
|
+
this.#handle_device_lost(info);
|
|
1209
|
+
})
|
|
1210
|
+
|
|
1211
|
+
if (context === undefined) {
|
|
1212
|
+
const canvas = document.createElement('canvas');
|
|
1213
|
+
canvas.width = window.innerWidth;
|
|
1214
|
+
canvas.height = window.innerHeight;
|
|
1215
|
+
|
|
1216
|
+
context = canvas.getContext('webgpu');
|
|
1217
|
+
|
|
1218
|
+
if (context === null) {
|
|
1219
|
+
throw new Error('Failed to bind GPUCanvasContext');
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
assert.ok(device.features.has("indirect-first-instance"), '"indirect-first-instance" feature needs to be enabled for non-zero firstInstance values to be used.')
|
|
1224
|
+
assert.isInstanceOf(context, GPUCanvasContext, 'context', 'GPUCanvasContext');
|
|
1225
|
+
|
|
1226
|
+
this.context = context;
|
|
1227
|
+
this.device = device;
|
|
1228
|
+
|
|
1229
|
+
this.#pixel_ratio = pixelRatio;
|
|
1230
|
+
|
|
1231
|
+
// clientWidth/clientHeight are 0 for a canvas that is not attached to the DOM,
|
|
1232
|
+
// which is always the case for the renderer-owned canvas created above.
|
|
1233
|
+
// Fall back to the backing-store size so that #configure_context doesn't
|
|
1234
|
+
// overwrite the just-set canvas size with the 1x1 minimum resolution.
|
|
1235
|
+
this.#size.set(
|
|
1236
|
+
context.canvas.clientWidth || context.canvas.width,
|
|
1237
|
+
context.canvas.clientHeight || context.canvas.height
|
|
1238
|
+
);
|
|
1239
|
+
|
|
1240
|
+
this.#update_output_resolution();
|
|
1241
|
+
|
|
1242
|
+
this.#graphics = new GraphicsContext(device);
|
|
1243
|
+
|
|
1244
|
+
const graphics = this.#graphics;
|
|
1245
|
+
|
|
1246
|
+
await graphics.initialize();
|
|
1247
|
+
|
|
1248
|
+
|
|
1249
|
+
this.#scenes = new SceneManager(graphics);
|
|
1250
|
+
|
|
1251
|
+
this.#cameras = new CameraManager(this.device);
|
|
1252
|
+
this.#views = new ViewManager(graphics, this.#cameras, this.#scenes);
|
|
1253
|
+
|
|
1254
|
+
const resolution_internal = this.#internal_resolution.asArray();
|
|
1255
|
+
|
|
1256
|
+
for (let i = 0; i < this.#textures_depth.length; i++) {
|
|
1257
|
+
|
|
1258
|
+
this.#textures_depth[i] = graphics.textures.contextFromDescriptor(TextureDescriptor.from({
|
|
1259
|
+
label: `Depth ${i}`,
|
|
1260
|
+
size: resolution_internal,
|
|
1261
|
+
format: 'depth32float',
|
|
1262
|
+
mipLevelCount: G_BUFFER_MIP_LEVELS,
|
|
1263
|
+
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_SRC,
|
|
1264
|
+
}));
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
|
|
1268
|
+
const resolution_out = this.#output_resolution.asArray();
|
|
1269
|
+
|
|
1270
|
+
for (let i = 0; i < this.#textures_taa_history.length; i++) {
|
|
1271
|
+
|
|
1272
|
+
this.#textures_taa_history[i] = graphics.textures.contextFromDescriptor(TextureDescriptor.from({
|
|
1273
|
+
label: `Color ${i}`,
|
|
1274
|
+
size: resolution_out,
|
|
1275
|
+
format: "rgba16float",
|
|
1276
|
+
mipLevelCount: 1,
|
|
1277
|
+
// STORAGE_BINDING is required for the NSS postprocess
|
|
1278
|
+
// compute shader to write here. TAA continues to use
|
|
1279
|
+
// RENDER_ATTACHMENT — the flags coexist on the same
|
|
1280
|
+
// texture and the active upscaler picks its preferred
|
|
1281
|
+
// write path each frame.
|
|
1282
|
+
usage: GPUTextureUsage.RENDER_ATTACHMENT
|
|
1283
|
+
| GPUTextureUsage.TEXTURE_BINDING
|
|
1284
|
+
| GPUTextureUsage.STORAGE_BINDING
|
|
1285
|
+
| GPUTextureUsage.COPY_SRC,
|
|
1286
|
+
}));
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
this.#autoexposure = new GPUCameraExposureManager(device);
|
|
1290
|
+
this.#depth_of_field = new DepthOfField(device);
|
|
1291
|
+
this.#depth_of_field_unreal = new DepthOfFieldU(device);
|
|
1292
|
+
this.#motion_blur = new MotionBlur();
|
|
1293
|
+
|
|
1294
|
+
this.#postprocess = new PostProcess(this.#graphics);
|
|
1295
|
+
|
|
1296
|
+
this.#restir_di = new ReSTIRDI(this.#graphics);
|
|
1297
|
+
|
|
1298
|
+
this.#configure_context();
|
|
1299
|
+
this.init_render_targets();
|
|
1300
|
+
|
|
1301
|
+
window.matchMedia("(dynamic-range: high)").addEventListener("change", this.#update_hdr_support);
|
|
1302
|
+
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
/**
|
|
1306
|
+
* Cleanup
|
|
1307
|
+
*/
|
|
1308
|
+
destroy() {
|
|
1309
|
+
|
|
1310
|
+
window.matchMedia("(dynamic-range: high)").removeEventListener("change", this.#update_hdr_support);
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
|
|
1314
|
+
/**
|
|
1315
|
+
* @type {RenderTarget}
|
|
1316
|
+
*/
|
|
1317
|
+
#vis_render_target;
|
|
1318
|
+
|
|
1319
|
+
init_render_targets() {
|
|
1320
|
+
const vis_rt = new RenderTarget();
|
|
1321
|
+
this.#vis_render_target = vis_rt;
|
|
1322
|
+
|
|
1323
|
+
const textures = this.#graphics.textures;
|
|
1324
|
+
|
|
1325
|
+
// TODO these can be moved to frame graph instead and managed in a transient manner
|
|
1326
|
+
const internal_resolution_array = this.#internal_resolution.asArray();
|
|
1327
|
+
|
|
1328
|
+
vis_rt.color_attachments = [
|
|
1329
|
+
textures.contextFromDescriptor(TextureDescriptor.from({
|
|
1330
|
+
size: internal_resolution_array,
|
|
1331
|
+
format: "r32uint",
|
|
1332
|
+
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING
|
|
1333
|
+
})),
|
|
1334
|
+
textures.contextFromDescriptor(TextureDescriptor.from({
|
|
1335
|
+
size: internal_resolution_array,
|
|
1336
|
+
format: "r32uint",
|
|
1337
|
+
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.TEXTURE_BINDING
|
|
1338
|
+
})),
|
|
1339
|
+
];
|
|
1340
|
+
|
|
1341
|
+
vis_rt.depth_attachment = this.#textures_depth[0];
|
|
1342
|
+
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
/**
|
|
1346
|
+
* If set to true, will force {@link #configure_context} on next render
|
|
1347
|
+
* @type {boolean}
|
|
1348
|
+
*/
|
|
1349
|
+
#context_needs_update = false;
|
|
1350
|
+
|
|
1351
|
+
#configure_context() {
|
|
1352
|
+
const context = this.context;
|
|
1353
|
+
|
|
1354
|
+
const resolution = this.#output_resolution;
|
|
1355
|
+
|
|
1356
|
+
context.canvas.width = resolution.x;
|
|
1357
|
+
context.canvas.height = resolution.y;
|
|
1358
|
+
|
|
1359
|
+
// canvas must be scaled on-screen differently from resolution to account for pixel ratio
|
|
1360
|
+
const size = this.#size;
|
|
1361
|
+
context.canvas.style.width = `${size.x}px`;
|
|
1362
|
+
context.canvas.style.height = `${size.y}px`;
|
|
1363
|
+
|
|
1364
|
+
const preferred_color_space = 'display-p3';
|
|
1365
|
+
|
|
1366
|
+
|
|
1367
|
+
const config = {
|
|
1368
|
+
device: this.device,
|
|
1369
|
+
format: this.#presentation_format,
|
|
1370
|
+
alphaMode: 'opaque',
|
|
1371
|
+
colorSpace: preferred_color_space,
|
|
1372
|
+
toneMapping: {
|
|
1373
|
+
// see https://www.w3.org/TR/webgpu/#dom-gpucanvastonemappingmode-extended
|
|
1374
|
+
mode: this.#hdr_supported ? "extended" : "standard"
|
|
1375
|
+
}
|
|
1376
|
+
};
|
|
1377
|
+
|
|
1378
|
+
|
|
1379
|
+
try {
|
|
1380
|
+
context.configure(config);
|
|
1381
|
+
} catch (e) {
|
|
1382
|
+
// try fall-back colorspace
|
|
1383
|
+
context.configure({
|
|
1384
|
+
...config,
|
|
1385
|
+
colorSpace: 'srgb'
|
|
1386
|
+
});
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
#apply_size() {
|
|
1392
|
+
const out_w = this.#output_resolution.x;
|
|
1393
|
+
const out_h = this.#output_resolution.y;
|
|
1394
|
+
|
|
1395
|
+
this.#textures_taa_history.forEach(t => t.resize(out_w, out_h));
|
|
1396
|
+
|
|
1397
|
+
|
|
1398
|
+
this.#context_needs_update = true;
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
|
|
1402
|
+
#update_internal_resolution() {
|
|
1403
|
+
const out_w = this.#output_resolution.x;
|
|
1404
|
+
const out_h = this.#output_resolution.y;
|
|
1405
|
+
|
|
1406
|
+
const dimension_limit = this.device.limits.maxTextureDimension2D;
|
|
1407
|
+
|
|
1408
|
+
const irs = this.#internal_resolution_scale;
|
|
1409
|
+
|
|
1410
|
+
const _iw = clamp(Math.floor(out_w * irs), INTERNAL_RESOLUTION_MIN, dimension_limit);
|
|
1411
|
+
const _ih = clamp(Math.floor(out_h * irs), INTERNAL_RESOLUTION_MIN, dimension_limit);
|
|
1412
|
+
|
|
1413
|
+
this.#internal_resolution.set(_iw, _ih);
|
|
1414
|
+
|
|
1415
|
+
// figure out exact x/y resolution scale
|
|
1416
|
+
const irs_x_inv = out_w / _iw;
|
|
1417
|
+
const irs_y_int = out_h / _ih;
|
|
1418
|
+
|
|
1419
|
+
// we need to make TAA sequence long enough to provide full coverage over output resolution texels
|
|
1420
|
+
const taa_sequence_scale = Math.max(1, irs_x_inv * irs_y_int);
|
|
1421
|
+
|
|
1422
|
+
const upscale_factor = 1 / irs;
|
|
1423
|
+
|
|
1424
|
+
// shrink the sequence as upscale factor increases
|
|
1425
|
+
// we lose crispness of the edges, but we have to trade it to get faster convergence
|
|
1426
|
+
const base_sequence_size = remap(
|
|
1427
|
+
1, 2,
|
|
1428
|
+
16, 4,
|
|
1429
|
+
clamp(upscale_factor, 1, 2),
|
|
1430
|
+
);
|
|
1431
|
+
|
|
1432
|
+
this.#taa.jitter_sequence_size = Math.ceil(base_sequence_size * taa_sequence_scale);
|
|
1433
|
+
|
|
1434
|
+
// ARM's NSS expects `8 * upscale_ratio^2` jitter phases. Apply the
|
|
1435
|
+
// same coverage scaling as TAA so DPR-mismatch resolutions still
|
|
1436
|
+
// get full coverage. Only applied if the NSS instance has been
|
|
1437
|
+
// created — no point spinning it up just to set a number.
|
|
1438
|
+
if (this.#nss !== undefined) {
|
|
1439
|
+
const nss_base = NSS.recommended_jitter_sequence_size(upscale_factor);
|
|
1440
|
+
this.#nss.jitter_sequence_size = Math.ceil(nss_base * taa_sequence_scale);
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
const in_w = this.#internal_resolution.x;
|
|
1444
|
+
const in_h = this.#internal_resolution.y;
|
|
1445
|
+
|
|
1446
|
+
this.#textures_depth.forEach(t => {
|
|
1447
|
+
t.resize(in_w, in_h)
|
|
1448
|
+
});
|
|
1449
|
+
|
|
1450
|
+
this.#vis_render_target.resize(in_w, in_h);
|
|
1451
|
+
|
|
1452
|
+
// resizing destroys BOTH ping-pong depth textures, including the one holding last
|
|
1453
|
+
// frame's depth — disocclusion/SSAO would read a zeroed "previous depth" this frame
|
|
1454
|
+
// and silently corrupt temporal history. The external resize() path resets history
|
|
1455
|
+
// via indicate_view_change(); internal-resolution changes (DRS steps) must too.
|
|
1456
|
+
this.indicate_view_change();
|
|
1457
|
+
|
|
1458
|
+
this.#internal_resolution_needs_update = false;
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
#update_output_resolution() {
|
|
1462
|
+
const size = this.#size;
|
|
1463
|
+
const pixel_ratio = this.#pixel_ratio;
|
|
1464
|
+
|
|
1465
|
+
const dimension_limit = this.device.limits.maxTextureDimension2D;
|
|
1466
|
+
|
|
1467
|
+
// limits are there to prevent crashing out
|
|
1468
|
+
const w = clamp(Math.ceil(size.x * pixel_ratio), 1, dimension_limit);
|
|
1469
|
+
const h = clamp(Math.ceil(size.y * pixel_ratio), 1, dimension_limit);
|
|
1470
|
+
|
|
1471
|
+
this.#output_resolution.set(w, h);
|
|
1472
|
+
|
|
1473
|
+
this.#internal_resolution_needs_update = true;
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
/**
|
|
1477
|
+
* Make sure to resize at the start of the frame to avoid flicker
|
|
1478
|
+
*
|
|
1479
|
+
* @param {number} x
|
|
1480
|
+
* @param {number} y
|
|
1481
|
+
*/
|
|
1482
|
+
resize(x, y) {
|
|
1483
|
+
assert.isNonNegativeInteger(x, 'x');
|
|
1484
|
+
assert.isNonNegativeInteger(y, 'y');
|
|
1485
|
+
|
|
1486
|
+
const size = this.#size;
|
|
1487
|
+
|
|
1488
|
+
if (size.x === x && size.y === y) {
|
|
1489
|
+
// no change
|
|
1490
|
+
return;
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
size.set(x, y);
|
|
1494
|
+
|
|
1495
|
+
this.#update_resolution();
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
/**
|
|
1499
|
+
* Does not check for changes, so make sure to call this sparingly
|
|
1500
|
+
*/
|
|
1501
|
+
#update_resolution() {
|
|
1502
|
+
|
|
1503
|
+
this.#update_output_resolution();
|
|
1504
|
+
|
|
1505
|
+
if (this.#internal_resolution_needs_update) {
|
|
1506
|
+
this.#update_internal_resolution();
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
this.#apply_size();
|
|
1510
|
+
|
|
1511
|
+
// drop history buffers to prevent artifacts
|
|
1512
|
+
this.indicate_view_change();
|
|
1513
|
+
}
|
|
1514
|
+
|
|
1515
|
+
/**
|
|
1516
|
+
* Bring the canvas context up to date with the size the renderer is drawing at.
|
|
1517
|
+
*
|
|
1518
|
+
* **Only {@link render} calls this, and that is the point.** Configuring a context resizes the
|
|
1519
|
+
* canvas and invalidates the texture it last handed out, so it has to happen before the frame
|
|
1520
|
+
* asks for one — and a frame going somewhere other than the canvas must not do it at all, or
|
|
1521
|
+
* every offscreen picture would resize the page's canvas to its own size and back.
|
|
1522
|
+
*/
|
|
1523
|
+
#ensure_context_configured() {
|
|
1524
|
+
this.#update_resolution_if_needed();
|
|
1525
|
+
|
|
1526
|
+
if (this.#context_needs_update) {
|
|
1527
|
+
this.#configure_context();
|
|
1528
|
+
this.#context_needs_update = false;
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1532
|
+
#update_resolution_if_needed() {
|
|
1533
|
+
if (this.#internal_resolution_needs_update) {
|
|
1534
|
+
this.#update_internal_resolution();
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
#begin_frame() {
|
|
1539
|
+
|
|
1540
|
+
this.#update_resolution_if_needed();
|
|
1541
|
+
|
|
1542
|
+
this.#graphics.update();
|
|
1543
|
+
|
|
1544
|
+
// Virtual texture maintenance: apply arrived pages (budgeted
|
|
1545
|
+
// uploads), flush page-table dirty rects and stack info, issue
|
|
1546
|
+
// streaming loads. Queue-ordered before this frame's submits, so
|
|
1547
|
+
// the material pass samples a consistent table+cache snapshot.
|
|
1548
|
+
if (this.feature_virtual_textures) {
|
|
1549
|
+
this.#graphics.virtual_textures.update();
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1552
|
+
// cycle depth attachment
|
|
1553
|
+
this.#vis_render_target.depth_attachment = this.texture_depth_current;
|
|
1554
|
+
this.#postprocess.update(this.#frame_count);
|
|
1555
|
+
|
|
1556
|
+
// Advance whichever upscaler we're going to ask for jitter on this
|
|
1557
|
+
// frame. Both share the same Halton(2, 3) sequence; we only tick
|
|
1558
|
+
// the active one to avoid spinning up NSS just to drive a counter.
|
|
1559
|
+
if (this.upscale_type === ShadeUpscalerType.NSS) {
|
|
1560
|
+
const nss = this.nss;
|
|
1561
|
+
nss.frame_count = this.#frame_count;
|
|
1562
|
+
nss.frame_index = this.#frame_count;
|
|
1563
|
+
} else {
|
|
1564
|
+
this.#taa.frame_index = this.#frame_count;
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
|
|
1568
|
+
#end_frame() {
|
|
1569
|
+
this.#frame_count++;
|
|
1570
|
+
|
|
1571
|
+
// dispatch event
|
|
1572
|
+
this.onFrameFinished.send1(this.#frame_count);
|
|
1573
|
+
}
|
|
1574
|
+
|
|
1575
|
+
/**
|
|
1576
|
+
* @type {AccumulatingPathTracer}
|
|
1577
|
+
*/
|
|
1578
|
+
#path_tracer;
|
|
1579
|
+
|
|
1580
|
+
get path_tracer() {
|
|
1581
|
+
if (this.#path_tracer === undefined) {
|
|
1582
|
+
this.#path_tracer = new AccumulatingPathTracer(this.#graphics);
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1585
|
+
return this.#path_tracer;
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1588
|
+
/**
|
|
1589
|
+
* Draw a frame onto the canvas this renderer is bound to.
|
|
1590
|
+
*
|
|
1591
|
+
* The canvas is one target among others: this is {@link render_to_target} with the canvas's
|
|
1592
|
+
* current texture as the target, and nothing else.
|
|
1593
|
+
*
|
|
1594
|
+
* @param {PerspectiveCamera} camera
|
|
1595
|
+
* @param {Scene} scene
|
|
1596
|
+
* @param {number} [time_delta_seconds]
|
|
1597
|
+
* @returns {boolean} whether frame was rendered, will return false if previous frame hasn't finished yet
|
|
1598
|
+
*/
|
|
1599
|
+
render(
|
|
1600
|
+
camera,
|
|
1601
|
+
scene,
|
|
1602
|
+
time_delta_seconds = 0.01666
|
|
1603
|
+
) {
|
|
1604
|
+
if (this.#device_lost) {
|
|
1605
|
+
// device is lost, can't render — and asking the context for a texture would throw
|
|
1606
|
+
return false;
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
this.#ensure_context_configured();
|
|
1610
|
+
|
|
1611
|
+
const canvas_texture = this.context.getCurrentTexture();
|
|
1612
|
+
|
|
1613
|
+
return this.render_to_target(
|
|
1614
|
+
camera,
|
|
1615
|
+
scene,
|
|
1616
|
+
time_delta_seconds,
|
|
1617
|
+
GPUTextureContext.fromTexture(canvas_texture, this.device)
|
|
1618
|
+
);
|
|
1619
|
+
}
|
|
1620
|
+
|
|
1621
|
+
/**
|
|
1622
|
+
* Draw a frame into a texture of the caller's choosing.
|
|
1623
|
+
*
|
|
1624
|
+
* **The target says where the picture goes, not how big it is.** Everything the frame is built
|
|
1625
|
+
* out of — the G-buffer, the visibility buffer, the depth ping-pong, the temporal history — is
|
|
1626
|
+
* sized from {@link output_resolution}, so a target has to be that size; a caller wanting a
|
|
1627
|
+
* different one calls {@link resize} first and puts the size back afterwards. Rendering into a
|
|
1628
|
+
* texture the caller owns is what makes a frame readable: a canvas texture is configured by the
|
|
1629
|
+
* presentation path and cannot carry `COPY_SRC`, and one of these can.
|
|
1630
|
+
*
|
|
1631
|
+
* @param {PerspectiveCamera} camera
|
|
1632
|
+
* @param {Scene} scene
|
|
1633
|
+
* @param {number} time_delta_seconds
|
|
1634
|
+
* @param {GPUTextureContext} target must match {@link output_resolution}
|
|
1635
|
+
* @returns {boolean} whether frame was rendered, will return false if previous frame hasn't finished yet
|
|
1636
|
+
*/
|
|
1637
|
+
render_to_target(
|
|
1638
|
+
camera,
|
|
1639
|
+
scene,
|
|
1640
|
+
time_delta_seconds,
|
|
1641
|
+
target
|
|
1642
|
+
) {
|
|
1643
|
+
assert.defined(target, 'target');
|
|
1644
|
+
assert.equal(target.isGPUTextureContext, true, 'target.isGPUTextureContext !== true');
|
|
1645
|
+
|
|
1646
|
+
if (this.#device_lost) {
|
|
1647
|
+
// device is lost, can't render
|
|
1648
|
+
return false;
|
|
1649
|
+
}
|
|
1650
|
+
|
|
1651
|
+
this.#begin_frame();
|
|
1652
|
+
|
|
1653
|
+
|
|
1654
|
+
if (this.indirect_lighting_mode === ShadeIndirectLightingMode.LPV) {
|
|
1655
|
+
this.update_lpv(scene);
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1658
|
+
const view = View.from(camera, scene);
|
|
1659
|
+
view.label = "Main View";
|
|
1660
|
+
const view_ctx = this.#views.obtain(view);
|
|
1661
|
+
|
|
1662
|
+
const graphics = this.#graphics;
|
|
1663
|
+
|
|
1664
|
+
// Shadow allocation + per-light shadow_id assignment happens inside
|
|
1665
|
+
// GPULightCollection.update (which view_ctx.update will trigger via
|
|
1666
|
+
// GPUSceneContext.update below), so by the time we reach select_for_draw the
|
|
1667
|
+
// light records on the GPU already carry their up-to-date shadow_id. Forward the
|
|
1668
|
+
// feature flag so process_lights inside lights.update can evict everything when
|
|
1669
|
+
// the renderer has shadows turned off — keeps CASTS_SHADOW_BIT cleared on every
|
|
1670
|
+
// light record without further plumbing.
|
|
1671
|
+
const sm = view_ctx.scene.lights.shadow_context;
|
|
1672
|
+
sm.enabled = this.#feature_shadows_enabled;
|
|
1673
|
+
// Which point-light shadow generator to use this frame; a flip triggers a rebuild of
|
|
1674
|
+
// existing point maps inside process_lights (run via view_ctx.update above/below).
|
|
1675
|
+
sm.use_tetrahedron_point_shadows = this.feature_tetrahedron_point_shadows;
|
|
1676
|
+
|
|
1677
|
+
const taa = this.#taa;
|
|
1678
|
+
|
|
1679
|
+
// Whichever upscaler is going to consume the temporal sequence
|
|
1680
|
+
// also has to dictate the jitter applied to the camera projection.
|
|
1681
|
+
// Both share Halton(2, 3); they just drive different jitter
|
|
1682
|
+
// sequence sizes via #update_internal_resolution.
|
|
1683
|
+
const jitter_source = this.upscale_type === ShadeUpscalerType.NSS
|
|
1684
|
+
? this.nss
|
|
1685
|
+
: taa;
|
|
1686
|
+
|
|
1687
|
+
const resolution_internal = this.#internal_resolution;
|
|
1688
|
+
{
|
|
1689
|
+
const jitter_x = jitter_source.Jitter[0];
|
|
1690
|
+
const jitter_y = jitter_source.Jitter[1];
|
|
1691
|
+
|
|
1692
|
+
view_ctx.setJitter(jitter_x, jitter_y);
|
|
1693
|
+
view_ctx.setViewportSize(resolution_internal.x, resolution_internal.y);
|
|
1694
|
+
view_ctx.setUpscaleRatio(
|
|
1695
|
+
this.#output_resolution.x / resolution_internal.x,
|
|
1696
|
+
this.#output_resolution.y / resolution_internal.y
|
|
1697
|
+
);
|
|
1698
|
+
// 2x offsets because the offsets are in NDC (-1, 1)
|
|
1699
|
+
view_ctx.camera.setViewportOffset(
|
|
1700
|
+
(2 * jitter_x) / resolution_internal.x,
|
|
1701
|
+
(2 * jitter_y) / resolution_internal.y
|
|
1702
|
+
);
|
|
1703
|
+
|
|
1704
|
+
}
|
|
1705
|
+
|
|
1706
|
+
view_ctx.update(graphics);
|
|
1707
|
+
|
|
1708
|
+
const command_ctx = ShadeGPUCommandContext.create(
|
|
1709
|
+
graphics,
|
|
1710
|
+
"Renderer/main-0"
|
|
1711
|
+
);
|
|
1712
|
+
|
|
1713
|
+
if (this.#debug_frame_count > 0) {
|
|
1714
|
+
this.#debug_frame_count--;
|
|
1715
|
+
|
|
1716
|
+
const current_frame = this.#frame_count;
|
|
1717
|
+
|
|
1718
|
+
command_ctx.enable_debug_timers((table) => {
|
|
1719
|
+
this.onFrameDebug.send2(current_frame, table);
|
|
1720
|
+
});
|
|
1721
|
+
}
|
|
1722
|
+
|
|
1723
|
+
/**
|
|
1724
|
+
* The frame recorder for this frame, or null when nothing is profiling.
|
|
1725
|
+
* @type {GPUFrameRecorder|null}
|
|
1726
|
+
*/
|
|
1727
|
+
let profile_recorder = null;
|
|
1728
|
+
|
|
1729
|
+
if (this.profile_session !== null) {
|
|
1730
|
+
// The session hands out the recorder; nothing here imports the profiler, which is what
|
|
1731
|
+
// keeps it out of a bundle that never asks for it. Null when the session is not running.
|
|
1732
|
+
profile_recorder = this.profile_session.begin_frame(this.#frame_count, performance.now());
|
|
1733
|
+
|
|
1734
|
+
if (profile_recorder !== null) {
|
|
1735
|
+
command_ctx.enable_profiling(profile_recorder, 0);
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
|
|
1739
|
+
// Per-frame animation tick — runs before shadow allocation so
|
|
1740
|
+
// animated transforms (joint poses, mesh.global from animated
|
|
1741
|
+
// parents) are in the scene database by the time shadow
|
|
1742
|
+
// culling samples it. No-op when nothing's registered.
|
|
1743
|
+
view_ctx.scene.tick(command_ctx, time_delta_seconds);
|
|
1744
|
+
|
|
1745
|
+
const viz_rt = this.#vis_render_target;
|
|
1746
|
+
|
|
1747
|
+
// prepare shadows (process_lights already ran inside lights.update via view_ctx.update,
|
|
1748
|
+
// so the GPU light records already carry their up-to-date shadow_id)
|
|
1749
|
+
if (this.#feature_shadows_enabled) {
|
|
1750
|
+
// Two-stage: (1) score+select which maps refresh this frame and publish their metadata,
|
|
1751
|
+
// (2) rasterize the selected maps. The context internally dispatches to the right
|
|
1752
|
+
// raster path per light type — directional/spot go direct, point lights do a cube
|
|
1753
|
+
// pass plus octahedral remap — so we don't have to juggle job arrays out here.
|
|
1754
|
+
// draw() also writes per-shadow records into the scene's GPU light database
|
|
1755
|
+
// (shadow_point/shadow_spot/shadow_directional tables) via its owner reference.
|
|
1756
|
+
sm.select_for_draw(camera, view_ctx.scene, view_ctx.frame_index, view_ctx.resolution);
|
|
1757
|
+
sm.draw(command_ctx);
|
|
1758
|
+
}
|
|
1759
|
+
|
|
1760
|
+
|
|
1761
|
+
const graph = new FrameGraph("Shading");
|
|
1762
|
+
|
|
1763
|
+
/*
|
|
1764
|
+
The view is updated and nothing has been rasterized, so an extension here is doing the
|
|
1765
|
+
per-frame compute that later phases depend on. There are no records yet — the frame has
|
|
1766
|
+
built nothing to hand out.
|
|
1767
|
+
*/
|
|
1768
|
+
const frame = new FrameContext(graph, view_ctx);
|
|
1769
|
+
|
|
1770
|
+
frame.phase = FramePhase.FrameStart;
|
|
1771
|
+
|
|
1772
|
+
this.#extensions.run(frame);
|
|
1773
|
+
|
|
1774
|
+
// build main view rasterization job
|
|
1775
|
+
const raster_main = new RasterizationJob();
|
|
1776
|
+
raster_main.view_ctx = view_ctx;
|
|
1777
|
+
raster_main.render_target = viz_rt;
|
|
1778
|
+
raster_main.opaque_pass = viz_rasterization_opaque_pass_descriptor;
|
|
1779
|
+
raster_main.alpha_tested_pass = viz_rasterization_alpha_tested_pass_descriptor;
|
|
1780
|
+
|
|
1781
|
+
const gr_render_buckets = graph_rasterize_scene({
|
|
1782
|
+
job: raster_main,
|
|
1783
|
+
graph,
|
|
1784
|
+
limits: graphics.collection_limits,
|
|
1785
|
+
});
|
|
1786
|
+
|
|
1787
|
+
// `let` rather than `const` because an extension at `AfterGBuffer` may publish replacements
|
|
1788
|
+
let gr_viz_buffer_triangle = graph_import_texture(graph, this.#vis_render_target.color_attachments[0], "viz_triangle");
|
|
1789
|
+
let gr_viz_buffer_mesh = graph_import_texture(graph, this.#vis_render_target.color_attachments[1], "viz_mesh");
|
|
1790
|
+
|
|
1791
|
+
// Virtual texture feedback: derive per-pixel page usage from the viz
|
|
1792
|
+
// buffer (no extra geometry pass) into a unique-request hash set and
|
|
1793
|
+
// kick its async readback. No-op unless VT stacks are registered.
|
|
1794
|
+
if (this.feature_virtual_textures) {
|
|
1795
|
+
graphics.virtual_textures.graph_feedback({
|
|
1796
|
+
graph,
|
|
1797
|
+
view: view_ctx,
|
|
1798
|
+
texture_viz_mesh: gr_viz_buffer_mesh,
|
|
1799
|
+
texture_viz_triangle: gr_viz_buffer_triangle,
|
|
1800
|
+
material_metadata_buffer: graphics.materials.metadata_table.buffer,
|
|
1801
|
+
});
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
// run materials
|
|
1805
|
+
const mat_g = graphics.materials.graph_viz_render({
|
|
1806
|
+
graph,
|
|
1807
|
+
view: view_ctx,
|
|
1808
|
+
texture_viz_mesh: gr_viz_buffer_mesh,
|
|
1809
|
+
texture_viz_triangle: gr_viz_buffer_triangle,
|
|
1810
|
+
});
|
|
1811
|
+
|
|
1812
|
+
// update texture references
|
|
1813
|
+
// `let` rather than `const` because a pass injected at `AfterGBuffer` may replace any of
|
|
1814
|
+
// them; see the read-back below.
|
|
1815
|
+
let gr_texture_pbr = mat_g.g_pbr;
|
|
1816
|
+
let gr_texture_normal = mat_g.g_normal;
|
|
1817
|
+
let gr_texture_material_albedo_ao = mat_g.g_albedo;
|
|
1818
|
+
let gr_texture_material_emissive = mat_g.g_emissive;
|
|
1819
|
+
|
|
1820
|
+
// do mips for G-buffer
|
|
1821
|
+
// mipmap_nearest(command_ctx, this.texture_depth_current);
|
|
1822
|
+
// this.gBuffer.mipmap(command_ctx);
|
|
1823
|
+
|
|
1824
|
+
// Update lights position
|
|
1825
|
+
command_ctx.pushDebugGroup("Shade");
|
|
1826
|
+
|
|
1827
|
+
const resolution = resolution_internal.asArray();
|
|
1828
|
+
|
|
1829
|
+
const scene_ctx = view_ctx.scene;
|
|
1830
|
+
const lights = scene_ctx.lights;
|
|
1831
|
+
|
|
1832
|
+
|
|
1833
|
+
const gr_texture_canvas = graph_import_texture(graph, target, "canvas");
|
|
1834
|
+
let gr_texture_depth_current = graph_import_texture(graph, this.texture_depth_current, "depth");
|
|
1835
|
+
const gr_buffer_camera_current = graph_import_buffer(graph, view_ctx.camera.gpu_buffer, "camera/current");
|
|
1836
|
+
const gr_buffer_camera_previous = graph_import_buffer(graph, view_ctx.gpu_previous_camera_state.gpu_buffer, "camera/previous");
|
|
1837
|
+
const gr_texture_hzb = graph_import_texture(graph, view_ctx.hierarchical_z_buffer.texture, "HZB");
|
|
1838
|
+
const gr_texture_environment = graph_import_texture(graph, view_ctx.scene.lights.environment);
|
|
1839
|
+
|
|
1840
|
+
const taa_history_0 = this.#get_texture_taa_history(0);
|
|
1841
|
+
const taa_history_1 = this.#get_texture_taa_history(-1);
|
|
1842
|
+
|
|
1843
|
+
const gr_texture_taa_history = graph_import_texture(graph, taa_history_0, "taa history");
|
|
1844
|
+
const gr_texture_taa_out = graph_import_texture(graph, taa_history_1, "taa out");
|
|
1845
|
+
let gr_texture_depth_previous = graph_import_texture(graph, this.texture_depth_previous, "depth previous");
|
|
1846
|
+
|
|
1847
|
+
const gr_shadowmap_atlas = graph_import_texture(graph, sm.texture);
|
|
1848
|
+
|
|
1849
|
+
// The frame's surface handles exist now, so this is where the records that carry them are
|
|
1850
|
+
// published. There is no colour yet, which is what makes this the phase for G-buffer work.
|
|
1851
|
+
frame.phase = FramePhase.AfterGBuffer;
|
|
1852
|
+
|
|
1853
|
+
const record_gbuffer = frame.create(GBufferTextures);
|
|
1854
|
+
const record_view_textures = frame.create(ViewTextures);
|
|
1855
|
+
|
|
1856
|
+
record_gbuffer.albedo = gr_texture_material_albedo_ao;
|
|
1857
|
+
record_gbuffer.normal = gr_texture_normal;
|
|
1858
|
+
record_gbuffer.pbr = gr_texture_pbr;
|
|
1859
|
+
record_gbuffer.emissive = gr_texture_material_emissive;
|
|
1860
|
+
|
|
1861
|
+
record_view_textures.depth = gr_texture_depth_current;
|
|
1862
|
+
record_view_textures.depth_previous = gr_texture_depth_previous;
|
|
1863
|
+
record_view_textures.visibility_mesh = gr_viz_buffer_mesh;
|
|
1864
|
+
record_view_textures.visibility_triangle = gr_viz_buffer_triangle;
|
|
1865
|
+
|
|
1866
|
+
this.#extensions.run(frame);
|
|
1867
|
+
|
|
1868
|
+
/*
|
|
1869
|
+
`GBufferTextures` is in/out at this phase, and frozen after it. An extension that wants to
|
|
1870
|
+
*change* surface properties — decals are the reason this exists — cannot blend into these
|
|
1871
|
+
targets: two of the four are integer formats, and one texture cannot be a render attachment
|
|
1872
|
+
and a sampled source in the same pass. So it reads them, writes replacements, and publishes
|
|
1873
|
+
the new handles. Everything downstream carries what it left.
|
|
1874
|
+
|
|
1875
|
+
Writing the originals in place would work by accident rather than by contract: a written
|
|
1876
|
+
handle is a *renamed* clone of the same physical resource, so the change would land in the
|
|
1877
|
+
texture the shading pass reads only because the graph happens to execute in insertion
|
|
1878
|
+
order, with no dependency edge saying so. Threading the handles makes the edge real.
|
|
1879
|
+
*/
|
|
1880
|
+
gr_texture_pbr = record_gbuffer.pbr;
|
|
1881
|
+
gr_texture_normal = record_gbuffer.normal;
|
|
1882
|
+
gr_texture_material_albedo_ao = record_gbuffer.albedo;
|
|
1883
|
+
gr_texture_material_emissive = record_gbuffer.emissive;
|
|
1884
|
+
|
|
1885
|
+
gr_texture_depth_current = record_view_textures.depth;
|
|
1886
|
+
gr_texture_depth_previous = record_view_textures.depth_previous;
|
|
1887
|
+
gr_viz_buffer_mesh = record_view_textures.visibility_mesh;
|
|
1888
|
+
gr_viz_buffer_triangle = record_view_textures.visibility_triangle;
|
|
1889
|
+
|
|
1890
|
+
// Velocity pass with three branches: rotation-reprojection
|
|
1891
|
+
// background, rigid per-object foreground (mesh.global delta),
|
|
1892
|
+
// and skinned per-vertex foreground (barycentric interpolation
|
|
1893
|
+
// of the triangle's mesh-local `position_prev` written by
|
|
1894
|
+
// skinning into the side-buffer the skinning context owns).
|
|
1895
|
+
// Per-vertex limb deformation lands in the final pixel-space
|
|
1896
|
+
// velocity, so TAA reads correct history for character animation.
|
|
1897
|
+
const gr_scene_database_for_velocity = graph_import_buffer(
|
|
1898
|
+
graph, scene_ctx.scene_database_buffer, "scene_database/velocity"
|
|
1899
|
+
);
|
|
1900
|
+
const gr_meshlet_metadata_for_velocity = graph_import_buffer(
|
|
1901
|
+
graph, scene_ctx.geometries.meshlets.buffer_metadata, "meshlet_metadata/velocity"
|
|
1902
|
+
);
|
|
1903
|
+
const gr_meshlet_data_for_velocity = graph_import_buffer(
|
|
1904
|
+
graph, scene_ctx.geometries.meshlets.buffer_data, "meshlet_data/velocity"
|
|
1905
|
+
);
|
|
1906
|
+
// Skinning side-buffers — both null when no SkinnedMesh has
|
|
1907
|
+
// been registered. The velocity shader still references these
|
|
1908
|
+
// bindings (the dormant per-vertex branch), so the bind group
|
|
1909
|
+
// must supply *something*; use the scene_database buffer as a
|
|
1910
|
+
// placeholder when skinning is inactive. The shader is told via
|
|
1911
|
+
// `skinning_active` whether the bindings are real — when false
|
|
1912
|
+
// it never reads them and forces the rigid path, so the
|
|
1913
|
+
// placeholder is never sampled. (Binding the placeholder
|
|
1914
|
+
// without that guard was the source of phantom velocity on
|
|
1915
|
+
// static meshes: `prev_position_offsets[meshlet_id]` read an
|
|
1916
|
+
// unrelated scene_database word, and any non-0xFFFFFFFF value
|
|
1917
|
+
// sent a static triangle down the skinned branch.)
|
|
1918
|
+
const skinning_ctx = scene_ctx.skinning;
|
|
1919
|
+
const skinning_active = skinning_ctx.prev_position_offsets_buffer !== null
|
|
1920
|
+
&& skinning_ctx.prev_positions_buffer !== null;
|
|
1921
|
+
const gr_prev_position_offsets = graph_import_buffer(
|
|
1922
|
+
graph,
|
|
1923
|
+
skinning_ctx.prev_position_offsets_buffer ?? scene_ctx.scene_database_buffer,
|
|
1924
|
+
"prev_position_offsets/velocity",
|
|
1925
|
+
);
|
|
1926
|
+
const gr_prev_positions = graph_import_buffer(
|
|
1927
|
+
graph,
|
|
1928
|
+
skinning_ctx.prev_positions_buffer ?? scene_ctx.scene_database_buffer,
|
|
1929
|
+
"prev_positions/velocity",
|
|
1930
|
+
);
|
|
1931
|
+
|
|
1932
|
+
let gr_velocity = graph_add_per_object_velocity({
|
|
1933
|
+
graph,
|
|
1934
|
+
texture_depth: gr_texture_depth_current,
|
|
1935
|
+
texture_viz_mesh: gr_viz_buffer_mesh,
|
|
1936
|
+
texture_viz_triangle: gr_viz_buffer_triangle,
|
|
1937
|
+
buffer_scene_database: gr_scene_database_for_velocity,
|
|
1938
|
+
buffer_meshlet_metadata: gr_meshlet_metadata_for_velocity,
|
|
1939
|
+
buffer_meshlet_data: gr_meshlet_data_for_velocity,
|
|
1940
|
+
buffer_prev_position_offsets: gr_prev_position_offsets,
|
|
1941
|
+
buffer_prev_positions: gr_prev_positions,
|
|
1942
|
+
skinning_active,
|
|
1943
|
+
resolution,
|
|
1944
|
+
view: view_ctx,
|
|
1945
|
+
enable_mipmap: true
|
|
1946
|
+
});
|
|
1947
|
+
|
|
1948
|
+
// gr_velocity = graph_mipmap_nearest(graph, gr_velocity, G_BUFFER_MIP_LEVELS);
|
|
1949
|
+
|
|
1950
|
+
let [gr_occlusion_clip] = graph_image_pass({
|
|
1951
|
+
graph,
|
|
1952
|
+
shader: shader_depth_occlusion_clip,
|
|
1953
|
+
output_resolution: view_ctx.resolution,
|
|
1954
|
+
// mipmaps are going to be necessary for half-resolution post-process passes
|
|
1955
|
+
output_mipmaps: true,
|
|
1956
|
+
inputs: {
|
|
1957
|
+
camera_current: gr_buffer_camera_current,
|
|
1958
|
+
camera_previous: gr_buffer_camera_previous,
|
|
1959
|
+
DepthBuffer: gr_texture_depth_current,
|
|
1960
|
+
PrevDepthBuffer: gr_texture_depth_previous,
|
|
1961
|
+
VelocityBuffer: gr_velocity
|
|
1962
|
+
}
|
|
1963
|
+
});
|
|
1964
|
+
|
|
1965
|
+
const light_clusters = graph_build_light_clusters({
|
|
1966
|
+
graph,
|
|
1967
|
+
lights: lights,
|
|
1968
|
+
camera: view_ctx.camera,
|
|
1969
|
+
hzb: gr_texture_hzb,
|
|
1970
|
+
resolution: view_ctx.resolution,
|
|
1971
|
+
});
|
|
1972
|
+
|
|
1973
|
+
// Build the view's volumetric fog LUTs (participating media -> per-froxel lighting ->
|
|
1974
|
+
// ray-marched integration). Needs the light clusters and shadow atlas. Built every frame so
|
|
1975
|
+
// the transparency (OIT) pass always has a valid LUT to sample — an empty scene integrates
|
|
1976
|
+
// to a no-op (transmittance 1, in-scatter 0). The opaque composite below is still skipped
|
|
1977
|
+
// when the scene has no fog.
|
|
1978
|
+
const has_volumetrics = view_ctx.scene.volumetrics.source.volumes.length > 0;
|
|
1979
|
+
|
|
1980
|
+
const volumetrics = view_ctx.volumetrics.graph_update({
|
|
1981
|
+
graph,
|
|
1982
|
+
light_cluster_data: light_clusters.data,
|
|
1983
|
+
light_cluster_lookup: light_clusters.lookup,
|
|
1984
|
+
light_cluster_parameters: light_clusters.parameters,
|
|
1985
|
+
shadowmap_atlas: gr_shadowmap_atlas,
|
|
1986
|
+
});
|
|
1987
|
+
|
|
1988
|
+
/**
|
|
1989
|
+
*
|
|
1990
|
+
* @type {number}
|
|
1991
|
+
*/
|
|
1992
|
+
let current_color_out = -1;
|
|
1993
|
+
|
|
1994
|
+
// ReSTIR DI — stochastic direct lighting of local (point+spot) lights.
|
|
1995
|
+
// When enabled, resolve per-pixel point+spot radiance and shade with the
|
|
1996
|
+
// ReSTIR deferred variant (no brute-force cluster loop). The variant is a
|
|
1997
|
+
// separate compiled shader, selected here at the JS level rather than via
|
|
1998
|
+
// a runtime branch inside the shader.
|
|
1999
|
+
let deferred_shader = shader_deferred_main;
|
|
2000
|
+
|
|
2001
|
+
const deferred_inputs = {
|
|
2002
|
+
gBufferDepth: gr_texture_depth_current,
|
|
2003
|
+
gBufferPBR: gr_texture_pbr,
|
|
2004
|
+
gBufferNormal: gr_texture_normal,
|
|
2005
|
+
gBufferAlbedo: gr_texture_material_albedo_ao,
|
|
2006
|
+
gBufferEmissive: gr_texture_material_emissive,
|
|
2007
|
+
|
|
2008
|
+
//
|
|
2009
|
+
light_data: lights.buffer_data,
|
|
2010
|
+
tEnvironment: gr_texture_environment,
|
|
2011
|
+
|
|
2012
|
+
// light clusters
|
|
2013
|
+
cluster_parameters: light_clusters.parameters,
|
|
2014
|
+
cluster_lookup: light_clusters.lookup,
|
|
2015
|
+
cluster_data: light_clusters.data,
|
|
2016
|
+
|
|
2017
|
+
// shadows
|
|
2018
|
+
shadowmapAtlas: gr_shadowmap_atlas,
|
|
2019
|
+
|
|
2020
|
+
//
|
|
2021
|
+
camera: view_ctx.camera.buffer,
|
|
2022
|
+
view: view_ctx.uniform_buffer.buffer,
|
|
2023
|
+
};
|
|
2024
|
+
|
|
2025
|
+
if (this.feature_restir_di_enabled) {
|
|
2026
|
+
deferred_shader = shader_deferred_main_restir;
|
|
2027
|
+
|
|
2028
|
+
deferred_inputs.tRestirRadiance = this.#restir_di.execute({
|
|
2029
|
+
graph,
|
|
2030
|
+
view: view_ctx,
|
|
2031
|
+
depth: gr_texture_depth_current,
|
|
2032
|
+
pbr: gr_texture_pbr,
|
|
2033
|
+
normal: gr_texture_normal,
|
|
2034
|
+
albedo: gr_texture_material_albedo_ao,
|
|
2035
|
+
emissive: gr_texture_material_emissive,
|
|
2036
|
+
velocity: gr_velocity,
|
|
2037
|
+
occlusion_clip: gr_occlusion_clip,
|
|
2038
|
+
hzb: gr_texture_hzb,
|
|
2039
|
+
cluster_parameters: light_clusters.parameters,
|
|
2040
|
+
cluster_lookup: light_clusters.lookup,
|
|
2041
|
+
cluster_data: light_clusters.data,
|
|
2042
|
+
});
|
|
2043
|
+
}
|
|
2044
|
+
|
|
2045
|
+
// Main shading pass
|
|
2046
|
+
[current_color_out] = graph_image_pass({
|
|
2047
|
+
graph,
|
|
2048
|
+
shader: deferred_shader,
|
|
2049
|
+
input_depth: gr_texture_depth_current,
|
|
2050
|
+
inputs: deferred_inputs,
|
|
2051
|
+
output_resolution: view_ctx.resolution,
|
|
2052
|
+
});
|
|
2053
|
+
|
|
2054
|
+
|
|
2055
|
+
let bent_normals = -1;
|
|
2056
|
+
|
|
2057
|
+
if (this.feature_ssao_enabled) {
|
|
2058
|
+
|
|
2059
|
+
const ssao = this.#postprocess.ssao.graph_pass({
|
|
2060
|
+
graph: graph,
|
|
2061
|
+
frame_index: this.#frame_count,
|
|
2062
|
+
input_depth: gr_texture_depth_current,
|
|
2063
|
+
input_color: current_color_out,
|
|
2064
|
+
input_depth_previous: gr_texture_depth_previous,
|
|
2065
|
+
input_velocity: gr_velocity,
|
|
2066
|
+
input_normal: gr_texture_normal,
|
|
2067
|
+
input_occlusion: gr_occlusion_clip,
|
|
2068
|
+
// NOTE: AO is blended into the G-buffer
|
|
2069
|
+
output: gr_texture_material_albedo_ao,
|
|
2070
|
+
camera: gr_buffer_camera_current,
|
|
2071
|
+
resolution: resolution,
|
|
2072
|
+
});
|
|
2073
|
+
|
|
2074
|
+
gr_texture_material_albedo_ao = ssao.occlusion;
|
|
2075
|
+
bent_normals = ssao.bent_normals;
|
|
2076
|
+
|
|
2077
|
+
} else {
|
|
2078
|
+
|
|
2079
|
+
// default to shading normals
|
|
2080
|
+
bent_normals = gr_texture_normal;
|
|
2081
|
+
|
|
2082
|
+
}
|
|
2083
|
+
|
|
2084
|
+
|
|
2085
|
+
// Shade background
|
|
2086
|
+
[current_color_out] = graph_image_pass({
|
|
2087
|
+
graph,
|
|
2088
|
+
shader: shader_background,
|
|
2089
|
+
inputs: {
|
|
2090
|
+
camera: view_ctx.camera.buffer,
|
|
2091
|
+
view: view_ctx.uniform_buffer.buffer,
|
|
2092
|
+
tEnvironment: gr_texture_environment,
|
|
2093
|
+
},
|
|
2094
|
+
input_depth: gr_texture_depth_current,
|
|
2095
|
+
load_op: "load",
|
|
2096
|
+
output: [current_color_out],
|
|
2097
|
+
});
|
|
2098
|
+
|
|
2099
|
+
{
|
|
2100
|
+
// Fused brick4 path: skip the intermediate diffuse/specular targets and the
|
|
2101
|
+
// separate resolve, doing it all in a single shader. SSR isn't compatible
|
|
2102
|
+
// since it consumes the standalone specular target.
|
|
2103
|
+
const use_fused_indirect = this.fused_indirect
|
|
2104
|
+
&& this.indirect_lighting_mode === ShadeIndirectLightingMode.Brick4
|
|
2105
|
+
&& !this.feature_ssr_enabled;
|
|
2106
|
+
|
|
2107
|
+
if (use_fused_indirect) {
|
|
2108
|
+
|
|
2109
|
+
[current_color_out] = graph_image_pass({
|
|
2110
|
+
graph,
|
|
2111
|
+
shader: shader_brick4_indirect_lighting,
|
|
2112
|
+
output: [current_color_out],
|
|
2113
|
+
input_depth: gr_texture_depth_current,
|
|
2114
|
+
load_op: "load",
|
|
2115
|
+
inputs: {
|
|
2116
|
+
tDepth: gr_texture_depth_current,
|
|
2117
|
+
tGBufferNormals: gr_texture_normal,
|
|
2118
|
+
tBentNormals: bent_normals,
|
|
2119
|
+
tGBufferAlbedo: gr_texture_material_albedo_ao,
|
|
2120
|
+
tGBufferPBR: gr_texture_pbr,
|
|
2121
|
+
tSTBN_vec2: STATIC_GRAPHICS_ENGINE_ASSETS.stbn_vec2,
|
|
2122
|
+
view: view_ctx.uniform_buffer.buffer,
|
|
2123
|
+
camera: gr_buffer_camera_current,
|
|
2124
|
+
//
|
|
2125
|
+
brick4: scene_ctx.volumetric_light_map.buffer,
|
|
2126
|
+
tSplitSum: STATIC_GRAPHICS_ENGINE_ASSETS.split_sum,
|
|
2127
|
+
},
|
|
2128
|
+
});
|
|
2129
|
+
|
|
2130
|
+
} else {
|
|
2131
|
+
|
|
2132
|
+
const { indirect_specular, indirect_diffuse } = this.#graph_indirect_lighting({
|
|
2133
|
+
graph,
|
|
2134
|
+
view_ctx,
|
|
2135
|
+
scene_ctx,
|
|
2136
|
+
bent_normals,
|
|
2137
|
+
current_color_out,
|
|
2138
|
+
//
|
|
2139
|
+
gr_texture_depth_current,
|
|
2140
|
+
gr_texture_hzb,
|
|
2141
|
+
gr_texture_material_albedo_ao,
|
|
2142
|
+
gr_texture_pbr,
|
|
2143
|
+
gr_texture_normal,
|
|
2144
|
+
gr_texture_environment,
|
|
2145
|
+
gr_velocity,
|
|
2146
|
+
gr_occlusion_clip,
|
|
2147
|
+
gr_buffer_camera_current,
|
|
2148
|
+
gr_buffer_camera_previous,
|
|
2149
|
+
resolution,
|
|
2150
|
+
});
|
|
2151
|
+
|
|
2152
|
+
// resolve indirect lighting
|
|
2153
|
+
[current_color_out] = graph_image_pass({
|
|
2154
|
+
graph,
|
|
2155
|
+
shader: shader_resolve_indirect_lighting,
|
|
2156
|
+
output: [current_color_out],
|
|
2157
|
+
input_depth: gr_texture_depth_current,
|
|
2158
|
+
load_op: "load",
|
|
2159
|
+
inputs: {
|
|
2160
|
+
tIndirectDiffuse: indirect_diffuse,
|
|
2161
|
+
tIndirectSpecular: indirect_specular,
|
|
2162
|
+
//
|
|
2163
|
+
tGBufferNormals: gr_texture_normal,
|
|
2164
|
+
tBentNormals: bent_normals,
|
|
2165
|
+
tGBufferAlbedo: gr_texture_material_albedo_ao,
|
|
2166
|
+
tGBufferPBR: gr_texture_pbr,
|
|
2167
|
+
tDepth: gr_texture_depth_current,
|
|
2168
|
+
//
|
|
2169
|
+
camera: gr_buffer_camera_current,
|
|
2170
|
+
//
|
|
2171
|
+
tSplitSum: STATIC_GRAPHICS_ENGINE_ASSETS.split_sum,
|
|
2172
|
+
},
|
|
2173
|
+
});
|
|
2174
|
+
|
|
2175
|
+
}
|
|
2176
|
+
|
|
2177
|
+
// current_color_out = indirect_diffuse
|
|
2178
|
+
// current_color_out = indirect_specular
|
|
2179
|
+
|
|
2180
|
+
}
|
|
2181
|
+
|
|
2182
|
+
// current_color_out = graph_decode_rgbe9995_to_rgb16float({
|
|
2183
|
+
// graph,
|
|
2184
|
+
// input:indirect_diffuse_near_field,
|
|
2185
|
+
// resolution: view_ctx.resolution,
|
|
2186
|
+
// });
|
|
2187
|
+
//
|
|
2188
|
+
// const [norm] = graph_image_pass({
|
|
2189
|
+
// shader: shader_decode_octahedral_normal,
|
|
2190
|
+
// inputs:{
|
|
2191
|
+
// tInput: bent_normals,
|
|
2192
|
+
// },
|
|
2193
|
+
// graph,
|
|
2194
|
+
// output_resolution: view_ctx.resolution,
|
|
2195
|
+
// });
|
|
2196
|
+
//
|
|
2197
|
+
// [current_color_out] = graph_image_pass({
|
|
2198
|
+
// graph,
|
|
2199
|
+
// shader: shader_draw_normals,
|
|
2200
|
+
// inputs:{
|
|
2201
|
+
// tInput: norm,
|
|
2202
|
+
// },
|
|
2203
|
+
// output_resolution: view_ctx.resolution,
|
|
2204
|
+
// });
|
|
2205
|
+
|
|
2206
|
+
// Composite volumetric fog over the finalized opaque + background + indirect colour.
|
|
2207
|
+
// A dedicated pass (not inline in the shading shaders) because indirect lighting is added
|
|
2208
|
+
// in a separate additively-blended pass, so the full surface radiance only exists here.
|
|
2209
|
+
// Runs before transparency (transparent surfaces blend over the fog) and before the main
|
|
2210
|
+
// TAA (which then smooths the fog's per-pixel sampling noise).
|
|
2211
|
+
if (has_volumetrics) {
|
|
2212
|
+
[current_color_out] = graph_image_pass({
|
|
2213
|
+
graph,
|
|
2214
|
+
shader: shader_composite_volumetrics,
|
|
2215
|
+
output_resolution: view_ctx.resolution,
|
|
2216
|
+
inputs: {
|
|
2217
|
+
tColor: current_color_out,
|
|
2218
|
+
gBufferDepth: gr_texture_depth_current,
|
|
2219
|
+
tVolumetrics: volumetrics.resolved,
|
|
2220
|
+
tSTBN_vec3: STATIC_GRAPHICS_ENGINE_ASSETS.stbn_vec3,
|
|
2221
|
+
volumetrics_metadata: volumetrics.metadata,
|
|
2222
|
+
camera: view_ctx.camera.buffer,
|
|
2223
|
+
view: view_ctx.uniform_buffer.buffer,
|
|
2224
|
+
},
|
|
2225
|
+
});
|
|
2226
|
+
}
|
|
2227
|
+
|
|
2228
|
+
/*
|
|
2229
|
+
The frame has a colour for the first time, so this is where `SceneColor` is published. It is
|
|
2230
|
+
republished before each later phase because the built-in passes between them replace it —
|
|
2231
|
+
the record names which handle currently *means* the scene colour, and the graph already
|
|
2232
|
+
holds the dependency edge underneath.
|
|
2233
|
+
*/
|
|
2234
|
+
frame.phase = FramePhase.AfterLighting;
|
|
2235
|
+
|
|
2236
|
+
const record_scene_color = frame.create(SceneColor);
|
|
2237
|
+
|
|
2238
|
+
record_scene_color.color = current_color_out;
|
|
2239
|
+
|
|
2240
|
+
this.#extensions.run(frame);
|
|
2241
|
+
|
|
2242
|
+
current_color_out = record_scene_color.color;
|
|
2243
|
+
gr_texture_depth_current = record_view_textures.depth;
|
|
2244
|
+
|
|
2245
|
+
if (this.#feature_enabled_transparencies) {
|
|
2246
|
+
// do transparent alpha pass
|
|
2247
|
+
current_color_out = graph_rasterize_meshes_transparent_oit({
|
|
2248
|
+
graph,
|
|
2249
|
+
buckets: gr_render_buckets,
|
|
2250
|
+
view_ctx,
|
|
2251
|
+
viewport: [0, 0, resolution_internal.x, resolution_internal.y],
|
|
2252
|
+
color_texture: current_color_out,
|
|
2253
|
+
depth_texture: gr_texture_depth_current,
|
|
2254
|
+
|
|
2255
|
+
limits: this.graphics.collection_limits,
|
|
2256
|
+
|
|
2257
|
+
light_cluster_data: light_clusters.data,
|
|
2258
|
+
light_cluster_lookup: light_clusters.lookup,
|
|
2259
|
+
light_cluster_parameters: light_clusters.parameters,
|
|
2260
|
+
|
|
2261
|
+
shadowmap_atlas: gr_shadowmap_atlas,
|
|
2262
|
+
|
|
2263
|
+
volumetrics_lut: volumetrics.resolved,
|
|
2264
|
+
volumetrics_metadata: volumetrics.metadata,
|
|
2265
|
+
|
|
2266
|
+
indirect_lighting_mode: this.indirect_lighting_mode,
|
|
2267
|
+
});
|
|
2268
|
+
}
|
|
2269
|
+
|
|
2270
|
+
frame.phase = FramePhase.AfterTransparency;
|
|
2271
|
+
|
|
2272
|
+
record_scene_color.color = current_color_out;
|
|
2273
|
+
|
|
2274
|
+
this.#extensions.run(frame);
|
|
2275
|
+
|
|
2276
|
+
current_color_out = record_scene_color.color;
|
|
2277
|
+
gr_texture_depth_current = record_view_textures.depth;
|
|
2278
|
+
|
|
2279
|
+
// current_color_out = gr_texture_material_albedo_ao;
|
|
2280
|
+
|
|
2281
|
+
if (this.feature_path_tracing_enabled) {
|
|
2282
|
+
current_color_out = this.path_tracer.render({
|
|
2283
|
+
graph,
|
|
2284
|
+
view: view_ctx
|
|
2285
|
+
});
|
|
2286
|
+
}
|
|
2287
|
+
|
|
2288
|
+
// Debug override: replace the post-shading color with a
|
|
2289
|
+
// visualization of the velocity buffer via shader_debug_velocity.
|
|
2290
|
+
// Direction is encoded as hue (red = +X, cyan = -X, etc.) and
|
|
2291
|
+
// magnitude as brightness; the AO channel of the albedo+AO
|
|
2292
|
+
// G-buffer modulates the static base so geometry shape is
|
|
2293
|
+
// still readable where motion is zero or near-zero. Done
|
|
2294
|
+
// BEFORE TAA so the chain stays well-formed; TAA blending
|
|
2295
|
+
// the debug view is meaningless, but it's debug.
|
|
2296
|
+
if (this.feature_velocity_debug_view) {
|
|
2297
|
+
[current_color_out] = graph_image_pass({
|
|
2298
|
+
graph,
|
|
2299
|
+
shader: shader_debug_velocity,
|
|
2300
|
+
inputs: {
|
|
2301
|
+
tInput: gr_velocity,
|
|
2302
|
+
tAlbedoAO: gr_texture_material_albedo_ao,
|
|
2303
|
+
},
|
|
2304
|
+
output_resolution: resolution_internal.asArray(),
|
|
2305
|
+
});
|
|
2306
|
+
}
|
|
2307
|
+
|
|
2308
|
+
if (this.feature_taa_enabled) {
|
|
2309
|
+
|
|
2310
|
+
if (this.upscale_type === ShadeUpscalerType.NSS) {
|
|
2311
|
+
current_color_out = this.nss.graph_pass({
|
|
2312
|
+
graph,
|
|
2313
|
+
texture_color_current: current_color_out,
|
|
2314
|
+
texture_depth_current: gr_texture_depth_current,
|
|
2315
|
+
texture_velocity: gr_velocity,
|
|
2316
|
+
texture_disocclusion_confidence: gr_occlusion_clip,
|
|
2317
|
+
texture_color_history: gr_texture_taa_history,
|
|
2318
|
+
texture_output: gr_texture_taa_out,
|
|
2319
|
+
render_resolution: resolution_internal.asArray(),
|
|
2320
|
+
output_resolution: this.#output_resolution.asArray(),
|
|
2321
|
+
});
|
|
2322
|
+
} else {
|
|
2323
|
+
current_color_out = taa.graph_pass({
|
|
2324
|
+
graph,
|
|
2325
|
+
texture_output: gr_texture_taa_out,
|
|
2326
|
+
texture_color_current: current_color_out,
|
|
2327
|
+
texture_color_history: gr_texture_taa_history,
|
|
2328
|
+
texture_velocity: gr_velocity,
|
|
2329
|
+
texture_occlusion: gr_occlusion_clip,
|
|
2330
|
+
camera_current: gr_buffer_camera_current,
|
|
2331
|
+
camera_previous: gr_buffer_camera_previous,
|
|
2332
|
+
});
|
|
2333
|
+
}
|
|
2334
|
+
}
|
|
2335
|
+
|
|
2336
|
+
// Bokeh depth of field on the resolved HDR colour. Runs after
|
|
2337
|
+
// TAA (blurs a clean, converged image — TAA's neighbourhood
|
|
2338
|
+
// clamp would otherwise fight the defocus) and before motion
|
|
2339
|
+
// blur / bloom, so out-of-focus highlights bloom and the bokeh
|
|
2340
|
+
// carries through the rest of the post chain. Perspective-only:
|
|
2341
|
+
// the thin-lens CoC has no meaning under orthographic.
|
|
2342
|
+
if (this.feature_dof_enabled && camera.isPerspectiveCamera === true) {
|
|
2343
|
+
// Both implementations share the same render() signature, so the
|
|
2344
|
+
// call site is identical — only the subsystem differs.
|
|
2345
|
+
const dof = this.dof_algorithm === "unreal"
|
|
2346
|
+
? this.#depth_of_field_unreal
|
|
2347
|
+
: this.#depth_of_field;
|
|
2348
|
+
|
|
2349
|
+
current_color_out = dof.render({
|
|
2350
|
+
graph,
|
|
2351
|
+
input_color: current_color_out,
|
|
2352
|
+
depth: gr_texture_depth_current,
|
|
2353
|
+
camera,
|
|
2354
|
+
camera_buffer: view_ctx.camera.buffer,
|
|
2355
|
+
resolution: this.#output_resolution.asArray(),
|
|
2356
|
+
});
|
|
2357
|
+
}
|
|
2358
|
+
|
|
2359
|
+
// Jimenez 2014 motion blur runs on the resolved-but-not-
|
|
2360
|
+
// sharpened HDR colour. TAA has already converged the
|
|
2361
|
+
// jittered samples; sharpening, bloom, and tonemap operate
|
|
2362
|
+
// on the blurred output after this. Skipped when the toggle
|
|
2363
|
+
// is off so the rest of the chain stays bit-identical.
|
|
2364
|
+
if (this.feature_motion_blur_enabled) {
|
|
2365
|
+
current_color_out = this.#motion_blur.render({
|
|
2366
|
+
graph,
|
|
2367
|
+
input_color: current_color_out,
|
|
2368
|
+
velocity: gr_velocity,
|
|
2369
|
+
depth: gr_texture_depth_current,
|
|
2370
|
+
resolution: this.#output_resolution.asArray(),
|
|
2371
|
+
});
|
|
2372
|
+
}
|
|
2373
|
+
|
|
2374
|
+
// TODO if TAA is disabled, and internal resolution is < 100% - we need to do upscale
|
|
2375
|
+
|
|
2376
|
+
if (this.feature_sharpening_enabled) {
|
|
2377
|
+
[current_color_out] = graph_image_pass({
|
|
2378
|
+
graph,
|
|
2379
|
+
shader: shader_ffx_rcas,
|
|
2380
|
+
output_resolution: this.#output_resolution.asArray(),
|
|
2381
|
+
inputs: {
|
|
2382
|
+
tInput: current_color_out,
|
|
2383
|
+
uSharpness: {
|
|
2384
|
+
value: 0.8
|
|
2385
|
+
}
|
|
2386
|
+
}
|
|
2387
|
+
});
|
|
2388
|
+
}
|
|
2389
|
+
|
|
2390
|
+
let exposure = -1;
|
|
2391
|
+
|
|
2392
|
+
if (this.feature_bloom_enabled || this.feature_automatic_exposure_enabled) {
|
|
2393
|
+
const bloom = graph_postprocess_bloom({
|
|
2394
|
+
graph,
|
|
2395
|
+
input: current_color_out,
|
|
2396
|
+
resolution: this.#output_resolution.asArray(),
|
|
2397
|
+
});
|
|
2398
|
+
|
|
2399
|
+
if (this.feature_bloom_enabled) {
|
|
2400
|
+
current_color_out = bloom.composited;
|
|
2401
|
+
}
|
|
2402
|
+
|
|
2403
|
+
if (this.feature_automatic_exposure_enabled) {
|
|
2404
|
+
// TODO force time_delta_second to a very high value on view transition
|
|
2405
|
+
|
|
2406
|
+
exposure = this.#autoexposure.update({
|
|
2407
|
+
graph,
|
|
2408
|
+
input_color: bloom.downsampled,
|
|
2409
|
+
time_delta_seconds,
|
|
2410
|
+
});
|
|
2411
|
+
}
|
|
2412
|
+
|
|
2413
|
+
}
|
|
2414
|
+
|
|
2415
|
+
|
|
2416
|
+
if (this.feature_automatic_exposure_enabled === false) {
|
|
2417
|
+
exposure = this.#autoexposure.unadapted({ graph });
|
|
2418
|
+
}
|
|
2419
|
+
|
|
2420
|
+
|
|
2421
|
+
// current_color_out = graph_draw_texture_as_rgba({
|
|
2422
|
+
// graph,
|
|
2423
|
+
// source: gr_shadowmap_atlas,
|
|
2424
|
+
// resolution: this.#output_resolution.asArray(),
|
|
2425
|
+
// });
|
|
2426
|
+
|
|
2427
|
+
/*
|
|
2428
|
+
Past the upscale: the colour published here is output-sized while the G-buffer beside it is
|
|
2429
|
+
still internal-sized, and `FrameContext.resolution` reads whichever of them the phase draws
|
|
2430
|
+
into rather than a number anybody wrote down. With `feature_taa_enabled === false` no
|
|
2431
|
+
upscale happened and the two agree — which a constant could not express.
|
|
2432
|
+
*/
|
|
2433
|
+
frame.phase = FramePhase.BeforePresent;
|
|
2434
|
+
|
|
2435
|
+
record_scene_color.color = current_color_out;
|
|
2436
|
+
|
|
2437
|
+
this.#extensions.run(frame);
|
|
2438
|
+
|
|
2439
|
+
current_color_out = record_scene_color.color;
|
|
2440
|
+
|
|
2441
|
+
if (this.#hdr_supported) {
|
|
2442
|
+
[current_color_out] = graph_image_pass({
|
|
2443
|
+
graph,
|
|
2444
|
+
shader: shader_tonemap_HDR,
|
|
2445
|
+
inputs: {
|
|
2446
|
+
input_color: current_color_out,
|
|
2447
|
+
settings: {
|
|
2448
|
+
peak_nits: this.#display_peak_brightness_nits,
|
|
2449
|
+
paper_white_nits: 100, // SDR spec is 80, but 100 has been accepted as de-facto in recent years
|
|
2450
|
+
},
|
|
2451
|
+
exposure
|
|
2452
|
+
},
|
|
2453
|
+
output: [gr_texture_canvas]
|
|
2454
|
+
});
|
|
2455
|
+
} else {
|
|
2456
|
+
[current_color_out] = graph_image_pass({
|
|
2457
|
+
graph,
|
|
2458
|
+
shader: shader_tonemap_LDR,
|
|
2459
|
+
inputs: {
|
|
2460
|
+
input_color: current_color_out,
|
|
2461
|
+
exposure
|
|
2462
|
+
},
|
|
2463
|
+
output: [gr_texture_canvas]
|
|
2464
|
+
});
|
|
2465
|
+
}
|
|
2466
|
+
|
|
2467
|
+
/*
|
|
2468
|
+
The canvas is written here and cannot be read: a texture may not be a render attachment and
|
|
2469
|
+
a sampled source in the same pass. So what this phase carries is a `PresentTarget` with one
|
|
2470
|
+
field and no colour to be tempted by — an extension that wants the finished image as input
|
|
2471
|
+
finds that out at `get` time and belongs at `BeforePresent`.
|
|
2472
|
+
*/
|
|
2473
|
+
frame.phase = FramePhase.Overlay;
|
|
2474
|
+
|
|
2475
|
+
frame.create(PresentTarget).canvas = current_color_out;
|
|
2476
|
+
|
|
2477
|
+
this.#extensions.run(frame);
|
|
2478
|
+
|
|
2479
|
+
frame.close();
|
|
2480
|
+
|
|
2481
|
+
if (profile_recorder !== null) {
|
|
2482
|
+
// Subscribed before the graph runs; the recorder drops the handlers when it closes.
|
|
2483
|
+
// A frame graph is single-use, so this never outlives the frame either way.
|
|
2484
|
+
profile_recorder.attach_graph(graph);
|
|
2485
|
+
}
|
|
2486
|
+
|
|
2487
|
+
command_ctx.encodeGraph(graph);
|
|
2488
|
+
|
|
2489
|
+
command_ctx.popDebugGroup();
|
|
2490
|
+
|
|
2491
|
+
view_ctx.finish_frame(command_ctx);
|
|
2492
|
+
|
|
2493
|
+
command_ctx.finish();
|
|
2494
|
+
|
|
2495
|
+
if (profile_recorder !== null) {
|
|
2496
|
+
/*
|
|
2497
|
+
Waits on `profiling_absorbed`, not on `done`. `done` resolves from `onFinished`, which
|
|
2498
|
+
fires synchronously at submit — the timings have not been read back yet at that point,
|
|
2499
|
+
and closing there would commit an empty frame every time.
|
|
2500
|
+
*/
|
|
2501
|
+
const recorder = profile_recorder;
|
|
2502
|
+
const session = this.profile_session;
|
|
2503
|
+
|
|
2504
|
+
command_ctx.profiling_absorbed.then(() => {
|
|
2505
|
+
session.end_frame(recorder, performance.now());
|
|
2506
|
+
});
|
|
2507
|
+
}
|
|
2508
|
+
|
|
2509
|
+
this.#end_frame();
|
|
2510
|
+
|
|
2511
|
+
return true;
|
|
2512
|
+
}
|
|
2513
|
+
}
|