|
1 | 1 | --- |
2 | 2 | author: mos9527 |
3 | | -lastmod: 2025-12-25T18:28:45.057640 |
| 3 | +lastmod: 2025-12-25T19:12:22.889619 |
4 | 4 | title: Foundation 施工笔记 【6】- 路径追踪 |
5 | 5 | tags: ["CG","Vulkan","Foundation"] |
6 | 6 | categories: ["CG","Vulkan"] |
@@ -80,13 +80,14 @@ float uintToFloat(uint x) { |
80 | 80 | 毕竟,我们的随机数种子也是由帧序号初始化的——这样做可以将多帧,可能不同但趋近最终积分的结过积累以逼近。小记积累部分的更新: |
81 | 81 |
|
82 | 82 | ```glsl |
83 | | -// Accumulation |
84 | | -float3 output = L; |
| 83 | +float4 output = float4(L, 1.0f); |
85 | 84 | float frameCount = float(globalParams.ptAccumualatedFrames + 1); |
86 | | -float3 prevAvg = (globalParams.ptAccumualatedFrames == 0) ? float3(0) : accumulation[pix].xyz; |
87 | | -// Welford mean update |
88 | | -float3 newAvg = prevAvg + (output - prevAvg) / frameCount; |
89 | | -accumulation[pix] = float4(newAvg, 1.0); |
| 85 | +if (frameCount == 1){ |
| 86 | + accumulation[pix] = lighting[pix] = output; |
| 87 | +} else { |
| 88 | + accumulation[pix] += output; |
| 89 | + lighting[pix] = accumulation[pix] / frameCount; |
| 90 | +} |
90 | 91 | ``` |
91 | 92 |
|
92 | 93 | 还有一个好处是:因为是多帧平均采样,若对镜头做jitter,这里就是一种 ~~五毛钱~~ TAA/Temporal抗锯齿的实现。Primiary Ray生成如下: |
@@ -1248,11 +1249,13 @@ public BSDFSample Sample_f(float3 wo, float uc, float2 u, TransportMode, BxDFRef |
1248 | 1249 |
|
1249 | 1250 | ##### 遗留问题 |
1250 | 1251 |
|
1251 | | -- 积累地足够久图像会以某种奇怪的规律变暗? |
| 1252 | +- 积累地足够久图像会以某种奇怪的规律变暗? **UPD:** 解决:是精度问题。积累buffer就别省着用FP16了...换成FP32解决 |
1252 | 1253 |  |
1253 | 1254 |
|
1254 | | -- nvpro-samples 中见到一个[限制路径roughness消除firefly的trick](https://github.com/nvpro-samples/vk_gltf_renderer/blob/master/shaders/gltf_pathtrace.slang#L761),但是不知道为什么这样有效。前后对比如下(注意左上角!) |
| 1255 | +- nvpro-samples 中见到一个[限制路径roughness消除firefly的trick](https://github.com/nvpro-samples/vk_gltf_renderer/blob/master/shaders/gltf_pathtrace.slang#L761),但是不知道为什么这样有效(限制PDF?需要考证) |
1255 | 1256 |
|
| 1257 | + 前后对比如下(注意左上角!) |
| 1258 | + |
1256 | 1259 | ```c++ |
1257 | 1260 | // Keep track of the maximum roughness to prevent firefly artifacts |
1258 | 1261 | // by forcing subsequent bounces to be at least as rough |
|
0 commit comments