-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathraytrace.h
More file actions
61 lines (50 loc) · 2.22 KB
/
raytrace.h
File metadata and controls
61 lines (50 loc) · 2.22 KB
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
/*
* Copyright (c) 2007 Alexander Strange <astrange@ithinksw.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef __raytrace_h
#define __raytrace_h
#include "scene.h"
struct image
{
f_pixel *buf;
f_real *depth_buf;
f_real minv, maxv;
size_t w, h;
image(size_t w, size_t h);
~image();
void write_to_bmp(const char *path);
inline void set(size_t x, size_t y, const f_pixel p, f_real depth) {
buf[y*w + x] = p;
depth_buf[y*w + x] = depth;
}
void finish();
f_pixel autolevel(const f_pixel &p) {
return p.range_fit(minv, maxv);
}
};
struct raytracer
{
scene sc;
color background;
raytracer(primitive **pr, size_t primcount) : sc(this,pr,primcount) {}
bool light_reaches(primitive *l, primitive *pi, point3 &to, color *c, vector3 *L, media *medium, unsigned index);
color color_of_primitive_at(const ray &r, world_distance dist, primitive *pi, media *medium, unsigned index, intersectResult res, primitive **backtracking=NULL);
primitive *find_primitive_along(const ray &r, world_distance *col_dist, bool closest = true, primitive *ignore = NULL, intersectResult *restype = NULL, world_distance max_dist = HUGE_VAL, bool consider_close_miss=false);
color trace(const ray &r, world_distance *dist_reached, media *medium, primitive *ignore = NULL, intersectResult *res = NULL, unsigned index=1, primitive **backtracking=NULL);
image *render(size_t w, size_t h, const camera &cam);
};
#define FOR_EACH_LIGHT() for (size_t i = 0; i < sc.primcount; i++) {primitive *light = sc.prims[i]; if (light->light) {
#define FOR_EACH_LIGHT_END() }}
#endif