String OgreSample13App::buildInstancedMaterial(const String &originalMaterialName) { if (StringUtil::endsWith(originalMaterialName,"/instanced")) { return originalMaterialName; } MaterialPtr originalMaterial = MaterialManager::getSingleton().getByName(originalMaterialName); const String instancedMaterialName(originalMaterial.isNull() ? "Instancing" : originalMaterialName + "/Instanced"); MaterialPtr instancedMaterial = MaterialManager::getSingleton().getByName(instancedMaterialName); if (instancedMaterial.isNull()) { instancedMaterial = originalMaterial->clone(instancedMaterialName); instancedMaterial->load(); Technique::PassIterator pIt = instancedMaterial->getBestTechnique()->getPassIterator(); while(pIt.hasMoreElements()) { Pass * const p = pIt.getNext(); p->setVertexProgram("Instancing",false); p->setShadowCasterVertexProgram("InstancingShadowCaster"); } } instancedMaterial->load(); return instancedMaterialName; }
virtual void execute(SceneManager *sm, RenderSystem *rs) { // Fire listener instance->_fireNotifyMaterialRender(pass_id, mat); Rectangle2D * mRectangle=static_cast<Rectangle2D *>(CompositorManager::getSingleton()._getTexturedRectangle2D()); if (mQuadCornerModified) { // insure positions are using peculiar render system offsets RenderSystem* rs = Root::getSingleton().getRenderSystem(); Viewport* vp = rs->_getViewport(); Real hOffset = rs->getHorizontalTexelOffset() / (0.5 * vp->getActualWidth()); Real vOffset = rs->getVerticalTexelOffset() / (0.5 * vp->getActualHeight()); mRectangle->setCorners(mQuadLeft + hOffset, mQuadTop - vOffset, mQuadRight + hOffset, mQuadBottom - vOffset); } // Queue passes from mat Technique::PassIterator i = technique->getPassIterator(); while(i.hasMoreElements()) { sm->_injectRenderWithPass( i.getNext(), mRectangle, false // don't allow replacement of shadow passes ); } }
void CarModel::ChangeClr() { int i = iColor; float c_h = pSet->gui.car_hue[i], c_s = pSet->gui.car_sat[i], c_v = pSet->gui.car_val[i], gloss = pSet->gui.car_gloss[i], refl = pSet->gui.car_refl[i]; color.setHSB(1-c_h, c_s, c_v); //set, mini pos clr MaterialPtr mtr = MaterialManager::getSingleton().getByName(sMtr[Mtr_CarBody]); if (!mtr.isNull()) { Material::TechniqueIterator techIt = mtr->getTechniqueIterator(); while (techIt.hasMoreElements()) { Technique* tech = techIt.getNext(); Technique::PassIterator passIt = tech->getPassIterator(); while (passIt.hasMoreElements()) { Pass* pass = passIt.getNext(); if (pass->hasFragmentProgram()) { GpuProgramParametersSharedPtr params = pass->getFragmentProgramParameters(); params->setNamedConstant("carColour", color); params->setNamedConstant("glossiness", 1 - gloss); params->setNamedConstant("reflectiveness", refl); } } } } if (pNickTxt) pNickTxt->setTextColour(MyGUI::Colour(color.r,color.g,color.b)); // opp list text and mini pos colors - auto in hud update }
void MaterialFactory::setShadowsEnabled(bool bEnable) { for (std::vector<MaterialDefinition*>::iterator it=mDefinitions.begin(); it!=mDefinitions.end(); ++it) { MaterialPtr mat = MaterialManager::getSingleton().getByName( (*it)->getName() ); if (mat.isNull()) continue; Material::TechniqueIterator techIt = mat->getTechniqueIterator(); while (techIt.hasMoreElements()) { Technique* tech = techIt.getNext(); Technique::PassIterator passIt = tech->getPassIterator(); while (passIt.hasMoreElements()) { Pass* pass = passIt.getNext(); if (pass->hasFragmentProgram()) { if ( pass->getFragmentProgramParameters()->_findNamedConstantDefinition("enableShadows", false)) pass->getFragmentProgramParameters()->setNamedConstant("enableShadows", Real(bEnable)); } } } } }
//----------------------------------------------------------------------- void RenderPriorityGroup::addTransparentRenderable(Technique* pTech, Renderable* rend) { Technique::PassIterator pi = pTech->getPassIterator(); while (pi.hasMoreElements()) { // Insert into transparent list mTransparents.addRenderable(pi.getNext(), rend); } }
void MaterialInstance::setSceneBlending (SceneBlendType sbt) { mSBT = sbt; if (!mCopyMat.isNull ()) { Material::TechniqueIterator techniqueIt = mCopyMat->getTechniqueIterator (); while (techniqueIt.hasMoreElements ()) { Technique *t = techniqueIt.getNext (); Technique::PassIterator passIt = t->getPassIterator (); while (passIt.hasMoreElements ()) { passIt.getNext ()->setSceneBlending (mSBT); } } } }
virtual void execute(SceneManager *sm, RenderSystem *rs) { // Fire listener instance->_fireNotifyMaterialRender(pass_id, mat); // Queue passes from mat Technique::PassIterator i = technique->getPassIterator(); while(i.hasMoreElements()) { sm->_injectRenderWithPass( i.getNext(), CompositorManager::getSingleton()._getTexturedRectangle2D(), false // don't allow replacement of shadow passes ); } }
//------------------------------------------------------------------------------------------------------- // utility //------------------------------------------------------------------------------------------------------- void CarModel::UpdateLightMap() { MaterialPtr mtr; for (int i=0; i < NumMaterials; ++i) { mtr = MaterialManager::getSingleton().getByName(sMtr[i]); if (!mtr.isNull()) { Material::TechniqueIterator techIt = mtr->getTechniqueIterator(); while (techIt.hasMoreElements()) { Technique* tech = techIt.getNext(); Technique::PassIterator passIt = tech->getPassIterator(); while (passIt.hasMoreElements()) { Pass* pass = passIt.getNext(); if (pass->hasFragmentProgram()) { GpuProgramParametersSharedPtr params = pass->getFragmentProgramParameters(); params->setIgnoreMissingParams(true); // don't throw exception if material doesnt use lightmap params->setNamedConstant("enableTerrainLightMap", bLightMapEnabled ? 1.f : 0.f); } } } } } }
void CarModel::UpdateBraking() { if (brakes) brakes->setVisible(bBraking && mbVisible); std::string texName = sDirname + (bBraking ? "_body00_brake.png" : "_body00_add.png"); MaterialPtr mtr = MaterialManager::getSingleton().getByName(sMtr[Mtr_CarBody]); if (!mtr.isNull()) { Material::TechniqueIterator techIt = mtr->getTechniqueIterator(); while (techIt.hasMoreElements()) { Technique* tech = techIt.getNext(); Technique::PassIterator passIt = tech->getPassIterator(); while (passIt.hasMoreElements()) { Pass* pass = passIt.getNext(); Pass::TextureUnitStateIterator tusIt = pass->getTextureUnitStateIterator(); while (tusIt.hasMoreElements()) { TextureUnitState* tus = tusIt.getNext(); if (tus->getName() == "diffuseMap") { tus->setTextureName( texName ); return; } } } } } }
//----------------------------------------------------------------------- void RenderPriorityGroup::addSolidRenderable(Technique* pTech, Renderable* rend, bool addToNoShadow) { Technique::PassIterator pi = pTech->getPassIterator(); QueuedRenderableCollection* collection; if (addToNoShadow) { collection = &mSolidsNoShadowReceive; } else { collection = &mSolidsBasic; } while (pi.hasMoreElements()) { // Insert into solid list Pass* p = pi.getNext(); collection->addRenderable(p, rend); } }
void MaterialFactory::update() { for (std::vector<std::string>::const_iterator it = timeMtrs.begin(); it != timeMtrs.end(); ++it) { MaterialPtr mtr = MaterialManager::getSingleton().getByName( (*it) ); if (!mtr.isNull()) { Material::TechniqueIterator techIt = mtr->getTechniqueIterator(); while (techIt.hasMoreElements()) { Technique* tech = techIt.getNext(); Technique::PassIterator passIt = tech->getPassIterator(); while (passIt.hasMoreElements()) { Pass* pass = passIt.getNext(); // time if (pass->hasFragmentProgram() && pass->getFragmentProgramParameters()->_findNamedConstantDefinition("time", false)) pass->getFragmentProgramParameters()->setNamedConstantFromTime( "time", 1 ); } } } } }
bool OcclusionQuery::isPotentialOccluder(Ogre::SceneNode* node) { bool result = false; for (unsigned int i=0; i < node->numAttachedObjects(); ++i) { MovableObject* ob = node->getAttachedObject(i); std::string type = ob->getMovableType(); if (type == "Entity") { Entity* ent = static_cast<Entity*>(ob); for (unsigned int j=0; j < ent->getNumSubEntities(); ++j) { // if any sub entity has a material with depth write off, // consider the object as not an occluder MaterialPtr mat = ent->getSubEntity(j)->getMaterial(); Material::TechniqueIterator techIt = mat->getTechniqueIterator(); while (techIt.hasMoreElements()) { Technique* tech = techIt.getNext(); Technique::PassIterator passIt = tech->getPassIterator(); while (passIt.hasMoreElements()) { Pass* pass = passIt.getNext(); if (pass->getDepthWriteEnabled() == false) return false; else result = true; } } } } } return result; }
//----------------------------------------------------------------------- void BspSceneManager::renderStaticGeometry(void) { // Check we should be rendering if (!isRenderQueueToBeProcessed(mWorldGeometryRenderQueue)) return; // Cache vertex/face data first vector<StaticFaceGroup*>::type::const_iterator faceGrpi; static RenderOperation patchOp; // no world transform required mDestRenderSystem->_setWorldMatrix(Matrix4::IDENTITY); // Set view / proj setViewMatrix(mCachedViewMatrix); mDestRenderSystem->_setProjectionMatrix(mCameraInProgress->getProjectionMatrixRS()); // For each material in turn, cache rendering data & render MaterialFaceGroupMap::const_iterator mati; for (mati = mMatFaceGroupMap.begin(); mati != mMatFaceGroupMap.end(); ++mati) { // Get Material Material* thisMaterial = mati->first; // Empty existing cache mRenderOp.indexData->indexCount = 0; // lock index buffer ready to receive data unsigned int* pIdx = static_cast<unsigned int*>( mRenderOp.indexData->indexBuffer->lock(HardwareBuffer::HBL_DISCARD)); for (faceGrpi = mati->second.begin(); faceGrpi != mati->second.end(); ++faceGrpi) { // Cache each unsigned int numelems = cacheGeometry(pIdx, *faceGrpi); mRenderOp.indexData->indexCount += numelems; pIdx += numelems; } // Unlock the buffer mRenderOp.indexData->indexBuffer->unlock(); // Skip if no faces to process (we're not doing flare types yet) if (mRenderOp.indexData->indexCount == 0) continue; Technique::PassIterator pit = thisMaterial->getTechnique(0)->getPassIterator(); while (pit.hasMoreElements()) { _setPass(pit.getNext()); mDestRenderSystem->_render(mRenderOp); } } // for each material /* if (mShowNodeAABs) { mDestRenderSystem->_render(mAABGeometry); } */ }
void CompositorInstance::collectPasses(TargetOperation &finalState, CompositionTargetPass *target) { /// Here, passes are converted into render target operations Pass *targetpass; Technique *srctech; MaterialPtr mat, srcmat; CompositionTargetPass::PassIterator it = target->getPassIterator(); while(it.hasMoreElements()) { CompositionPass *pass = it.getNext(); switch(pass->getType()) { case CompositionPass::PT_CLEAR: queueRenderSystemOp(finalState, new RSClearOperation( pass->getClearBuffers(), pass->getClearColour(), pass->getClearDepth(), pass->getClearStencil() )); break; case CompositionPass::PT_STENCIL: queueRenderSystemOp(finalState, new RSStencilOperation( pass->getStencilCheck(),pass->getStencilFunc(), pass->getStencilRefValue(), pass->getStencilMask(), pass->getStencilFailOp(), pass->getStencilDepthFailOp(), pass->getStencilPassOp(), pass->getStencilTwoSidedOperation() )); break; case CompositionPass::PT_RENDERSCENE: if(pass->getFirstRenderQueue() < finalState.currentQueueGroupID) { /// Mismatch -- warn user /// XXX We could support repeating the last queue, with some effort LogManager::getSingleton().logMessage("Warning in compilation of Compositor " +mCompositor->getName()+": Attempt to render queue "+ StringConverter::toString(pass->getFirstRenderQueue())+" before "+ StringConverter::toString(finalState.currentQueueGroupID)); } /// Add render queues for(int x=pass->getFirstRenderQueue(); x<=pass->getLastRenderQueue(); ++x) { assert(x>=0); finalState.renderQueues.set(x); } finalState.currentQueueGroupID = pass->getLastRenderQueue()+1; finalState.findVisibleObjects = true; finalState.materialScheme = target->getMaterialScheme(); break; case CompositionPass::PT_RENDERQUAD: srcmat = pass->getMaterial(); if(srcmat.isNull()) { /// No material -- warn user LogManager::getSingleton().logMessage("Warning in compilation of Compositor " +mCompositor->getName()+": No material defined for composition pass"); break; } srcmat->compile(); if(srcmat->getNumSupportedTechniques()==0) { /// No supported techniques -- warn user LogManager::getSingleton().logMessage("Warning in compilation of Compositor " +mCompositor->getName()+": material "+srcmat->getName()+" has no supported techniques"); break; } srctech = srcmat->getBestTechnique(0); /// Create local material MaterialPtr mat = createLocalMaterial(); /// Copy and adapt passes from source material Technique::PassIterator i = srctech->getPassIterator(); while(i.hasMoreElements()) { Pass *srcpass = i.getNext(); /// Create new target pass targetpass = mat->getTechnique(0)->createPass(); (*targetpass) = (*srcpass); /// Set up inputs for(size_t x=0; x<pass->getNumInputs(); ++x) { String inp = pass->getInput(x); if(!inp.empty()) { if(x < targetpass->getNumTextureUnitStates()) { targetpass->getTextureUnitState((ushort)x)->setTextureName(getSourceForTex(inp)); } else { /// Texture unit not there LogManager::getSingleton().logMessage("Warning in compilation of Compositor " +mCompositor->getName()+": material "+srcmat->getName()+" texture unit " +StringConverter::toString(x)+" out of bounds"); } } } } queueRenderSystemOp(finalState, new RSQuadOperation(this,pass->getIdentifier(),mat)); break; } } }
void MaterialFactory::generate(bool force) { if (bSettingsChanged || force) { QTimer ti; ti.update(); /// time LogO("[MaterialFactory] generating new materials..."); deleteShaderCache(); fogMtrs.clear(); timeMtrs.clear(); softMtrs.clear(); for (std::vector<MaterialDefinition*>::iterator it=mDefinitions.begin(); it!=mDefinitions.end(); ++it) { // don't generate abstract materials if ((*it)->getProps()->abstract) continue; // find an appropriate generator MaterialGenerator* generator; if ((*it)->getProps()->customGenerator == "") generator = mGenerator; // default else { // iterate through custom generators std::vector<MaterialGenerator*>::iterator gIt; for (gIt = mCustomGenerators.begin(); gIt != mCustomGenerators.end(); ++gIt) { if ( (*gIt)->mName == (*it)->getProps()->customGenerator) { generator = (*gIt); break; } } if (gIt == mCustomGenerators.end()) { LogO("[MaterialFactory] WARNING: Custom generator '" + (*it)->getProps()->customGenerator + "' referenced by material '" + (*it)->getName() + "' not found. Using default generator."); generator = mGenerator; } } // shader cache - check if same shader already exists ShaderProperties* shaderProps = new ShaderProperties( (*it)->mProps, this ); bool exists = false; shaderMap::iterator sit; for (sit = mShaderCache.begin(); sit != mShaderCache.end(); ++sit) { if ( sit->second->isEqual( shaderProps ) ) { exists = true; break; } } if (!exists) generator->mShaderCached = false; else { generator->mShaderCached = true; generator->mVertexProgram = sit->first.first; generator->mFragmentProgram = sit->first.second; } generator->mDef = (*it); generator->mShader = shaderProps; generator->generate(); // insert into cache #ifdef USE_CACHE if (!exists) { if (!generator->mVertexProgram.isNull() && !generator->mFragmentProgram.isNull()) mShaderCache[ std::make_pair(generator->mVertexProgram, generator->mFragmentProgram) ] = shaderProps; else delete shaderProps; } else delete shaderProps; #else delete shaderProps; #endif } bSettingsChanged = false; ti.update(); /// time float dt = ti.dt * 1000.f; LogO(String("::: Time MaterialFactory: ") + toStr(dt) + " ms"); // recreate cloned car materials #ifndef ROAD_EDITOR pApp->recreateCarMtr(); #endif } else { LogO("[MaterialFactory] settings not changed, using old materials"); } // update params for (std::vector<MaterialDefinition*>::iterator it=mDefinitions.begin(); it!=mDefinitions.end(); ++it) { MaterialPtr mat = MaterialManager::getSingleton().getByName( (*it)->getName() ); setShaderParams(mat); } #ifdef USE_CUSTOM_TERRAIN_MATERIAL // update terrain params if (!mTerrain) return; MaterialPtr terrainMat = mTerrain->_getMaterial(); if (!terrainMat.isNull()) { Material::TechniqueIterator techIt = terrainMat->getTechniqueIterator(); while (techIt.hasMoreElements()) { Technique* tech = techIt.getNext(); Technique::PassIterator passIt = tech->getPassIterator(); while (passIt.hasMoreElements()) { Pass* pass = passIt.getNext(); if (!pass->hasFragmentProgram() || !pass->getFragmentProgramParameters()->_findNamedConstantDefinition("fadeStart_farDist", false)) continue; float fadeDist; if (mSceneMgr->getShadowFarDistance() != 0) fadeDist = getShadowsFadeDistance()/mSceneMgr->getShadowFarDistance(); else fadeDist = 0.f; pass->getFragmentProgramParameters()->setNamedConstant("fadeStart_farDist", Vector3( fadeDist, mSceneMgr->getShadowFarDistance(), float(getShadowsFade()) )); } } } #endif }
void MaterialFactory::setShaderParams(MaterialPtr mat) { if (mat.isNull()) return; Material::TechniqueIterator techIt = mat->getTechniqueIterator(); while (techIt.hasMoreElements()) { Technique* tech = techIt.getNext(); Technique::PassIterator passIt = tech->getPassIterator(); while (passIt.hasMoreElements()) { Pass* pass = passIt.getNext(); if (pass->hasFragmentProgram()) { // shadow fading parameters if ( getShadowsFade() && pass->getFragmentProgramParameters()->_findNamedConstantDefinition("fadeStart_farDist", false) && mSceneMgr ) { float fadeDist; if (mSceneMgr->getShadowFarDistance() != 0) fadeDist = getShadowsFadeDistance()/mSceneMgr->getShadowFarDistance(); else fadeDist = 0.f; pass->getFragmentProgramParameters()->setNamedConstant("fadeStart_farDist", Vector3( fadeDist, mSceneMgr->getShadowFarDistance(), float(getShadowsFade()) )); } // terrain lightmap name & size if ( mTerrain && !mTerrain->getLightmap().isNull() ) { if (pass->getFragmentProgramParameters()->_findNamedConstantDefinition("terrainWorldSize", false)) pass->getFragmentProgramParameters()->setNamedConstant( "terrainWorldSize", Real( mTerrain->getWorldSize() ) ); Pass::TextureUnitStateIterator tusIt = pass->getTextureUnitStateIterator(); while (tusIt.hasMoreElements()) { TextureUnitState* tus = tusIt.getNext(); if (tus->getName() == "terrainLightMap") { tus->setTextureName( mTerrain->getLightmap()->getName() ); } } } if (pass->getFragmentProgramParameters()->_findNamedConstantDefinition("invTerSize", false)) pass->getFragmentProgramParameters()->setNamedConstant("invTerSize", 1.f / Real(pApp->sc.td.fTerWorldSize)); // pssm split points if ( pass->getFragmentProgramParameters()->_findNamedConstantDefinition("pssmSplitPoints", false) && mPSSM) { const PSSMShadowCameraSetup::SplitPointList& splitPointList = mPSSM->getSplitPoints(); Vector4 splitPoints; for (size_t i = 0; i < splitPointList.size(); ++i) splitPoints[i] = splitPointList[i]; pass->getFragmentProgramParameters()->setNamedConstant("pssmSplitPoints", splitPoints); } } } } }
void CarReflection::Create() { bFirstFrame = true; if (pSet->refl_mode == "single") cubetexName = "ReflectionCube"; // single: use 1st cubemap else if (pSet->refl_mode == "full") { cubetexName = "ReflectionCube" + toStr(iIndex); // first cubemap: no index if (cubetexName == "ReflectionCube0") cubetexName = "ReflectionCube"; } else /* static */ cubetexName = "ReflectionCube"; TextureManager* tm = TextureManager::getSingletonPtr(); int size = ciShadowSizesA[pSet->refl_size]; // /2 ? // create cube render texture if (! (pSet->refl_mode == "single" && iIndex != 0) ) { cubetex = tm->createManual(cubetexName, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, TEX_TYPE_CUBE_MAP, size,size, 0/*mips*/, PF_R8G8B8, TU_RENDERTARGET); //LogO("created rt cube"); for (int face = 0; face < 6; face++) { Camera* mCam = pSceneMgr->createCamera("Reflect_" + toStr(iIndex) + "_" + toStr(face)); mCam->setAspectRatio(1.0f); mCam->setFOVy(Degree(90)); mCam->setNearClipDistance(0.1); //mCam->setFarClipDistance(pSet->refl_dist); //sky- RenderTarget* mRT = cubetex->getBuffer(face)->getRenderTarget(); //LogO( "rt face Name: " + mRT->getName() ); mRT->removeAllViewports(); Viewport* vp = mRT->addViewport(mCam); vp->setOverlaysEnabled(false); vp->setVisibilityMask(RV_MaskReflect); mRT->setAutoUpdated(false); //mRT->addListener(this); //- mCam->setPosition(Vector3::ZERO); Vector3 lookAt(0,0,0), up(0,0,0), right(0,0,0); switch(face) { case 0: lookAt.x =-1; up.y = 1; right.z = 1; break; // +X case 1: lookAt.x = 1; up.y = 1; right.z =-1; break; // -X case 2: lookAt.y =-1; up.z = 1; right.x = 1; break; // +Y case 3: lookAt.y = 1; up.z =-1; right.x = 1; break; // -Y case 4: lookAt.z = 1; up.y = 1; right.x =-1; break; // +Z case 5: lookAt.z =-1; up.y = 1; right.x =-1; break; // -Z } Quaternion orient( right, up, lookAt ); mCam->setOrientation( orient ); pCams[face] = mCam; pRTs[face] = mRT; } } // Iterate through our materials and add an index to ReflectionCube texture reference for (int i=0; i < NumMaterials; i++) { MaterialPtr mtr = MaterialManager::getSingleton().getByName(sMtr[i]); if (!mtr.isNull()) { Material::TechniqueIterator techIt = mtr->getTechniqueIterator(); while (techIt.hasMoreElements()) { Technique* tech = techIt.getNext(); Technique::PassIterator passIt = tech->getPassIterator(); while (passIt.hasMoreElements()) { Pass* pass = passIt.getNext(); Pass::TextureUnitStateIterator tusIt = pass->getTextureUnitStateIterator(); while (tusIt.hasMoreElements()) { TextureUnitState* tus = tusIt.getNext(); if (tus->getTextureName() == "ReflectionCube") tus->setTextureName(cubetexName); } } } } } }
/// Shadows config //--------------------------------------------------------------------------------------------------- void App::changeShadows() { QTimer ti; ti.update(); /// time // get settings bool enabled = pSet->shadow_type != 0; bool bDepth = pSet->shadow_type == 3; pSet->shadow_size = std::max(0,std::min(ciShadowNumSizes-1, pSet->shadow_size)); int fTex = /*2048*/ ciShadowSizesA[pSet->shadow_size], fTex2 = fTex/2; int num = /*3*/ pSet->shadow_count; // disable 4 shadow textures (does not work because no texcoord's left in shader) if (num == 4) num = 3; TerrainMaterialGeneratorB::SM2Profile* matProfile = 0; if (mTerrainGlobals) { matProfile = (TerrainMaterialGeneratorB::SM2Profile*) mTerrainGlobals->getDefaultMaterialGenerator()->getActiveProfile(); matProfile->setReceiveDynamicShadowsEnabled(enabled); matProfile->setReceiveDynamicShadowsLowLod(true); matProfile->setGlobalColourMapEnabled(false); matProfile->setLayerSpecularMappingEnabled(pSet->ter_mtr >= 1); // ter mtr matProfile->setLayerNormalMappingEnabled( pSet->ter_mtr >= 2); matProfile->setLayerParallaxMappingEnabled(pSet->ter_mtr >= 3); } // shadows old- if (pSet->shadow_type == 1) { //mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_ADDITIVE); mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE); //mSceneMgr->setShadowTextureCount(2); //mSceneMgr->setShadowTexturePixelFormat(PF_L8); //mSceneMgr->setShadowTextureCasterMaterial(StringUtil::BLANK); //mSceneMgr->setShadowTextureSelfShadow(true); mSceneMgr->setShadowCasterRenderBackFaces(true); mSceneMgr->setShadowTextureSettings(fTex, 1, PF_L8); mSceneMgr->setShadowColour(ColourValue(0.4, 0.4, 0.4)); mSceneMgr->setShadowFarDistance(pSet->shadow_dist / 50.f); // 36 72 mSceneMgr->setShadowDirLightTextureOffset(0.5); //-ShadowCameraSetupPtr mShadowCameraSetup = ShadowCameraSetupPtr(new PlaneOptimalShadowCameraSetup(mPlane)); ShadowCameraSetupPtr mShadowCameraSetup = ShadowCameraSetupPtr(new LiSPSMShadowCameraSetup()); mSceneMgr->setShadowCameraSetup(mShadowCameraSetup);/**/ mSceneMgr->setShadowTextureCountPerLightType(Light::LT_DIRECTIONAL, 1); mSceneMgr->setShadowTextureCount(1); //return; // ! } if (!enabled) { mSceneMgr->setShadowTechnique(SHADOWTYPE_NONE); /*return;*/ } else { // General scene setup //mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED); mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE_INTEGRATED); mSceneMgr->setShadowFarDistance(pSet->shadow_dist); // 3000 mSceneMgr->setShadowTextureCountPerLightType(Light::LT_DIRECTIONAL, num); if (mPSSMSetup.isNull()) { // shadow camera setup PSSMShadowCameraSetup* pssmSetup = new PSSMShadowCameraSetup(); #ifndef ROAD_EDITOR pssmSetup->setSplitPadding(mSplitMgr->mCameras.front()->getNearClipDistance()); //pssmSetup->setSplitPadding(10); pssmSetup->calculateSplitPoints(num, mSplitMgr->mCameras.front()->getNearClipDistance(), mSceneMgr->getShadowFarDistance()); #else pssmSetup->setSplitPadding(mCamera->getNearClipDistance()); //pssmSetup->setSplitPadding(10); pssmSetup->calculateSplitPoints(num, mCamera->getNearClipDistance(), mSceneMgr->getShadowFarDistance()); #endif for (int i=0; i < num; ++i) { int size = i==0 ? fTex : fTex2; const Real cAdjfA[5] = {2, 1, 0.5, 0.25, 0.125}; pssmSetup->setOptimalAdjustFactor(i, cAdjfA[std::min(i, 4)]); } mPSSMSetup.bind(pssmSetup); } mSceneMgr->setShadowCameraSetup(mPSSMSetup); mSceneMgr->setShadowTextureCount(num); for (int i=0; i < num; ++i) { int size = i==0 ? fTex : fTex2; mSceneMgr->setShadowTextureConfig(i, size, size, bDepth ? PF_FLOAT32_R : PF_X8B8G8R8); } mSceneMgr->setShadowTextureSelfShadow(bDepth ? true : false); //-? mSceneMgr->setShadowCasterRenderBackFaces(bDepth ? true : false); mSceneMgr->setShadowTextureCasterMaterial(bDepth ? "PSSM/shadow_caster" : StringUtil::BLANK); if (matProfile && terrain) { matProfile->setReceiveDynamicShadowsDepth(bDepth); matProfile->setReceiveDynamicShadowsPSSM(static_cast<PSSMShadowCameraSetup*>(mPSSMSetup.get())); MaterialPtr mtr = matProfile->generateForCompositeMap(terrain); //LogO(mtr->getBestTechnique()->getPass(0)->getTextureUnitState(0)->getName()); //LogO(String("Ter mtr: ") + mtr->getName()); } #if 0 // shadow tex overlay // add the overlay elements to show the shadow maps: // init overlay elements OverlayManager& mgr = OverlayManager::getSingleton(); Overlay* overlay; // destroy if already exists if (overlay = mgr.getByName("DebugOverlay")) mgr.destroy(overlay); overlay = mgr.create("DebugOverlay"); for (size_t i = 0; i < num; ++i) { TexturePtr tex = mSceneMgr->getShadowTexture(i); // Set up a debug panel to display the shadow if (MaterialManager::getSingleton().resourceExists("Ogre/DebugTexture" + toStr(i))) MaterialManager::getSingleton().remove("Ogre/DebugTexture" + toStr(i)); MaterialPtr debugMat = MaterialManager::getSingleton().create( "Ogre/DebugTexture" + toStr(i), ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); debugMat->getTechnique(0)->getPass(0)->setLightingEnabled(false); TextureUnitState *t = debugMat->getTechnique(0)->getPass(0)->createTextureUnitState(tex->getName()); t->setTextureAddressingMode(TextureUnitState::TAM_CLAMP); OverlayContainer* debugPanel; // destroy container if exists try { if (debugPanel = static_cast<OverlayContainer*>( mgr.getOverlayElement("Ogre/DebugTexPanel" + toStr(i) ))) mgr.destroyOverlayElement(debugPanel); } catch (Ogre::Exception&) {} debugPanel = (OverlayContainer*) (OverlayManager::getSingleton().createOverlayElement("Panel", "Ogre/DebugTexPanel" + StringConverter::toString(i))); debugPanel->_setPosition(0.8, i*0.25); debugPanel->_setDimensions(0.2, 0.24); debugPanel->setMaterialName(debugMat->getName()); debugPanel->show(); overlay->add2D(debugPanel); overlay->show(); } #endif } materialFactory->setNumShadowTex(num); materialFactory->setShadows(pSet->shadow_type != 0); materialFactory->setShadowsDepth(bDepth); materialFactory->generate(); // set terrain lightmap texture and terrainWorldSize for all materials that need it if (terrain) // naive check if a game has been started already { for (std::vector<std::string>::const_iterator it = materialFactory->terrainLightMapMtrs.begin(); it != materialFactory->terrainLightMapMtrs.end(); ++it) { MaterialPtr mtr = MaterialManager::getSingleton().getByName( (*it) ); if (!mtr.isNull()) { Material::TechniqueIterator techIt = mtr->getTechniqueIterator(); while (techIt.hasMoreElements()) { Technique* tech = techIt.getNext(); Technique::PassIterator passIt = tech->getPassIterator(); while (passIt.hasMoreElements()) { Pass* pass = passIt.getNext(); Pass::TextureUnitStateIterator tusIt = pass->getTextureUnitStateIterator(); while (tusIt.hasMoreElements()) { TextureUnitState* tus = tusIt.getNext(); if (tus->getName() == "terrainLightMap") { tus->setTextureName( terrain->getLightmap()->getName() ); pass->getFragmentProgramParameters()->setNamedConstant( "terrainWorldSize", Real( sc.td.fTerWorldSize ) ); } } } } } } } // ------------------- update the paged-geom materials // grass is not cloned, just need to set new shader parameters if (grass) { GrassLoader *grassLoader = static_cast<GrassLoader*>(grass->getPageLoader()); for (std::list<GrassLayer*>::iterator it= grassLoader->getLayerList().begin(); it != grassLoader->getLayerList().end(); ++it) { GrassLayer* layer = (*it); layer->applyShader(); } } // trees are more complicated since they are cloned if(trees) { trees->reloadGeometry(); std::vector<ResourcePtr> reosurceToDelete; ResourceManager::ResourceMapIterator it = MaterialManager::getSingleton().getResourceIterator(); while (it.hasMoreElements()) { ResourcePtr material = it.getNext(); String materialName = material->getName(); std::string::size_type pos =materialName.find("BatchMat|"); if( pos != std::string::npos ) { reosurceToDelete.push_back(material); } } for(int i=0;i<reosurceToDelete.size();i++) { MaterialManager::getSingleton().remove(reosurceToDelete[i]); } } UpdPSSMMaterials(); ti.update(); /// time float dt = ti.dt * 1000.f; LogO(String("::: Time Shadows: ") + toStr(dt) + " ms"); }