Overlay* OverlayLibrary::addOverlay(const std::string& name, const std::string& type) { Overlay* newOverlay; if (type.compare(ColourShiftOverlay::NAME)==0) { newOverlay = new ColourShiftOverlay; } else if (type.compare(BlobOverlay::NAME) ==0) { newOverlay = new BlobOverlay; } else if (type.compare(PerspectiveImageOverlay::NAME) ==0) { newOverlay = new PerspectiveImageOverlay; } else if (type.compare(PerspectiveObjectOverlay::NAME) ==0) { newOverlay = new PerspectiveObjectOverlay; } else if (type.compare(PongOverlay::NAME) ==0) { newOverlay = new PongOverlay; } else if (type.compare(StageObjectOverlay::NAME) ==0) { newOverlay = new StageObjectOverlay; } else if (type.compare(ShakeOverlay::NAME) ==0) { newOverlay = new ShakeOverlay; } else if (type.compare(CutOutOverlay::NAME) ==0) { newOverlay = new CutOutOverlay; } else if (type.compare(CineOverlay::NAME) ==0) { newOverlay = new CineOverlay; } else if (type.compare(ParticleStormOverlay::NAME) ==0) { newOverlay = new ParticleStormOverlay; } else if (type.compare(EffectChangeOverlay::NAME) ==0) { newOverlay = new EffectChangeOverlay; } else if (type.compare(TeleportOverlay::NAME) ==0) { newOverlay = new TeleportOverlay; } else if (type.compare(LinesOverlay::NAME) ==0) { newOverlay = new LinesOverlay; } else if (type.compare(GravityStageOverlay::NAME) ==0) { newOverlay = new GravityStageOverlay; } else if (type.compare(PerspectiveVideoOverlay::NAME) ==0) { newOverlay = new PerspectiveVideoOverlay; } else if (type.compare(StutterOverlay::NAME) ==0) { newOverlay = new StutterOverlay; } else if (type.compare(RandomStuttersOverlay::NAME) ==0) { newOverlay = new RandomStuttersOverlay; } else if (type.compare(CubeRainOverlay::NAME) ==0) { newOverlay = new CubeRainOverlay; } else if (type.compare(MottledCineOverlay::NAME) ==0) { newOverlay = new MottledCineOverlay; } else if (type.compare(DividedCine::NAME) ==0) { newOverlay = new DividedCine; } if (!newOverlay) return 0; // TODO: exceptions! newOverlay->setInstanceName(name); newOverlay->setChoreography(choreography); overlays[name] = newOverlay; return newOverlay; }
void View::Draw(DrawingEngine* drawingEngine, BRegion* effectiveClipping, BRegion* windowContentClipping, bool deep) { if (!fVisible) { // child views cannot be visible either return; } if (fViewBitmap != NULL || fViewColor != B_TRANSPARENT_COLOR) { // we can only draw within our own area BRegion* redraw; if ((fFlags & B_DRAW_ON_CHILDREN) != 0) { // The client may actually want to prevent the background to // be painted outside the user clipping. redraw = fWindow->GetRegion( ScreenAndUserClipping(windowContentClipping)); } else { // Ignore user clipping as in BeOS for painting the background. redraw = fWindow->GetRegion( _ScreenClipping(windowContentClipping)); } if (!redraw) return; // add the current clipping redraw->IntersectWith(effectiveClipping); Overlay* overlayCookie = _Overlay(); if (fViewBitmap != NULL && overlayCookie == NULL) { // draw view bitmap // TODO: support other options! BRect rect = fBitmapDestination; ConvertToScreenForDrawing(&rect); align_rect_to_pixels(&rect); if (fBitmapOptions & B_TILE_BITMAP_Y) { // move rect up as much as needed while (rect.top > redraw->Frame().top) rect.OffsetBy(0.0, -(rect.Height() + 1)); } if (fBitmapOptions & B_TILE_BITMAP_X) { // move rect left as much as needed while (rect.left > redraw->Frame().left) rect.OffsetBy(-(rect.Width() + 1), 0.0); } // XXX: locking removed because the Window keeps the engine locked // because it keeps track of syncing right now // lock the drawing engine for as long as we need the clipping // to be valid if (rect.IsValid()/* && drawingEngine->Lock()*/) { drawingEngine->ConstrainClippingRegion(redraw); drawing_mode oldMode; drawingEngine->SetDrawingMode(B_OP_COPY, oldMode); if (fBitmapOptions & B_TILE_BITMAP) { // tile across entire view float start = rect.left; while (rect.top < redraw->Frame().bottom) { while (rect.left < redraw->Frame().right) { drawingEngine->DrawBitmap(fViewBitmap, fBitmapSource, rect, fBitmapOptions); rect.OffsetBy(rect.Width() + 1, 0.0); } rect.OffsetBy(start - rect.left, rect.Height() + 1); } // nothing left to be drawn redraw->MakeEmpty(); } else if (fBitmapOptions & B_TILE_BITMAP_X) { // tile in x direction while (rect.left < redraw->Frame().right) { drawingEngine->DrawBitmap(fViewBitmap, fBitmapSource, rect, fBitmapOptions); rect.OffsetBy(rect.Width() + 1, 0.0); } // remove horizontal stripe from clipping rect.left = redraw->Frame().left; rect.right = redraw->Frame().right; redraw->Exclude(rect); } else if (fBitmapOptions & B_TILE_BITMAP_Y) { // tile in y direction while (rect.top < redraw->Frame().bottom) { drawingEngine->DrawBitmap(fViewBitmap, fBitmapSource, rect, fBitmapOptions); rect.OffsetBy(0.0, rect.Height() + 1); } // remove vertical stripe from clipping rect.top = redraw->Frame().top; rect.bottom = redraw->Frame().bottom; redraw->Exclude(rect); } else { // no tiling at all drawingEngine->DrawBitmap(fViewBitmap, fBitmapSource, rect, fBitmapOptions); redraw->Exclude(rect); } drawingEngine->SetDrawingMode(oldMode); // NOTE: It is ok not to reset the clipping, that // would only waste time // drawingEngine->Unlock(); } } if (fViewColor != B_TRANSPARENT_COLOR) { // fill visible region with view color, // this version of FillRegion ignores any // clipping, that's why "redraw" needs to // be correct // see #634 // if (redraw->Frame().left < 0 || redraw->Frame().top < 0) { // char message[1024]; // BRect c = effectiveClipping->Frame(); // BRect w = windowContentClipping->Frame(); // BRect r = redraw->Frame(); // sprintf(message, "invalid background: current clipping: (%d, %d)->(%d, %d), " // "window content: (%d, %d)->(%d, %d), redraw: (%d, %d)->(%d, %d)", // (int)c.left, (int)c.top, (int)c.right, (int)c.bottom, // (int)w.left, (int)w.top, (int)w.right, (int)w.bottom, // (int)r.left, (int)r.top, (int)r.right, (int)r.bottom); // debugger(message); // } drawingEngine->FillRegion(*redraw, overlayCookie != NULL ? overlayCookie->Color() : fViewColor); } fWindow->RecycleRegion(redraw); } fBackgroundDirty = false; // let children draw if (deep) { for (View* child = FirstChild(); child; child = child->NextSibling()) { child->Draw(drawingEngine, effectiveClipping, windowContentClipping, deep); } } }
Movable *Level::createMovable (XmlFile *file, int type, std::string name, Movable *parent, XMLElement *element, bool createNow) { Movable *objObject = 0; if (type == GOT_ENTITY) { Entity *eEntity = new Entity (name); if (element != 0) eEntity->parseXML (file, element, parent); if (createNow == true) eEntity->create (parent); objObject = eEntity; } if (type == GOT_CAMERA) { Camera *cCamera = new Camera (name); if (element != 0) cCamera->parseXML (file, element, parent); if (createNow == true) cCamera->create (0, parent); objObject = cCamera; } if (type == GOT_PARTICLE_SYSTEM) { ParticleSystem *psSystem = new ParticleSystem (name); if (element != 0) psSystem->parseXML (file, element, parent); if (createNow == true) psSystem->create (parent); objObject = psSystem; } if (type == GOT_LIGHT) { Light *lLight = new Light (name); if (element != 0) lLight->parseXML (file, element, parent); if (createNow == true) lLight->create (parent); objObject = lLight; } if (type == GOT_ANIMATION_TRACK) { AnimationTrackObject *atoObject = new AnimationTrackObject (name); if (element != 0) atoObject->parseXML (file, element, parent); if (createNow == true) atoObject->create (parent); objObject = atoObject; aryAnimations.push_back (atoObject); } if (type == GOT_AUDIO_LISTENER) { AudioListener *alListener = new AudioListener (name); if (element != 0) alListener->parseXML (file, element, parent); if (createNow == true) alListener->create (parent); objObject = alListener; } if (type == GOT_SOUND) { Sound *sSound = new Sound (name); if (element != 0) sSound->parseXML (file, element, parent); if (createNow == true) sSound->create (parent); objObject = sSound; } if (type == GOT_OVERLAY) { Overlay *oOverlay = new Overlay (name); if (element != 0) oOverlay->parseXML (file, element, parent); if (createNow == true) oOverlay->create (parent); aryOverlays.push_back (oOverlay); objObject = oOverlay; } if (type == GOT_OVERLAY_ELEMENT) { OverlayElement *oOverlayElement = new OverlayElement (name); if (element != 0) oOverlayElement->parseXML (file, element, parent); if (createNow == true) oOverlayElement->create (parent); aryOverlayElements.push_back (oOverlayElement); objObject = oOverlayElement; } addMovable (objObject); return (objObject); }
// Just override the mandatory create scene method void createScene(void) { RenderSystem *rs = Root::getSingleton().getRenderSystem(); const RenderSystemCapabilities* caps = rs->getCapabilities(); if (!caps->hasCapability(RSC_VERTEX_PROGRAM) || !(caps->hasCapability(RSC_FRAGMENT_PROGRAM))) { OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "Your card does not support vertex and fragment programs, so cannot " "run this demo. Sorry!", "DeferredShading::createScene"); } if (caps->getNumMultiRenderTargets()<2) { OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "Your card does not support at least two simultaneous render targets, so cannot " "run this demo. Sorry!", "DeferredShading::createScene"); } // Prepare athene mesh for normalmapping MeshPtr pAthene = MeshManager::getSingleton().load("athene.mesh", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); unsigned short src, dest; if (!pAthene->suggestTangentVectorBuildParams(VES_TANGENT, src, dest)) pAthene->buildTangentVectors(VES_TANGENT, src, dest); // Prepare knot mesh for normal mapping pAthene = MeshManager::getSingleton().load("knot.mesh", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); if (!pAthene->suggestTangentVectorBuildParams(VES_TANGENT, src, dest)) pAthene->buildTangentVectors(VES_TANGENT, src, dest); // Set ambient light mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.15)); // Skybox mSceneMgr->setSkyBox(true, "DeferredDemo/SkyBox"); // Create "root" node SceneNode* rootNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); Entity* athena = mSceneMgr->createEntity("Athena", "athene.mesh"); athena->setMaterialName("DeferredDemo/DeferredAthena"); SceneNode *aNode = rootNode->createChildSceneNode(); aNode->attachObject( athena ); aNode->setPosition(-100, 40, 100); // Create a prefab plane mPlane = new MovablePlane("ReflectPlane"); mPlane->d = 0; mPlane->normal = Vector3::UNIT_Y; MeshManager::getSingleton().createCurvedPlane("ReflectionPlane", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, *mPlane, 2000, 2000, -1000, 20, 20, true, 1, 10, 10, Vector3::UNIT_Z); mPlaneEnt = mSceneMgr->createEntity( "Plane", "ReflectionPlane" ); mPlaneNode = rootNode->createChildSceneNode(); mPlaneNode->attachObject(mPlaneEnt); mPlaneNode->translate(-5, -30, 0); //mPlaneNode->roll(Degree(5)); mPlaneEnt->setMaterialName("DeferredDemo/Ground"); // Create an entity from a model (will be loaded automatically) Entity* knotEnt = mSceneMgr->createEntity("Knot", "knot.mesh"); knotEnt->setMaterialName("DeferredDemo/RockWall"); knotEnt->setMeshLodBias(0.25f); // Create an entity from a model (will be loaded automatically) Entity* ogreHead = mSceneMgr->createEntity("Head", "ogrehead.mesh"); ogreHead->getSubEntity(0)->setMaterialName("DeferredDemo/Ogre/Eyes");// eyes ogreHead->getSubEntity(1)->setMaterialName("DeferredDemo/Ogre/Skin"); ogreHead->getSubEntity(2)->setMaterialName("DeferredDemo/Ogre/EarRing"); // earrings ogreHead->getSubEntity(3)->setMaterialName("DeferredDemo/Ogre/Tusks"); // tusks rootNode->createChildSceneNode( "Head" )->attachObject( ogreHead ); // Add a whole bunch of extra entities to fill the scene a bit Entity *cloneEnt; int N=4; for (int n = 0; n < N; ++n) { float theta = 2.0f*Math::PI*(float)n/(float)N; // Create a new node under the root SceneNode* node = mSceneMgr->createSceneNode(); // Random translate Vector3 nodePos; nodePos.x = Math::SymmetricRandom() * 40.0 + Math::Sin(theta) * 500.0; nodePos.y = Math::SymmetricRandom() * 20.0 - 40.0; nodePos.z = Math::SymmetricRandom() * 40.0 + Math::Cos(theta) * 500.0; node->setPosition(nodePos); Quaternion orientation(Math::SymmetricRandom(),Math::SymmetricRandom(),Math::SymmetricRandom(),Math::SymmetricRandom()); orientation.normalise(); node->setOrientation(orientation); rootNode->addChild(node); // Clone knot char cloneName[12]; sprintf(cloneName, "Knot%d", n); cloneEnt = knotEnt->clone(cloneName); // Attach to new node node->attachObject(cloneEnt); } mCamera->setPosition(-50, 100, 500); mCamera->lookAt(0,0,0); // show overlay Overlay* overlay = OverlayManager::getSingleton().getByName("Example/ShadowsOverlay"); overlay->show(); mSystem = new DeferredShadingSystem(mWindow->getViewport(0), mSceneMgr, mCamera); // Create main, moving light MLight* l1 = mSystem->createMLight();//"MainLight"); l1->setDiffuseColour(0.75f, 0.7f, 0.8f); l1->setSpecularColour(0.85f, 0.9f, 1.0f); SceneNode *lightNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); lightNode->attachObject(l1); // Create a track for the light Animation* anim = mSceneMgr->createAnimation("LightTrack", 16); // Spline it for nice curves anim->setInterpolationMode(Animation::IM_SPLINE); // Create a track to animate the camera's node NodeAnimationTrack* track = anim->createNodeTrack(0, lightNode); // Setup keyframes TransformKeyFrame* key = track->createNodeKeyFrame(0); // A start position key->setTranslate(Vector3(300,300,-300)); key = track->createNodeKeyFrame(4);//B key->setTranslate(Vector3(300,300,300)); key = track->createNodeKeyFrame(8);//C key->setTranslate(Vector3(-300,300,300)); key = track->createNodeKeyFrame(12);//D key->setTranslate(Vector3(-300,300,-300)); key = track->createNodeKeyFrame(16);//D key->setTranslate(Vector3(300,300,-300)); // Create a new animation state to track this SharedData::getSingleton().mAnimState = mSceneMgr->createAnimationState("LightTrack"); SharedData::getSingleton().mAnimState->setEnabled(true); // Create some happy little lights createSampleLights(); // safely setup application's (not postfilter!) shared data SharedData::getSingleton().iCamera = mCamera; SharedData::getSingleton().iRoot = mRoot; SharedData::getSingleton().iWindow = mWindow; SharedData::getSingleton().iActivate = true; SharedData::getSingleton().iGlobalActivate = true; SharedData::getSingleton().iSystem = mSystem; SharedData::getSingleton().iMainLight = l1; }
Lock(Overlay& overlay) : overlay(overlay) { overlay.lock(); }
void OverlayPanel::OnEvent(PEvent evt) { int i; switch(evt->EventType()) { case RANGE_SLIDER_UPDATED: //Update Overlay range { //PEvent evt(new EventOverlayRangeChanged(_rangeSlider->Left(), _rangeSlider->Right())); //the_global_frame->Interactor()->VolumeViz()->GetOverlay(_selected)->OnEvent(evt); Overlay *o = _volviz->GetOverlay(_selected).get(); o->SetRange(_rangeSlider->Left(), _rangeSlider->Right()); //NotifyAllListeners(PEvent(new EventOverlayColorChanged(o))); // if this item is the background too, notify quench controller to update the mapping info if ( VPOverlayItem::operator[](_selected)->IsBackground() ) NotifyAllListeners(PEvent(new EventUpdateBackground(1))); NotifyAllListeners(PEvent(new EventUpdateMesh(1))); } break; case BACKGROUND_CHANGED_IN_OVERLAY_ITEM: // deselect the previous selected background image for(i=0; i < (int)VPOverlayItem::size(); i++) if(i != _selected) VPOverlayItem::operator[](i)->SelectBackground(false); // select this one NotifyAllListeners(PEvent(new EventSetBackground(_selected))); //the_global_frame->_qCtrlr->SetBackgroundVolume(_selected); break; case OVERLAY_ITEM_SELECTED: { //the_global_frame->_qCtrlr->UpdateMesh(); EventOverlayItemSelected*e = dynamic_cast<EventOverlayItemSelected*>(evt.get()); size_t i = 0; // figure out the selected selected item for(; i < VPOverlayItem::size(); i++) if(VPOverlayItem::operator[](i).get() == e->Value()) break; // if it is already selected do nothing if(i == VPOverlayItem::size() || i == _selected) return; // if nothing was selected, unselect the last one if(_selected != -1) VPOverlayItem::operator[](_selected)->Select(false); // select the new item _selected = (int)i; VPOverlayItem::operator [](_selected)->Select(true); //Setup Ranges and opacity Overlay *o = _volviz->GetOverlay(_selected).get(); //the_global_frame->Interactor()->VolumeViz()->GetOverlay(_selected).get(); float left,right,min,max; o->Range(left,right,min,max); _rangeSlider->SetMin(min); _rangeSlider->SetMax(max); _rangeSlider->SetLeft(left); _rangeSlider->SetRight(right); m_slider1->SetValue(o->Opacity()*100); NotifyAllListeners(PEvent(new EventUpdateMesh(1))); //the_global_frame->_qCtrlr->UpdateMesh(); //the_global_frame->Refresh(); } } }
/// Shadows config //--------------------------------------------------------------------------------------------------- void App::changeShadows() { QTimer ti; ti.update(); /// time // get settings bool enabled = pSet->shadow_type != 0; bool bDepth = pSet->shadow_type >= 2; bool bSoft = 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(); if (matProfile) { 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); } } 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)]); } materialFactory->setPSSMCameraSetup(pssmSetup); mPSSMSetup.bind(pssmSetup); } mSceneMgr->setShadowCameraSetup(mPSSMSetup); mSceneMgr->setShadowTextureCount(num); for (int i=0; i < num; ++i) { int size = i==0 ? fTex : fTex2; PixelFormat pf; if (bDepth && !bSoft) pf = PF_FLOAT32_R; else if (bSoft) pf = PF_FLOAT16_RGB; else pf = PF_X8B8G8R8; mSceneMgr->setShadowTextureConfig(i, size, size, pf); } mSceneMgr->setShadowTextureSelfShadow(bDepth ? true : false); //-? mSceneMgr->setShadowCasterRenderBackFaces((bDepth && !bSoft) ? true : false); String shadowCasterMat; if (bDepth && !bSoft) shadowCasterMat = "PSSM/shadow_caster"; else if (bSoft) shadowCasterMat = "PSVSM/shadow_caster"; else shadowCasterMat = StringUtil::BLANK; mSceneMgr->setShadowTextureCasterMaterial(shadowCasterMat); 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()); } } materialFactory->setTerrain(terrain); materialFactory->setNumShadowTex(num); materialFactory->setShadows(pSet->shadow_type != 0); materialFactory->setShadowsDepth(bDepth); materialFactory->setShadowsSoft(bSoft); materialFactory->generate(); #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"); TexturePtr tex; for (size_t i = 0; i < 2; ++i) { //TexturePtr tex = mSceneMgr->getShadowTexture(i); if (i == 0) tex = TextureManager::getSingleton().getByName("PlaneReflection"); else tex = TextureManager::getSingleton().getByName("PlaneRefraction"); // 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 // ------------------- 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 //!todo this doesn't work (tree material does not update immediately) 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"); }
/// Shadows config //--------------------------------------------------------------------------------------------------- void CScene::changeShadows() { Ogre::Timer ti; // get settings SETTINGS* pSet = app->pSet; bool enabled = pSet->shadow_type != Sh_None; bool bDepth = pSet->shadow_type >= Sh_Depth; bool bSoft = pSet->shadow_type == Sh_Soft; pSet->shadow_size = std::max(0,std::min(ciShadowSizesNum-1, pSet->shadow_size)); int fTex = ciShadowSizesA[pSet->shadow_size], fTex2 = fTex/2; int num = pSet->shadow_count; sh::Vector4* fade = new sh::Vector4( pSet->shadow_dist, pSet->shadow_dist * 0.6, // fade start 0, 0); sh::Factory* mFactory = app->mFactory; SceneManager* mSceneMgr = app->mSceneMgr; if (terrain) mFactory->setTextureAlias("TerrainLightMap", terrain->getLightmap()->getName()); // disable 4 shadow textures (does not work because no texcoord's left in shader) if (num == 4) num = 3; if (!enabled) mSceneMgr->setShadowTechnique(SHADOWTYPE_NONE); 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 (num == 1) // 1 tex, fast { ShadowCameraSetupPtr mShadowCameraSetup = ShadowCameraSetupPtr(new LiSPSMShadowCameraSetup()); mSceneMgr->setShadowCameraSetup(mShadowCameraSetup); }else { if (mPSSMSetup.isNull()) // pssm { PSSMShadowCameraSetup* pssmSetup = new PSSMShadowCameraSetup(); #ifndef SR_EDITOR pssmSetup->setSplitPadding(app->mSplitMgr->mCameras.front()->getNearClipDistance()); pssmSetup->calculateSplitPoints(num, app->mSplitMgr->mCameras.front()->getNearClipDistance(), mSceneMgr->getShadowFarDistance()); #else pssmSetup->setSplitPadding(app->mCamera->getNearClipDistance()); pssmSetup->calculateSplitPoints(num, app->mCamera->getNearClipDistance(), app->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; PixelFormat pf; if (bDepth && !bSoft) pf = PF_FLOAT32_R; else if (bSoft) pf = PF_FLOAT16_RGB; else pf = PF_X8B8G8R8; mSceneMgr->setShadowTextureConfig(i, size, size, pf); } mSceneMgr->setShadowTextureSelfShadow(bDepth ? true : false); //-? mSceneMgr->setShadowCasterRenderBackFaces((bDepth && !bSoft) ? true : false); mSceneMgr->setShadowTextureCasterMaterial(bDepth ? "shadowcaster_default" : ""); } mSceneMgr->setShadowColour(Ogre::ColourValue(0,0,0,1)); #if 0 /// TEST overlays // add overlay elements to show shadow or terrain maps OverlayManager& mgr = OverlayManager::getSingleton(); Overlay* overlay = mgr.getByName("DebugOverlay"); if (overlay) mgr.destroy(overlay); overlay = mgr.create("DebugOverlay"); TexturePtr tex; #if 0 /// shadow for (int i = 0; i < pSet->shadow_count; ++i) { TexturePtr tex = mSceneMgr->getShadowTexture(i); #else /// terrain for (int i = 0; i < 2/*pSet->shadow_count*/; ++i) { TexturePtr tex = !terrain ? mSceneMgr->getShadowTexture(i) : i==0 ? terrain->getCompositeMap() : terrain->getLightmap(); #endif // 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), rgDef); 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.31); //aspect.. 0.25 0.24 debugPanel->_setDimensions(0.2, 0.3); debugPanel->setMaterialName(debugMat->getName()); debugPanel->show(); overlay->add2D(debugPanel); overlay->show(); } #endif UpdPSSMMaterials(); // rebuild static geom after materials change if (vdrTrack) { vdrTrack->destroy(); vdrTrack->build(); } LogO(String("::: Time Shadows: ") + fToStr(ti.getMilliseconds(),0,3) + " ms"); } /// . . . . . . . . void CScene::UpdPSSMMaterials() { if (app->pSet->shadow_type == Sh_None) return; if (app->pSet->shadow_count == 1) // 1 tex { float dist = app->pSet->shadow_dist; sh::Vector3* splits = new sh::Vector3(dist, 0,0); //dist*2, dist*3); sh::Factory::getInstance().setSharedParameter("pssmSplitPoints", sh::makeProperty<sh::Vector3>(splits)); return; } if (!mPSSMSetup.get()) return; //-- pssm params PSSMShadowCameraSetup* pssmSetup = static_cast<PSSMShadowCameraSetup*>(mPSSMSetup.get()); const PSSMShadowCameraSetup::SplitPointList& sp = pssmSetup->getSplitPoints(); const int last = sp.size()-1; sh::Vector3* splits = new sh::Vector3( sp[std::min(1,last)], sp[std::min(2,last)], sp[std::min(3,last)] ); sh::Factory::getInstance().setSharedParameter("pssmSplitPoints", sh::makeProperty<sh::Vector3>(splits)); }
//--------------------------------------------------------------------- void OverlayManager::parseScript(DataStreamPtr& stream, const String& groupName) { // check if we've seen this script before (can happen if included // multiple times) if (!stream->getName().empty() && mLoadedScripts.find(stream->getName()) != mLoadedScripts.end()) { LogManager::getSingleton().logMessage( "Skipping loading overlay include: '" + stream->getName() + " as it is already loaded."); return; } String line; Overlay* pOverlay = 0; bool skipLine; while(!stream->eof()) { bool isTemplate = false; skipLine = false; line = stream->getLine(); // Ignore comments & blanks if (!(line.length() == 0 || line.substr(0,2) == "//")) { if (line.substr(0,8) == "#include") { std::vector<String> params = StringUtil::split(line, "\t\n ()<>"); DataStreamPtr includeStream = ResourceGroupManager::getSingleton().openResource( params[1], groupName); parseScript(includeStream, groupName); continue; } if (!pOverlay) { // No current overlay // check to see if there is a template if (line.substr(0,8) == "template") { isTemplate = true; } else { // So first valid data should be overlay name pOverlay = create(line); pOverlay->_notifyOrigin(stream->getName()); // Skip to and over next { skipToNextOpenBrace(stream); skipLine = true; } } if ((pOverlay && !skipLine) || isTemplate) { // Already in overlay std::vector<String> params = StringUtil::split(line, "\t\n ()"); if (line == "}") { // Finished overlay pOverlay = 0; isTemplate = false; } else if (parseChildren(stream,line, pOverlay, isTemplate, NULL)) { } else { // Attribute if (!isTemplate) { parseAttrib(line, pOverlay); } } } } } // record as parsed mLoadedScripts.insert(stream->getName()); }
void Templates::load(){ string temp; string file; //read items file = path + "../HQClient/data/items.dat"; ifstream in(file.c_str()); if (!in){ cerr << "Could not load items.dat"; } while (in >> temp){ Item ite; ite.setName(temp); in >> temp; in >> temp; in >> temp; ite.setId((short)toInt(temp)); in >> temp; in >> temp; if (temp == "potion") ite.setType(Item::Potion); else if (temp == "unusable") ite.setType(Item::Unusable); else if (temp == "artifact") ite.setType(Item::Artifact); in >> temp; in >> temp; string desc; while(temp != "/description"){ desc += temp; desc +=" "; in >> temp; } ite.setDescription(desc); items_.push_back(ite); } in.close(); //read armory file = path + "../HQClient/data/armory.dat"; ifstream in2(file.c_str()); if (!in2){ cerr << "Could not load armory.dat"; } while (in2 >> temp){ Item ite; ite.setType(Item::Armory); ite.setName(temp); in2 >> temp; in2 >> temp; in2 >> temp; ite.setId((short)toInt(temp)); in2 >> temp; in2 >> temp; ite.setAdditional(temp); in2 >> temp; in2 >> temp; string desc; while(temp != "/description"){ desc += temp; desc +=" "; in2 >> temp; } ite.setDescription(desc); armory_.push_back(ite); } in2.close(); //read monsters file = path + "../HQClient/data/monsters.dat"; ifstream in3(file.c_str()); if (!in3){ cerr << "Could not load monsters.dat"; } while(in3 >> temp){ Monster m; m.setType(temp); in3 >> temp; in3 >> temp; in3 >> temp; m.setId(toInt(temp)); in3 >> temp; in3 >> temp; if (temp.size() < 2) temp += " "; m.setBrev(temp); in3 >> temp; in3 >> temp; m.setMovement(toInt(temp)); in3 >> temp; in3 >> temp; m.setAttack(toInt(temp)); in3 >> temp; in3 >> temp; m.setDefence(toInt(temp)); in3 >> temp; in3 >> temp; m.setBody(toInt(temp)); m.setMaxBody(toInt(temp)); in3 >> temp; in3 >> temp; m.setMind(toInt(temp)); m.setMaxMind(toInt(temp)); monsterTypes_.push_back(m); } in3.close(); //read spells file = path + "../HQClient/data/spells.dat"; ifstream in4(file.c_str()); if (!in4){ cerr << "Could not load spells.dat"; } while (in4 >> temp){ Item spell; spell.setType(Item::Spell); spell.setName(temp); in4 >> temp; in4 >> temp; in4 >> temp; spell.setId((short)toInt(temp)); in4 >> temp; in4 >> temp; spell.setAdditional(temp); in4 >> temp; in4 >> temp; string desc; while(temp != "/description"){ desc += temp; desc +=" "; in4 >> temp; } spell.setDescription(desc); spells_.push_back(spell); } in4.close(); //read overlays file = path + "../HQClient/data/overlays.dat"; ifstream in5(file.c_str()); if (!in5){ cerr << "Could not load overlays.dat"; } while (in5 >> temp){ Overlay* o = new Overlay(); o->setName(temp); in5 >> temp; in5 >> temp; in5 >> temp; o->setId((short)toInt(temp)); in5 >> temp; in5 >> temp; o->setShort(temp); in5 >> temp; in5 >> temp; o->setWidth((short)toInt(temp)); in5 >> temp; in5 >> temp; o->setHeight((short)toInt(temp)); in5 >> temp; in5 >> temp; if (temp == "yes") o->setWalkable(true); else o->setWalkable(false); in5 >> temp; in5 >> temp; string desc; while(temp != "/description"){ desc += temp; desc +=" "; in5 >> temp; } o->setDescription(desc); overlays_.push_back(o); } in5.close(); //read models file = path + "../HQClient/models/models.dat"; ifstream in6(file.c_str()); if (!in6){ cerr << "Could not load models.dat"; } string name; int idx; int number; in6 >> temp; in6 >> number; for (int i = 0; i < number; i++){ in6 >> name; in6 >> idx; CGE::Mesh* msh = new CGE::Mesh(); #ifdef _CLIENT_ msh->loadFromFile("../HQClient/models/"+name); #endif CGE::Model* mod = new CGE::Model(msh); models_.push_back(mod); } in6.close(); }