30.1 封面图片

先完成封面图片。

Code如下:

----------------------------------------------main.cpp------------------------------------------

main.cpp

    hitable *random_scene() {int n = 500;hitable **list = new hitable *[n+1];
/*定义一个包含n+1个元素的数组,数组的每个元素是指向hitable对象的指针。然后将数组的指针赋值给list。所以,list是指针的指针。*/list[0] = new sphere(vec3(0,-1000,0), 1000, new lambertian(vec3(0.5, 0.5, 0.5)));
/*先创建一个中心在(0,-1000,0)半径为1000的超大漫射球,将其指针保存在list的第一个元素中。*/int i = 1;for (int a = -11; a < 11; a++) {for (int b = -11; b < 11; b++) {
/*两个for循环中会产生(11+11)*(11+11)=484个随机小球*/float choose_mat = (rand()%(100)/(float)(100));
/*产生一个(0,1)的随机数,作为设置小球材料的阀值*/vec3 center(a+0.9*(rand()%(100)/(float)(100)), 0.2,
b+0.9*(rand()%(100)/(float)(100)));
/*” a+0.9*(rand()%(100)/(float)(100))”配合[-11,11]产生(-11,11)之间的随机数,而不是[-11,11)之间的22个整数。使得球心的x,z坐标是(-11,11)之间的随机数*/if ((center-vec3(4,0.2,0)).length() > 0.9) {
/*避免小球的位置和最前面的大球的位置太靠近*/if (choose_mat < 0.8) {     //diffuse
/*材料阀值小于0.8,则设置为漫反射球,漫反射球的衰减系数x,y,z都是(0,1)之间的随机数的平方*/list[i++] = new sphere(center, 0.2,new lambertian(vec3(
(rand()%(100)/(float)(100))*(rand()%(100)/(float)(100)),
(rand()%(100)/(float)(100))*(rand()%(100)/(float)(100)),
(rand()%(100)/(float)(100))*(rand()%(100)/(float)(100)))));}else if (choose_mat < 0.95) {
/*材料阀值大于等于0.8小于0.95,则设置为镜面反射球,镜面反射球的衰减系数x,y,z及模糊系数都是(0,1)之间的随机数加一再除以2*/list[i++] = new sphere(center, 0.2,new metal(vec3(0.5*(1+(rand()%(100)/(float)(100))),
0.5*(1+(rand()%(100)/(float)(100))),
0.5*(1+(rand()%(100)/(float)(100)))),
0.5*(1+(rand()%(100)/(float)(100))));}else {
/*材料阀值大于等于0.95,则设置为介质球*/list[i++] = new sphere(center, 0.2, new dielectric(1.5));}}}}list[i++] = new sphere(vec3(0, 1, 0), 1.0, new dielectric(1.5));list[i++] = new sphere(vec3(-4, 1, 0), 1.0, new lambertian(vec3(0.4, 0.2, 0.1)));list[i++] = new sphere(vec3(4, 1, 0), 1.0, new metal(vec3(0.7, 0.6, 0.5), 0.0));
/*定义三个大球*/return new hitable_list(list, i);}

书上坑爹的是,没有给出相机参数,而是直接贴了张结果图。坑爹啊!我是根据三个大球在画面中的相对位置,调了一组参数,得到的图片和参考图片近似吧。

vec3 lookfrom(11,2,3);

vec3 lookat(0,0.6,0);

float dist_to_focus = (lookfrom - lookat).length();

float aperture = 0.0;

camera cam(lookfrom, lookat, vec3(0,1,0), 20, float(nx)/float(ny), aperture,0.7*dist_to_focus);

调试过程中的几张图片

vec3 lookfrom(11,1,4);

vec3 lookat(0,1,0);

float dist_to_focus = (lookfrom - lookat).length();

float aperture = 0.0;

camera cam(lookfrom, lookat, vec3(0,1,0), 20, float(nx)/float(ny), aperture,0.7*dist_to_focus);

vec3 lookfrom(11,1,3.5);

vec3 lookat(0,0.6,0);

float dist_to_focus = (lookfrom - lookat).length();

float aperture = 0.0;

camera cam(lookfrom, lookat, vec3(0,1,0), 20, float(nx)/float(ny), aperture,0.7*dist_to_focus);

改变/增加大球后的code如下:

----------------------------------------------main.cpp------------------------------------------

main.cpp

    hitable *random_scene() {int n = 500;hitable **list = new hitable *[n+1];list[0] = new sphere(vec3(0,-1000,0), 1000, new lambertian(vec3(0.5, 0.5, 0.5)));int i = 1;for (int a = -11; a < 11; a++) {for (int b = -11; b < 11; b++) {float choose_mat = (rand()%(100)/(float)(100));vec3 center(a+0.9*(rand()%(100)/(float)(100)), 0.2,
b+0.9*(rand()%(100)/(float)(100)));if ((center-vec3(4,0.2,0)).length() > 0.9) {if (choose_mat < 0.8) {     //diffuselist[i++] = new sphere(center, 0.2,new lambertian(vec3(
(rand()%(100)/(float)(100))*(rand()%(100)/(float)(100)),
(rand()%(100)/(float)(100))*(rand()%(100)/(float)(100)),
(rand()%(100)/(float)(100))*(rand()%(100)/(float)(100)))));}else if (choose_mat < 0.95) {list[i++] = new sphere(center, 0.2,new metal(vec3(0.5*(1+(rand()%(100)/(float)(100))),
0.5*(1+(rand()%(100)/(float)(100))),
0.5*(1+(rand()%(100)/(float)(100)))),
0.5*(1+(rand()%(100)/(float)(100))));}else {list[i++] = new sphere(center, 0.2, new dielectric(1.5));}}}}        list[i++] = new sphere(vec3(-6, 2, -6), 2.0, new metal(vec3(0.7, 0.6, 0.5), 0.0));list[i++] = new sphere(vec3(6, 2, -6), 2.0, new metal(vec3(0.7, 0.6, 0.5), 0.0));list[i++] = new sphere(vec3(0, 2, -7), 2.0, new metal(vec3(0.7, 0.6, 0.5), 0.0));list[i++] = new sphere(vec3(-2, 1, -4), 1.0, new dielectric(1.5));list[i++] = new sphere(vec3(2, 1, -4), 1.0, new dielectric(1.5));list[i++] = new sphere(vec3(0, 1, 0), 1.0, new dielectric(1.5));list[i++] = new sphere(vec3(-4, 1, -2), 1.0, new lambertian(vec3(0.4, 0.2, 0.1)));list[i++] = new sphere(vec3(4, 1, -2), 1.0, new lambertian(vec3(0.4, 0.2, 0.1)));list[i++] = new sphere(vec3(-6, 1, 0), 1.0, new metal(vec3(0.7, 0.6, 0.5), 0.0));list[i++] = new sphere(vec3(6, 1, 0), 1.0, new metal(vec3(0.7, 0.6, 0.5), 0.0));
return new hitable_list(list, i);}

不同的观测角度,得到不同的几张图片:

vec3 lookfrom(0,1,8);

vec3 lookat(0,3,-8);

float dist_to_focus = (lookfrom - lookat).length();

float aperture = 0.0;

camera cam(lookfrom, lookat, vec3(0,1,0), 40, float(nx)/float(ny), aperture,0.7*dist_to_focus);

vec3 lookfrom(0,8,8);

vec3 lookat(0,0,-4);

float dist_to_focus = (lookfrom - lookat).length();

float aperture = 0.0;

camera cam(lookfrom, lookat, vec3(0,1,0), 40, float(nx)/float(ny), aperture,0.7*dist_to_focus);

30.2 What next?

1. Lights. You can do this explicitly, bysending shadow rays to lights. Or it can be done implicitly by making someobjects emit light.

2. biasing scattered rays toward them, andthen downweighting those rays to cancel out the bias. Both work. I am in theminority in favoring the latter approach.

3. Triangles. Most cool models are intriangles form. The model I/O is the worst and almost everybody tries to getsomebody else’s code to do this.

4. Surface textures. This lets you pasteimages on like wall paper. Pretty easy and a good thing to do.

5. Solid textures. Ken Perlin has his codeonline. Andrew Kensler has some very cool info at his blog.

6. Volumes and media. Cool stuff and willchallenge your software architecture. I favor making volumes have the hitableinterface and probabilistically have intersections based on density. Yourrendering code doesn’t even have to know it has volumes with that method.

7. Parallelism. Run N copies of your codeon N cores with different random seeds. Average the N runs. This averaging canalso be done hierarchically where N/2 pairs can be averaged to get N/4 images,and pairs of those can be averaged. That method of parallelism should extendwell into the thousands of cores with very little coding.

30.3 补充封面图片标准答案

在第二本书《ray tracing the next week》(还没买,只能试读一章)的第一章中看到了这个标准答案。

vec3 lookfrom(13,2,3);

vec3 lookat(0,0,0);

float dist_to_focus = (lookfrom - lookat).length();

float aperture = 0.0;

camera cam(lookfrom, lookat, vec3(0,1,0), 20, float(nx)/float(ny), aperture, 0.7*dist_to_focus);

其实之前已经调到(11,2,3)(0,0.6,0)已经很接近了。

------------------------------------《Ray TracingIn One Weekend》学习完毕------------------------------------

问题三十:《Ray Tracing In One Weekend》封面图形生成相关推荐

  1. Q77:怎么用Ray Tracing画仿射变换之后的图形

    77.1 理论说明 如上图所示,椭球面是球面通过仿射变换T得到的. 现在我们的问题是:怎么ray trace变换后的椭球面? (先重申一点:经过仿射变换之后,直线还是直线,光线还是光线) 我们应该这么 ...

  2. 【人工智能笔记】第三十六节:TF2实现VITGAN对抗生成网络,MSA多头注意力 实现

    该章节介绍VITGAN对抗生成网络中,MSA多头注意力 部分的代码实现. 目录(文章发布后会补上链接): 网络结构简介 Mapping NetWork 实现 PositionalEmbedding 实 ...

  3. 《Ray Tracing in One Weekend》——Chapter 12: What's next?

    总结<Ray Tracing in One Weekend>全文 第一部分:学习总结 问题三十:<Ray Tracing In One Weekend>封面图形生成 第二部分: ...

  4. 总结《Ray Tracing from the Ground Up》

    之前已经学习过<Ray Tracing in One Weekend>和<An Introduction to Ray Tracing>的一些内容,相关总结文档链接如下: 总结 ...

  5. 问题三十一:ray tracing中Convex Quadrilateral Inverse Mapping

    从这一章节开始,主要是学习<An Introduction to Ray Tracing> 光线和多边形相交问题的求解: 1,光线和多边形所在的平面相交,求出交点: 2,判断交点是否在多边 ...

  6. 问题五十四:怎么用ray tracing画参数方程表示的曲面(2)—— bezier surface

    首先,需要说明的是: 这一章节可以看作"问题五十三"的另一个例子--bicubic bezier surface: 之前已经用"球面"和"牛角面&qu ...

  7. 问题三十三:怎么用ray tracing画特殊长方体(box)

    33.1 怎么用ray tracing画特殊长方体 在光线追踪中被用到的一种常见形态是长方体盒子.这种基本物体被用于可见物体和包围盒,包围盒被用于加速复杂物体的相交测试. 吐槽:单词都认识,就是不知道 ...

  8. 闫令琪:Games101 现代计算机图形学-光线追踪(三):渲染方程和路径追踪path ray tracing 作业Assignment07解析

    文章目录 0 whitted光线追踪的局限 1 辐射度量学 1.1 光线的表示 Radiance 1.2 物体表面上一个点的亮度 Irradiance 1.3 BRDF(Bidirectional R ...

  9. 问题六十八: 着色模型(shading model)(0)——《Ray Tracing from the Ground Up》代码的移植

    用ray tracing的方式来生成图形,主要是分两步: 1,几何建模.即为"光线撞击物体",求得撞击点. 2,给撞击点着色.我们之前的做法是:根据被撞击物体的材质(材质的颜色.材 ...

最新文章

  1. Momenta造“飞轮式”自动驾驶,4年内实现Robotaxi单车盈利,路线图首次公布
  2. 技术贴]强大的DELPHI RTTI–兼谈需要了解多种开发语言
  3. 448. Find All Numbers Disappeared in an Array
  4. sap gateway data provider - /IWFND/IF_MGW_CORE_RUNTIME
  5. 1560F1. Nearest Beautiful Number (easy version)
  6. java怎么输出点,Java实现控制台输出两点间距离
  7. Sun HotSpot JVM内存管理及垃圾收集
  8. python找到二维数据矩阵中的最大最小值直接使用min、max函数
  9. wsdl2java 生成不带JAXBElement的客户端
  10. win7下快捷方式关联错误的修复
  11. 《机器学习实战》--资料下载和运行环境
  12. SpringBoot 快速入门
  13. Beyond Compare 提示“缺少评估信息或损坏”
  14. C++中std::endl的作用
  15. Matplotlib从入门到精通05-样式色彩秀芳华
  16. 管理经济学的大作业——边际效应分析在学习生活中的应用
  17. 排列 组合 算法(一)
  18. HTML 标签 02
  19. RTL8211 uboot 模式下4芯网线对接千兆如何协商成百兆
  20. ubuntu18.04配置ORB-SLAM3(包含ROS)完整版教程

热门文章

  1. linux DISPLAY变量
  2. 将long型转换为多少MB的方法
  3. [WCF编程]8.服务实例的生命周期
  4. VirtualBox、CentOS 6.4、Hadoop、Hive玩起
  5. Leetcode 99. 恢复搜索二叉树
  6. 折半查找的平均查找次数分析
  7. LaTex中编译时出现“Undefined control sequence. l.178 \newlab”问题
  8. win10 通过xrdp远程连接到ubuntu后,显示顶端快捷工具栏,显示最小化后的应用
  9. 第2节 mapreduce深入学习:15、reduce端的join算法的实现
  10. 51nod1380 夹克老爷的逢三抽一