Raytracing треугольник нормалей.странный эффект - PullRequest
0 голосов
/ 23 июня 2019

Я пытаюсь проследить комнату с сферой внутри.У меня есть модель из блендера.Геометрия выглядит так, как должно быть.

enter image description here

Каждая плоскость состоит из 2 прямоугольников.Я не могу понять, почему это происходит.

enter image description here

Я проверил нормали, и у каждого треугольника на плоскости есть те же самые нормали.Что может вызвать эту проблему?

// COLOR FUNCTION
V3 color(const Ray &r, Hitable *world, int depth)
{
  hit_record rec;
  if (world->hit(r, 0.001, MAXFLOAT, rec))
  {
    Ray scattered;
    V3 attenuation;
    if (depth < 50 && rec.mat_ptr->scatter(r, rec, attenuation, scattered))
    {
      return attenuation * color(scattered, world, depth + 1);
    }
    else
    {
      return V3(0, 0, 0);
    }
  }
  V3 unit_dierection = unit_vector(r.direction());
  float t = 0.5 * (unit_dierection.y() + 1.0);
  return (1.0 - t) * V3(1.0, 1.0, 1.0) + t * V3(0.5, 0.7, 1.0);
}

/// DEFINITION OF LAMBERTIAN SCATTER
 virtual bool scatter(const Ray &ray_in, const hit_record &rec, V3& attentation, Ray &scattered) const {
    V3 target = rec.p + rec.normal + random_in_unit_sphere();
    scattered = Ray(rec.p, target - rec.p);
    attentation = albedo;
    return true;
  }
// RENDER LOOP
for (int y = height - 1; y >= 0; y--)
  {
    for (int x = 0; x < width; x++)
    {
      V3 col(0, 0, 0);
      for (int i = 0; i < p_scene.camera.max_bounces; i++)
      {
        float u = float(x + drand48()) / float(width);
        float v = float(y + drand48()) / float(height);
        Ray ray = camera.get_ray(u, v);
        col += color(ray, world, 0);
      }

      col /= float(p_scene.camera.max_bounces);
      col = V3(sqrt(col[0]), sqrt(col[1]), sqrt(col[2]));
      int Cr = int(255.99 * col.r());
      int Cg = int(255.99 * col.g());
      int Cb = int(255.99 * col.b());

      img << Cr << " " << Cg << " " << Cb << "\n";
    }
  }

Я пытаюсь следовать учебник

...