Initial support of reflection map(refl).
This commit is contained in:
25
models/refl.mtl
Normal file
25
models/refl.mtl
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
newmtl white
|
||||||
|
Ka 0 0 0
|
||||||
|
Kd 1 1 1
|
||||||
|
Ks 0 0 0
|
||||||
|
refl reflection.tga
|
||||||
|
|
||||||
|
newmtl red
|
||||||
|
Ka 0 0 0
|
||||||
|
Kd 1 0 0
|
||||||
|
Ks 0 0 0
|
||||||
|
|
||||||
|
newmtl green
|
||||||
|
Ka 0 0 0
|
||||||
|
Kd 0 1 0
|
||||||
|
Ks 0 0 0
|
||||||
|
|
||||||
|
newmtl blue
|
||||||
|
Ka 0 0 0
|
||||||
|
Kd 0 0 1
|
||||||
|
Ks 0 0 0
|
||||||
|
|
||||||
|
newmtl light
|
||||||
|
Ka 20 20 20
|
||||||
|
Kd 1 1 1
|
||||||
|
Ks 0 0 0
|
||||||
32
models/refl.obj
Normal file
32
models/refl.obj
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# Test for `refl` material parameter
|
||||||
|
mtllib refl.mtl
|
||||||
|
|
||||||
|
v 0.000000 2.000000 2.000000
|
||||||
|
v 0.000000 0.000000 2.000000
|
||||||
|
v 2.000000 0.000000 2.000000
|
||||||
|
v 2.000000 2.000000 2.000000
|
||||||
|
v 0.000000 2.000000 0.000000
|
||||||
|
v 0.000000 0.000000 0.000000
|
||||||
|
v 2.000000 0.000000 0.000000
|
||||||
|
v 2.000000 2.000000 0.000000
|
||||||
|
# 8 vertices
|
||||||
|
|
||||||
|
g front cube
|
||||||
|
usemtl white
|
||||||
|
f 1 2 3 4
|
||||||
|
g back cube
|
||||||
|
# expects white material
|
||||||
|
f 8 7 6 5
|
||||||
|
g right cube
|
||||||
|
usemtl red
|
||||||
|
f 4 3 7 8
|
||||||
|
g top cube
|
||||||
|
usemtl white
|
||||||
|
f 5 1 4 8
|
||||||
|
g left cube
|
||||||
|
usemtl green
|
||||||
|
f 5 6 2 1
|
||||||
|
g bottom cube
|
||||||
|
usemtl white
|
||||||
|
f 2 6 7 3
|
||||||
|
# 6 elements
|
||||||
@@ -145,6 +145,7 @@ static void PrintInfo(const tinyobj::attrib_t &attrib, const std::vector<tinyobj
|
|||||||
printf(" material.map_bump = %s\n", materials[i].bump_texname.c_str());
|
printf(" material.map_bump = %s\n", materials[i].bump_texname.c_str());
|
||||||
printf(" material.map_d = %s\n", materials[i].alpha_texname.c_str());
|
printf(" material.map_d = %s\n", materials[i].alpha_texname.c_str());
|
||||||
printf(" material.disp = %s\n", materials[i].displacement_texname.c_str());
|
printf(" material.disp = %s\n", materials[i].displacement_texname.c_str());
|
||||||
|
printf(" material.refl = %s\n", materials[i].reflection_texname.c_str());
|
||||||
std::map<std::string, std::string>::const_iterator it(materials[i].unknown_parameter.begin());
|
std::map<std::string, std::string>::const_iterator it(materials[i].unknown_parameter.begin());
|
||||||
std::map<std::string, std::string>::const_iterator itEnd(materials[i].unknown_parameter.end());
|
std::map<std::string, std::string>::const_iterator itEnd(materials[i].unknown_parameter.end());
|
||||||
|
|
||||||
@@ -564,6 +565,26 @@ TEST_CASE("tr_and_d", "[Issue43]") {
|
|||||||
REQUIRE(0.75 == Approx(materials[1].dissolve));
|
REQUIRE(0.75 == Approx(materials[1].dissolve));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("refl", "[refl]") {
|
||||||
|
tinyobj::attrib_t attrib;
|
||||||
|
std::vector<tinyobj::shape_t> shapes;
|
||||||
|
std::vector<tinyobj::material_t> materials;
|
||||||
|
|
||||||
|
std::string err;
|
||||||
|
bool ret = tinyobj::LoadObj(&attrib, &shapes, &materials, &err, "../models/refl.obj", gMtlBasePath);
|
||||||
|
|
||||||
|
if (!err.empty()) {
|
||||||
|
std::cerr << err << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
PrintInfo(attrib, shapes, materials);
|
||||||
|
|
||||||
|
REQUIRE(true == ret);
|
||||||
|
REQUIRE(5 == materials.size());
|
||||||
|
|
||||||
|
REQUIRE(materials[0].reflection_texname.compare("reflection.tga") == 0);
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
int
|
int
|
||||||
main(
|
main(
|
||||||
|
|||||||
@@ -156,6 +156,7 @@ typedef struct {
|
|||||||
std::string bump_texname; // map_bump, bump
|
std::string bump_texname; // map_bump, bump
|
||||||
std::string displacement_texname; // disp
|
std::string displacement_texname; // disp
|
||||||
std::string alpha_texname; // map_d
|
std::string alpha_texname; // map_d
|
||||||
|
std::string reflection_texname; // refl
|
||||||
|
|
||||||
texture_option_t ambient_texopt;
|
texture_option_t ambient_texopt;
|
||||||
texture_option_t diffuse_texopt;
|
texture_option_t diffuse_texopt;
|
||||||
@@ -164,6 +165,7 @@ typedef struct {
|
|||||||
texture_option_t bump_texopt;
|
texture_option_t bump_texopt;
|
||||||
texture_option_t displacement_texopt;
|
texture_option_t displacement_texopt;
|
||||||
texture_option_t alpha_texopt;
|
texture_option_t alpha_texopt;
|
||||||
|
texture_option_t reflection_texopt;
|
||||||
|
|
||||||
// PBR extension
|
// PBR extension
|
||||||
// http://exocortex.com/blog/extending_wavefront_mtl_to_support_pbr
|
// http://exocortex.com/blog/extending_wavefront_mtl_to_support_pbr
|
||||||
@@ -859,6 +861,7 @@ static void InitMaterial(material_t *material) {
|
|||||||
material->specular_highlight_texname = "";
|
material->specular_highlight_texname = "";
|
||||||
material->bump_texname = "";
|
material->bump_texname = "";
|
||||||
material->displacement_texname = "";
|
material->displacement_texname = "";
|
||||||
|
material->reflection_texname = "";
|
||||||
material->alpha_texname = "";
|
material->alpha_texname = "";
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
material->ambient[i] = 0.f;
|
material->ambient[i] = 0.f;
|
||||||
@@ -1265,6 +1268,15 @@ void LoadMtl(std::map<std::string, int> *material_map,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reflection map
|
||||||
|
if ((0 == strncmp(token, "refl", 4)) && IS_SPACE(token[4])) {
|
||||||
|
token += 5;
|
||||||
|
ParseTextureNameAndOption(&(material.reflection_texname),
|
||||||
|
&(material.reflection_texopt), token,
|
||||||
|
/* is_bump */ false);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// PBR: roughness texture
|
// PBR: roughness texture
|
||||||
if ((0 == strncmp(token, "map_Pr", 6)) && IS_SPACE(token[6])) {
|
if ((0 == strncmp(token, "map_Pr", 6)) && IS_SPACE(token[6])) {
|
||||||
token += 7;
|
token += 7;
|
||||||
|
|||||||
Reference in New Issue
Block a user