| 1269 | } |
| 1270 | |
| 1271 | std::string RenderManager::colourizeMaterial(const std::string& materialName, const Seat* seat, bool markedForDigging, bool playerHasVision) |
| 1272 | { |
| 1273 | if (seat == nullptr && !markedForDigging && playerHasVision) |
| 1274 | return materialName; |
| 1275 | |
| 1276 | std::stringstream tempSS; |
| 1277 | |
| 1278 | tempSS.str(""); |
| 1279 | |
| 1280 | tempSS << materialName << "##"; |
| 1281 | |
| 1282 | // Create the material name. |
| 1283 | if(seat != nullptr) |
| 1284 | tempSS << "Color_" << seat->getColorId() << "_" ; |
| 1285 | else |
| 1286 | tempSS << "Color_null_" ; |
| 1287 | |
| 1288 | if (markedForDigging) |
| 1289 | tempSS << "dig_"; |
| 1290 | else if(!playerHasVision) |
| 1291 | tempSS << "novision_"; |
| 1292 | |
| 1293 | Ogre::MaterialPtr requestedMaterial = Ogre::MaterialManager::getSingleton().getByName(tempSS.str()); |
| 1294 | |
| 1295 | //cout << "\nCloning material: " << tempSS.str(); |
| 1296 | |
| 1297 | // If this texture has been copied and colourized, we can return |
| 1298 | if (!requestedMaterial.isNull()) |
| 1299 | return tempSS.str(); |
| 1300 | |
| 1301 | // If not yet, then do so |
| 1302 | |
| 1303 | // Check to see if we find a seat with the requested color, if not then just use the original, uncolored material. |
| 1304 | if (seat == nullptr && !markedForDigging && playerHasVision) |
| 1305 | return materialName; |
| 1306 | |
| 1307 | Ogre::MaterialPtr oldMaterial = Ogre::MaterialManager::getSingleton().getByName(materialName); |
| 1308 | |
| 1309 | //std::cout << "\nMaterial does not exist, creating a new one."; |
| 1310 | Ogre::MaterialPtr newMaterial = oldMaterial->clone(tempSS.str()); |
| 1311 | bool cloned = mShaderGenerator->cloneShaderBasedTechniques(oldMaterial->getName(), oldMaterial->getGroup(), |
| 1312 | newMaterial->getName(), newMaterial->getGroup()); |
| 1313 | if(!cloned) |
| 1314 | { |
| 1315 | OD_LOG_ERR("Failed to clone rtss for material: " + materialName); |
| 1316 | } |
| 1317 | |
| 1318 | // Loop over the techniques for the new material |
| 1319 | for (unsigned int j = 0; j < newMaterial->getNumTechniques(); ++j) |
| 1320 | { |
| 1321 | Ogre::Technique* technique = newMaterial->getTechnique(j); |
| 1322 | if (technique->getNumPasses() == 0) |
| 1323 | continue; |
| 1324 | |
| 1325 | if (markedForDigging) |
| 1326 | { |
| 1327 | // Color the material with yellow on the latest pass |
| 1328 | // so we're sure to see the taint. |