Clean up bumpmap code a bit

master
kwolekr 2013-07-12 00:03:41 -04:00
parent 320a00e7c6
commit fc6725f14e
1 changed files with 31 additions and 28 deletions

View File

@ -1156,38 +1156,41 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data):
material.setFlag(video::EMF_FOG_ENABLE, true); material.setFlag(video::EMF_FOG_ENABLE, true);
//material.setFlag(video::EMF_ANTI_ALIASING, video::EAAM_OFF); //material.setFlag(video::EMF_ANTI_ALIASING, video::EAAM_OFF);
//material.setFlag(video::EMF_ANTI_ALIASING, video::EAAM_SIMPLE); //material.setFlag(video::EMF_ANTI_ALIASING, video::EAAM_SIMPLE);
material.MaterialType material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
= video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
material.setTexture(0, p.tile.texture); material.setTexture(0, p.tile.texture);
if (enable_shaders)
{ if (enable_shaders) {
if (enable_bumpmapping) video::E_MATERIAL_TYPE smat1 = shadermat1;
{ video::E_MATERIAL_TYPE smat2 = shadermat2;
ITextureSource *tsrc = data->m_gamedef->tsrc(); video::E_MATERIAL_TYPE smat3 = shadermat3;
std::string basename,normal,replace;
replace = "_normal.png"; if (enable_bumpmapping) {
basename = tsrc->getTextureName(p.tile.texture_id); ITextureSource *tsrc = data->m_gamedef->tsrc();
unsigned pos = basename.find("."); std::string fname_base = tsrc->getTextureName(p.tile.texture_id);
normal = basename.substr (0, pos) + replace;
if (tsrc->isKnownSourceImage(normal)) std::string normal_ext = "_normal.png";
{ size_t pos = fname_base.find(".");
// look for image extension and replace it std::string fname_normal = fname_base.substr(0, pos) + normal_ext;
for(std::string::size_type i = 0; (i = basename.find(".", i)) != std::string::npos;)
{ if (tsrc->isKnownSourceImage(fname_normal)) {
basename.replace(i, 4, replace); // look for image extension and replace it
i += replace.length(); size_t i = 0;
} while ((i = fname_base.find(".", i)) != std::string::npos) {
material.setTexture(1, tsrc->getTexture(basename)); fname_base.replace(i, 4, normal_ext);
p.tile.applyMaterialOptionsWithShaders(material, bumpmaps1,bumpmaps2, shadermat3); i += normal_ext.length();
}
else
p.tile.applyMaterialOptionsWithShaders(material, shadermat1, shadermat2, shadermat3);
} }
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); p.tile.applyMaterialOptions(material);
}
// Create meshbuffer // Create meshbuffer