aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2013-07-12 00:03:41 -0400
committerkwolekr <kwolekr@minetest.net>2013-07-12 00:11:46 -0400
commitfc6725f14ed371fc626c023faf89e370ea8c2105 (patch)
tree13d88c650a2ac3140c2da34882bed8a91a5d2b04
parent320a00e7c65c43c2aa64d1da6e855428101c4aa6 (diff)
downloadminetest-fc6725f14ed371fc626c023faf89e370ea8c2105.tar.gz
minetest-fc6725f14ed371fc626c023faf89e370ea8c2105.tar.bz2
minetest-fc6725f14ed371fc626c023faf89e370ea8c2105.zip
Clean up bumpmap code a bit
-rw-r--r--src/mapblock_mesh.cpp59
1 files changed, 31 insertions, 28 deletions
diff --git a/src/mapblock_mesh.cpp b/src/mapblock_mesh.cpp
index 4386a1f13..1a38d1098 100644
--- a/src/mapblock_mesh.cpp
+++ b/src/mapblock_mesh.cpp
@@ -1156,38 +1156,41 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data):
material.setFlag(video::EMF_FOG_ENABLE, true);
//material.setFlag(video::EMF_ANTI_ALIASING, video::EAAM_OFF);
//material.setFlag(video::EMF_ANTI_ALIASING, video::EAAM_SIMPLE);
- material.MaterialType
- = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
+ material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
material.setTexture(0, p.tile.texture);
- if (enable_shaders)
- {
- if (enable_bumpmapping)
- {
- ITextureSource *tsrc = data->m_gamedef->tsrc();
- std::string basename,normal,replace;
- replace = "_normal.png";
- basename = tsrc->getTextureName(p.tile.texture_id);
- unsigned pos = basename.find(".");
- normal = basename.substr (0, pos) + replace;
- if (tsrc->isKnownSourceImage(normal))
- {
- // look for image extension and replace it
- for(std::string::size_type i = 0; (i = basename.find(".", i)) != std::string::npos;)
- {
- basename.replace(i, 4, replace);
- i += replace.length();
- }
- material.setTexture(1, tsrc->getTexture(basename));
- p.tile.applyMaterialOptionsWithShaders(material, bumpmaps1,bumpmaps2, shadermat3);
- }
- else
- p.tile.applyMaterialOptionsWithShaders(material, shadermat1, shadermat2, shadermat3);
+
+ if (enable_shaders) {
+ video::E_MATERIAL_TYPE smat1 = shadermat1;
+ video::E_MATERIAL_TYPE smat2 = shadermat2;
+ video::E_MATERIAL_TYPE smat3 = shadermat3;
+
+ if (enable_bumpmapping) {
+ ITextureSource *tsrc = data->m_gamedef->tsrc();
+ std::string fname_base = tsrc->getTextureName(p.tile.texture_id);
+
+ std::string normal_ext = "_normal.png";
+ size_t pos = fname_base.find(".");
+ std::string fname_normal = fname_base.substr(0, pos) + normal_ext;
+
+ if (tsrc->isKnownSourceImage(fname_normal)) {
+ // look for image extension and replace it
+ size_t i = 0;
+ while ((i = fname_base.find(".", i)) != std::string::npos) {
+ fname_base.replace(i, 4, normal_ext);
+ i += normal_ext.length();
}
- else
- p.tile.applyMaterialOptionsWithShaders(material, shadermat1, shadermat2, shadermat3);
+
+ material.setTexture(1, tsrc->getTexture(fname_base));
+
+ smat1 = bumpmaps1;
+ smat2 = bumpmaps2;
+ }
}
- else
+
+ p.tile.applyMaterialOptionsWithShaders(material, smat1, smat2, smat3);
+ } else {
p.tile.applyMaterialOptions(material);
+ }
// Create meshbuffer