Fooling around : added simple support for normal maps

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@7802 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2011-03-04 00:58:00 +00:00
parent 5fcccd6f32
commit 970fb985d3
3 changed files with 83 additions and 21 deletions

View File

@ -89,6 +89,11 @@ Material::Material(const XMLNode *node, int index)
node->get("backface-culling", &m_backface_culling );
node->get("disable-z-write", &m_disable_z_write );
if (node->get("normal-map", &m_normal_map_tex))
{
m_normal_map = true;
}
s="";
node->get("graphical-effect", &s );
@ -211,6 +216,7 @@ void Material::init(unsigned int index)
m_zipper_fade_out_time = -1.0f;
m_zipper_max_speed_increase = -1.0f;
m_zipper_speed_gain = -1.0f;
m_normal_map = false;
for (int n=0; n<EMIT_KINDS_COUNT; n++)
{
@ -411,16 +417,23 @@ void Material::setMaterialProperties(video::SMaterial *m) const
video::EMFN_MODULATE_1X, video::EAS_TEXTURE | video::EAS_VERTEX_COLOR);
modes++;
}
if (m_disable_z_write)
if (m_normal_map)
{
m->ZWriteEnable = false;
// TODO: allow searching in per-track dir too...
m->setTexture(1, irr_driver->getTexture(m_normal_map_tex));
m->MaterialType = video::EMT_NORMAL_MAP_SOLID ;
modes++;
}
if (modes > 1)
{
std::cerr << "[Material::setMaterialProperties] More than one main mode set for " << m_texname.c_str() << "\n";
}
if (m_disable_z_write)
{
m->ZWriteEnable = false;
}
if (!m_lighting)
{
@ -455,6 +468,7 @@ void Material::setMaterialProperties(video::SMaterial *m) const
m->setFlag(video::EMF_TRILINEAR_FILTER, true);
}
// UV clamping
if ( (m_clamp_tex & UCLAMP) != 0)
{
// m->setFlag();
@ -480,10 +494,11 @@ void Material::setMaterialProperties(video::SMaterial *m) const
}
}
// Backface culling
if(!m_backface_culling)
m->setFlag(video::EMF_BACK_FACE_CULLING, false);
// Material color
m->ColorMaterial = video::ECM_DIFFUSE_AND_AMBIENT;
#ifdef DEBUG
@ -492,5 +507,6 @@ void Material::setMaterialProperties(video::SMaterial *m) const
m->ColorMaterial = video::ECM_NONE; // Override one above
}
#endif
} // setMaterialProperties

View File

@ -81,6 +81,10 @@ private:
ParticleKind* m_particles_effects[EMIT_KINDS_COUNT];
/** For normal maps */
bool m_normal_map;
std::string m_normal_map_tex;
/** Texture clamp bitmask */
unsigned int m_clamp_tex;
bool m_lighting;
@ -219,6 +223,8 @@ public:
*zipper_fade_out_time = m_zipper_fade_out_time;
} // getZipperParameter
bool isNormalMap() const { return m_normal_map; }
} ;

View File

@ -533,32 +533,72 @@ bool Track::loadMainTrack(const XMLNode &root)
n->getName().c_str());
continue;
}
bool tangent = false;
n->get("tangents", &tangent);
scene::ISceneNode* scene_node;
model_name="";
n->get("model", &model_name);
full_path = m_root+"/"+model_name;
scene::IAnimatedMesh *a_mesh = irr_driver->getAnimatedMesh(full_path);
if(!a_mesh)
{
fprintf(stderr, "Warning: object model '%s' not found, ignored.\n",
full_path.c_str());
continue;
}
m_all_meshes.push_back(a_mesh);
scene::ISceneNode *scene_node = irr_driver->addAnimatedMesh(a_mesh);
#ifdef DEBUG
std::string debug_name = model_name+" (static track-object)";
scene_node->setName(debug_name.c_str());
#endif
core::vector3df xyz(0,0,0);
n->get("xyz", &xyz);
scene_node->setPosition(xyz);
core::vector3df hpr(0,0,0);
n->get("hpr", &hpr);
scene_node->setRotation(hpr);
core::vector3df scale(1.0f, 1.0f, 1.0f);
n->get("scale", &scale);
scene_node->setScale(scale);
if (tangent)
{
scene::IMeshManipulator* manip = irr_driver->getVideoDriver()->getMeshManipulator();
scene::IMesh* original_mesh = irr_driver->getMesh(full_path);
// create a node out of this mesh just for bullet; delete it after, normal maps are special
// and require tangent meshes
scene_node = irr_driver->addMesh(original_mesh);
scene_node->setPosition(xyz);
scene_node->setRotation(hpr);
scene_node->setScale(scale);
convertTrackToBullet(scene_node);
scene_node->remove();
scene::IMesh* mesh = manip->createMeshWithTangents(original_mesh);
m_all_meshes.push_back(mesh);
scene_node = irr_driver->addMesh(mesh);
scene_node->setPosition(xyz);
scene_node->setRotation(hpr);
scene_node->setScale(scale);
#ifdef DEBUG
std::string debug_name = model_name+" (tangent static track-object)";
scene_node->setName(debug_name.c_str());
#endif
}
else
{
scene::IAnimatedMesh *a_mesh = irr_driver->getAnimatedMesh(full_path);
if(!a_mesh)
{
fprintf(stderr, "Warning: object model '%s' not found, ignored.\n",
full_path.c_str());
continue;
}
m_all_meshes.push_back(a_mesh);
scene_node = irr_driver->addAnimatedMesh(a_mesh);
scene_node->setPosition(xyz);
scene_node->setRotation(hpr);
scene_node->setScale(scale);
#ifdef DEBUG
std::string debug_name = model_name+" (static track-object)";
scene_node->setName(debug_name.c_str());
#endif
}
handleAnimatedTextures(scene_node, *n);
m_all_nodes.push_back(scene_node);