//------------------------------------------------------------------------------- Ogre::MaterialPtr CSceneManagerEditor::buildDepthShadowMaterial(Ogre::MaterialPtr cpyMat) { if(mShadowsTechnique->get() >= (int)Ogre::SHADOWTYPE_TEXTURE_ADDITIVE && mShadowsTechnique->get() <= (int)Ogre::SHADOWTYPE_TEXTURE_MODULATIVE_INTEGRATED) { Ogre::String matName = "DepthShadows/" + cpyMat->getName(); Ogre::MaterialPtr ret = Ogre::MaterialManager::getSingleton().getByName(matName); if (ret.isNull()) { ret = cpyMat->clone(matName); Ogre::Technique *t = ret->getTechnique(0); t->setShadowCasterMaterial("Ogre/shadow/depth/caster"); Ogre::Pass *p = t->getPass(0); p->setVertexProgram("Ogre/shadow/receiver/depth/pssm3/vp"); p->setFragmentProgram("Ogre/shadow/receiver/depth/pssm3/fp"); Ogre::TextureUnitState *tu = p->createTextureUnitState(); tu->setName("shadow0"); tu->setContentType(Ogre::TextureUnitState::CONTENT_SHADOW); tu->setTextureAddressingMode(Ogre::TextureUnitState::TAM_BORDER); tu->setTextureBorderColour(Ogre::ColourValue(1,1,1,1)); tu = p->createTextureUnitState(); tu->setName("shadow1"); tu->setContentType(Ogre::TextureUnitState::CONTENT_SHADOW); tu->setTextureAddressingMode(Ogre::TextureUnitState::TAM_BORDER); tu->setTextureBorderColour(Ogre::ColourValue(1,1,1,1)); tu = p->createTextureUnitState(); tu->setName("shadow2"); tu->setContentType(Ogre::TextureUnitState::CONTENT_SHADOW); tu->setTextureAddressingMode(Ogre::TextureUnitState::TAM_BORDER); tu->setTextureBorderColour(Ogre::ColourValue(1,1,1,1)); Ogre::Vector4 splitPoints; const Ogre::PSSMShadowCameraSetup::SplitPointList& splitPointList = static_cast<Ogre::PSSMShadowCameraSetup*>(mPSSMSetup.get())->getSplitPoints(); for (int i = 0; i < 3; ++i) { splitPoints[i] = splitPointList[i]; } p->getFragmentProgramParameters()->setNamedConstant("pssmSplitPoints", splitPoints); } return ret; } else return cpyMat; }
void MaterialGenerator::createTexUnits(Ogre::Pass* pass) { Ogre::TextureUnitState* tu; // diffuse / light / blend maps if (needDiffuseMap()) { tu = pass->createTextureUnitState( mDiffuseMap ); tu->setName("diffuseMap"); tu->setTextureAddressingMode(mDef->mProps->textureAddressMode); mDiffuseTexUnit = mTexUnit_i; mTexUnit_i++; } if (needLightMap()) { tu = pass->createTextureUnitState( mLightMap ); tu->setName("lightMap"); tu->setTextureAddressingMode(mDef->mProps->textureAddressMode); mLightTexUnit = mTexUnit_i; mTexUnit_i++; } if (needBlendMap()) { tu = pass->createTextureUnitState( mBlendMap ); tu->setName("blendMap"); tu->setTextureAddressingMode(mDef->mProps->textureAddressMode); mBlendTexUnit = mTexUnit_i; mTexUnit_i++; } // spec map if (needSpecMap()) { tu = pass->createTextureUnitState( mSpecMap ); tu->setName("specMap"); tu->setTextureAddressingMode(mDef->mProps->textureAddressMode); mSpecTexUnit = mTexUnit_i; mTexUnit_i++; } // reflectivity map if (needReflectivityMap()) { tu = pass->createTextureUnitState( mReflMap ); tu->setName("reflectivityMap"); tu->setTextureAddressingMode(mDef->mProps->textureAddressMode); mReflTexUnit = mTexUnit_i; mTexUnit_i++; } // global terrain lightmap (static) if (needTerrainLightMap()) { tu = pass->createTextureUnitState(String("white.png")); // texture name set later (in changeShadows) tu->setName("terrainLightMap"); mTerrainLightTexUnit = mTexUnit_i; mTexUnit_i++; } // alpha map if (needAlphaMap()) { tu = pass->createTextureUnitState( mAlphaMap ); tu->setName("alphaMap"); mAlphaTexUnit = mTexUnit_i; mTexUnit_i++; } // normal map if (needNormalMap()) { tu = pass->createTextureUnitState( mNormalMap ); tu->setName("normalMap"); mNormalTexUnit = mTexUnit_i; mTexUnit_i++; } // env map if (needEnvMap()) { tu = pass->createTextureUnitState( mDef->mProps->envMap ); tu->setName("envMap"); tu->setTextureAddressingMode(TextureUnitState::TAM_CLAMP); mEnvTexUnit = mTexUnit_i; mTexUnit_i++; } // realtime shadow maps if (needShadows()) { mShadowTexUnit_start = mTexUnit_i; for (int i = 0; i < mParent->getNumShadowTex(); ++i) { tu = pass->createTextureUnitState(); tu->setName("shadowMap" + toStr(i)); tu->setContentType(TextureUnitState::CONTENT_SHADOW); tu->setTextureAddressingMode(TextureUnitState::TAM_BORDER); tu->setTextureBorderColour(ColourValue::White); mTexUnit_i++; } } }
void WaterMaterialGenerator::generate() { mMaterial = prepareMaterial(mDef->getName()); resetTexUnitCounter(); // we need a lot of uniform constants, disabling shadows reduces them significantly so that it can still run on PS2 const RenderSystemCapabilities *caps = Root::getSingleton().getRenderSystem()->getCapabilities(); if(!caps->isShaderProfileSupported("ps_4_0") && !caps->isShaderProfileSupported("fp40")) mDef->mProps->receivesShadows = false; // -------------------------- Main technique ----------------------------- // Ogre::Technique* technique = mMaterial->createTechnique(); // Main pass ----------------------------------------------------------- Ogre::Pass* pass = technique->createPass(); pass->setCullingMode(CULL_NONE); pass->setDepthWriteEnabled(true); if (!mParent->getRefract()) pass->setSceneBlending(SBT_TRANSPARENT_ALPHA); Ogre::TextureUnitState* tu; // normal map mNormalMap = pickTexture(&mDef->mProps->normalMaps); tu = pass->createTextureUnitState( mNormalMap ); tu->setName("normalMap"); mNormalTexUnit = mTexUnit_i; mTexUnit_i++; // global terrain lightmap (static) if (needTerrainLightMap()) { tu = pass->createTextureUnitState(""); // texture name set later (in changeShadows) tu->setName("terrainLightMap"); mTerrainLightTexUnit = mTexUnit_i; mTexUnit_i++; } if (mParent->getRefract()) { tu = pass->createTextureUnitState( "PlaneRefraction" ); tu->setName("refractionMap"); tu->setTextureAddressingMode(TextureUnitState::TAM_CLAMP); mScreenRefrUnit = mTexUnit_i++; } if (mParent->getReflect()) { tu = pass->createTextureUnitState( "PlaneReflection" ); tu->setName("reflectionMap"); tu->setTextureAddressingMode(TextureUnitState::TAM_CLAMP); mScreenReflUnit = mTexUnit_i++; } //else { // retrieve sky texture name from scene std::string skyTexName; if (mParent->pApp->terrain) { MaterialPtr mtrSky = MaterialManager::getSingleton().getByName(mParent->pApp->sc.skyMtr); if(!mtrSky.isNull()) { Pass* passSky = mtrSky->getTechnique(0)->getPass(0); TextureUnitState* tusSky = passSky->getTextureUnitState(0); skyTexName = tusSky->getTextureName(); } } else skyTexName = String("white.png"); tu = pass->createTextureUnitState( skyTexName ); tu->setName("skyMap"); tu->setTextureAddressingMode(TextureUnitState::TAM_MIRROR); mEnvTexUnit = mTexUnit_i++; } // waterDepth tu = pass->createTextureUnitState( "waterDepth.png" ); tu->setName("depthMap"); tu->setTextureAddressingMode(TextureUnitState::TAM_BORDER); tu->setTextureBorderColour(ColourValue::White); // outside tex water always visible mWaterDepthUnit = mTexUnit_i; mTexUnit_i++; // realtime shadow maps if (needShadows()) { mShadowTexUnit_start = mTexUnit_i; for (int i = 0; i < mParent->getNumShadowTex(); ++i) { tu = pass->createTextureUnitState(); tu->setName("shadowMap" + toStr(i)); tu->setContentType(TextureUnitState::CONTENT_SHADOW); tu->setTextureAddressingMode(TextureUnitState::TAM_BORDER); tu->setTextureBorderColour(ColourValue::White); mTexUnit_i++; } } // shader if (!mShaderCached) { mVertexProgram = createVertexProgram(); mFragmentProgram = createFragmentProgram(); } pass->setVertexProgram(mVertexProgram->getName()); pass->setFragmentProgram(mFragmentProgram->getName()); if (mShaderCached) { individualFragmentProgramParams(pass->getFragmentProgramParameters()); individualVertexProgramParams(pass->getFragmentProgramParameters()); } // ----------------------------------------------------------------------- // createSSAOTechnique(); createOccluderTechnique(); // indicate we need 'time' parameter set every frame mParent->timeMtrs.push_back(mDef->getName()); /* if (mDef->getName() == "Grease_jelly") { LogO("[MaterialFactory] Vertex program source: "); StringUtil::StrStreamType vSourceStr; generateVertexProgramSource(vSourceStr); LogO(vSourceStr.str()); LogO("[MaterialFactory] Fragment program source: "); StringUtil::StrStreamType fSourceStr; generateFragmentProgramSource(fSourceStr); LogO(fSourceStr.str()); } /**/ }