-
大小: 5.77MB文件类型: .rar金币: 1下载: 0 次发布日期: 2023-09-30
- 语言: C/C++
- 标签: Raytracing 光线追踪 离线渲染
资源简介
《Ray Tracing in One Weekend》Peter Shirley 的书2016版,非常好的光线追踪入门教材,包括 pdf 文件以及两份 c++源码
代码片段和文件信息
#include
#include
#include “sphere.h“
#include “hitable_list.h“
#include “float.h“
#include “camera.h“
#include “material.h“
#include “helper.h“
vec3 color(const ray& r hitable *world int depth) {
hit_record rec;
if (world->hit(r 0.001 (0x1.fffffep+127f) rec)) {
ray scattered;
vec3 attenuation;
if (depth < 50 && rec.mat_ptr->scatter(r rec attenuation scattered)) {
return attenuation*color(scattered world depth+1);
}
else {
return vec3(000);
}
}
else {
vec3 unit_direction = unit_vector(r.direction());
float t = 0.5*(unit_direction.y() + 1.0);
return (1.0-t)*vec3(1.0 1.0 1.0) + t*vec3(0.5 0.7 1.0);
}
}
hitable *random_scene() {
int n = 500;
hitable **list = new hitable*[n+1];
//产生一个超大球 作为地面
list[0] = new sphere(vec3(0-10000) 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 = drand48();
float choose_y = drand48();
vec3 center(a+0.9*drand48() 0.4*choose_y b+0.9*drand48());
//
if ((center-vec3(40.20)).length() > 0.9) {
if (choose_mat < 0.8) { // diffuse
list[i++] = new sphere(center 0.2 new lambertian(vec3(drand48()*drand48() drand48()*drand48() drand48()*drand48())));
}
else if (choose_mat < 0.95) { // metal
list[i++] = new sphere(center 0.2
new metal(vec3(0.5*(1 + drand48()) 0.5*(1 + drand48()) 0.5*(1 + drand48())) 0.5*drand48()));
}
else { // glass
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(listi);
}
int main() {
int nx = 1200;
int ny = 800;
int ns = 100;
freopen(“out.ppm““w“stdout);
std::cout << “P3\n“ << nx << “ “ << ny << “\n255\n“;
hitable *list[5];
list[0] = new sphere(vec3(00-1) 0.5 new lambertian(vec3(0.1 0.2 0.5)));
list[1] = new sphere(vec3(0-100.5-1) 100 new lambertian(vec3(0.8 0.8 0.0)));
list[2] = new sphere(vec3(10-1) 0.5 new metal(vec3(0.8 0.6 0.2) 0.0));
list[3] = new sphere(vec3(-10-1) 0.5 new dielectric(1.5));
list[4] = new sphere(vec3(-10-1) -0.45 new dielectric(1.5));
hitable *world = new hitable_list(list5);
world = random_scene();
vec3 lookfrom(1323);
vec3 lookat(000);
float dist_to_focus = 10.0;
float aperture = 0.1;
camera cam(lookfrom lookat vec3(010) 20 float(nx)/flo
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1356 2017-12-09 18:18 Peter Shirley-Ray Tracing\Book1_Code\camera.h
文件 344 2017-12-09 18:18 Peter Shirley-Ray Tracing\Book1_Code\helper.h
文件 305 2017-12-09 18:18 Peter Shirley-Ray Tracing\Book1_Code\hitable.h
文件 834 2017-12-09 18:18 Peter Shirley-Ray Tracing\Book1_Code\hitable_list.h
文件 3734 2017-12-09 18:18 Peter Shirley-Ray Tracing\Book1_Code\main.cpp
文件 3580 2017-12-09 18:18 Peter Shirley-Ray Tracing\Book1_Code\material.h
文件 361 2017-12-09 18:18 Peter Shirley-Ray Tracing\Book1_Code\ray.h
文件 1299 2017-12-09 18:18 Peter Shirley-Ray Tracing\Book1_Code\sphere.h
文件 3642 2017-12-09 18:18 Peter Shirley-Ray Tracing\Book1_Code\vec3.h
文件 1712 2017-12-09 18:03 Peter Shirley-Ray Tracing\Book2_Code\aabb.h
文件 5096 2017-12-09 18:04 Peter Shirley-Ray Tracing\Book2_Code\box.h
文件 2621 2017-12-09 18:15 Peter Shirley-Ray Tracing\Book2_Code\bvh.h
文件 1782 2017-12-09 18:15 Peter Shirley-Ray Tracing\Book2_Code\camera.h
文件 1916 2017-12-09 18:15 Peter Shirley-Ray Tracing\Book2_Code\constant_medium.h
文件 381 2017-12-09 18:12 Peter Shirley-Ray Tracing\Book2_Code\helper.h
文件 1591 2017-12-09 18:14 Peter Shirley-Ray Tracing\Book2_Code\hitable.h
文件 831 2016-05-06 05:26 Peter Shirley-Ray Tracing\Book2_Code\hitable_list.h
文件 11674 2017-12-09 18:12 Peter Shirley-Ray Tracing\Book2_Code\main.cpp
文件 4330 2017-12-09 18:13 Peter Shirley-Ray Tracing\Book2_Code\material.h
文件 2302 2017-12-09 18:14 Peter Shirley-Ray Tracing\Book2_Code\moving_sphere.h
文件 2213 2017-12-09 18:14 Peter Shirley-Ray Tracing\Book2_Code\perlin.h
文件 440 2017-12-09 18:13 Peter Shirley-Ray Tracing\Book2_Code\ray.h
文件 1954 2017-12-09 18:13 Peter Shirley-Ray Tracing\Book2_Code\sphere.h
文件 258056 2017-12-09 18:12 Peter Shirley-Ray Tracing\Book2_Code\stb_image.h
文件 61500 2017-12-09 18:12 Peter Shirley-Ray Tracing\Book2_Code\stb_image_write.h
文件 1860 2017-12-09 18:12 Peter Shirley-Ray Tracing\Book2_Code\texture.h
文件 186138 2017-12-06 09:17 Peter Shirley-Ray Tracing\Book2_Code\timg.jpg
文件 3018 2017-12-09 18:12 Peter Shirley-Ray Tracing\Book2_Code\translate.h
文件 3646 2017-12-09 18:12 Peter Shirley-Ray Tracing\Book2_Code\vec3.h
文件 1429227 2017-12-09 13:19 Peter Shirley-Ray Tracing\Output\Cornell_Box_sample_100_BVH.jpg
............此处省略11个文件信息
- 上一篇:二维码生成 C++
- 下一篇:C语言大全(第四版)
评论
共有 条评论