首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么我的图像在库达路径追踪器中有一个方形图案?

为什么我的图像在库达路径追踪器中有一个方形图案?
EN

Computer Graphics用户
提问于 2020-09-20 18:14:03
回答 1查看 198关注 0票数 3

我正在根据雪莉的书在库达中写一个路径追踪器。我的输出是正方形的。

如果改变块的尺寸,块的大小就会改变。对于这个图像,块的尺寸遵循长宽比,基本上16 *9是块大小。我知道,如果不实际显示整个代码,就很难调试它。我只是问你是否知道我应该从哪里开始调试它。我的预感是我的随机数发生器出了问题。这是它的代码,以防我做错了什么。以下是主机代码:

代码语言:javascript
复制
int total_pixel_size = WIDTH * HEIGHT;
size_t frameSize = 3 * total_pixel_size;

// declare random state
int SEED = time(NULL);
thrust::device_ptr<curandState> randState1 = thrust::device_malloc<curandState>(frameSize);
CUDA_CONTROL(cudaGetLastError());

// declare random state 2
thrust::device_ptr<curandState> randState2 = thrust::device_malloc<curandState>(1);
CUDA_CONTROL(cudaGetLastError());
rand_init<<<1, 1>>>(thrust::raw_pointer_cast(randState2),
                      SEED);
CUDA_CONTROL(cudaGetLastError());
CUDA_CONTROL(cudaDeviceSynchronize());

dim3 blocks(WIDTH / BLOCK_WIDTH + 1,
              HEIGHT / BLOCK_HEIGHT + 1);
  dim3 threads(BLOCK_WIDTH, BLOCK_HEIGHT);
  render_init<<<blocks, threads>>>(
      WIDTH, HEIGHT, thrust::raw_pointer_cast(randState1),
      SEED);

以下是设备代码:

代码语言:javascript
复制
__global__ void rand_init(curandState *randState,
                          int seed) {
  if (threadIdx.x == 0 && blockIdx.x == 0) {
    curand_init(seed, 0, 0, randState);
  }
}

__global__ void render_init(int mx, int my,
                            curandState *randState,
                            int seed) {
  if (threadIdx.x == 0 && threadIdx.y == 0) {
    curand_init(seed, 0, 0, randState);
  }
  int i = threadIdx.x + blockIdx.x * blockDim.x;
  int j = threadIdx.y + blockIdx.y * blockDim.y;

  if ((i >= mx) || (j >= my)) {
    return;
  }
  int pixel_index = j * mx + i;
  // same seed, different index
  curand_init(seed + pixel_index, pixel_index, 0,
              &randState[pixel_index]);
}

我真的很感激任何关于这个问题的建议。

下面是另一幅具有不同块大小和尺寸但具有相同问题的图像:

EN

回答 1

Computer Graphics用户

发布于 2020-10-08 02:30:57

我设法修好了。它确实与重复的随机序列有关。问题如下。curandState* randStatecurandStates的数组,对curand_*的大多数调用都需要一个curandState指针。我将randState (数组)发送到curand_*函数,而不是它的一个成员的指针。现在我的大部分图片都是这样的:

票数 1
EN
页面原文内容由Computer Graphics提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://computergraphics.stackexchange.com/questions/10247

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档