From 970fb985d3a157e327f25d5f8cfbab1aab6a7d7b Mon Sep 17 00:00:00 2001 From: auria Date: Fri, 4 Mar 2011 00:58:00 +0000 Subject: [PATCH] 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 --- src/graphics/material.cpp | 24 ++++++++++--- src/graphics/material.hpp | 6 ++++ src/tracks/track.cpp | 74 ++++++++++++++++++++++++++++++--------- 3 files changed, 83 insertions(+), 21 deletions(-) diff --git a/src/graphics/material.cpp b/src/graphics/material.cpp index 96ddf4383..4d0257093 100644 --- a/src/graphics/material.cpp +++ b/src/graphics/material.cpp @@ -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; nZWriteEnable = 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 diff --git a/src/graphics/material.hpp b/src/graphics/material.hpp index 29c4f6bb8..f4f6f3d69 100644 --- a/src/graphics/material.hpp +++ b/src/graphics/material.hpp @@ -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; } + } ; diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index 29803bf28..a1cca44a3 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -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);