《Ray Tracing in One Weekend》阅读笔记 - 12、下一步

12.1最后渲染

    渲染出封面——许多随机的球体:

// 网页上的代码 [main.cc] Final scene
hittable_list random_scene() {
    hittable_list world;

    auto ground_material = make_shared<lambertian>(color(0.5, 0.5, 0.5));
    world.add(make_shared<sphere>(point3(0,-1000,0), 1000, ground_material));

       for (int a = -11; a < 11; a++) {
        for (int b = -11; b < 11; b++) {
            auto choose_mat = random_double();
            point3 center(a + 0.9*random_double(), 0.2, b + 0.9*random_double());
                      if ((center - vec3(4, 0.2, 0)).length() > 0.9) {
                shared_ptr<material> sphere_material;
                              if (choose_mat < 0.8) {
                    // diffuse
                    auto albedo = color::random() * color::random();
                    sphere_material = make_shared<lambertian>(albedo);
                    world.add(make_shared<sphere>(center, 0.2, sphere_material));
                } else if (choose_mat < 0.95) {
                    // metal
                    auto albedo = color::random(0.5, 1);
                    auto fuzz = random_double(0, 0.5);
                    sphere_material = make_shared<metal>(albedo, fuzz);
                    world.add(make_shared<sphere>(center, 0.2, sphere_material));
                } else {
                    // glass
                    sphere_material = make_shared<dielectric>(1.5);
                    world.add(make_shared<sphere>(center, 0.2, sphere_material));
                }
            }
        }
    }
       auto material1 = make_shared<dielectric>(1.5);
    world.add(make_shared<sphere>(point3(0, 1, 0), 1.0, material1));
       auto material2 = make_shared<lambertian>(color(0.4, 0.2, 0.1));
    world.add(make_shared<sphere>(point3(-4, 1, 0), 1.0, material2));
       auto material3 = make_shared<metal>(color(0.7, 0.6, 0.5), 0.0);
    world.add(make_shared<sphere>(point3(4, 1, 0), 1.0, material3));
       return world;
}

int main() {
    ...
    auto world = random_scene();
       point3 lookfrom(13,2,3);
    point3 lookat(0,0,0);
    vec3 vup(0,1,0);
    auto dist_to_focus = 10.0;
    auto aperture = 0.1;
       camera cam(lookfrom, lookat, vup, 20, aspect_ratio, aperture, dist_to_focus);
    ...
}

注意:在直接复制网页上的代码到编译器中时,报错:"{":未找到匹配令牌,原因是:

可参考博客:https://www.jianshu.com/p/51354266aa0e

运行结果:

运行很慢,我跑了3个多小时,画面没有网站上的清晰,猜想可能是因为每个像素点的采样少了、图片大小设小了。

 

     你可能会注意到一件有趣的事情,那就是玻璃球并没有真正的阴影,这使得它们看起来像在漂浮。这不是一个bug——在现实生活中,你不会经常看到玻璃球,它们看起来也有点奇怪,而且似乎在阴天会漂浮。玻璃球下面的大球体上的一点仍然有很多光线击中它,因为天空是重新排列的,而不是被遮挡的。

 

12.2下一步

    在完成以上工作后,可以在以下几个方面继续深入:

  1. Lights — You can do this explicitly, by sending shadow rays to lights, or it can be done implicitly by making some objects emit light, biasing scattered rays toward them, and then downweighting those rays to cancel out the bias. Both work. I am in the minority in favoring the latter approach.
  2. Triangles — Most cool models are in triangle form. The model I/O is the worst and almost everybody tries to get somebody else’s code to do this.
  3. Surface Textures — This lets you paste images on like wall paper. Pretty easy and a good thing to do.
  4. Solid textures — Ken Perlin has his code online. Andrew Kensler has some very cool info at his blog.
  5. Volumes and Media — Cool stuff and will challenge your software architecture. I favor making volumes have the hittable interface and probabilistically have intersections based on density. Your rendering code doesn’t even have to know it has volumes with that method.
  6. Parallelism — Run NN copies of your code on NN cores with different random seeds. Average the NN runs. This averaging can also be done hierarchically where N/2N/2 pairs can be averaged to get N/4N/4 images, and pairs of those can be averaged. That method of parallelism should extend well into the thousands of cores with very little coding.

 

来自 <https://raytracing.github.io/books/RayTracingInOneWeekend.html#metal/anabstractclassformaterials>

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值