void Shader::setTexture(std::string name, std::string parameterName) { TextureUnitState* texture = getPass()->createTextureUnitState(name); texture->setTextureNameAlias(parameterName); texture->setName(parameterName); }
void NIFLoader::createMaterial(const String &name, const Vector &ambient, const Vector &diffuse, const Vector &specular, const Vector &emissive, float glossiness, float alpha, int alphaFlags, float alphaTest, const String &texName) { MaterialPtr material = MaterialManager::getSingleton().create(name, resourceGroup); //Hardware Skinning code, textures may be the wrong color if enabled /* if(!mSkel.isNull()){ material->removeAllTechniques(); Ogre::Technique* tech = material->createTechnique(); //tech->setSchemeName("blahblah"); Pass* pass = tech->createPass(); pass->setVertexProgram("Ogre/BasicVertexPrograms/AmbientOneTexture");*/ // This assigns the texture to this material. If the texture name is // a file name, and this file exists (in a resource directory), it // will automatically be loaded when needed. If not (such as for // internal NIF textures that we might support later), we should // already have inserted a manual loader for the texture. if (!texName.empty()) { Pass *pass = material->getTechnique(0)->getPass(0); /*TextureUnitState *txt =*/ pass->createTextureUnitState(texName); pass->setVertexColourTracking(TVC_DIFFUSE); // As of yet UNTESTED code from Chris: /*pass->setTextureFiltering(Ogre::TFO_ANISOTROPIC); pass->setDepthFunction(Ogre::CMPF_LESS_EQUAL); pass->setDepthCheckEnabled(true); // Add transparency if NiAlphaProperty was present if (alphaFlags != -1) { std::cout << "Alpha flags set!" << endl; if ((alphaFlags&1)) { pass->setDepthWriteEnabled(false); pass->setSceneBlending(getBlendFactor((alphaFlags>>1)&0xf), getBlendFactor((alphaFlags>>5)&0xf)); } else pass->setDepthWriteEnabled(true); if ((alphaFlags>>9)&1) pass->setAlphaRejectSettings(getTestMode((alphaFlags>>10)&0x7), alphaTest); pass->setTransparentSortingEnabled(!((alphaFlags>>13)&1)); } else pass->setDepthWriteEnabled(true); */ // Add transparency if NiAlphaProperty was present if (alphaFlags != -1) { // The 237 alpha flags are by far the most common. Check // NiAlphaProperty in nif/property.h if you need to decode // other values. 237 basically means normal transparencly. if (alphaFlags == 237) { NifOverrides::TransparencyResult result = NifOverrides::Overrides::getTransparencyOverride(texName); if (result.first) { pass->setAlphaRejectFunction(CMPF_GREATER_EQUAL); pass->setAlphaRejectValue(result.second); } else { // Enable transparency pass->setSceneBlending(SBT_TRANSPARENT_ALPHA); //pass->setDepthCheckEnabled(false); pass->setDepthWriteEnabled(false); //std::cout << "alpha 237; material: " << name << " texName: " << texName << std::endl; } } else warn("Unhandled alpha setting for texture " + texName); } else { material->getTechnique(0)->setShadowCasterMaterial("depth_shadow_caster_noalpha"); } } if (Settings::Manager::getBool("enabled", "Shadows")) { bool split = Settings::Manager::getBool("split", "Shadows"); const int numsplits = 3; for (int i = 0; i < (split ? numsplits : 1); ++i) { TextureUnitState* tu = material->getTechnique(0)->getPass(0)->createTextureUnitState(); tu->setName("shadowMap" + StringConverter::toString(i)); tu->setContentType(TextureUnitState::CONTENT_SHADOW); tu->setTextureAddressingMode(TextureUnitState::TAM_BORDER); tu->setTextureBorderColour(ColourValue::White); } } if (Settings::Manager::getBool("shaders", "Objects")) { material->getTechnique(0)->getPass(0)->setVertexProgram("main_vp"); material->getTechnique(0)->getPass(0)->setFragmentProgram("main_fp"); material->getTechnique(0)->getPass(0)->setFog(true); // force-disable fixed function fog, it is calculated in shader } // Create a fallback technique without shadows and without mrt Technique* tech2 = material->createTechnique(); tech2->setSchemeName("Fallback"); Pass* pass2 = tech2->createPass(); pass2->createTextureUnitState(texName); pass2->setVertexColourTracking(TVC_DIFFUSE); if (Settings::Manager::getBool("shaders", "Objects")) { pass2->setVertexProgram("main_fallback_vp"); pass2->setFragmentProgram("main_fallback_fp"); pass2->setFog(true); // force-disable fixed function fog, it is calculated in shader } // Add material bells and whistles material->setAmbient(ambient.array[0], ambient.array[1], ambient.array[2]); material->setDiffuse(diffuse.array[0], diffuse.array[1], diffuse.array[2], alpha); material->setSpecular(specular.array[0], specular.array[1], specular.array[2], alpha); material->setSelfIllumination(emissive.array[0], emissive.array[1], emissive.array[2]); material->setShininess(glossiness); }