project is dead
This commit is contained in:
parent
b0dd97ee6b
commit
c05aa71f40
1
src/README.md
Normal file
1
src/README.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
I overcomplicated this. This project is now dead
|
44
src/camera.cu
Normal file
44
src/camera.cu
Normal file
@ -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;
|
||||||
|
}
|
@ -1,25 +1,26 @@
|
|||||||
#ifndef CAMERA_H
|
#ifndef CAMERA_H
|
||||||
#define CAMERA_H
|
#define CAMERA_H
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <limits>
|
||||||
#include "entity.cuh"
|
#include "entity.cuh"
|
||||||
#include "common.cuh"
|
#include "common.cuh"
|
||||||
#include <limits>
|
#include "scene.cuh"
|
||||||
|
|
||||||
|
|
||||||
//template <class T> class scene;
|
//template <class T> class scene;
|
||||||
|
|
||||||
//I am soooo high lol
|
//I am soooo high lol
|
||||||
class camera : public entity {
|
class Camera : public Entity {
|
||||||
public:
|
public:
|
||||||
__device__ camera(scene *pscene, const T fov = 1, const vect3 pos = make_vect3(0), const vect3 rot = make_vect3(0))
|
__device__ Camera(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)) {};
|
: fov(fov), Entity(pos, rot, make_vect3(0)) {};
|
||||||
|
__device__ void render(Scene scene, uint8_t *image);
|
||||||
private:
|
private:
|
||||||
|
const T clip_min = .1;
|
||||||
|
const T clip_max = 100;
|
||||||
|
const int max_steps = 100;
|
||||||
T fov;
|
T fov;
|
||||||
float2 size;
|
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
|
#endif
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define COMMON_H
|
#define COMMON_H
|
||||||
|
|
||||||
#include "include/helper_math.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 float2 vect2;
|
||||||
typedef float3 vect3;
|
typedef float3 vect3;
|
||||||
typedef float T;
|
typedef float T;
|
||||||
|
#define T_MAX FLT_MAX
|
||||||
|
|
||||||
#define make_vect3(...) (make_float3(__VA_ARGS__))
|
#define make_vect3(...) (make_float3(__VA_ARGS__))
|
||||||
|
|
||||||
|
@ -2,9 +2,11 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "scene.cuh"
|
#include "scene.cuh"
|
||||||
|
#include "camera.cuh"
|
||||||
|
|
||||||
__global__ void render(uint8_t *image) {
|
__global__ void render(uint8_t *image) {
|
||||||
Scene scene;
|
Scene scene;
|
||||||
scene.debug();
|
Camera cam(1, make_vect3(0,0,0));
|
||||||
|
cam.render(scene, image);
|
||||||
//scene.render(image);
|
//scene.render(image);
|
||||||
}
|
}
|
||||||
|
@ -7,10 +7,10 @@ CU_SRCFILES := $(wildcard *.cu)
|
|||||||
CU_OBJFILES := $(patsubst %.cu, %.o, $(CU_SRCFILES))
|
CU_OBJFILES := $(patsubst %.cu, %.o, $(CU_SRCFILES))
|
||||||
|
|
||||||
all: $(CU_OBJFILES)
|
all: $(CU_OBJFILES)
|
||||||
nvcc $(LIBS) -o build/indigo_worlds build/*.o
|
nvcc $(LIBS) -g -G -o build/indigo_worlds build/*.o
|
||||||
|
|
||||||
%.o: %.cu
|
%.o: %.cu
|
||||||
nvcc --device-debug -dc -c $< -o build/$@
|
nvcc -g -G -dc -c $< -o build/$@
|
||||||
|
|
||||||
run: all
|
run: all
|
||||||
build/indigo_worlds
|
build/indigo_worlds
|
||||||
|
@ -12,3 +12,4 @@ __device__ Color Scene::raycast(struct Ray ray) {
|
|||||||
for(size_t obj_i = 0; obj_i < obj_count; obj_i++);
|
for(size_t obj_i = 0; obj_i < obj_count; obj_i++);
|
||||||
return make_color(0);
|
return make_color(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
#define SCENE_H
|
#define SCENE_H
|
||||||
|
|
||||||
#include "common.cuh"
|
#include "common.cuh"
|
||||||
#include "sphere.cuh"
|
|
||||||
#include "render_object.cuh"
|
#include "render_object.cuh"
|
||||||
|
#include "sphere.cuh"
|
||||||
#include "include/helper_math.h"
|
#include "include/helper_math.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
@ -14,17 +14,15 @@
|
|||||||
class Scene {
|
class Scene {
|
||||||
const int max_bounces = 10;
|
const int max_bounces = 10;
|
||||||
public:
|
public:
|
||||||
//__device__ void render(uint8_t *image) { cam.render(); };
|
|
||||||
__device__ Render_object **get_objs() { return objs; }
|
|
||||||
__device__ void debug();
|
__device__ void debug();
|
||||||
__device__ Color raycast(struct Ray ray);
|
__device__ Color raycast(struct Ray ray);
|
||||||
|
__device__ Render_object **get_objects() { return objs; }
|
||||||
private:
|
private:
|
||||||
//camera cam = camera();
|
Sphere sp1 = Sphere(make_vect3(0, -2, 5));
|
||||||
Sphere sp1 = Sphere(make_vect3(0, .4, -5));
|
Sphere sp2 = Sphere(make_vect3(2, 0, 5));
|
||||||
Sphere sp2 = Sphere(make_vect3(0, -0.4,-5));
|
|
||||||
protected:
|
protected:
|
||||||
//idk why I need to specify the size... why can't the compiler figure that out?
|
//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;
|
uint8_t *image;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
#include "sphere.cuh"
|
#include "sphere.cuh"
|
||||||
|
|
||||||
__device__ T Sphere::distance_estimator(vect3 point) const {
|
__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 {
|
__device__ Color Sphere::get_color(struct Ray ray) const {
|
||||||
return make_color(0);
|
return normalize(ray.start);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user