83 lines
1.8 KiB
Plaintext
83 lines
1.8 KiB
Plaintext
#pragma once
|
|
|
|
|
|
|
|
typedef struct ViewportF32 ViewportF32;
|
|
struct ViewportF32
|
|
{
|
|
F32 width;
|
|
F32 height;
|
|
F32 aspect_ratio;
|
|
Vec3F32 u; // along horizontal edge, right from top left corner
|
|
Vec3F32 v; // along vertical edge, down from top left corner
|
|
Vec3F32 upper_left;
|
|
Vec3F32 pixel_origin;
|
|
Vec3F32 pixel_delta_u;
|
|
Vec3F32 pixel_delta_v;
|
|
};
|
|
|
|
typedef struct CameraF32 CameraF32;
|
|
struct CameraF32
|
|
{
|
|
Vec3F32 center;
|
|
Vec3F32 up;
|
|
F32 focal_length;
|
|
F32 pixel_sample_scale;
|
|
};
|
|
|
|
typedef struct ImageF32 ImageF32;
|
|
struct ImageF32
|
|
{
|
|
U32 width;
|
|
U32 height;
|
|
F32 aspect_ratio;
|
|
U32 total_num_pixels;
|
|
};
|
|
|
|
enum EntityKind
|
|
{
|
|
EntityKind_Nil,
|
|
EntityKind_Sphere,
|
|
EntityKind_Tri,
|
|
Num_EntityKinds
|
|
};
|
|
|
|
typedef struct HitRecord HitRecord;
|
|
struct HitRecord
|
|
{
|
|
Vec3F32 point;
|
|
Vec3F32 normal;
|
|
F32 t; // Root parameter for hit sphere
|
|
F32 hit; // Hit true or false
|
|
F32 front_face;
|
|
};
|
|
|
|
typedef struct Entity Entity;
|
|
struct Entity
|
|
{
|
|
EntityKind kind;
|
|
Vec3F32 center;
|
|
Vec3F32 vertex0;
|
|
Vec3F32 vertex1;
|
|
Vec3F32 vertex2;
|
|
F32 radius;
|
|
};
|
|
|
|
|
|
|
|
__host__ function void write_buffer_to_ppm(Vec3F32 *buffer, U32 image_width,
|
|
U32 image_height, const char *filename);
|
|
|
|
__device__ function RayF32 ray_get_F32(F32 x, F32 y, Vec3F32 cam_center,
|
|
curandState *local_rand_state);
|
|
|
|
__host__ __device__ inline function void
|
|
triangle_intersection_common(RayF32 *ray, HitRecord *rec, Vec3F32 edge1, Vec3F32 edge2,
|
|
Entity* triangle);
|
|
__device__ function HitRecord hit_triangle(RayF32 *ray, Entity *triangle,
|
|
F32 closest_so_far);
|
|
__host__ function void hit_triangle_host(RayF32 *ray, HitRecord *rec, Entity *triangle);
|
|
|
|
__global__ void cuda_init_state(curandState *rand_state);
|
|
__host__ void cuda_free(void *device_ptr);
|