commit 01556a67343cb7658a5ca5a0093ce4493de5f253
parent 8bd58de2fa8341c8614dbfb14f52c54f6c416315
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Mon, 24 Apr 2017 14:16:33 +0200
Parse and handle matte reflectivity mtl_data
The matte reflectivity can be either defined as a real or as a spectrum.
Diffstat:
6 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/src/parser/solparser_material.c b/src/parser/solparser_material.c
@@ -175,7 +175,7 @@ parse_material_matte
res = parse_image(parser, doc, val, &mtl->normal_map);
} else if(!strcmp((char*)key->data.scalar.value, "reflectivity")) {
SETUP_MASK(REFLECTIVITY, "reflectivity");
- res = parse_real(parser, val, 0, 1, &mtl->reflectivity);
+ res = parse_mtl_data(parser, doc, val, 0, 1, &mtl->reflectivity);
} else {
log_err(parser, key, "unknown matte parameter `%s'.\n",
key->data.scalar.value);
diff --git a/src/parser/solparser_material.h b/src/parser/solparser_material.h
@@ -47,7 +47,7 @@ solparser_material_dielectric_init
}
struct solparser_material_matte {
- double reflectivity; /* In [0, 1] */
+ struct solparser_mtl_data reflectivity; /* In [0, 1] */
struct solparser_image_id normal_map;
};
diff --git a/src/parser/test_solparser2.c b/src/parser/test_solparser2.c
@@ -137,7 +137,8 @@ main(int argc, char** argv)
CHECK(mtl == mtls[0] || mtl == mtls[1], 1);
CHECK(mtl->type, SOLPARSER_MATERIAL_MATTE);
matte = solparser_get_material_matte(parser, mtl->data.matte);
- CHECK(matte->reflectivity, 1);
+ CHECK(matte->reflectivity.type, SOLPARSER_MTL_DATA_REAL);
+ CHECK(matte->reflectivity.value.real, 1);
entity_id = solparser_entity_get_child(entity, 0);
entity1a = solparser_get_entity(parser, entity_id);
diff --git a/src/parser/test_solparser3.c b/src/parser/test_solparser3.c
@@ -135,7 +135,8 @@ check_entity0
CHECK(mtl->type, SOLPARSER_MATERIAL_MATTE);
matte = solparser_get_material_matte(parser, mtl->data.matte);
- CHECK(matte->reflectivity, 0.5);
+ CHECK(matte->reflectivity.type, SOLPARSER_MTL_DATA_REAL);
+ CHECK(matte->reflectivity.value.real, 0.5);
CHECK(solparser_entity_get_children_count(entity0), 3);
CHECK(solparser_entity_get_anchors_count(entity0), 3);
diff --git a/src/parser/test_solparser_normal_map.c b/src/parser/test_solparser_normal_map.c
@@ -152,7 +152,8 @@ test_matte(struct solparser* parser)
mtl = solparser_get_material(parser, mtl2->front);
CHECK(mtl->type, SOLPARSER_MATERIAL_MATTE);
matte = solparser_get_material_matte(parser, mtl->data.matte);
- CHECK(matte->reflectivity, 0.123);
+ CHECK(matte->reflectivity.type, SOLPARSER_MTL_DATA_REAL);
+ CHECK(matte->reflectivity.value.real, 0.123);
CHECK(SOLPARSER_ID_IS_VALID(matte->normal_map), 1);
img = solparser_get_image(parser, matte->normal_map);
CHECK(strcmp(str_cget(&img->filename), "path to normal map"), 0);
diff --git a/src/solstice_material.c b/src/solstice_material.c
@@ -25,7 +25,7 @@ struct dielectric_param {
};
struct matte_param {
- double reflectivity;
+ struct ssol_data reflectivity;
struct ssol_image* normal_map;
};
@@ -109,7 +109,7 @@ matte_get_reflectivity
{
const struct matte_param* param = ssol_param_buffer_get(buf);
(void)dev, (void)wavelength, (void)frag;
- *val = param->reflectivity;
+ *val = ssol_data_get_value(¶m->reflectivity, wavelength);
}
static void
@@ -131,6 +131,7 @@ matte_param_release(void* mem)
struct matte_param* param = mem;
ASSERT(param);
if(param->normal_map) SSOL(image_ref_put(param->normal_map));
+ ssol_data_clear(¶m->reflectivity);
}
static void
@@ -417,7 +418,9 @@ create_material_matte
}
memset(param, 0, sizeof(struct matte_param));
- param->reflectivity = matte->reflectivity;
+ res = mtl_to_ssol_data(solstice, &matte->reflectivity, ¶m->reflectivity);
+ if(res != RES_OK) goto error;
+
if(!SOLPARSER_ID_IS_VALID(matte->normal_map)) {
shader.normal = mtl_get_normal;
} else {