我正在尝试从 Cycles 源代码中收集渲染算法期间每个样本的颜色。但是,经过 2 个月的研究(...),我仍然不明白如何获得它们。
我一直在查看device_cpu.cpp文件,尤其是 path_trace() 函数。
查看 render_buffer 变量并打印其内容时,它似乎没有存储样本的颜色:我将值写入 .txt 文件 (samplesOutput) 并写入以下行
void path_trace(DeviceTask &task, RenderTile &tile, KernelGlobals *kg)
{
float *render_buffer = (float*)tile.buffer;
int start_sample = tile.start_sample;
int end_sample = tile.start_sample + tile.num_samples;
for(int sample = start_sample; sample < end_sample; sample++) {
if(task.get_cancel() || task_pool.canceled()) {
if(task.need_finish_queue == false)
break;
}
for(int y = tile.y; y < tile.y + tile.h; y++) {
for(int x = tile.x; x < tile.x + tile.w; x++) {
path_trace_kernel()(kg, render_buffer,
sample, x, y, tile.offset,
tile.stride);
int step = tile.offset + x + y*tile.stride;
step *= kernel_data.film.pass_stride;
samplesOutput << x << " " << y << " " << *(render_buffer + step) << " "
<< *(render_buffer + step + 1) << " " << *(render_buffer + step + 2) << " "
<< *(render_buffer + step + 3) << " " << std::endl;
task.update_progress(&tile, tile.w*tile.h);
}
}
这是我从这张图片中得到的摘录
25 2 0.0508761 0.0508761 0.0508761 1
26 2 0.0508761 0.0508761 0.0508761 1
27 2 0.0508761 0.0508761 0.0508761 1
28 2 0.0508761 0.0508761 0.0508761 1
1 164 0.661389 0.661389 0.661389 13
1 164 0.661389 0.661389 0.661389 13
29 2 0.0508761 0.0508761 0.0508761 1
2 164 0.661389 0.661389 0.661389 13
2 164 0.661389 0.661389 0.661389 13
30 2 0.0508761 0.0508761 0.0508761 1
3 164 0.661389 0.661389 0.661389 13
3 164 0.661389 0.661389 0.661389 13
31 2 0.0508761 0.0508761 0.0508761 1
4 164 0.661389 0.661389 0.661389 13
4 164 0.661389 0.661389 0.661389 13
...
立方体的颜色是 rgba(0.8, 0, 0.8, 1.0)。
我发现 (0.0508761 0.0508761 0.0508761 1) 是背景的颜色(灰色)。
奇怪的是,我期望的第四个值是 alpha,但我得到了 13,它大于 1。
任何线索如何查看这些样本的颜色?
谢谢