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
|
#ifndef CAMERA_H
#define CAMERA_H
#include <stdint.h>
#include <limits>
#include "entity.cuh"
#include "common.cuh"
#include "scene.cuh"
//template <class T> class scene;
//I am soooo high lol
class Camera : public Entity {
public:
__device__ Camera(const T fov = 1, const vect3 pos = make_vect3(0), const vect3 rot = make_vect3(0))
: fov(fov), Entity(pos, rot, make_vect3(0)) {};
__device__ void render(Scene scene, uint8_t *image);
private:
const T clip_min = .1;
const T clip_max = 100;
const int max_steps = 100;
T fov;
float2 size;
};
/**
//later we'll make scenes objects, rn im lazy (TODO)
template <class T> __device__ void camera::render() {
//TODO *really* need to clean this up once you get further
//extra dimentions is extra math
//either generisize float3 or stop using this fucking template nonsense
const uint3 unnormalized_uv = ((blockDim * blockIdx) + threadIdx);
const unsigned int img_index = (unnormalized_uv.x + (unnormalized_uv.y * blockDim.x * gridDim.x)) * 4;
const vect3 uv = ((2 * make_vect3(unnormalized_uv)) / make_vect3(gridDim * blockDim)) - 1;
const vect3 ray_direction = normalize(make_vect3(uv.x, uv.y, 1));
T dist;
T total_dist = 0;
vect3 ray;
int i;
//if(img_index == 640) { printf("%f, %f, %f\n", uv.x, uv.y, uv.z); }
T min_dist = clip_max;
render_object **objs = pscene->get_objs();
for(i = 0; i < steps; i++) {
ray = this->pos_ + (total_dist * ray_direction);
//gyagh memory lookups
for(unsigned int oi = 0; objs[oi] != NULL; oi++) {
dist = object.distance_estimator(ray);
}
if((dist < clip_min)) {
//image[img_index] = 0xff;
break;
}
if((dist > clip_max)) {
//image[img_index+2] = 0xff;
break;
}
total_dist += dist;
}
//image[img_index] = 0x00;
//image[img_index+1] = 0x00;
//image[img_index+2] = p;
//image[img_index+3] = 0xff;
}
**/
#endif
|