-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathraytracer.cpp
98 lines (84 loc) · 2.72 KB
/
raytracer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "raytracer.h"
inline Material MATERIAL(cl_float3 diffuse, cl_float3 specular, cl_float3 reflection, float shine)
{
Material result;
result.diffuse = diffuse;
result.specular = specular;
result.reflection = reflection;
result.shine = shine;
result.mirror = false;
return result;
}
inline Ray RAY(Vec3 o, Vec3 d)
{
Ray result;
result.o = o;
result.d = d;
return result;
}
// bool WorldHitGeometry(World *world, Ray ray, Hit *hit)
// {
// bool isHit = false;
// Hit nextHit;
// Hit closestHit;
// for (int i = 0; i < world->geometryCount; i++)
// {
// bool hitSuccess = false;
// if (world->geometries[i].type == Geo_Sphere)
// {
// hitSuccess = SphereHit(world->spheres[world->geometries[i].id], ray, &nextHit);
// }
// else if (world->geometries[i].type = Geo_Plane)
// {
// hitSuccess = PlaneHit(world->planes[world->geometries[i].id], ray, &nextHit);
// }
// if (hitSuccess)
// {
// if (!isHit)
// {
// isHit = true;
// closestHit = nextHit;
// }
// else if (nextHit.t < closestHit.t)
// {
// closestHit = nextHit;
// }
// }
// }
// *hit = closestHit;
// return isHit;
// }
// Vec3 WorldHit(World *world, Ray ray, bool nolight, int n)
// {
// n++;
// Hit hit;
// if (WorldHitGeometry(world, ray, &hit))
// {
// return hit.mat.diffuse;
// Vec3 p = ray.o + (ray.d * hit.t);
// Vec3 result = hit.mat.diffuse * world->ambient;
// for(int i = 0; i < world->pointLightCount; i++)
// {
// if (PointLightIlluminates(world, world->pointLights[i], p))
// {
// result += LightGetColor(Norm(world->dirLight.dir * -1), world->dirLight.color, hit);
// Vec3 pointFrom = Norm(world->pointLights[i].pos - p);
// result += LightGetColor(pointFrom, world->pointLights[i].color, hit);
// }
// }
// if (hit.mat.mirror)
// {
// if (n < 100)
// {
// Vec3 reflectionDir = Norm(Reflect(hit.ray.o - p, hit.normal));
// Vec3 adjustedP = p + (reflectionDir * EPSILON);
// Ray reflectionRay;
// reflectionRay.o = adjustedP;
// reflectionRay.d = reflectionDir;
// result += hit.mat.reflection * WorldHit(world, reflectionRay, false, n);
// }
// }
// return result;
// }
// return world->bgCol;
// }