-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.cuh
79 lines (66 loc) · 1.77 KB
/
common.cuh
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
#ifndef COMMON_CUH
#define COMMON_CUH
#include <iostream>
#include <curand_kernel.h>
#include "vec3double.cuh"
#define IMAGE_WIDTH 3840
#define IMAGE_HEIGHT 2160
// #define IMAGE_WIDTH 1080
// #define IMAGE_HEIGHT 720
#define SAMPLES_PER_PIXEL 50
#define RAY_T_MIN 0.0001
#define RAY_T_MAX 1.0e30
// for cuda
#define BLOCK_SIZE 32
template <class T>
__device__ inline T square(T x) {
return x * x;
}
struct ray
{
vec3double origin;
vec3double direction;
__device__ ray();
__device__ ray(const ray &ray);
__device__ ~ray();
__device__ ray(vec3double origin, vec3double direction);
};
class camera
{
private:
vec3double origin, horizontal, vertical, lower_left_corner;
vec3double u, v, w;
double lens_radius;
public:
// __device__ camera(double viewport_height, double focal_length);
__device__ camera(vec3double lookfrom, vec3double lookat, vec3double vup, double vfov, double aspect_ratio, double aperture, double focus_dist);
// __device__ ray get_ray(double u, double v);
__device__ ray get_ray(double u, double v, curandState &rand_state);
};
enum
{
MATERIAL_LAMBERTIAN,
MATERIAL_METAL,
MATERIAL_DIELECTRIC,
};
class sphere
{
public:
vec3double color;
int type;
union {
double fuzz;
double ir; // Index of Refraction
};
private:
vec3double center;
double radius;
public:
sphere(const vec3double ¢er, double radius, const vec3double &color);
sphere& as_metal(double fuzz);
sphere& as_dielectric(double ir);
__device__ bool hit(ray &in_ray, ray &out_ray, bool &into, double &t_max);
};
void write_pixels(std::ostream &out, vec3double *pixels);
__global__ void render(vec3double *pixels, camera** camera, sphere* spheres, int sphere_size, int* tasks_done);
#endif