commit c68a66bebde297713dfb5bb61dd8afa2bbdcb139
parent 46c03416d6ee00f3ed6f8de98d62ff67b82476d6
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 7 Jun 2017 14:58:25 +0200
Bump version number of the SMC dependencies
Fix the code to handle the update of the dependencies.
Diffstat:
2 files changed, 40 insertions(+), 41 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -39,10 +39,10 @@ option(NO_TEST "Disable the test" OFF)
################################################################################
# Check dependencies
################################################################################
-find_package(RCMake 0.2.3 REQUIRED)
-find_package(RSys 0.3 REQUIRED)
-find_package(StarSP 0.3 REQUIRED)
-find_package(Star3D 0.3)
+find_package(RCMake 0.3 REQUIRED)
+find_package(RSys 0.4 REQUIRED)
+find_package(StarSP 0.4 REQUIRED)
+find_package(Star3D 0.4)
find_package(OpenMP)
if(NOT OPENMP_FOUND)
diff --git a/src/test_smc_light_path.c b/src/test_smc_light_path.c
@@ -193,14 +193,15 @@ camera_ray
* Integrator
******************************************************************************/
struct integrator_context {
- struct s3d_scene* scn;
+ struct s3d_scene_view* view;
struct camera* cam;
float pixel_size[2]; /* Normalized pixel size */
size_t ipixel[2]; /* Image space pixel coordinates */
};
static float
-direct_lighting(struct s3d_scene* scn, const float pos[3], const float N[3])
+direct_lighting
+ (struct s3d_scene_view* view, const float pos[3], const float N[3])
{
const float light_pos[3] = { 200.f, 200.f, 400.f };
const float flux = 60.0; /* Radiant flux in watt */
@@ -210,7 +211,7 @@ direct_lighting(struct s3d_scene* scn, const float pos[3], const float N[3])
float wi[3];
float range[2];
- NCHECK(scn, NULL);
+ NCHECK(view, NULL);
NCHECK(pos, NULL);
NCHECK(N, NULL);
CHECK(f3_is_normalized(N), 1);
@@ -221,7 +222,7 @@ direct_lighting(struct s3d_scene* scn, const float pos[3], const float N[3])
/* Trace shadow ray */
range[0] = EPSILON;
range[1] = len;
- CHECK(s3d_scene_trace_ray(scn, pos, wi, range, NULL, &hit), RES_OK);
+ CHECK(s3d_scene_view_trace_ray(view, pos, wi, range, NULL, &hit), RES_OK);
if(!S3D_HIT_NONE(&hit)) return 0.f; /* Light is occluded */
len *= 0.01f; /* Transform len from centimer to meter */
@@ -274,14 +275,15 @@ light_path_integrator(void* value, struct ssp_rng* rng, void* data)
FOR_EACH(idepth, 0, LIGHT_PATH_DEPTH) {
struct s3d_hit hit = S3D_HIT_NULL;
+ double Nd[3];
+ double sample[4];
float cos_theta;
- float sample[4];
float pdf;
float pos[3];
- float N[3];
+ float N[3] = {0, 0, 0};
- CHECK(s3d_scene_trace_ray
- (ctx->scn, ray_org, ray_dir, ray_range, NULL, &hit), RES_OK);
+ CHECK(s3d_scene_view_trace_ray
+ (ctx->view, ray_org, ray_dir, ray_range, NULL, &hit), RES_OK);
if(S3D_HIT_NONE(&hit)) { /* Skydome lighting */
L += throughput * skydome_lighting(ray_dir);
@@ -294,14 +296,15 @@ light_path_integrator(void* value, struct ssp_rng* rng, void* data)
f3_add(pos, f3_mulf(pos, ray_dir, hit.distance), ray_org);
/* Direct lighting */
- L += throughput * direct_lighting(ctx->scn, pos, N);
+ L += throughput * direct_lighting(ctx->view, pos, N);
/* New ray */
- ssp_ran_hemisphere_cos(rng, N, sample);
- pdf = sample[3];
- cos_theta = f3_dot(N, sample);
+ d3_normalize(Nd, d3_set_f3(Nd, N));
+ ssp_ran_hemisphere_cos(rng, Nd, sample);
+ pdf = (float)sample[3];
+ cos_theta = (float)d3_dot(Nd, sample);
f3_set(ray_org, pos);
- f3_set(ray_dir, sample);
+ f3_normalize(ray_dir, f3_set_d3(ray_dir, sample));
ray_range[0] = EPSILON;
throughput *= (float)(ALBEDO / PI) / pdf * cos_theta;
}
@@ -316,28 +319,28 @@ int
main(int argc, char** argv)
{
struct mem_allocator allocator;
+ struct image img;
struct integrator_context* contexts;
struct s3d_device* dev;
struct s3d_scene* scn;
+ struct s3d_scene_view* view;
struct s3d_shape* shape;
struct s3d_vertex_data attrib;
struct smc_device* smc;
struct smc_integrator integrator = SMC_INTEGRATOR_NULL;
struct smc_estimator** estimators;
struct camera cam;
- unsigned char* img = NULL;
size_t ix, iy;
float pos[3];
(void)argc, (void)argv;
mem_init_proxy_allocator(&allocator, &mem_default_allocator);
- if(argc > 1) {
- img = MEM_ALLOC(&allocator, 3 * IMG_WIDTH * IMG_HEIGHT);
- NCHECK(img, NULL);
- }
+ CHECK(image_init(&allocator, &img), RES_OK);
+ CHECK(image_setup
+ (&img, IMG_WIDTH, IMG_HEIGHT, 3*IMG_WIDTH, IMAGE_RGB8, NULL), RES_OK);
- CHECK(s3d_device_create(NULL, &allocator, 1, &dev), RES_OK);
+ CHECK(s3d_device_create(NULL, &allocator, 0, &dev), RES_OK);
CHECK(s3d_scene_create(dev, &scn), RES_OK);
attrib.usage = S3D_POSITION;
@@ -370,7 +373,7 @@ main(int argc, char** argv)
CHECK(s3d_scene_attach_shape(scn, shape), RES_OK);
CHECK(s3d_shape_ref_put(shape), RES_OK);
- CHECK(s3d_scene_begin_session(scn, S3D_TRACE), RES_OK);
+ CHECK(s3d_scene_view_create(scn, S3D_TRACE, &view), RES_OK);
CHECK(smc_device_create(NULL, &allocator, SMC_NTHREADS_DEFAULT, NULL, &smc),
RES_OK);
@@ -391,7 +394,7 @@ main(int argc, char** argv)
FOR_EACH(iy, 0, IMG_HEIGHT) {
FOR_EACH(ix, 0, IMG_WIDTH) {
const size_t ictx = iy * IMG_WIDTH + ix;
- contexts[ictx].scn = scn;
+ contexts[ictx].view = view;
contexts[ictx].cam = &cam;
contexts[ictx].pixel_size[0] = 1.f / (float)IMG_WIDTH;
contexts[ictx].pixel_size[1] = 1.f / (float)IMG_HEIGHT;
@@ -405,29 +408,25 @@ main(int argc, char** argv)
FOR_EACH(iy, 0, IMG_HEIGHT) {
FOR_EACH(ix, 0, IMG_WIDTH) {
const size_t iestimator = (iy*IMG_WIDTH + ix);
- if(img) { /* Write image pixel */
- struct smc_estimator_status status;
- const size_t ipix = iestimator * 3/*RGB*/;
- float col;
- unsigned char colu;
-
- CHECK(smc_estimator_get_status(estimators[iestimator], &status), RES_OK);
- col = (float)pow(SMC_FLOAT(status.E), 1.0/GAMMA); /* Gamma correction */
- colu = (unsigned char)(CLAMP(col, 0.f, 1.f) * 255.f); /* Float to U8 */
- img[ipix + 0] = img[ipix + 1] = img[ipix + 2] = colu;
- }
+ uint8_t* pix = (uint8_t*)(img.pixels + iy*img.pitch + ix*3/*RGB*/);
+ struct smc_estimator_status status;
+ float col;
+ unsigned char colu;
+
+ CHECK(smc_estimator_get_status(estimators[iestimator], &status), RES_OK);
+ col = (float)pow(SMC_FLOAT(status.E), 1.0/GAMMA); /* Gamma correction */
+ colu = (uint8_t)(CLAMP(col, 0.f, 1.f) * 255.f); /* Float to U8 */
+ pix[0] = pix[1] = pix[2] = colu;
CHECK(smc_estimator_ref_put(estimators[iestimator]), RES_OK);
}}
+ image_write_ppm_stream(&img, 0, stdout);
+ CHECK(image_release(&img), RES_OK);
MEM_RM(&allocator, contexts);
MEM_RM(&allocator, estimators);
- if(argc > 1) {
- CHECK(image_ppm_write(argv[1], IMG_WIDTH, IMG_HEIGHT, 3, img), RES_OK);
- MEM_RM(&allocator, img);
- }
- CHECK(s3d_scene_end_session(scn), RES_OK);
+ CHECK(s3d_scene_view_ref_put(view), RES_OK);
CHECK(s3d_device_ref_put(dev), RES_OK);
CHECK(s3d_scene_ref_put(scn), RES_OK);