-
Notifications
You must be signed in to change notification settings - Fork 1
/
world_gpu.h
41 lines (36 loc) · 1004 Bytes
/
world_gpu.h
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
//
// Created by Palash on 12-04-2018.
//
#ifndef PATHTRACER_CUDA_WORLD_GPU_H
#define PATHTRACER_CUDA_WORLD_GPU_H
#include "world.h"
#include "sphere_gpu.h"
#include "pathtracer_params.h"
struct World_GPU{
Sphere_GPU spheres[25];
unsigned char n = 0;
__host__ World_GPU(World *wor){
for(int i=0; i<wor->getObjectList().size(); i++){
spheres[i] = Sphere_GPU((Sphere*)wor->getObjectList()[i]);
n++;
}
}
__device__ unsigned char intersectRay(Ray_GPU &ray) {
float t = INF;
unsigned char sph = 255;
for (unsigned char i = 0; i < n; i++){
float nt = spheres[i].intersect(ray);
if(nt>0&&nt<t){
t = nt;
sph = i;
}
}
if(sph<n) {
float3 er = ray.orig + t * ray.dir;
ray.orig = er;
ray.normal = normalize(er - spheres[sph].pos);
}
return sph;
}
};
#endif //PATHTRACER_CUDA_WORLD_GPU_H