summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/README.md1
-rw-r--r--src/camera.cu44
-rw-r--r--src/camera.cuh20
-rw-r--r--src/common.cuh2
-rw-r--r--src/kernel.cu4
-rw-r--r--src/makefile4
-rw-r--r--src/scene.cu1
-rw-r--r--src/scene.cuh12
-rw-r--r--src/sphere.cu4
9 files changed, 70 insertions, 22 deletions
diff --git a/src/README.md b/src/README.md
new file mode 100644
index 0000000..871c4ff
--- /dev/null
+++ b/src/README.md
@@ -0,0 +1 @@
+I overcomplicated this. This project is now dead
diff --git a/src/camera.cu b/src/camera.cu
new file mode 100644
index 0000000..da527b9
--- /dev/null
+++ b/src/camera.cu
@@ -0,0 +1,44 @@
+#include <limits>
+#include "camera.cuh"
+
+__device__ void Camera::render(Scene scene, uint8_t *image) {
+ 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;
+ Ray ray;
+ ray.direction = normalize(make_vect3(uv.x, uv.y, 1));
+ Render_object **objects = scene.get_objects();
+ Render_object *closest_obj;
+ T total_dist = 0;
+ Color pcolor;
+ for(int steps = 0; steps < max_steps; steps++) {
+ T min_dist = T_MAX;
+ T dist;
+ ray.start = this->pos_ + (total_dist * ray.direction);
+ for(size_t obj_i = 0; objects[obj_i] != nullptr; obj_i++) {
+
+ dist = objects[obj_i]->distance_estimator(ray.start);
+ if(dist < min_dist) {
+ min_dist = dist;
+ if(dist < clip_min) {
+ steps = max_steps;
+ pcolor = objects[obj_i]->get_color(ray);
+ image[img_index+3] = 0xff;
+ break;
+ }
+ if(dist > clip_max) {
+ steps = max_steps;
+ image[img_index+3] = 0x00;
+ break;
+ }
+ }
+ }
+ total_dist += min_dist;
+ }
+
+
+ //TODO gamma space
+ image[img_index] = pcolor.x * 255;
+ image[img_index+1] = pcolor.y * 255;
+ image[img_index+2] = pcolor.z * 255;
+}
diff --git a/src/camera.cuh b/src/camera.cuh
index 4d04fcd..7d04d98 100644
--- a/src/camera.cuh
+++ b/src/camera.cuh
@@ -1,25 +1,26 @@
#ifndef CAMERA_H
#define CAMERA_H
-
+#include <stdint.h>
+#include <limits>
#include "entity.cuh"
#include "common.cuh"
-#include <limits>
+#include "scene.cuh"
//template <class T> class scene;
//I am soooo high lol
-class camera : public entity {
+class Camera : public Entity {
public:
- __device__ camera(scene *pscene, const T fov = 1, const vect3 pos = make_vect3(0), const vect3 rot = make_vect3(0))
- : pscene(pscene), fov(fov), entity(pos, rot, make_vect3(0)) {};
+ __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;
- int steps = 100;
- T clip_min = .1;
- T clip_max = 100;
- //scene *pscene;
};
/**
@@ -71,5 +72,4 @@ template <class T> __device__ void camera::render() {
}
**/
-
#endif
diff --git a/src/common.cuh b/src/common.cuh
index 9e026f4..2897213 100644
--- a/src/common.cuh
+++ b/src/common.cuh
@@ -2,6 +2,7 @@
#define COMMON_H
#include "include/helper_math.h"
+#include <float.h>
/**
@@ -35,6 +36,7 @@ ways, so I'm switching over to typedefs. **/
typedef float2 vect2;
typedef float3 vect3;
typedef float T;
+#define T_MAX FLT_MAX
#define make_vect3(...) (make_float3(__VA_ARGS__))
diff --git a/src/kernel.cu b/src/kernel.cu
index 40944c0..fd0ae68 100644
--- a/src/kernel.cu
+++ b/src/kernel.cu
@@ -2,9 +2,11 @@
#include <stdint.h>
#include <stdio.h>
#include "scene.cuh"
+#include "camera.cuh"
__global__ void render(uint8_t *image) {
Scene scene;
- scene.debug();
+ Camera cam(1, make_vect3(0,0,0));
+ cam.render(scene, image);
//scene.render(image);
}
diff --git a/src/makefile b/src/makefile
index 4d86411..eb8e91b 100644
--- a/src/makefile
+++ b/src/makefile
@@ -7,10 +7,10 @@ CU_SRCFILES := $(wildcard *.cu)
CU_OBJFILES := $(patsubst %.cu, %.o, $(CU_SRCFILES))
all: $(CU_OBJFILES)
- nvcc $(LIBS) -o build/indigo_worlds build/*.o
+ nvcc $(LIBS) -g -G -o build/indigo_worlds build/*.o
%.o: %.cu
- nvcc --device-debug -dc -c $< -o build/$@
+ nvcc -g -G -dc -c $< -o build/$@
run: all
build/indigo_worlds
diff --git a/src/scene.cu b/src/scene.cu
index 100af14..2214019 100644
--- a/src/scene.cu
+++ b/src/scene.cu
@@ -12,3 +12,4 @@ __device__ Color Scene::raycast(struct Ray ray) {
for(size_t obj_i = 0; obj_i < obj_count; obj_i++);
return make_color(0);
}
+
diff --git a/src/scene.cuh b/src/scene.cuh
index e3d5896..a8802ad 100644
--- a/src/scene.cuh
+++ b/src/scene.cuh
@@ -2,8 +2,8 @@
#define SCENE_H
#include "common.cuh"
-#include "sphere.cuh"
#include "render_object.cuh"
+#include "sphere.cuh"
#include "include/helper_math.h"
#include <stdint.h>
@@ -14,17 +14,15 @@
class Scene {
const int max_bounces = 10;
public:
- //__device__ void render(uint8_t *image) { cam.render(); };
- __device__ Render_object **get_objs() { return objs; }
__device__ void debug();
__device__ Color raycast(struct Ray ray);
+ __device__ Render_object **get_objects() { return objs; }
private:
- //camera cam = camera();
- Sphere sp1 = Sphere(make_vect3(0, .4, -5));
- Sphere sp2 = Sphere(make_vect3(0, -0.4,-5));
+ Sphere sp1 = Sphere(make_vect3(0, -2, 5));
+ Sphere sp2 = Sphere(make_vect3(2, 0, 5));
protected:
//idk why I need to specify the size... why can't the compiler figure that out?
- Render_object *objs[3] = {&sp1, &sp2, NULL};
+ Render_object *objs[3] = {&sp1, &sp2, nullptr};
uint8_t *image;
};
diff --git a/src/sphere.cu b/src/sphere.cu
index 849a37d..d1ae9e9 100644
--- a/src/sphere.cu
+++ b/src/sphere.cu
@@ -1,9 +1,9 @@
#include "sphere.cuh"
__device__ T Sphere::distance_estimator(vect3 point) const {
- return length(point) - r_;
+ return length(this->pos_ - point) - r_;
}
__device__ Color Sphere::get_color(struct Ray ray) const {
- return make_color(0);
+ return normalize(ray.start);
}