commit 2226e05667eb32b0b117bc15216ea7952dcc0a25
parent 57e3ab910e896fc3892039e4b1c804ac34b1071a
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 2 Mar 2017 14:23:19 +0100
Handle the loaded thin_dielectric material
Diffstat:
1 file changed, 121 insertions(+), 0 deletions(-)
diff --git a/src/solstice_material.c b/src/solstice_material.c
@@ -27,6 +27,12 @@ struct matte_param {
double reflectivity;
};
+struct thin_dielectric_param {
+ double absorption;
+ double thickness;
+ double refractive_index;
+};
+
/*******************************************************************************
* Helper functions
******************************************************************************/
@@ -99,6 +105,58 @@ mirror_get_roughness
*val = param->roughness;
}
+static void
+thin_dielectric_get_absorption
+ (struct ssol_device* dev,
+ struct ssol_param_buffer* buf,
+ const double wavelength,
+ const double P[3],
+ const double Ng[3],
+ const double Ns[3],
+ const double uv[2],
+ const double w[3],
+ double* val)
+{
+ const struct thin_dielectric_param* param = ssol_param_buffer_get(buf);
+ (void)dev, (void)wavelength, (void)P, (void)Ng, (void)Ns, (void)uv, (void)w;
+ *val = param->absorption;
+}
+
+static void
+thin_dielectric_get_thickness
+ (struct ssol_device* dev,
+ struct ssol_param_buffer* buf,
+ const double wavelength,
+ const double P[3],
+ const double Ng[3],
+ const double Ns[3],
+ const double uv[2],
+ const double w[3],
+ double* val)
+{
+ const struct thin_dielectric_param* param = ssol_param_buffer_get(buf);
+ (void)dev, (void)wavelength, (void)P, (void)Ng, (void)Ns, (void)uv, (void)w;
+ *val = param->thickness;
+}
+
+static void
+thin_dielectric_get_refractive_index
+ (struct ssol_device* dev,
+ struct ssol_param_buffer* buf,
+ const double wavelength,
+ const double P[3],
+ const double Ng[3],
+ const double Ns[3],
+ const double uv[2],
+ const double w[3],
+ double* val)
+{
+ const struct thin_dielectric_param* param = ssol_param_buffer_get(buf);
+ (void)dev, (void)wavelength, (void)P, (void)Ng, (void)Ns, (void)uv, (void)w;
+ *val = param->refractive_index;
+}
+
+
static res_T
create_material_matte
(struct solstice* solstice,
@@ -199,6 +257,62 @@ error:
goto exit;
}
+static res_T
+create_material_thin_dielectric
+ (struct solstice* solstice,
+ const struct solparser_material_thin_dielectric* thin,
+ struct ssol_material** out_mtl)
+{
+ struct ssol_thin_dielectric_shader shader = SSOL_THIN_DIELECTRIC_SHADER_NULL;
+ struct ssol_material* mtl = NULL;
+ struct ssol_param_buffer* pbuf = NULL;
+ struct thin_dielectric_param* param;
+ res_T res = RES_OK;
+ ASSERT(solstice && thin && out_mtl);
+
+ res = ssol_material_create_thin_dielectric(solstice->ssol, &mtl);
+ if(res != RES_OK) {
+ fprintf(stderr,
+ "Could not allocate the Solstice Solver thin dielectric material.\n");
+ goto error;
+ }
+
+ res = ssol_param_buffer_create
+ (solstice->ssol, sizeof(struct thin_dielectric_param), &pbuf);
+ if(res != RES_OK) {
+ fprintf(stderr, "Could not create the Solstice Solver parameter buffer.\n");
+ goto error;
+ }
+
+ param = ssol_param_buffer_allocate(pbuf,
+ sizeof(struct thin_dielectric_param), ALIGNOF(struct thin_dielectric_param));
+ if(!param) {
+ fprintf(stderr, "Could not allocate the thin dielectric parameters.\n");
+ res = RES_MEM_ERR;
+ goto error;
+ }
+
+ param->thickness = thin->thickness;
+ param->absorption = thin->absorption;
+ param->refractive_index = thin->refractive_index;
+
+ shader.normal = mtl_get_normal;
+ shader.absorption = thin_dielectric_get_absorption;
+ shader.thickness = thin_dielectric_get_thickness;
+ shader.refractive_index = thin_dielectric_get_refractive_index;
+ SSOL(thin_dielectric_set_shader(mtl, &shader));
+ SSOL(material_set_param_buffer(mtl, pbuf));
+
+exit:
+ if(pbuf) SSOL(param_buffer_ref_put(pbuf));
+ *out_mtl = mtl;
+ return res;
+error:
+ if(mtl) SSOL(material_ref_put(mtl)), mtl = NULL;
+ goto exit;
+}
+
+
/*******************************************************************************
* Local functions
******************************************************************************/
@@ -227,6 +341,7 @@ solstice_create_ssol_material
} else {
const struct solparser_material_matte* matte;
const struct solparser_material_mirror* mirror;
+ const struct solparser_material_thin_dielectric* thin_dielectric;
switch(mtl->type) {
case SOLPARSER_MATERIAL_MIRROR:
@@ -237,6 +352,12 @@ solstice_create_ssol_material
matte = solparser_get_material_matte(solstice->parser, mtl->data.matte);
res = create_material_matte(solstice, matte, &ssol_mtl);
break;
+ case SOLPARSER_MATERIAL_THIN_DIELECTRIC:
+ thin_dielectric = solparser_get_material_thin_dielectric
+ (solstice->parser, mtl->data.thin_dielectric);
+ res = create_material_thin_dielectric
+ (solstice, thin_dielectric, &ssol_mtl);
+ break;
default: FATAL("Unreachable code.\n"); break;
}
if(res != RES_OK) goto error;