commit c1303e068cd1319a86ed863c921b15aa3f9eda6b
parent f3e567e4c0d6b8dff9b60a58ca047d524d59a6ef
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 27 Apr 2017 15:36:38 +0200
Update the ssol_draw_pt API
Add a up vector to the ssol_draw_pt function defining where is the
skydome.
Diffstat:
3 files changed, 32 insertions(+), 6 deletions(-)
diff --git a/src/ssol.h b/src/ssol.h
@@ -1194,6 +1194,7 @@ ssol_draw_pt
const size_t width, /* #pixels in X */
const size_t height, /* #pixels in Y */
const size_t spp,
+ const double up[3], /* Direction toward the top of the skydome */
ssol_write_pixels_T writer,
void* writer_data);
diff --git a/src/ssol_draw_pt.c b/src/ssol_draw_pt.c
@@ -39,6 +39,7 @@ struct thread_context {
struct ssp_rng* rng;
struct ssf_bsdf* bsdf;
struct ranst_sun_wl* ran_wl;
+ float up[3];
};
static void
@@ -71,14 +72,16 @@ static void
thread_context_setup
(struct thread_context* ctx,
struct ssp_rng* rng,
- struct ranst_sun_wl* ran_wl)
+ struct ranst_sun_wl* ran_wl,
+ const double up[3])
{
- ASSERT(ctx && rng && ran_wl);
+ ASSERT(ctx && rng && ran_wl && up);
if(ctx->rng) SSP(rng_ref_put(ctx->rng));
SSP(rng_ref_get(rng));
ranst_sun_wl_ref_get(ran_wl);
ctx->rng = rng;
ctx->ran_wl = ran_wl;
+ f3_set_d3(ctx->up, up);
}
/* Declare the container of the per thread contexts */
@@ -179,7 +182,7 @@ Li(struct ssol_scene* scn,
}
if(S3D_HIT_NONE(&hit)) { /* Background lighting */
- if(ray_dir[2] > 0) L += throughput * 1.e-1;
+ if(f3_dot(ray_dir, ctx->up) > 0) L += throughput * 1.e-1;
break;
}
@@ -345,6 +348,7 @@ ssol_draw_pt
const size_t width,
const size_t height,
const size_t spp,
+ const double up[3],
ssol_write_pixels_T writer,
void* data)
{
@@ -354,7 +358,7 @@ ssol_draw_pt
size_t i;
res_T res = RES_OK;
- if(!scn) return RES_BAD_ARG;
+ if(!scn || !up) return RES_BAD_ARG;
darray_thread_context_init(scn->dev->allocator, &thread_ctxs);
@@ -381,7 +385,7 @@ ssol_draw_pt
res = ssp_rng_proxy_create_rng(rng_proxy, i, &rng);
if(res != RES_OK) goto error;
- thread_context_setup(ctx, rng, ran_sun_wl);
+ thread_context_setup(ctx, rng, ran_sun_wl, up);
SSP(rng_ref_put(rng));
}
diff --git a/src/test_ssol_draw.c b/src/test_ssol_draw.c
@@ -186,6 +186,22 @@ setup_cornell_box(struct ssol_device* dev, struct ssol_scene* scn)
CHECK(f3_eq_eps(upper, f3(tmp, 552.f, 559.f, 548.f), 1.e-6f), 1);
}
+
+/* Wrap the ssol_draw_pt function to match the ssol_draw_draft profile */
+static INLINE res_T
+draw_pt
+ (struct ssol_scene* scn,
+ struct ssol_camera* cam,
+ const size_t width,
+ const size_t height,
+ const size_t spp,
+ ssol_write_pixels_T writer,
+ void* data)
+{
+ const double up[3] = {0, 0, 1};
+ return ssol_draw_pt(scn, cam, width, height, spp, up, writer, data);
+}
+
int
main(int argc, char** argv)
{
@@ -220,7 +236,7 @@ main(int argc, char** argv)
if(!strcmp(argv[1], "draft")) {
draw_func = ssol_draw_draft;
} else if(!strcmp(argv[1], "pt")) {
- draw_func = ssol_draw_pt;
+ draw_func = draw_pt;
} else {
fprintf(stderr, "Usage: %s <draft|pt>\n", argv[0]);
return -1;
@@ -326,6 +342,11 @@ main(int argc, char** argv)
CHECK(image_write_ppm_stream(&img, 0, stdout), RES_OK);
+ if(draw_func == draw_pt) {
+ CHECK(ssol_draw_pt
+ (scn, cam, WIDTH, HEIGHT, 4, NULL, write_RGB8, pixels), RES_BAD_ARG);
+ }
+
CHECK(image_release(&img), RES_OK);
CHECK(ssol_device_ref_put(dev), RES_OK);
CHECK(ssol_camera_ref_put(cam), RES_OK);