@naanouff/w3dts-path-tracer 0.0.0-stage → 0.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/README.md +44 -3
  2. package/dist/PathTracer2Project.d.ts +17 -0
  3. package/dist/PathTracer2Project.d.ts.map +1 -0
  4. package/dist/PathTracerFrameUploadController.d.ts +186 -0
  5. package/dist/PathTracerFrameUploadController.d.ts.map +1 -0
  6. package/dist/PathTracerProject.d.ts +19 -0
  7. package/dist/PathTracerProject.d.ts.map +1 -0
  8. package/dist/SceneToRayData.d.ts +72 -0
  9. package/dist/SceneToRayData.d.ts.map +1 -0
  10. package/dist/bloomSubgraph.d.ts +14 -0
  11. package/dist/bloomSubgraph.d.ts.map +1 -0
  12. package/dist/buildPathTracerBvh.d.ts +34 -0
  13. package/dist/buildPathTracerBvh.d.ts.map +1 -0
  14. package/dist/buildPathTracerTwoLevel.d.ts +66 -0
  15. package/dist/buildPathTracerTwoLevel.d.ts.map +1 -0
  16. package/dist/emissiveTriangles.d.ts +28 -0
  17. package/dist/emissiveTriangles.d.ts.map +1 -0
  18. package/dist/fsr1EasuConstants.d.ts +7 -0
  19. package/dist/fsr1EasuConstants.d.ts.map +1 -0
  20. package/dist/hybridAtrous.d.ts +25 -0
  21. package/dist/hybridAtrous.d.ts.map +1 -0
  22. package/dist/hybridOidn.d.ts +15 -0
  23. package/dist/hybridOidn.d.ts.map +1 -0
  24. package/dist/hybridTemporal.d.ts +59 -0
  25. package/dist/hybridTemporal.d.ts.map +1 -0
  26. package/dist/index.d.ts +32 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/khronosPathTraceReference.d.ts +143 -0
  29. package/dist/khronosPathTraceReference.d.ts.map +1 -0
  30. package/dist/pathTracerBackplate.d.ts +29 -0
  31. package/dist/pathTracerBackplate.d.ts.map +1 -0
  32. package/dist/pathTracerBaselineMetrics.d.ts +98 -0
  33. package/dist/pathTracerBaselineMetrics.d.ts.map +1 -0
  34. package/dist/pathTracerBounceBudget.d.ts +32 -0
  35. package/dist/pathTracerBounceBudget.d.ts.map +1 -0
  36. package/dist/pathTracerCameraLens.d.ts +12 -0
  37. package/dist/pathTracerCameraLens.d.ts.map +1 -0
  38. package/dist/pathTracerConstants.d.ts +165 -0
  39. package/dist/pathTracerConstants.d.ts.map +1 -0
  40. package/dist/pathTracerDielectric.d.ts +30 -0
  41. package/dist/pathTracerDielectric.d.ts.map +1 -0
  42. package/dist/pathTracerEnvMap.d.ts +83 -0
  43. package/dist/pathTracerEnvMap.d.ts.map +1 -0
  44. package/dist/pathTracerGraphDefinition.d.ts +11 -0
  45. package/dist/pathTracerGraphDefinition.d.ts.map +1 -0
  46. package/dist/pathTracerInteractionEpoch.d.ts +11 -0
  47. package/dist/pathTracerInteractionEpoch.d.ts.map +1 -0
  48. package/dist/pathTracerInterleave.d.ts +74 -0
  49. package/dist/pathTracerInterleave.d.ts.map +1 -0
  50. package/dist/pathTracerLightFingerprint.d.ts +26 -0
  51. package/dist/pathTracerLightFingerprint.d.ts.map +1 -0
  52. package/dist/pathTracerMaterialTable.d.ts +63 -0
  53. package/dist/pathTracerMaterialTable.d.ts.map +1 -0
  54. package/dist/pathTracerMaterialTextureArrays.d.ts +58 -0
  55. package/dist/pathTracerMaterialTextureArrays.d.ts.map +1 -0
  56. package/dist/pathTracerOidnDenoiser.d.ts +43 -0
  57. package/dist/pathTracerOidnDenoiser.d.ts.map +1 -0
  58. package/dist/pathTracerPost.d.ts +137 -0
  59. package/dist/pathTracerPost.d.ts.map +1 -0
  60. package/dist/pathTracerRuntimeConfig.d.ts +6 -0
  61. package/dist/pathTracerRuntimeConfig.d.ts.map +1 -0
  62. package/dist/pathTracerSceneCache.d.ts +32 -0
  63. package/dist/pathTracerSceneCache.d.ts.map +1 -0
  64. package/dist/pathTracerSceneSettings.d.ts +43 -0
  65. package/dist/pathTracerSceneSettings.d.ts.map +1 -0
  66. package/dist/progressiveRenderState.d.ts +34 -0
  67. package/dist/progressiveRenderState.d.ts.map +1 -0
  68. package/dist/w3dts-path-tracer.es.js +4555 -0
  69. package/dist/w3dts-path-tracer.umd.js +46 -0
  70. package/package.json +55 -3
  71. package/shaders/clear_composite.compute.wgsl +20 -0
  72. package/shaders/clear_composite_layers.compute.wgsl +32 -0
  73. package/shaders/clear_path_trace_tile.compute.wgsl +30 -0
  74. package/shaders/copy_accum.compute.wgsl +15 -0
  75. package/shaders/denoise.compute.wgsl +88 -0
  76. package/shaders/denoise_atrous.compute.wgsl +104 -0
  77. package/shaders/display_grade.wgsl +74 -0
  78. package/shaders/fsr1_easu_path.compute.wgsl +240 -0
  79. package/shaders/fsr1_rcas_path.compute.wgsl +84 -0
  80. package/shaders/hole_fill.compute.wgsl +57 -0
  81. package/shaders/hybrid_atrous.compute.wgsl +239 -0
  82. package/shaders/hybrid_copy_aov.compute.wgsl +24 -0
  83. package/shaders/hybrid_gbuffer.wgsl +150 -0
  84. package/shaders/hybrid_history_copy.compute.wgsl +35 -0
  85. package/shaders/hybrid_primary_aov.compute.wgsl +784 -0
  86. package/shaders/hybrid_taa.compute.wgsl +131 -0
  87. package/shaders/hybrid_temporal.compute.wgsl +507 -0
  88. package/shaders/path_trace.compute.wgsl +923 -0
  89. package/shaders/path_trace_common.wgsl +1738 -0
  90. package/shaders/pt_bloom.compute.wgsl +91 -0
  91. package/shaders/pt_bloom_down.compute.wgsl +88 -0
  92. package/shaders/pt_bloom_up.compute.wgsl +76 -0
  93. package/shaders/pt_display.frag.wgsl +29 -0
  94. package/shaders/tile_composite.compute.wgsl +22 -0
  95. package/shaders/tile_composite_layers.compute.wgsl +86 -0
@@ -0,0 +1,239 @@
1
+ /**
2
+ * One SVGF à-trous step for the four hybrid signals.
3
+ * STEP is the pixel stride (1, 2, 4, 8, 16). PASS is the iteration index (0..4).
4
+ * A signal whose iteration budget is already spent is copied unchanged.
5
+ * History (.a of shadow, reflection and GI) and the shadow distance (.g) are not filtered.
6
+ */
7
+
8
+ struct HybridHistoryParams {
9
+ viewProj: mat4x4<f32>,
10
+ invViewProj: mat4x4<f32>,
11
+ prevViewProj: mat4x4<f32>,
12
+ prevInvViewProj: mat4x4<f32>,
13
+ cameraPos: vec4<f32>,
14
+ prevCameraPos: vec4<f32>,
15
+ frameIndex: u32,
16
+ historyReset: u32,
17
+ resX: u32,
18
+ resY: u32,
19
+ traceX: u32,
20
+ traceY: u32,
21
+ traceScale: f32,
22
+ offsetX: f32,
23
+ offsetY: f32,
24
+ sigmaZ: f32,
25
+ sigmaN: f32,
26
+ sigmaL: f32,
27
+ alphaMin: f32,
28
+ _pad0: f32,
29
+ _pad1: f32,
30
+ _pad2: f32,
31
+ }
32
+
33
+ override STEP: f32 = 1.0;
34
+ override PASS: f32 = 0.0;
35
+
36
+ @group(0) @binding(0) var<storage, read> hybridHistory: HybridHistoryParams;
37
+ @group(0) @binding(1) var shadowIn: texture_2d<f32>;
38
+ @group(0) @binding(2) var reflIn: texture_2d<f32>;
39
+ @group(0) @binding(3) var giIn: texture_2d<f32>;
40
+ @group(0) @binding(4) var lightVisIn: texture_2d<f32>;
41
+ @group(0) @binding(5) var hybridGDist: texture_2d<f32>;
42
+ @group(0) @binding(6) var hybridGNormal: texture_2d<f32>;
43
+ @group(0) @binding(7) var hybridMoments: texture_2d<f32>;
44
+ @group(0) @binding(8) var reflRaw: texture_2d<f32>;
45
+ @group(0) @binding(9) var<storage, read> pathTracerParams: array<u32>;
46
+ @group(0) @binding(20) var shadowOut: texture_storage_2d<rgba16float, write>;
47
+ @group(0) @binding(21) var reflOut: texture_storage_2d<rgba16float, write>;
48
+ @group(0) @binding(22) var giOut: texture_storage_2d<rgba16float, write>;
49
+ @group(0) @binding(23) var lightVisOut: texture_storage_2d<rgba16float, write>;
50
+
51
+ const EPS = 1e-4;
52
+
53
+ fn b3(i: i32) -> f32 {
54
+ if (i == 0) { return 0.375; }
55
+ if (abs(i) == 1) { return 0.25; }
56
+ return 0.0625;
57
+ }
58
+
59
+ fn luma(c: vec3<f32>) -> f32 {
60
+ return dot(c, vec3<f32>(0.25, 0.5, 0.25));
61
+ }
62
+
63
+ fn sign_not_zero(v: vec2<f32>) -> vec2<f32> {
64
+ return vec2<f32>(select(-1.0, 1.0, v.x >= 0.0), select(-1.0, 1.0, v.y >= 0.0));
65
+ }
66
+
67
+ fn decode_oct(e: vec2<f32>) -> vec3<f32> {
68
+ var n = vec3<f32>(e.xy, 1.0 - abs(e.x) - abs(e.y));
69
+ if (n.z < 0.0) {
70
+ let xy = (1.0 - abs(n.yx)) * sign_not_zero(n.xy);
71
+ n = vec3<f32>(xy, n.z);
72
+ }
73
+ return normalize(n);
74
+ }
75
+
76
+ fn inside(p: vec2<i32>, dims: vec2<u32>) -> bool {
77
+ return p.x >= 0 && p.y >= 0 && u32(p.x) < dims.x && u32(p.y) < dims.y;
78
+ }
79
+
80
+ fn grad_t(p: vec2<i32>, dims: vec2<u32>) -> vec2<f32> {
81
+ let xm = max(p.x - 1, 0);
82
+ let xp = min(p.x + 1, i32(dims.x) - 1);
83
+ let ym = max(p.y - 1, 0);
84
+ let yp = min(p.y + 1, i32(dims.y) - 1);
85
+ let dx = textureLoad(hybridGDist, vec2<i32>(xp, p.y), 0).x - textureLoad(hybridGDist, vec2<i32>(xm, p.y), 0).x;
86
+ let dy = textureLoad(hybridGDist, vec2<i32>(p.x, yp), 0).x - textureLoad(hybridGDist, vec2<i32>(p.x, ym), 0).x;
87
+ return vec2<f32>(dx / max(f32(xp - xm), 1.0), dy / max(f32(yp - ym), 1.0));
88
+ }
89
+
90
+ fn moment_var(mu1: f32, mu2: f32) -> f32 {
91
+ return max(mu2 - mu1 * mu1, 0.0);
92
+ }
93
+
94
+ fn shadow_iters(sun_angle: f32) -> i32 {
95
+ return select(3, 1, sun_angle <= 1e-6);
96
+ }
97
+
98
+ fn refl_iters(rough: f32) -> i32 {
99
+ return i32(round(mix(0.0, 5.0, smoothstep(0.02, 0.5, rough))));
100
+ }
101
+
102
+ @compute @workgroup_size(8, 8, 1)
103
+ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
104
+ let dims = textureDimensions(hybridGDist);
105
+ if (gid.x >= dims.x || gid.y >= dims.y) { return; }
106
+ let p = vec2<i32>(i32(gid.x), i32(gid.y));
107
+ let centerS = textureLoad(shadowIn, p, 0);
108
+ let centerR = textureLoad(reflIn, p, 0);
109
+ let centerG = textureLoad(giIn, p, 0);
110
+ let centerV = textureLoad(lightVisIn, p, 0);
111
+ // Pause with no reset: identity so HistoryCopy does not keep softening the freeze.
112
+ if (pathTracerParams[8] == 0u && pathTracerParams[0] == 0u) {
113
+ textureStore(shadowOut, p, centerS);
114
+ textureStore(reflOut, p, centerR);
115
+ textureStore(giOut, p, centerG);
116
+ textureStore(lightVisOut, p, centerV);
117
+ return;
118
+ }
119
+ let step = max(i32(round(STEP)), 1);
120
+ let iter = i32(round(PASS));
121
+ let t = textureLoad(hybridGDist, p, 0).x;
122
+ if (t <= 1e-4) {
123
+ textureStore(shadowOut, p, centerS);
124
+ textureStore(reflOut, p, centerR);
125
+ textureStore(giOut, p, centerG);
126
+ textureStore(lightVisOut, p, centerV);
127
+ return;
128
+ }
129
+ let packedN = textureLoad(hybridGNormal, p, 0);
130
+ let n = decode_oct(packedN.xy);
131
+ let rough = packedN.z;
132
+ let sun = bitcast<f32>(pathTracerParams[19]);
133
+ let nShadow = shadow_iters(sun);
134
+ let nRefl = refl_iters(rough);
135
+ let filterS = iter < nShadow;
136
+ let filterR = iter < nRefl;
137
+ let filterG = iter < 5;
138
+ let filterV = iter < 5;
139
+ if (!filterS && !filterR && !filterG && !filterV) {
140
+ textureStore(shadowOut, p, centerS);
141
+ textureStore(reflOut, p, centerR);
142
+ textureStore(giOut, p, centerG);
143
+ textureStore(lightVisOut, p, centerV);
144
+ return;
145
+ }
146
+ let grad = grad_t(p, dims);
147
+ let moments = textureLoad(hybridMoments, p, 0);
148
+ let varR = moment_var(moments.r, moments.g);
149
+ let varG = moment_var(moments.b, moments.a);
150
+ let yS = centerS.r;
151
+ let yR = luma(centerR.rgb);
152
+ let yG = luma(centerG.rgb);
153
+ let yV = luma(centerV.rgb);
154
+ let varS = max(yS * 0.05, 1e-4);
155
+ let varV = max(yV * 0.05, 1e-4);
156
+ let sigmaLS = select(4.0, 8.0, centerS.a < 8.0);
157
+ let sigmaLR = select(4.0, 8.0, centerR.a < 8.0);
158
+ let sigmaLG = select(4.0, 8.0, centerG.a < 8.0);
159
+ let sigmaLV = select(4.0, 8.0, centerS.a < 8.0);
160
+ let hitP = textureLoad(reflRaw, p, 0).a;
161
+ var accS = vec2<f32>(0.0);
162
+ var accR = vec3<f32>(0.0);
163
+ var accG = vec3<f32>(0.0);
164
+ var accV = vec4<f32>(0.0);
165
+ var wS = 0.0;
166
+ var wR = 0.0;
167
+ var wG = 0.0;
168
+ var wV = 0.0;
169
+ for (var j = -2; j <= 2; j++) {
170
+ for (var i = -2; i <= 2; i++) {
171
+ let q = p + vec2<i32>(i, j) * step;
172
+ if (!inside(q, dims)) { continue; }
173
+ let tq = textureLoad(hybridGDist, q, 0).x;
174
+ if (tq <= 1e-4) { continue; }
175
+ let nq = decode_oct(textureLoad(hybridGNormal, q, 0).xy);
176
+ let kernel = b3(i) * b3(j);
177
+ let delta = vec2<f32>(f32(i * step), f32(j * step));
178
+ let depthW = exp(-abs(t - tq) / (max(hybridHistory.sigmaZ, 1.0) * abs(dot(grad, delta)) + EPS));
179
+ let normalW = pow(max(dot(n, nq), 0.0), hybridHistory.sigmaN);
180
+ let base = kernel * depthW * normalW;
181
+ if (filterS) {
182
+ let s = textureLoad(shadowIn, q, 0);
183
+ let lumaW = exp(-abs(s.r - yS) / (sigmaLS * sqrt(varS) + EPS));
184
+ let w = base * lumaW;
185
+ accS += vec2<f32>(s.r, s.b) * w;
186
+ wS += w;
187
+ }
188
+ if (filterR) {
189
+ let r = textureLoad(reflIn, q, 0);
190
+ let lumaW = exp(-abs(luma(r.rgb) - yR) / (sigmaLR * sqrt(varR) + EPS));
191
+ var hitW = 1.0;
192
+ if (hitP > 1e-3 && hitP < 60000.0) {
193
+ let hitQ = textureLoad(reflRaw, q, 0).a;
194
+ if (hitQ > 1e-3 && hitQ < 60000.0) {
195
+ hitW = exp(-abs(hitP - hitQ) / (0.1 * hitP));
196
+ }
197
+ }
198
+ let w = base * lumaW * hitW;
199
+ accR += r.rgb * w;
200
+ wR += w;
201
+ }
202
+ if (filterG) {
203
+ let g = textureLoad(giIn, q, 0);
204
+ let lumaW = exp(-abs(luma(g.rgb) - yG) / (sigmaLG * sqrt(varG) + EPS));
205
+ let w = base * lumaW;
206
+ accG += g.rgb * w;
207
+ wG += w;
208
+ }
209
+ if (filterV) {
210
+ let v = textureLoad(lightVisIn, q, 0);
211
+ let lumaW = exp(-abs(luma(v.rgb) - yV) / (sigmaLV * sqrt(varV) + EPS));
212
+ let w = base * lumaW;
213
+ accV += v * w;
214
+ wV += w;
215
+ }
216
+ }
217
+ }
218
+ var outS = centerS;
219
+ if (filterS && wS > 1e-5) {
220
+ let f = accS / wS;
221
+ outS = vec4<f32>(f.x, centerS.g, f.y, centerS.a);
222
+ }
223
+ var outR = centerR;
224
+ if (filterR && wR > 1e-5) {
225
+ outR = vec4<f32>(accR / wR, centerR.a);
226
+ }
227
+ var outG = centerG;
228
+ if (filterG && wG > 1e-5) {
229
+ outG = vec4<f32>(accG / wG, centerG.a);
230
+ }
231
+ var outV = centerV;
232
+ if (filterV && wV > 1e-5) {
233
+ outV = accV / wV;
234
+ }
235
+ textureStore(shadowOut, p, outS);
236
+ textureStore(reflOut, p, outR);
237
+ textureStore(giOut, p, outG);
238
+ textureStore(lightVisOut, p, outV);
239
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Copy this frame's AOV writes into the previous-frame textures.
3
+ * rgba16float cannot be read_write, so each AOV is a pair.
4
+ */
5
+
6
+ @group(0) @binding(0) var shadowSrc: texture_storage_2d<rgba16float, read>;
7
+ @group(0) @binding(1) var shadowDst: texture_storage_2d<rgba16float, write>;
8
+ @group(0) @binding(2) var reflSrc: texture_storage_2d<rgba16float, read>;
9
+ @group(0) @binding(3) var reflDst: texture_storage_2d<rgba16float, write>;
10
+ @group(0) @binding(4) var giSrc: texture_storage_2d<rgba16float, read>;
11
+ @group(0) @binding(5) var giDst: texture_storage_2d<rgba16float, write>;
12
+ @group(0) @binding(6) var lightVisSrc: texture_storage_2d<rgba16float, read>;
13
+ @group(0) @binding(7) var lightVisDst: texture_storage_2d<rgba16float, write>;
14
+
15
+ @compute @workgroup_size(8, 8, 1)
16
+ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
17
+ let dims = textureDimensions(shadowSrc);
18
+ if (gid.x >= dims.x || gid.y >= dims.y) { return; }
19
+ let p = vec2<i32>(gid.xy);
20
+ textureStore(shadowDst, p, textureLoad(shadowSrc, p));
21
+ textureStore(reflDst, p, textureLoad(reflSrc, p));
22
+ textureStore(giDst, p, textureLoad(giSrc, p));
23
+ textureStore(lightVisDst, p, textureLoad(lightVisSrc, p));
24
+ }
@@ -0,0 +1,150 @@
1
+ /**
2
+ * Hybrid G-buffer for static opaque meshes.
3
+ * Same vertex layout as the shader-graph pass (no skin, wind, or billboard).
4
+ * Geometric normal. Roughness and metal come from the per-material uniform.
5
+ * Albedo is the base-color factor. The instance color already holds diffuseColor (BatchingSystem),
6
+ * which the graph PBR does not apply, so it is not multiplied in. Sky stays at distance 0.
7
+ */
8
+
9
+ struct FrameUniforms {
10
+ projectionMatrix: mat4x4<f32>,
11
+ viewMatrix: mat4x4<f32>,
12
+ inverseViewProjectionMatrix: mat4x4<f32>,
13
+ cameraPosition: vec3<f32>,
14
+ @size(64) lightMatrix: mat4x4<f32>,
15
+ lightDirection: vec3<f32>,
16
+ lightColor: vec3<f32>,
17
+ ambientLightIntensity: f32,
18
+ debugViewMode: u32,
19
+ totalTime: f32,
20
+ };
21
+
22
+ struct VertexInput {
23
+ @location(0) position: vec3<f32>,
24
+ @location(1) uv: vec2<f32>,
25
+ @location(2) uv1: vec2<f32>,
26
+ @location(3) normal: vec3<f32>,
27
+ @location(4) tangent: vec3<f32>,
28
+ @location(5) bitangent: vec3<f32>,
29
+ @location(6) color: vec4<f32>,
30
+ };
31
+
32
+ struct InstanceInput {
33
+ @location(7) modelMatrix_r1: vec4<f32>,
34
+ @location(8) modelMatrix_r2: vec4<f32>,
35
+ @location(9) modelMatrix_r3: vec4<f32>,
36
+ @location(10) modelMatrix_r4: vec4<f32>,
37
+ @location(11) inverseModel_r1: vec4<f32>,
38
+ @location(12) inverseModel_r2: vec4<f32>,
39
+ @location(13) inverseModel_r3: vec4<f32>,
40
+ @location(14) inverseModel_r4: vec4<f32>,
41
+ @location(15) color: vec4<f32>,
42
+ };
43
+
44
+ struct VertexOutput {
45
+ @builtin(position) clip_position: vec4<f32>,
46
+ @location(0) world_position: vec3<f32>,
47
+ @location(1) world_normal: vec3<f32>,
48
+ @location(2) prev_clip: vec4<f32>,
49
+ @location(3) cur_clip: vec4<f32>,
50
+ };
51
+
52
+ struct GBufferMaterial {
53
+ baseColor: vec4<f32>,
54
+ roughness: f32,
55
+ metallic: f32,
56
+ _pad: vec2<f32>,
57
+ };
58
+
59
+ struct HybridHistoryParams {
60
+ viewProj: mat4x4<f32>,
61
+ invViewProj: mat4x4<f32>,
62
+ prevViewProj: mat4x4<f32>,
63
+ prevInvViewProj: mat4x4<f32>,
64
+ cameraPos: vec4<f32>,
65
+ prevCameraPos: vec4<f32>,
66
+ frameIndex: u32,
67
+ historyReset: u32,
68
+ resX: u32,
69
+ resY: u32,
70
+ traceX: u32,
71
+ traceY: u32,
72
+ traceScale: f32,
73
+ offsetX: f32,
74
+ offsetY: f32,
75
+ sigmaZ: f32,
76
+ sigmaN: f32,
77
+ sigmaL: f32,
78
+ alphaMin: f32,
79
+ jitterX: f32,
80
+ jitterY: f32,
81
+ _pad2: f32,
82
+ };
83
+
84
+ struct GBufferOutput {
85
+ @location(0) dist: f32,
86
+ @location(1) normalRoughMetal: vec4<f32>,
87
+ @location(2) motion: vec2<f32>,
88
+ @location(3) albedo: vec4<f32>,
89
+ };
90
+
91
+ @group(0) @binding(0) var<uniform> frame: FrameUniforms;
92
+ @group(1) @binding(0) var<storage, read> history: HybridHistoryParams;
93
+ @group(2) @binding(0) var<uniform> gbufMat: GBufferMaterial;
94
+
95
+ @vertex
96
+ fn vs_main(vertex: VertexInput, instance: InstanceInput) -> VertexOutput {
97
+ let modelMatrix = mat4x4<f32>(
98
+ instance.modelMatrix_r1,
99
+ instance.modelMatrix_r2,
100
+ instance.modelMatrix_r3,
101
+ instance.modelMatrix_r4
102
+ );
103
+ let normalMatrix = mat4x4<f32>(
104
+ instance.inverseModel_r1,
105
+ instance.inverseModel_r2,
106
+ instance.inverseModel_r3,
107
+ instance.inverseModel_r4
108
+ );
109
+ let world_pos_4d = modelMatrix * vec4<f32>(vertex.position, 1.0);
110
+ var output: VertexOutput;
111
+ output.world_position = world_pos_4d.xyz;
112
+ output.world_normal = normalize((normalMatrix * vec4<f32>(vertex.normal, 0.0)).xyz);
113
+ output.clip_position = frame.projectionMatrix * frame.viewMatrix * world_pos_4d;
114
+ output.cur_clip = history.viewProj * world_pos_4d;
115
+ output.prev_clip = history.prevViewProj * world_pos_4d;
116
+ return output;
117
+ }
118
+
119
+ fn clip_uv(clip: vec4<f32>) -> vec2<f32> {
120
+ let ndc = clip.xy / max(clip.w, 1e-6);
121
+ return ndc * vec2<f32>(0.5, -0.5) + vec2<f32>(0.5);
122
+ }
123
+
124
+ fn sign_not_zero(v: f32) -> f32 {
125
+ return select(-1.0, 1.0, v >= 0.0);
126
+ }
127
+
128
+ fn encode_oct(nIn: vec3<f32>) -> vec2<f32> {
129
+ let n = normalize(nIn);
130
+ let l1 = abs(n.x) + abs(n.y) + abs(n.z);
131
+ let xy = n.xy / l1;
132
+ if (n.z < 0.0) {
133
+ return vec2<f32>(
134
+ (1.0 - abs(xy.y)) * sign_not_zero(xy.x),
135
+ (1.0 - abs(xy.x)) * sign_not_zero(xy.y)
136
+ );
137
+ }
138
+ return xy;
139
+ }
140
+
141
+ @fragment
142
+ fn fs_main(input: VertexOutput) -> GBufferOutput {
143
+ var output: GBufferOutput;
144
+ output.dist = length(input.world_position - frame.cameraPosition);
145
+ output.normalRoughMetal = vec4<f32>(encode_oct(input.world_normal), gbufMat.roughness, gbufMat.metallic);
146
+ output.albedo = vec4<f32>(gbufMat.baseColor.rgb, 1.0);
147
+ // The fragment clip_position is in pixels; the interpolated clip copy is not.
148
+ output.motion = clip_uv(input.cur_clip) - clip_uv(input.prev_clip);
149
+ return output;
150
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Keeps last frame's filtered AOVs and G-buffer for the next reprojection.
3
+ * Sampled sources, storage destinations: the pair cannot be the same texture.
4
+ */
5
+
6
+ @group(0) @binding(0) var shadowSrc: texture_2d<f32>;
7
+ @group(0) @binding(1) var reflSrc: texture_2d<f32>;
8
+ @group(0) @binding(2) var giSrc: texture_2d<f32>;
9
+ @group(0) @binding(3) var lightVisSrc: texture_2d<f32>;
10
+ @group(0) @binding(4) var shadowDst: texture_storage_2d<rgba16float, write>;
11
+ @group(0) @binding(5) var reflDst: texture_storage_2d<rgba16float, write>;
12
+ @group(0) @binding(6) var giDst: texture_storage_2d<rgba16float, write>;
13
+ @group(0) @binding(7) var lightVisDst: texture_storage_2d<rgba16float, write>;
14
+ @group(0) @binding(8) var distSrc: texture_2d<f32>;
15
+ @group(0) @binding(9) var normalSrc: texture_2d<f32>;
16
+ @group(0) @binding(10) var distDst: texture_storage_2d<r32float, write>;
17
+ @group(0) @binding(11) var normalDst: texture_storage_2d<rgba16float, write>;
18
+ @group(0) @binding(12) var<storage, read> pathTracerParams: array<u32>;
19
+
20
+ @compute @workgroup_size(8, 8, 1)
21
+ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
22
+ let dims = textureDimensions(shadowSrc);
23
+ if (gid.x >= dims.x || gid.y >= dims.y) { return; }
24
+ let p = vec2<i32>(gid.xy);
25
+ textureStore(shadowDst, p, textureLoad(shadowSrc, p, 0));
26
+ textureStore(reflDst, p, textureLoad(reflSrc, p, 0));
27
+ textureStore(giDst, p, textureLoad(giSrc, p, 0));
28
+ textureStore(lightVisDst, p, textureLoad(lightVisSrc, p, 0));
29
+ // Pause with no reset: keep G-buffer prev frozen with the AOV history.
30
+ if (pathTracerParams[8] == 0u && pathTracerParams[0] == 0u) {
31
+ return;
32
+ }
33
+ textureStore(distDst, p, textureLoad(distSrc, p, 0));
34
+ textureStore(normalDst, p, textureLoad(normalSrc, p, 0));
35
+ }