solstice-solver

Solver library of the solstice app
git clone git://git.meso-star.com/solstice-solver.git
Log | Files | Refs | README | LICENSE

commit 939426a3fb2c390daadce7bd1fa5c04253053c11
parent fc664155a91f99f0edeab607bdda811e830ad556
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu, 13 Oct 2016 10:13:33 +0200

Discard the virtual materials for primary rays

Diffstat:
Msrc/ssol_c.h | 14++++++++++----
Msrc/ssol_scene.c | 9++++++---
Msrc/ssol_solver.c | 5++++-
3 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/src/ssol_c.h b/src/ssol_c.h @@ -19,6 +19,7 @@ #include "ssol.h" #include "ssol_instance_c.h" +#include <rsys/math.h> #include <star/s3d.h> #include <math.h> @@ -38,16 +39,21 @@ #endif struct ray_data { - struct ssol_scene* scn; - struct s3d_primitive prim_from; - struct ssol_instance* inst_from; - enum ssol_side_flag side_from; + struct ssol_scene* scn; /* The scene into which the ray is traced */ + struct s3d_primitive prim_from; /* Primitive from which the ray starts */ + struct ssol_instance* inst_from; /* Instance from which the ray starts */ + enum ssol_side_flag side_from; /* Primitive side from which the ray starts */ + int discard_virtual_materials; /* Define if virtual materials are not RT */ /* Output data */ double N[3]; double dst; }; +static const struct ray_data RAY_DATA_NULL = { + NULL, S3D_PRIMITIVE_NULL__, NULL, 0, 0, {NaN, NaN, NaN}, NaN +}; + static FINLINE enum s3d_attrib_usage ssol_to_s3d_attrib_usage(const enum ssol_attrib_usage usage) diff --git a/src/ssol_scene.c b/src/ssol_scene.c @@ -418,10 +418,13 @@ hit_filter_function default: FATAL("Unreachable code.\n"); break; } - /* Discard virtual material that are not receivers */ mtl = hit_side == SSOL_FRONT ? sshape->mtl_front : sshape->mtl_back; - if(!(inst->receiver_mask & (int)hit_side) && mtl->type == MATERIAL_VIRTUAL) - return 1; + if(mtl->type == MATERIAL_VIRTUAL) { + /* Discard all virtual materials */ + if(rdata->discard_virtual_materials) return 1; + /* Discard virtual material that are not receivers */ + if((inst->receiver_mask&(int)hit_side) == 0) return 1; + } /* Save the nearest intersected quadric point */ if(sshape->shape->type == SHAPE_PUNCHED && rdata->dst >= dst) { diff --git a/src/ssol_solver.c b/src/ssol_solver.c @@ -896,7 +896,7 @@ ssol_solve struct surface_fragment frag; struct ssol_instance* inst; const struct shaded_shape* sshape; - struct ray_data ray_data; + struct ray_data ray_data = RAY_DATA_NULL; double pos[3], dir[3], N[3], tmp[3], weight, cos_dir_N, wl; float posf[3], dirf[3], uv[2]; float range[2] = { 0, FLT_MAX }; @@ -942,6 +942,7 @@ ssol_solve ray_data.prim_from = prim; ray_data.inst_from = inst; ray_data.side_from = cos_dir_N < 0 ? SSOL_FRONT : SSOL_BACK; + ray_data.discard_virtual_materials = 1; /* Trace a ray toward the sun to check if the sampled point is occluded */ f3_minus(dirf, f3_set_d3(dirf, dir)); @@ -952,6 +953,8 @@ ssol_solve estimator->shadow.sqr_weight += weight*weight; continue; } + /* Virtual materials are discarded for primary rays only */ + ray_data.discard_virtual_materials = 0; /* Sample a wavelength */ wl = ranst_sun_wl_get(ran_sun_wl, rng);