X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Frt.c;fp=src%2Frt.c;h=0ad8a7c9809beb63092514d7d25e39d20926678b;hb=a886acd491daf3faa62d45bf5503eb2c5313f335;hp=2c6ceaff4477a8febc5aa267ef8a6b798c83dc19;hpb=1e541ac7382e9cf96287ff2ec810d79623cc80be;p=cyberay diff --git a/src/rt.c b/src/rt.c index 2c6ceaf..0ad8a7c 100644 --- a/src/rt.c +++ b/src/rt.c @@ -1,6 +1,14 @@ #include "rt.h" struct framebuffer fb; +struct thread_pool *tpool; +float view_xform[16]; +float vfov = M_PI / 4; + +static float aspect; + +static void ray_trace(cgm_vec3 *color, cgm_ray *ray); +static void primary_ray(cgm_ray *ray, int x, int y, int sample); int fbsize(int width, int height) { @@ -14,24 +22,43 @@ int fbsize(int width, int height) fb.pixels = tmp; fb.width = width; fb.height = height; + + aspect = (float)fb.width / (float)fb.height; + return 0; } void render(void) { int i, j; + cgm_ray ray; cgm_vec3 *fbptr = fb.pixels; for(i=0; i= fb.height - 3 || j < 3 || j >= fb.width - 3) { - fbptr->x = 1.0f; - fbptr->y = fbptr->z = 0.0f; - } else { - fbptr->x = fbptr->z = 0.0f; - fbptr->y = 1.0f; - } + primary_ray(&ray, j, i, 0); + ray_trace(fbptr, &ray); fbptr++; } } } + +static void ray_trace(cgm_vec3 *color, cgm_ray *ray) +{ + color->x = ray->dir.x * 0.5f + 0.5f; + color->y = ray->dir.y * 0.5f + 0.5f; + color->z = 0.0f; +} + +static void primary_ray(cgm_ray *ray, int x, int y, int sample) +{ + ray->origin.x = ray->origin.y = ray->origin.z = 0.0f; + ray->dir.x = (2.0f * (float)x / (float)fb.width - 1.0f) * aspect; + ray->dir.y = 1.0f - 2.0f * (float)y / (float)fb.height; + ray->dir.z = -1.0f / tan(vfov / 2.0f); + cgm_vnormalize(&ray->dir); + + /* TODO jitter */ + + cgm_rmul_mr(ray, view_xform); +}