summaryrefslogtreecommitdiff
path: root/camera.cuh
diff options
context:
space:
mode:
authorBrett Weiland <brettsweiland@gmail.com>2024-05-27 20:56:59 -0500
committerBrett Weiland <brettsweiland@gmail.com>2024-05-27 20:56:59 -0500
commit093200a449ea38952de52012e324036c106e294b (patch)
tree6030076eb894ca100d6aa0d6550ab56955e7fb2f /camera.cuh
parent7e9e2150619c05f9e8a74432e596b11f373518b9 (diff)
boutta switch away from templates
Diffstat (limited to 'camera.cuh')
-rw-r--r--camera.cuh81
1 files changed, 81 insertions, 0 deletions
diff --git a/camera.cuh b/camera.cuh
new file mode 100644
index 0000000..61944fe
--- /dev/null
+++ b/camera.cuh
@@ -0,0 +1,81 @@
+#ifndef CAMERA_H
+#define CAMERA_H
+
+#include "entity.cuh"
+#include "common.cuh"
+#include <limits>
+
+
+//template <class T> class scene;
+
+//I am soooo high lol
+template<class T>
+class camera : public entity<T> {
+ using T3 = typename vect_t3<T>::vect_t;
+ using T2 = typename vect_t2<T>::vect_t;
+ public:
+ __device__ void render();
+ __device__ camera(scene<T> *pscene, const T fov = 1, const T3 pos = vect_create<T3>(0), const T3 rot = vect_create<T3>(0))
+ : pscene(pscene), fov(fov), entity<T>(pos, rot, vect_create<T3>(0)) {};
+
+ //__device__ ~camera();
+ private:
+ T fov;
+ T2 size;
+ int steps = 100;
+ T clip_min = .1;
+ T clip_max = 100;
+ scene<T> *pscene;
+};
+
+/**
+//later we'll make scenes objects, rn im lazy (TODO)
+template <class T> __device__ void camera<T>::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 T3 uv = ((2 * vect_create<T3>(unnormalized_uv)) / vect_create<T3>(gridDim * blockDim)) - 1;
+ const T3 ray_direction = normalize(vect_create<T3>(uv.x, uv.y, 1));
+ T dist;
+ T total_dist = 0;
+ T3 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<T> **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