-
Notifications
You must be signed in to change notification settings - Fork 0
/
diff.output
453 lines (429 loc) · 20.4 KB
/
diff.output
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
diff --git a/Fast MinimumStorage RayTriangle Intersection.pdf b/Fast MinimumStorage RayTriangle Intersection.pdf
new file mode 100644
index 0000000..be38f0d
Binary files /dev/null and b/Fast MinimumStorage RayTriangle Intersection.pdf differ
diff --git a/bin/Debug/raytracer b/bin/Debug/raytracer
index aed9330..57baf6d 100755
Binary files a/bin/Debug/raytracer and b/bin/Debug/raytracer differ
diff --git a/img.png b/img.png
index e5508c3..86d6271 100644
Binary files a/img.png and b/img.png differ
diff --git a/img_c2.png b/img_c2.png
new file mode 100644
index 0000000..b0ca3a5
Binary files /dev/null and b/img_c2.png differ
diff --git a/include/Primitive.h b/include/Primitive.h
index 6ff8051..bd08fa2 100644
--- a/include/Primitive.h
+++ b/include/Primitive.h
@@ -24,7 +24,8 @@ class Sphere : public Primitive
//Pass by reference (PrimaryRay&) doesn't copy the object, but it also doesn't treat it like a pointer (INtersection*)
bool intersects(PrimaryRay&, Intersection*);
bool intersects(ShadowRay&); //may not need a pass by reference, but it does save time
-
+ private:
+ float calculate_intersection(Ray&);
};
class Triangle : public Primitive
@@ -35,6 +36,9 @@ class Triangle : public Primitive
Triangle(vec3, vec3, vec3, LightProperties, mat4);
bool intersects(PrimaryRay&, Intersection*);
bool intersects(ShadowRay&);
+ private:
+ float calculate_intersection(Ray&);
+ float calculate_intersection2(Ray&);
};
#endif // PRIMITIVE_H
diff --git a/main.cpp b/main.cpp
index 9367888..32d0bee 100644
--- a/main.cpp
+++ b/main.cpp
@@ -16,7 +16,6 @@ using namespace std;
int main()
{
-
FreeImage_Initialise();
vec3 ambient(0.1,0,0);
vec3 diffuse(1,1,1);
@@ -33,21 +32,17 @@ int main()
mat4 transforms = mat4(1);
- //for simplicity's sake I may remove the Raytracer's constructor from whichever of these guys has it ATM
- //light is not being properly initiated
-
- Triangle triangle = Triangle(vec3(0, 1, -1.5), vec3(1, 0, -5), vec3(-1, 0, -2), properties, transforms);
+ //Triangle triangle = Triangle(vec3(0, 1, -3), vec3(1, 0, -5), vec3(-1, 0, -2), properties, transforms);
Sphere sphere1 = Sphere(vec3(0,0,-7), 2, properties, transforms);
- Sphere sphere2 = Sphere(vec3(0,0,-10), 0.5, properties, transforms);
- Primitive* objects[] = {&triangle};
+ //Sphere sphere2 = Sphere(vec3(0,0,-10), 0.5, properties, transforms);
+ Primitive* objects[] = {&sphere1};
Raytracer raytracer = Raytracer(&objects[0], 1, &light, 1);
Camera cam(vec3(0,0,0), vec3(0,1,0), vec3(0,0,-1), 90, 90);
Scene scene(cam, raytracer, 500, 500); //Right now scene only has one function. Maybe remove unless I end up expanding it with picture making.
scene.render();
- //FIBITMAP *img = FreeImage_ConvertFromRawBits(scene.image, scene.img_width, scene.img_height, scene.img_width * 8 * 3, 24, 0xFF0000, 0x00FF00, 0x0000FF, true);
if(!FreeImage_Save(FIF_PNG, scene.bitmap, "img.png", 0))
std::cout<<"bad things"<<std::endl;
FreeImage_DeInitialise();
diff --git a/obj/Debug/main.o b/obj/Debug/main.o
index 49dcd21..44bbd6f 100644
Binary files a/obj/Debug/main.o and b/obj/Debug/main.o differ
diff --git a/obj/Debug/src/Primitive.o b/obj/Debug/src/Primitive.o
index 4d2d9d4..955fd49 100644
Binary files a/obj/Debug/src/Primitive.o and b/obj/Debug/src/Primitive.o differ
diff --git a/raytracer.depend b/raytracer.depend
index ffb7555..56b5823 100644
--- a/raytracer.depend
+++ b/raytracer.depend
@@ -1,15 +1,15 @@
# depslib dependency file v1.0
-1457802460 source:/home/kodomo/workspace/OpenGL/raytracer/main.cpp
+1458409862 source:/home/kodomo/workspace/OpenGL/raytracer/main.cpp
<iostream>
<Primitive.h>
"Scene.h"
<FreeImage.h>
<string>
-1457802801 source:/home/kodomo/workspace/OpenGL/raytracer/src/Primitive.cpp
+1458409836 source:/home/kodomo/workspace/OpenGL/raytracer/src/Primitive.cpp
"Primitive.h"
-1457802482 /home/kodomo/workspace/OpenGL/raytracer/include/Primitive.h
+1458409698 /home/kodomo/workspace/OpenGL/raytracer/include/Primitive.h
"variables.h"
"Ray.h"
@@ -275,7 +275,7 @@
<cstring>
<iostream>
-1457802607 source:/home/kodomo/workspace/OpenGL/raytracer/src/Raytracer.cpp
+1458349180 source:/home/kodomo/workspace/OpenGL/raytracer/src/Raytracer.cpp
"Raytracer.h"
"variables.h"
<algorithm>
diff --git a/raytracer.layout b/raytracer.layout
index 8060f39..5a3b521 100644
--- a/raytracer.layout
+++ b/raytracer.layout
@@ -1,69 +1,69 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<ActiveTarget name="Debug" />
- <File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <File name="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
- <Cursor1 position="401" topLine="0" />
+ <Cursor1 position="756" topLine="15" />
</Cursor>
</File>
- <File name="src/Primitive.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <File name="src/Raytracer.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
- <Cursor1 position="362" topLine="0" />
+ <Cursor1 position="4096" topLine="17" />
</Cursor>
</File>
- <File name="include/Primitive.h" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <File name="include/Ray.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
- <Cursor1 position="572" topLine="9" />
+ <Cursor1 position="180" topLine="0" />
</Cursor>
</File>
- <File name="include/Raytracer.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <File name="src/Scene.cpp" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
- <Cursor1 position="260" topLine="0" />
+ <Cursor1 position="537" topLine="10" />
</Cursor>
</File>
- <File name="include/Camera.h" open="0" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <File name="src/Ray.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
- <Cursor1 position="588" topLine="0" />
+ <Cursor1 position="870" topLine="2" />
</Cursor>
</File>
- <File name="include/variables.h" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <File name="include/Scene.h" open="0" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
- <Cursor1 position="666" topLine="11" />
+ <Cursor1 position="341" topLine="0" />
</Cursor>
</File>
- <File name="src/Scene.cpp" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <File name="include/Camera.h" open="0" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
- <Cursor1 position="537" topLine="10" />
+ <Cursor1 position="588" topLine="0" />
</Cursor>
</File>
- <File name="src/Raytracer.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <File name="src/Primitive.cpp" open="1" top="1" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
- <Cursor1 position="943" topLine="29" />
+ <Cursor1 position="3231" topLine="39" />
</Cursor>
</File>
- <File name="include/Ray.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <File name="include/Primitive.h" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
- <Cursor1 position="180" topLine="0" />
+ <Cursor1 position="572" topLine="4" />
</Cursor>
</File>
- <File name="include/Scene.h" open="0" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <File name="src/Camera.cpp" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
- <Cursor1 position="341" topLine="0" />
+ <Cursor1 position="172" topLine="0" />
</Cursor>
</File>
- <File name="src/Camera.cpp" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <File name="include/variables.h" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
- <Cursor1 position="172" topLine="0" />
+ <Cursor1 position="666" topLine="11" />
</Cursor>
</File>
- <File name="include/Transforms.h" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <File name="include/Raytracer.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
- <Cursor1 position="43" topLine="0" />
+ <Cursor1 position="260" topLine="0" />
</Cursor>
</File>
- <File name="src/Ray.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+ <File name="include/Transforms.h" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
- <Cursor1 position="870" topLine="2" />
+ <Cursor1 position="43" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>
diff --git a/src/Primitive.cpp b/src/Primitive.cpp
index fa3200a..495f559 100644
--- a/src/Primitive.cpp
+++ b/src/Primitive.cpp
@@ -1,5 +1,8 @@
#include "Primitive.h"
+#define EPSILON 0.01
+///So I might not need an intersects method for each subclass, as long as each subclass has its own unique calculate_intersection method.
+///Could maybe just do Primitive.intersects. I'd have to implement a get_normal method for subclasses.
///tri v1 v2 v3 create a triangle from 3 vertices
Triangle::Triangle(vec3 vertex1, vec3 vertex2, vec3 vertex3, LightProperties properties, mat4 obj_transforms)
@@ -7,65 +10,103 @@ Triangle::Triangle(vec3 vertex1, vec3 vertex2, vec3 vertex3, LightProperties pro
{
this->properties = properties;
this->obj_transforms = obj_transforms;
- this->normal = glm::normalize(glm::cross((v1-v2), (v3-v2)));
+ this->normal = glm::normalize(glm::cross((v1 - v2), (v3 - v2)));
}
+/*
+ Solution found by setting the ray's parametric equation equal to the barycentric coordinate equation for the triangle,
+ setting up a new set of parametric equations, and solving for t, beta, gamma.
+ Doesn't require you to do ray-plane intersect and therefore doesn't need the triangle's normal.
+ To understand what's going on here check this out (pdf also found in the root directory of this project):
+ http://www.cs.virginia.edu/~gfx/Courses/2003/ImageSynthesis/papers/Acceleration/Fast%20MinimumStorage%20RayTriangle%20Intersection.pdf
+*/
+float Triangle::calculate_intersection2(Ray& r) {
+ //Transform vectors by -v1 to put v1 at origin
+ vec3 t1, t2, t3;
+ t2 = this->v2 - this->v1;
+ t3 = this->v3 - this->v1;
+ vec3 r_origin, r_direction;
+ r_origin = r.origin - this->v1;
+ r_direction = -r.direction; //moved to the other side of the equation so we can set up parametric equations
+ // mat{r_direction, t2, t3} * vec[t , beta, gamma] = vec[r_origin]
+ //For vectors A, B, C, det({A, B, C}) = -(A x C) * B
+ float determinant = -glm::dot(glm::cross(r_direction, t3) , t2);
+ //Zero determinant means no solution
+ //!We seem to need a negative determinant. Not sure of significance of positive determinant.
+ if((determinant < EPSILON) && (determinant > -EPSILON)) return -1;
+ //Cramer's Rule
+ float t = -glm::dot(glm::cross(r_origin, t3), t2) / determinant;
+ if(t<0) return -1; //t is the coefficient for direction, so if it's negative the intersection is behind you.
+ //Barycentric coords: alpha + beta + gamma = 1
+ //alpha, beta, gamma > 0
+ float beta = -glm::dot(glm::cross(r_direction, t3), r_origin) / determinant;
+ if(beta > 1 || beta < 0) return -1;
+ float gamma = -glm::dot(glm::cross(r_direction, r_origin), t2) / determinant;
+ if(gamma > 1 || gamma < 0) return -1;
+ if(beta + gamma > 1) return -1;
+ else return t;
+}
-
-bool Triangle::intersects(PrimaryRay& r, Intersection* i){
- ///Does it intersect with the plane?
- //(r.origin + r.direction * t) dot (normal) - (v1) dot (normal) = 0, solved for t
- if(glm::dot(r.direction, normal) == 0) return false;
+//!This is giving me a cleaner result. Maybe glm's calculations are more lossy.
+/*
+ Solution using ray - plane intersect to get the point t where r.origin + r.direction*t lies within the plane of the triangle.
+ alpha, beta, and gamma refer to barycentric coordinate constants,
+The equations for them are taken from the solution of a 3x3 matrix whose rows are derived from setting this point:
+ P = r.origin + r.direction * t
+equal to the equation for barycentric coordinates in terms of the vertices v1, v2, v3 of this triangle:
+ P = v1 * alpha + v2 * beta + v3 * gamma
+and then used this property of barycentric coordinates:
+ beta + alpha + gamma = 1
+ therefore v1 = alpha * v1 + beta * v1 + gamma * v1 (that is, 1 * v1 = v1)
+subtracting the above form of v1 from both sides to get the system of equations:
+ P - v1 = beta (v2 - v1) + gamma(v3 - v1)
+ P - v2 = alpha (v1 - v2) + gamma(v3 - v2)
+ P - v3 = alpha (v1 - v3) + beta (v2 - v3)
+I used 3 of the like 9 parametric equations that come out of this as rows of a 3x3 matrix, plugged it into Wolfram Alpha, and below is the result.
+(tl;dr: magic)
+*/
+float Triangle::calculate_intersection(Ray& r) {
+ if(glm::dot(r.direction, normal) == 0) return -1;
float t = (glm::dot(v1, normal) - glm::dot(r.origin, normal)) / (glm::dot(r.direction, normal));
- if(t < 0) return false;
+ if(t < 0) return -1;
- ///Is it in the triangle?
- //See notes for development of this thing. It's done using parametric equations, barycentric coords, etc.
- ///TODO document this &or develop a better method.
else {
float a1 = v1.x, a2 = v1.y, b1 = v2.x, b2 = v2.y, c1 = v3.x, c2 = v3.y, p1 = (r.origin + r.direction*t).x, p2 = (r.origin + r.direction*t).y;
+ //Only one computation of denominator necessary for each triangle, can store in memory.
float denominator = (a2*b1 - a1*b2 - a2*c1 + b2*c1 + a1*c2 - b1*c2);
float alpha = (b2*c1 - b1*c2 - b2*p1 + c2*p1 + b1*p2 - c1*p2) / denominator;
float beta = (-(a2*c1) + a1*c2 + a2*p1 - c2*p1 - a1*p2 + c1*p2)/ denominator;
float gamma = (a2*b1 - a1*b2 - a2*p1 + b2*p1 + a1*p2 - b1*p2)/ denominator;
if((alpha >= 0) && (beta >= 0) && (gamma >= 0)){
- i->light = this->properties;
- i->point = r.origin + r.direction * t;
- i->distance = glm::length(i->point - r.origin);
- i->normal = this->normal;
-
- return true;
+ return t;
}
- else return false;
+ else return -1;
}
-
-
-
}
-bool Triangle::intersects(ShadowRay& r){
- ///Does it intersect with the plane?
- //(r.origin + r.direction * t) dot (normal) - (v1) dot (normal) = 0, solved for t
- float t = (glm::dot(v1, normal) - glm::dot(r.origin, normal)) / (glm::dot(r.direction, normal));
- if(t < 0) return false;
+//May need some epsilon or some jumping up of t to handle rounding errors
+bool Triangle::intersects(PrimaryRay& r, Intersection* i){
+ float t = calculate_intersection(r);
- ///Is it in the triangle?
- //See notes for development of this thing. It's done using parametric equations and barycentric coords.
- ///TODO document this &or develop a better method.
+ if(t < -EPSILON) return false;
+ if((t > -EPSILON) && (t < 0)) t = 0; //round up negative values of t within epsilon range to zero
else {
- float a1 = v1.x, a2 = v1.y, b1 = v2.x, b2 = v2.y, c1 = v3.x, c2 = v3.y, p1 = (r.origin + r.direction*t).x, p2 = (r.origin + r.direction*t).y;
- float denominator = (a2*b1 - a1*b2 - a2*c1 + b2*c1 + a1*c2 - b1*c2);
- float alpha = (b2*c1 - b1*c2 - b2*p1 + c2*p1 + b1*p2 - c1*p2) / denominator;
- float beta = (-(a2*c1) + a1*c2 + a2*p1 - c2*p1 - a1*p2 + c1*p2)/ denominator;
- float gamma = (a2*b1 - a1*b2 - a2*p1 + b2*p1 + a1*p2 - b1*p2)/ denominator;
-
- if((alpha >= 0) && (beta >= 0) && (gamma >= 0)) return true;
- else return false;
+ i->light = this->properties;
+ i->point = r.origin + r.direction * t;
+ i->distance = glm::length(i->point - r.origin);
+ i->normal = this->normal;
+ return true;
}
}
+bool Triangle::intersects(ShadowRay& r){
+ if(calculate_intersection(r) < -EPSILON) return false;
+ else return true;
+}
+
+
Sphere::Sphere(vec3 center, float radius, LightProperties lp, mat4 obj_transforms) {
this->center = center;
this->radius = radius;
@@ -73,6 +114,46 @@ Sphere::Sphere(vec3 center, float radius, LightProperties lp, mat4 obj_transform
this->obj_transforms = obj_transforms;
}
+float Sphere::calculate_intersection(Ray& r) {
+ //(PdotP) t^2 + 2(Pdot(P0-C)) t + (P0 - C)dot(P0 - C) - r^2 = 0
+ //Solving mag((r.origin + r.direction * t) - sphere.center) = r^2 for t
+ ///Should I be normalizing slope and stuff? Somewhere I think, maybe in Ray constructors
+ vec3 origin_to_center = (r.origin - this->center);
+ ///Do I normalize direction? Should I? If so this should just be 1, always.
+ float a = glm::dot(r.direction, r.direction);
+ float b = 2 * glm::dot(r.direction, origin_to_center);
+ float c = glm::dot(origin_to_center, origin_to_center) - (this->radius * this->radius);
+ float discriminant = b*b - 4*a*c;
+
+ //complex roots only
+ if(discriminant < 0) return -1;
+ float closest_x;
+ //1 root, so we're inside the sphere
+ if((0.01f > discriminant) && (discriminant > 0.01f)){
+ closest_x = -b / (2 * a);
+ if(closest_x < 0) return -1;
+ }
+ //discriminant greater than zero, 2 roots
+ else {
+ float x1 = (-b + glm::sqrt(discriminant)) / (2 * a);
+ float x2 = (-b - glm::sqrt(discriminant)) / (2 * a);
+ //use the smallest positive point to get intersect
+ //here, maybe, some wiggle room could be put in s.t. near-zero stuff gets discarded
+ ///current logic: if your ray starts at the edge of the sphere, or is tangent to the sphere, no intersect.
+ if((x1 == x2) /*tangent*/ || (x1 <= 0 && x2 <= 0)){
+ return -1;
+ }
+ ///here, to decrease computation time, return a positive value if r is a ShadowRay. It doesn't need an exact location.
+ else if((x2 < 0) || (0 < x1 && x1 < x2)) {
+ closest_x = x1;
+ }
+ else if((x1 < 0) || (0 < x2 && x2 < x1)) { //remove test for speed
+ closest_x = x2;
+ }
+ return closest_x;
+ }
+}
+
//Fill in intersect struct if intersect is found, else return false
bool Sphere::intersects(PrimaryRay& r, Intersection* i) {
//(PdotP) t^2 + 2(Pdot(P0-C)) t + (P0 - C)dot(P0 - C) - r^2 = 0
@@ -142,3 +223,26 @@ bool Sphere::intersects(ShadowRay& r) {
}
return false;
}
+
+
+/*
+//Fill in intersect struct if intersect is found, else return false
+bool Sphere::intersects(PrimaryRay& r, Intersection* i) {
+ float t = calculate_intersection(r);
+ if(t < 0) return false;
+ //if((t > -EPSILON) && (t < 0)) t = 0; //round up negative values of t within epsilon range to zero
+ else {
+ i->point = r.origin + r.direction * t;
+ i->light = this->properties;
+ i->normal = glm::normalize(i->point - this->center);
+ i->distance = glm::length(i->point - r.origin);
+ return true;
+ }
+}
+
+///TODO put in some wiggle room s.t. being slightly under the surface of an object doesn't return an intersect
+bool Sphere::intersects(ShadowRay& r) {
+ if(calculate_intersection(r) < 0) return false;
+ else return true;
+}
+*/
diff --git a/src/Raytracer.cpp b/src/Raytracer.cpp
index dabe476..b6fe30a 100644
--- a/src/Raytracer.cpp
+++ b/src/Raytracer.cpp
@@ -85,7 +85,7 @@ vec3 Raytracer::trace(PrimaryRay& ray) {
return color;
}
-vec3 Raytracer::get_lighting(Light light, Intersection intersect) {\
+vec3 Raytracer::get_lighting(Light light, Intersection intersect) {
vec3 eye_to_object = intersect.point;
vec3 object_to_light = light.is_directional ? light.pos : light.pos - intersect.point;
vec3 normal = intersect.normal;