mirror of
https://github.com/libretro/modelviewer-libretro.git
synced 2026-11-07 12:27:51 -10:00
Add use of ambient texture.
This commit is contained in:
1 parent
d663d5af9a
commit
f16b0973bb
4 files changed
+30
-7
No files matched your search
@@ -80,12 +80,14 @@ namespace GL
|
||||
return;
|
||||
|
||||
if (material.diffuse_map)
|
||||
material.diffuse_map->bind();
|
||||
material.diffuse_map->bind(0);
|
||||
if (material.ambient_map)
|
||||
material.ambient_map->bind(1);
|
||||
|
||||
shader->use();
|
||||
|
||||
SYM(glUniform1i)(shader->uniform("sDiffuse"), 0);
|
||||
SYM(glUniform1i)(shader->uniform("sAmbient"), 0);
|
||||
SYM(glUniform1i)(shader->uniform("sAmbient"), 1);
|
||||
|
||||
SYM(glUniformMatrix4fv)(shader->uniform("uModel"),
|
||||
1, GL_FALSE, value_ptr(model));
|
||||
@@ -151,7 +153,8 @@ namespace GL
|
||||
|
||||
SYM(glBindBuffer)(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
Texture::unbind();
|
||||
Texture::unbind(0);
|
||||
Texture::unbind(1);
|
||||
Shader::unbind();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ namespace GL
|
||||
float specular_power;
|
||||
float alpha_mod;
|
||||
std1::shared_ptr<Texture> diffuse_map;
|
||||
std1::shared_ptr<Texture> ambient_map;
|
||||
};
|
||||
|
||||
class Mesh
|
||||
|
||||
+20
-4
@@ -108,7 +108,7 @@ namespace OBJ
|
||||
}
|
||||
}
|
||||
|
||||
static map<string, Material> parse_mtllib(const string& path)
|
||||
static map<string, Material> parse_mtllib(const string& path, map<string, shared_ptr<Texture> >& textures)
|
||||
{
|
||||
map<string, Material> materials;
|
||||
|
||||
@@ -149,8 +149,23 @@ namespace OBJ
|
||||
current.alpha_mod = 1.0f - String::stof(data);
|
||||
else if (type == "map_Kd")
|
||||
{
|
||||
string diffuse_path = Path::join(Path::basedir(path), data);
|
||||
current.diffuse_map = shared_ptr<Texture>(new Texture(diffuse_path));
|
||||
if (!textures[data])
|
||||
{
|
||||
string diffuse_path = Path::join(Path::basedir(path), data);
|
||||
textures[data] = shared_ptr<Texture>(new Texture(diffuse_path));
|
||||
}
|
||||
|
||||
current.diffuse_map = textures[data];
|
||||
}
|
||||
else if (type == "map_Ka")
|
||||
{
|
||||
if (!textures[data])
|
||||
{
|
||||
string ambient_path = Path::join(Path::basedir(path), data);
|
||||
textures[data] = shared_ptr<Texture>(new Texture(ambient_path));
|
||||
}
|
||||
|
||||
current.ambient_map = textures[data];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,6 +229,7 @@ namespace OBJ
|
||||
|
||||
current_material = Material();
|
||||
current_material.diffuse_map = textures[data];
|
||||
current_material.ambient_map = textures[data];
|
||||
}
|
||||
else if (type == "usemtl")
|
||||
{
|
||||
@@ -230,7 +246,7 @@ namespace OBJ
|
||||
current_material = materials[data];
|
||||
}
|
||||
else if (type == "mtllib")
|
||||
materials = parse_mtllib(Path::join(Path::basedir(path), data));
|
||||
materials = parse_mtllib(Path::join(Path::basedir(path), data), textures);
|
||||
}
|
||||
|
||||
if (vertices.size())
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
newmtl block
|
||||
Ka 1.0 1.0 1.0
|
||||
Kd 1.0 1.0 1.0
|
||||
Ks 0.2 0.2 0.2
|
||||
Ns 60.0
|
||||
map_Kd blockDiamond.png
|
||||
map_Ka blockDiamond.png
|
||||
d 1.0
|
||||
Reference in new issue
Block a user