void ReplaceTextureOnMaterial(Ogre::MaterialPtr material, const std::string& original_name, const std::string& texture_name) { if (material.isNull()) return; Ogre::TextureManager &tm = Ogre::TextureManager::getSingleton(); Ogre::TexturePtr tex = tm.getByName(texture_name); Ogre::Material::TechniqueIterator iter = material->getTechniqueIterator(); while(iter.hasMoreElements()) { Ogre::Technique *tech = iter.getNext(); assert(tech); Ogre::Technique::PassIterator passIter = tech->getPassIterator(); while(passIter.hasMoreElements()) { Ogre::Pass *pass = passIter.getNext(); Ogre::Pass::TextureUnitStateIterator texIter = pass->getTextureUnitStateIterator(); while(texIter.hasMoreElements()) { Ogre::TextureUnitState *texUnit = texIter.getNext(); if (texUnit->getTextureName() == original_name) { if (tex.get()) texUnit->setTextureName(texture_name); else texUnit->setTextureName("TextureMissing.png"); } } } } }
//------------------------------------------------------------------------------ Background2D::Background2D(): m_AlphaMaxVertexCount( 0 ), m_AddMaxVertexCount( 0 ), m_ScrollEntity( NULL ), m_ScrollPositionStart( Ogre::Vector2::ZERO ), m_ScrollPositionEnd( Ogre::Vector2::ZERO ), m_ScrollType( Background2D::NONE ), m_ScrollSeconds( 0 ), m_ScrollCurrentSeconds( 0 ), m_Position( Ogre::Vector2::ZERO ), m_PositionReal( Ogre::Vector2::ZERO ) ,m_range( Ogre::AxisAlignedBox::BOX_INFINITE ) // for ffvii ,m_virtual_screen_size( 320, 240 ) { m_SceneManager = Ogre::Root::getSingleton().getSceneManager( "Scene" ); m_RenderSystem = Ogre::Root::getSingletonPtr()->getRenderSystem(); CreateVertexBuffers(); m_AlphaMaterial = Ogre::MaterialManager::getSingleton().create( "Background2DAlpha", "General" ); Ogre::Pass* pass = m_AlphaMaterial->getTechnique( 0 )->getPass( 0 ); pass->setVertexColourTracking( Ogre::TVC_AMBIENT ); pass->setCullingMode( Ogre::CULL_NONE ); pass->setDepthCheckEnabled( true ); pass->setDepthWriteEnabled( true ); pass->setLightingEnabled( false ); pass->setSceneBlending( Ogre::SBT_TRANSPARENT_ALPHA ); pass->setAlphaRejectFunction( Ogre::CMPF_GREATER ); pass->setAlphaRejectValue( 0 ); Ogre::TextureUnitState* tex = pass->createTextureUnitState(); tex->setTextureName( "system/blank.png" ); tex->setNumMipmaps( -1 ); tex->setTextureFiltering( Ogre::TFO_NONE ); m_AddMaterial = Ogre::MaterialManager::getSingleton().create( "Background2DAdd", "General" ); pass = m_AddMaterial->getTechnique( 0 )->getPass( 0 ); pass->setVertexColourTracking( Ogre::TVC_AMBIENT ); pass->setCullingMode( Ogre::CULL_NONE ); pass->setDepthCheckEnabled( true ); pass->setDepthWriteEnabled( true ); pass->setLightingEnabled( false ); pass->setSceneBlending( Ogre::SBT_ADD ); pass->setAlphaRejectFunction( Ogre::CMPF_GREATER ); pass->setAlphaRejectValue( 0 ); tex = pass->createTextureUnitState(); tex->setTextureName( "system/blank.png" ); tex->setNumMipmaps( -1 ); tex->setTextureFiltering( Ogre::TFO_NONE ); m_SceneManager->addRenderQueueListener( this ); }
//------------------------------------------------------------------------------ void Background2D::SetImage( const Ogre::String& image ) { Ogre::LogManager::getSingleton().stream() << "Background2D::SetImage " << image; Ogre::Pass* pass = m_AlphaMaterial->getTechnique( 0 )->getPass( 0 ); Ogre::TextureUnitState* tex = pass->getTextureUnitState( 0 ); tex->setTextureName( image ); pass = m_AddMaterial->getTechnique( 0 )->getPass( 0 ); tex = pass->getTextureUnitState( 0 ); tex->setTextureName( image ); }
void SkyDome::setSkyGradientsImage (const Ogre::String& gradients) { Ogre::TextureUnitState* gradientsTus = mMaterial->getTechnique (0)->getPass (0)->getTextureUnitState(0); gradientsTus->setTextureAddressingMode (Ogre::TextureUnitState::TAM_CLAMP); // Per 1.4 compatibility. Not tested with recent svn. #if OGRE_VERSION < ((1 << 16) | (3 << 8)) gradientsTus->setTextureName (gradients, Ogre::TEX_TYPE_2D, -1, true); #else gradientsTus->setTextureName (gradients, Ogre::TEX_TYPE_2D); gradientsTus->setIsAlpha (true); #endif }
bool Simple::compileMaterial(Ogre::MaterialPtr material, std::set<std::string>& managedTextures) const { material->removeAllTechniques(); Ogre::Technique* technique = material->createTechnique(); if (!mTerrainPageSurfaces.empty()) { //First add a base pass auto surfaceLayer = mTerrainPageSurfaces.begin()->second; Ogre::Pass* pass = technique->createPass(); pass->setLightingEnabled(false); Ogre::TextureUnitState * textureUnitState = pass->createTextureUnitState(); textureUnitState->setTextureScale(1.0f / surfaceLayer->getScale(), 1.0f / surfaceLayer->getScale()); textureUnitState->setTextureName(surfaceLayer->getDiffuseTextureName()); textureUnitState->setTextureCoordSet(0); for (auto& layer : mLayers) { addPassToTechnique(*mGeometry, technique, layer, managedTextures); } } if (mTerrainPageShadow) { addShadow(technique, mTerrainPageShadow, material, managedTextures); } // addLightingPass(technique, managedTextures); material->load(); if (material->getNumSupportedTechniques() == 0) { S_LOG_WARNING("The material '" << material->getName() << "' has no supported techniques. The reason for this is: \n" << material->getUnsupportedTechniquesExplanation()); return false; } return true; }
Ogre::MaterialPtr TextureManager::makeOgreMaterial(int16_t MaterialTypeID, int16_t TextureID) { Ogre::MaterialPtr NewMaterial = Ogre::MaterialManager::getSingleton().create("GrassMaterial", "General", true); Ogre::Image* NewImage = new Ogre::Image(); // Delete? uint16_t ImageID = IMAGE->GenerateMaterialImage(MaterialTypeID, TextureID); uint8_t* iData = IMAGE->getImageData(ImageID); uint16_t Width = IMAGE->getImageWidth(ImageID); uint16_t Height = IMAGE->getImageHeight(ImageID); NewImage->loadDynamicImage(iData, Width, Height, Ogre::PF_A8R8G8B8); Ogre::TexturePtr NewTex = Ogre::TextureManager::getSingleton().loadImage("TextureX", "General", *NewImage, Ogre::TEX_TYPE_2D, 1); Ogre::Technique* FirstTechnique = NewMaterial->getTechnique(0); Ogre::Pass* FirstPass = FirstTechnique->getPass(0); FirstPass->setLightingEnabled(false); Ogre::TextureUnitState* TextureUnit = FirstPass->createTextureUnitState(); TextureUnit->setTextureName("TextureX", Ogre::TEX_TYPE_2D); delete NewImage; return NewMaterial; }
bool Simple::compileMaterial(Ogre::MaterialPtr material) { material->removeAllTechniques(); Ogre::Technique* technique = material->createTechnique(); for (SurfaceLayerStore::const_iterator I = mTerrainPageSurfaces.begin(); I != mTerrainPageSurfaces.end(); ++I) { const TerrainPageSurfaceLayer* surfaceLayer = I->second; if (I == mTerrainPageSurfaces.begin()) { Ogre::Pass* pass = technique->createPass(); pass->setLightingEnabled(false); //add the first layer of the terrain, no alpha or anything Ogre::TextureUnitState * textureUnitState = pass->createTextureUnitState(); textureUnitState->setTextureScale(1.0f / surfaceLayer->getScale(), 1.0f / surfaceLayer->getScale()); textureUnitState->setTextureName(surfaceLayer->getDiffuseTextureName()); textureUnitState->setTextureCoordSet(0); } else { if (surfaceLayer->intersects(*mGeometry)) { addPassToTechnique(*mGeometry, technique, surfaceLayer); } } } if (mTerrainPageShadow) { addShadow(technique, mTerrainPageShadow, material); } material->load(); if (material->getNumSupportedTechniques() == 0) { S_LOG_WARNING("The material '" << material->getName() << "' has no supported techniques. The reason for this is: \n" << material->getUnsupportedTechniquesExplanation()); return false; } return true; }
void ImageDisplay::onInitialize() { ImageDisplayBase::onInitialize(); { static uint32_t count = 0; std::stringstream ss; ss << "ImageDisplay" << count++; img_scene_manager_ = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC, ss.str()); } img_scene_node_ = img_scene_manager_->getRootSceneNode()->createChildSceneNode(); { static int count = 0; std::stringstream ss; ss << "ImageDisplayObject" << count++; screen_rect_ = new Ogre::Rectangle2D(true); screen_rect_->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY - 1); screen_rect_->setCorners(-1.0f, 1.0f, 1.0f, -1.0f); ss << "Material"; material_ = Ogre::MaterialManager::getSingleton().create( ss.str(), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME ); material_->setSceneBlending( Ogre::SBT_REPLACE ); material_->setDepthWriteEnabled(false); material_->setReceiveShadows(false); material_->setDepthCheckEnabled(false); material_->getTechnique(0)->setLightingEnabled(false); Ogre::TextureUnitState* tu = material_->getTechnique(0)->getPass(0)->createTextureUnitState(); tu->setTextureName(texture_.getTexture()->getName()); tu->setTextureFiltering( Ogre::TFO_NONE ); material_->setCullingMode(Ogre::CULL_NONE); Ogre::AxisAlignedBox aabInf; aabInf.setInfinite(); screen_rect_->setBoundingBox(aabInf); screen_rect_->setMaterial(material_->getName()); img_scene_node_->attachObject(screen_rect_); } render_panel_ = new RenderPanel(); render_panel_->getRenderWindow()->setAutoUpdated(false); render_panel_->getRenderWindow()->setActive( false ); render_panel_->resize( 640, 480 ); render_panel_->initialize(img_scene_manager_, context_); setAssociatedWidget( render_panel_ ); render_panel_->setAutoRender(false); render_panel_->setOverlaysEnabled(false); render_panel_->getCamera()->setNearClipDistance( 0.01f ); updateNormalizeOptions(); }
//-------------------------------------------------------------------------------- static void setTextureAndTexAniFPS(const MaterialPtr& _material, const String& _texture, Real _texAniFPS) { Technique* technique = _material->getTechnique(0); Pass* pass = technique->getPass(0); if(_texture.empty()) { pass->removeAllTextureUnitStates(); } else { TextureManager& tmgr = TextureManager::getSingleton(); Ogre::TextureUnitState* tus = pass->getNumTextureUnitStates() ? pass->getTextureUnitState(0) : pass->createTextureUnitState(); if(_texAniFPS == 0) { TexturePtr ogreTexture = tmgr.createOrRetrieve(_texture).first; const String& ogreTexName = ogreTexture->getName(); tus->setTextureName(ogreTexName); } else { vector<String>::type ogreTexNames; TexturePtr ogreTexture = tmgr.createOrRetrieve(_texture).first; ogreTexNames.push_back(ogreTexture->getName()); size_t dotpos = _texture.rfind('.'); if(dotpos != String::npos && dotpos >= 1 && '0' <= _texture[dotpos-1] && _texture[dotpos-1] < '9') { String tmpname = _texture; char& dig0 = tmpname[dotpos - 1]; ++dig0; while(!tmgr.getByName(tmpname).isNull() || tmgr.canLoadResource(tmpname, TextureManager::GROUP_NAME)) { TexturePtr ogreTexture = tmgr.createOrRetrieve(tmpname).first; ogreTexNames.push_back(ogreTexture->getName()); ++dig0; if(dig0 > '9') { if(dotpos >= 2 && '0' <= _texture[dotpos-2] && _texture[dotpos-2] < '9') { char& dig1 = tmpname[dotpos-2]; ++dig1; dig0 = '0'; } else break; } } } Real duration = ogreTexNames.size() / _texAniFPS; tus->setAnimatedTextureName(&ogreTexNames[0], ogreTexNames.size(), duration); } } }
void SkyDome::setAtmosphereDepthImage (const Ogre::String& atmosphereDepth) { if (!mShadersEnabled) { return; } Ogre::TextureUnitState* atmosphereTus = mMaterial->getTechnique (0)->getPass (0)->getTextureUnitState(1); atmosphereTus->setTextureName (atmosphereDepth, Ogre::TEX_TYPE_1D); atmosphereTus->setTextureAddressingMode (Ogre::TextureUnitState::TAM_CLAMP, Ogre::TextureUnitState::TAM_WRAP, Ogre::TextureUnitState::TAM_WRAP); }
void EffectManager::addEffect(const std::string &model, std::string textureOverride, const Ogre::Vector3 &worldPosition, float scale) { Ogre::SceneNode* sceneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(worldPosition); sceneNode->setScale(scale,scale,scale); // fix texture extension to .dds if (textureOverride.size() > 4) { textureOverride[textureOverride.size()-3] = 'd'; textureOverride[textureOverride.size()-2] = 'd'; textureOverride[textureOverride.size()-1] = 's'; } NifOgre::ObjectScenePtr scene = NifOgre::Loader::createObjects(sceneNode, model); // TODO: turn off shadow casting MWRender::Animation::setRenderProperties(scene, RV_Misc, RQG_Main, RQG_Alpha, 0.f, false, NULL); for(size_t i = 0;i < scene->mControllers.size();i++) { if(scene->mControllers[i].getSource().isNull()) scene->mControllers[i].setSource(Ogre::SharedPtr<EffectAnimationTime> (new EffectAnimationTime())); } if (!textureOverride.empty()) { for(size_t i = 0;i < scene->mParticles.size(); ++i) { Ogre::ParticleSystem* partSys = scene->mParticles[i]; Ogre::MaterialPtr mat = scene->mMaterialControllerMgr.getWritableMaterial(partSys); for (int t=0; t<mat->getNumTechniques(); ++t) { Ogre::Technique* tech = mat->getTechnique(t); for (int p=0; p<tech->getNumPasses(); ++p) { Ogre::Pass* pass = tech->getPass(p); for (int tex=0; tex<pass->getNumTextureUnitStates(); ++tex) { Ogre::TextureUnitState* tus = pass->getTextureUnitState(tex); tus->setTextureName("textures\\" + textureOverride); } } } } } mEffects.push_back(std::make_pair(sceneNode, scene)); }
//---------------------------------------------------------------------------------------- QImage ImageConverter::_imageFromRenderTarget(const Ogre::Image& img) { Ogre::TextureManager::getSingletonPtr()->loadImage("QTTextureName", "QTImageConverter", img); // create our material Ogre::MaterialPtr material = Ogre::MaterialManager::getSingletonPtr()->create("terrainMaterial", "QTImageConverter"); Ogre::Technique * technique = material->getTechnique(0); Ogre::Pass* pass = technique->getPass(0); Ogre::TextureUnitState* textureUnit = pass->createTextureUnitState(); textureUnit->setTextureName("QTTextureName"); return _getRenderTarget(material->getName()); }
//------------------------------------------------------------------------------------- void BasicTutorial2::createScene(void) { mSceneMgr->setAmbientLight(Ogre::ColourValue(0, 0, 0)); //mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE); //Create cube //Create a basic green color texture Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create("BoxColor", "General", true ); Ogre::Technique* tech = mat->getTechnique(0); Ogre::Pass* pass = tech->getPass(0); Ogre::TextureUnitState* tex = pass->createTextureUnitState(); tex->setTextureName("grassTexture.png"); //tex->setNumMipmaps(4); tex->setTextureAnisotropy(1); tex->setTextureFiltering(Ogre::FO_POINT, Ogre::FO_POINT, Ogre::FO_POINT); //Create the one box and the supporting class objects Ogre::ManualObject* testBox = createCubeMesh("TestBox1", "BoxColor"); Ogre::SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); Ogre::MeshPtr Mesh = testBox->convertToMesh("TestBox2"); Ogre::StaticGeometry* pGeom = new Ogre::StaticGeometry (mSceneMgr, "Boxes"); Ogre::Entity* pEnt = mSceneMgr->createEntity("TestBox2"); //testBox->triangle pGeom->setRegionDimensions(Ogre::Vector3(300, 300, 300)); World::Instance(); pGeom->build (); mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5)); Ogre::Light* l = mSceneMgr->createLight("MainLight"); l->setPosition(20,80,50); //Create Cube /* Ogre::Entity* entNinja = mSceneMgr->createEntity("Ninja", "ninja.mesh"); entNinja->setCastShadows(true); mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entNinja);*/ Ogre::Light* directionalLight = mSceneMgr->createLight("directionalLight"); directionalLight->setType(Ogre::Light::LT_DIRECTIONAL); directionalLight->setDiffuseColour(Ogre::ColourValue(.25, .25, 0)); directionalLight->setSpecularColour(Ogre::ColourValue(.25, .25, 0)); directionalLight->setDirection(Ogre::Vector3( 0, -1, 1 )); }
void IntroState::createScene() { MaterialPtr material = MaterialManager::getSingleton().create("Background", "General"); material->getTechnique(0)->getPass(0)->createTextureUnitState("rockwall.tga"); material->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false); material->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false); material->getTechnique(0)->getPass(0)->setLightingEnabled(false); //Ustvarimo 2D kvadrat, ki prekrije celonti ekrat Rectangle2D* rect = new Rectangle2D(true); rect->setCorners(-1.0, 1.0, 1.0, -1.0); rect->setMaterial("Background"); //najprej renderiramo ozadje potem pa vse ostalo rect->setRenderQueueGroup(RENDER_QUEUE_BACKGROUND); rect->setBoundingBox(AxisAlignedBox(-100000.0*Ogre::Vector3::UNIT_SCALE, 100000.0*Ogre::Vector3::UNIT_SCALE)); // pripnemo teksturo na ozadje SceneNode* node = m_pSceneMgr->getRootSceneNode()->createChildSceneNode("Background"); node->attachObject(rect); Ogre::MaterialPtr mat; Ogre::TextureUnitState* tex; Ogre::String materialName="Background"; if (!Ogre::MaterialManager::getSingleton().resourceExists(materialName)) { throw("Error, material doesn't exist!"); } //tukaj prilepimo film na prej ustvarjeno teksturo mat=Ogre::MaterialManager::getSingleton().getByName(materialName); tex=mat->getTechnique(0)->getPass(0)->getTextureUnitState(0); tex->setTextureName(dshowMovieTextureSystem->getMovieTexture()->getName()); mTitleLabel->setCaption("Intro"); mTitleLabel->show(); mTitleLabel2->setCaption("Press ESC to Exit Game!"); mTitleLabel2->show(); mTitleLabel3->setCaption("Press Space to skip!"); mTitleLabel3->show(); }
void Simple::addShadow(Ogre::Technique* technique, const TerrainPageShadow* terrainPageShadow, Ogre::MaterialPtr material, std::set<std::string>& managedTextures) const { Ogre::Pass* shadowPass = technique->createPass(); shadowPass->setSceneBlending(Ogre::SBT_MODULATE); shadowPass->setLightingEnabled(false); // shadowPass->setFog(true, Ogre::FOG_NONE); Ogre::TextureUnitState * textureUnitStateSplat = shadowPass->createTextureUnitState(); Ogre::TexturePtr texture = updateShadowTexture(material, terrainPageShadow, managedTextures); textureUnitStateSplat->setTextureName(texture->getName()); textureUnitStateSplat->setTextureCoordSet(0); textureUnitStateSplat->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP); textureUnitStateSplat->setTextureFiltering(Ogre::TFO_ANISOTROPIC); }
void CubeWorld::createTexture (const TCHAR* pName, const TCHAR* pImageFilename) { Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create(pName, "General", true ); Ogre::Technique* tech = mat->getTechnique(0); Ogre::Pass* pass = tech->getPass(0); Ogre::TextureUnitState* tex = pass->createTextureUnitState(); tex->setTextureName(pImageFilename); tex->setNumMipmaps(4); tex->setTextureAnisotropy(1); tex->setTextureFiltering(Ogre::FO_POINT, Ogre::FO_POINT, Ogre::FO_POINT); pass->setVertexColourTracking(Ogre::TVC_DIFFUSE); tex->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_DIFFUSE, Ogre::LBS_TEXTURE); tech->setLightingEnabled(false); }
void OgreCursor::setImage(const std::string& filename) { //std::cerr << __PRETTY_FUNCTION__ << filename << std::endl; _texture = Ogre::TextureManager::getSingleton().load(filename, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); //"General" Ogre::TextureUnitState *pTexState; if (_material->getTechnique(0)->getPass(0)->getNumTextureUnitStates()) { pTexState = _material->getTechnique(0)->getPass(0)->getTextureUnitState(0); } else { pTexState = _material->getTechnique(0)->getPass(0)->createTextureUnitState(_texture->getName()); } pTexState->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP); pTexState->setTextureName(filename); _material->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA); }
void RenderWindow::CreateRenderTargetOverlay(int width, int height) { width = max(1, width); height = max(1, height); Ogre::TexturePtr renderTarget = Ogre::TextureManager::getSingleton().createManual( rttTextureName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, width, height, 0, Ogre::PF_A8R8G8B8, Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE); Ogre::MaterialPtr rttMaterial = Ogre::MaterialManager::getSingleton().create( rttMaterialName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); Ogre::TextureUnitState *rttTuState = rttMaterial->getTechnique(0)->getPass(0)->createTextureUnitState(); rttTuState->setTextureName(rttTextureName); rttTuState->setTextureFiltering(Ogre::TFO_NONE); rttTuState->setNumMipmaps(1); rttTuState->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP); rttMaterial->setFog(true, Ogre::FOG_NONE); ///\todo Check, shouldn't here be false? rttMaterial->setReceiveShadows(false); rttMaterial->setTransparencyCastsShadows(false); rttMaterial->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBF_SOURCE_ALPHA, Ogre::SBF_ONE_MINUS_SOURCE_ALPHA); rttMaterial->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false); rttMaterial->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false); rttMaterial->getTechnique(0)->getPass(0)->setLightingEnabled(false); rttMaterial->getTechnique(0)->getPass(0)->setCullingMode(Ogre::CULL_NONE); overlayContainer = Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "MainWindow Overlay Panel"); overlayContainer->setMaterialName(rttMaterialName); overlayContainer->setMetricsMode(Ogre::GMM_PIXELS); overlayContainer->setPosition(0, 0); overlayContainer->setDimensions((Ogre::Real)width, (Ogre::Real)height); overlayContainer->setPosition(0,0); overlay = Ogre::OverlayManager::getSingleton().create("MainWindow Overlay"); overlay->add2D(static_cast<Ogre::OverlayContainer *>(overlayContainer)); overlay->setZOrder(500); overlay->show(); // ResizeOverlay(width, height); }
Ogre::MaterialPtr AssetLoader::createMaterial(Ogre::String name, int index, aiMaterial* mat) { Ogre::MaterialManager* omatMgr = Ogre::MaterialManager::getSingletonPtr(); std::ostringstream matname; matname << name.data() << "_mat"; matname.widen(4); matname.fill('0'); matname << index; Ogre::String matName = matname.str(); Ogre::ResourceManager::ResourceCreateOrRetrieveResult status = omatMgr->createOrRetrieve(matName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true); Ogre::MaterialPtr omat = status.first; aiColor4D clr(1.0, 1.0, 1.0, 1.0); aiGetMaterialColor(mat, AI_MATKEY_COLOR_DIFFUSE, &clr); omat->getTechnique(0)->getPass(0)->setDiffuse(clr.r, clr.g, clr.b, clr.a); aiGetMaterialColor(mat, AI_MATKEY_COLOR_SPECULAR, &clr); omat->getTechnique(0)->getPass(0)->setSpecular(clr.r, clr.g, clr.b, clr.a); aiGetMaterialColor(mat, AI_MATKEY_COLOR_AMBIENT, &clr); omat->getTechnique(0)->getPass(0)->setAmbient(clr.r, clr.g, clr.b); aiGetMaterialColor(mat, AI_MATKEY_COLOR_EMISSIVE, &clr); omat->getTechnique(0)->getPass(0)->setSelfIllumination(clr.r, clr.g, clr.b); omat->getTechnique(0)->getPass(0)->setShadingMode(Ogre::SO_GOURAUD); omat->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA); omat->getTechnique(0)->getPass(0)->setLightingEnabled(true); omat->getTechnique(0)->getPass(0)->setDepthCheckEnabled(true); //omat->getTechnique(0)->getPass(0)->setVertexColourTracking(Ogre::TVC_DIFFUSE); aiString path; aiReturn res = mat->GetTexture(aiTextureType_DIFFUSE, 0, &path); if (res == AI_SUCCESS) { Ogre::TextureUnitState* stateBase = omat->getTechnique(0)->getPass(0)->createTextureUnitState(); stateBase->setColourOperation(Ogre::LBO_MODULATE); stateBase->setTextureName(path.data); } return omat; }
void GraphicsController::_attachTextureToMaterials(const Ogre::String &textureUnitName, Ogre::TexturePtr texturePtr, const std::vector<Ogre::String> materialNames) { //for(auto iter = materialNames.cbegin(); iter != materialNames.cend(); ++iter) for(const Ogre::String &materialName : materialNames) { Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(materialName); Ogre::String errorMessage("This material "); errorMessage += materialName + " was not found."; if(mat.isNull()) { OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS, errorMessage, "GraphicsController::_attachTextureToMaterials"); } Ogre::TextureUnitState* txUnit = mat->getTechnique(0)->getPass(0)->getTextureUnitState(textureUnitName); if(!txUnit) OGRE_EXCEPT(Ogre::Exception::ERR_ITEM_NOT_FOUND, textureUnitName + " was not found", "GraphicsController::_attachTextureToMaterials"); txUnit->setTextureName(texturePtr->getName()); } }
void Simple::addLightingPass(Ogre::Technique* technique, std::set<std::string>& managedTextures) const { Ogre::Pass* lightingPass = technique->createPass(); lightingPass->setSceneBlending(Ogre::SBT_MODULATE); lightingPass->setLightingEnabled(false); Ogre::TextureUnitState * textureUnitStateSplat = lightingPass->createTextureUnitState(); //we need an unique name for our alpha texture std::stringstream lightingTextureNameSS; lightingTextureNameSS << technique->getParent()->getName() << "_lighting"; const Ogre::String lightingTextureName(lightingTextureNameSS.str()); Ogre::TexturePtr texture = static_cast<Ogre::TexturePtr>(Ogre::Root::getSingletonPtr()->getTextureManager()->getByName(lightingTextureName)); if (texture.isNull()) { texture = Ogre::Root::getSingletonPtr()->getTextureManager()->createManual(lightingTextureName, "General", Ogre::TEX_TYPE_2D, mPage.getBlendMapSize(), mPage.getBlendMapSize(), 1, Ogre::PF_L8, Ogre::TU_DYNAMIC_WRITE_ONLY); managedTextures.insert(texture->getName()); } Ogre::Image ogreImage; ogreImage.loadDynamicImage(const_cast<unsigned char*>(mLightingImage->getData()), mLightingImage->getResolution(), mLightingImage->getResolution(), 1, Ogre::PF_L8); texture->loadImage(ogreImage); //blit the whole image to the hardware buffer Ogre::PixelBox sourceBox(ogreImage.getPixelBox()); //blit for each mipmap for (unsigned int i = 0; i <= texture->getNumMipmaps(); ++i) { Ogre::HardwarePixelBufferSharedPtr hardwareBuffer(texture->getBuffer(0, i)); hardwareBuffer->blitFromMemory(sourceBox); } textureUnitStateSplat->setTextureName(texture->getName()); textureUnitStateSplat->setTextureCoordSet(0); textureUnitStateSplat->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP); textureUnitStateSplat->setTextureFiltering(Ogre::TFO_ANISOTROPIC); }
void CubeWorld::createSkyTexture(const TCHAR* pName) { Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create(pName, "General", true); Ogre::Technique* tech = mat->getTechnique(0); Ogre::Pass* pass = tech->getPass(0); Ogre::TextureUnitState* tex = pass->createTextureUnitState(); pass->setLightingEnabled(false); pass->setDepthCheckEnabled(false); pass->setDepthWriteEnabled(false); pass->setFog(true); tex->setTextureName("clouds.jpg"); tex->setScrollAnimation(0.05, 0); // This is a new texture state to simulate lightning tex = pass->createTextureUnitState(); tex->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, Ogre::ColourValue(1, 1, 1)); m_SkyMaterial = mat; updateSkyTextureLight(); }
void InputHandler::setUpMoive() { dshowMovieTextureSystem = new OgreUtils::DirectShowMovieTexture(mWindow->getWidth(), mWindow->getHeight()); Ogre::Vector2 v = dshowMovieTextureSystem->getMovieDimensions(); char c[100]; sprintf(c, "w:%d,h:%d", mWindow->getWidth(), mWindow->getHeight()); debug->setText4(c); Ogre::String movieName="Content/new2.avi"; panelGUIMV=static_cast<OverlayContainer*>(olmGUIBG->createOverlayElement("Panel","TextPanelGUIMV")); panelGUIMV->setMetricsMode(Ogre::GMM_RELATIVE); // Use relative dimensions for positions, size, etc //panelGUI->setPosition(.,.2); // Panel starts at 20$ to the right, and 20% down from the top panelGUIMV->setDimensions(1.0f, 1.0f); // Panel is half the width and half the height of the screen panelGUIMV->setMaterialName("myMoive"); // Give the panel a background material. overlayGUIBG->add2D(panelGUIMV); // Add our panel to the overlay Ogre::String materialName="myMoive"; if (!Ogre::MaterialManager::getSingleton().resourceExists(materialName)) { throw("Error, material doesn't exist!"); } Ogre::MaterialPtr mat; Ogre::TextureUnitState* tex; mat=Ogre::MaterialManager::getSingleton().getByName(materialName); tex=mat->getTechnique(0)->getPass(0)->getTextureUnitState(0); tex->setTextureName(dshowMovieTextureSystem->getMovieTexture()->getName()); dshowMovieTextureSystem->loadMovie(movieName); dshowMovieTextureSystem->playMovie(); //OgreUtils::DirectShowManager::getSingleton().createDirectshowControl("videotest","../../Content/new2.mpg",mWindow->getWidth(),mWindow->getHeight()); //Ogre::Root::getSingletonPtr()->addFrameListener(new OgreUtils::DirectShowManager(vp)); }
void IntroState::exit() { OgreFramework::getSingletonPtr()->m_pLog->logMessage("Leaving IntroState..."); m_pSceneMgr->destroyCamera(m_pCamera); if(m_pSceneMgr) OgreFramework::getSingletonPtr()->m_pRoot->destroySceneManager(m_pSceneMgr); dshowMovieTextureSystem->stopMovie(); OgreFramework::getSingletonPtr()->m_pTrayMgr->clearAllTrays(); OgreFramework::getSingletonPtr()->m_pTrayMgr->destroyAllWidgets(); OgreFramework::getSingletonPtr()->m_pTrayMgr->setListener(0); Ogre::String materialName="MyMaterial"; if (Ogre::MaterialManager::getSingleton().resourceExists(materialName)) { Ogre::MaterialPtr mat; Ogre::TextureUnitState* tex; mat=Ogre::MaterialManager::getSingleton().getByName(materialName); tex=mat->getTechnique(0)->getPass(0)->getTextureUnitState(0); tex->setTextureName(Ogre::String("")); } delete dshowMovieTextureSystem; }
//----------------------------------------------------------------------- bool RTShaderSRSSegmentedLights::preAddToRenderState(const RenderState* renderState, Pass* srcPass, Pass* dstPass) { if (srcPass->getLightingEnabled() == false) return false; mUseSegmentedLightTexture = SegmentedDynamicLightManager::getSingleton().isActive(); setTrackVertexColourType(srcPass->getVertexColourTracking()); if (srcPass->getShininess() > 0.0 && srcPass->getSpecular() != ColourValue::Black) { setSpecularEnable(true); } else { setSpecularEnable(false); } int lightCount[3]; renderState->getLightCount(lightCount); setLightCount(lightCount); if (mUseSegmentedLightTexture) { const_cast<RenderState*>(renderState)->setLightCountAutoUpdate(false); Ogre::TextureUnitState* pLightTexture = dstPass->createTextureUnitState(); pLightTexture->setTextureName(SegmentedDynamicLightManager::getSingleton().getSDLTextureName(), Ogre::TEX_TYPE_2D); pLightTexture->setTextureFiltering(Ogre::TFO_NONE); mLightSamplerIndex = dstPass->getNumTextureUnitStates() - 1; } return true; }
//----------------------------------------------------------------------- void RTShaderSRSSegmentedLights::updateGpuProgramsParams(Renderable* rend, Pass* pass, const AutoParamDataSource* source, const LightList* pLightList) { if ((mLightParamsList.empty()) && (!mUseSegmentedLightTexture)) return; const Matrix4& matWorld = source->getWorldMatrix(); Light::LightTypes curLightType = Light::LT_DIRECTIONAL; unsigned int curSearchLightIndex = 0; //update spot strength float spotIntensity = 1; // Update per light parameters. for (unsigned int i=0; i < mLightParamsList.size(); ++i) { const LightParams& curParams = mLightParamsList[i]; if (curLightType != curParams.mType) { curLightType = curParams.mType; curSearchLightIndex = 0; } Light* srcLight = NULL; Vector4 vParameter; ColourValue colour; // Search a matching light from the current sorted lights of the given renderable. for (unsigned int j = curSearchLightIndex; j < pLightList->size(); ++j) { if (pLightList->at(j)->getType() == curLightType) { srcLight = pLightList->at(j); curSearchLightIndex = j + 1; break; } } // No matching light found -> use a blank dummy light for parameter update. if (srcLight == NULL) { srcLight = &msBlankLight; } switch (curParams.mType) { case Light::LT_DIRECTIONAL: // Update light direction. vParameter = matWorld.transformAffine(srcLight->getAs4DVector(true)); curParams.mDirection->setGpuParameter(vParameter.ptr(),3,1); break; case Light::LT_POINT: // Update light position. vParameter = matWorld.transformAffine(srcLight->getAs4DVector(true)); curParams.mPosition->setGpuParameter(vParameter.ptr(),3,1); // Update light attenuation parameters. curParams.mSpotParams->setGpuParameter(Ogre::Vector3(1 / srcLight->getAttenuationRange(),0,0)); break; case Light::LT_SPOTLIGHT: { Ogre::Vector3 vec3; Ogre::Matrix3 matWorldIT; // Update light position. vParameter = matWorld.transformAffine(srcLight->getAs4DVector(true)); curParams.mPosition->setGpuParameter(vParameter.ptr(),3,1); // Update light direction. source->getInverseTransposeWorldMatrix().extract3x3Matrix(matWorldIT); vec3 = matWorldIT * srcLight->getDerivedDirection(); vec3.normalise(); vParameter.x = -vec3.x; vParameter.y = -vec3.y; vParameter.z = -vec3.z; vParameter.w = 0.0; curParams.mDirection->setGpuParameter(vParameter.ptr(),3,1); // Update spotlight parameters. Real phi = Math::Cos(srcLight->getSpotlightOuterAngle().valueRadians() * 0.5f); Real theta = Math::Cos(srcLight->getSpotlightInnerAngle().valueRadians() * 0.5f); vec3.x = 1 / srcLight->getAttenuationRange(); vec3.y = phi; vec3.z = 1 / (theta - phi); curParams.mSpotParams->setGpuParameter(vec3); } break; } float lightIntensity = 1; if (curParams.mType == Light::LT_SPOTLIGHT) { lightIntensity = spotIntensity; } // Update diffuse colour. colour = srcLight->getDiffuseColour() * lightIntensity; if ((mTrackVertexColourType & TVC_DIFFUSE) == 0) { colour = colour * pass->getDiffuse(); } curParams.mDiffuseColour->setGpuParameter(colour.ptr(),3,1); // Update specular colour if need to. if ((mSpecularEnable) && (curParams.mType == Light::LT_DIRECTIONAL)) { // Update diffuse colour. colour = srcLight->getSpecularColour() * lightIntensity; if ((mTrackVertexColourType & TVC_SPECULAR) == 0) { colour = colour * pass->getSpecular(); } curParams.mSpecularColour->setGpuParameter(colour.ptr(),3,1); } } if (mUseSegmentedLightTexture) { unsigned int indexStart = 0, indexEnd = 0; Ogre::Vector4 lightBounds; SegmentedDynamicLightManager::getSingleton().getLightListRange(rend, lightBounds, indexStart, indexEnd); mPSLightTextureIndexLimit->setGpuParameter(Ogre::Vector2((Ogre::Real)indexStart, (Ogre::Real)indexEnd)); mPSLightTextureLightBounds->setGpuParameter(lightBounds); Ogre::TextureUnitState* pLightTexture = pass->getTextureUnitState(mLightSamplerIndex); const Ogre::String& textureName = SegmentedDynamicLightManager::getSingleton().getSDLTextureName(); if (textureName != pLightTexture->getTextureName()) { pLightTexture->setTextureName(textureName, Ogre::TEX_TYPE_2D); } } }
Ogre::MaterialPtr OgreMaterialProperties::ToOgreMaterial() { // Make clone from the original and uset that for creating the new material. Ogre::MaterialPtr matPtr = material_->GetMaterial(); Ogre::MaterialPtr matPtrClone = matPtr->clone(objectName().toStdString() + "Clone"); // Material if (!matPtrClone.isNull()) { // Technique Ogre::Material::TechniqueIterator tIter = matPtrClone->getTechniqueIterator(); while(tIter.hasMoreElements()) { Ogre::Technique *tech = tIter.getNext(); Ogre::Technique::PassIterator pIter = tech->getPassIterator(); while(pIter.hasMoreElements()) { // Pass Ogre::Pass *pass = pIter.getNext(); if (!pass) continue; if (pass->hasVertexProgram()) { // Vertex program const Ogre::GpuProgramPtr &verProg = pass->getVertexProgram(); if (!verProg.isNull()) { Ogre::GpuProgramParametersSharedPtr verPtr = pass->getVertexProgramParameters(); if (verPtr->hasNamedParameters()) { // Named parameters (constants) Ogre::GpuConstantDefinitionIterator mapIter = verPtr->getConstantDefinitionIterator(); int constNum = 0; while(mapIter.hasMoreElements()) { QString paramName(mapIter.peekNextKey().c_str()); const Ogre::GpuConstantDefinition ¶mDef = mapIter.getNext(); // Filter names that end with '[0]' if (paramName.lastIndexOf("[0]") != -1) continue; if (!paramDef.isFloat()) continue; size_t size = paramDef.elementSize * paramDef.arraySize; QVector<float> newParamValue; QVector<float>::iterator it; newParamValue.resize(size); // Find the corresponding property value. QVariant val = property(paramName.append(" VP").toLatin1()); if (!val.isValid() || val.isNull()) continue; TypeValuePair typeValuePair = val.toMap(); QString newValueString(typeValuePair.begin().value().toByteArray()); newValueString.trimmed(); // fill the float vector with new values it = newParamValue.begin(); int i = 0, j = 0; bool ok = true; while(j != -1 && ok) { j = newValueString.indexOf(' ', i); QString newValue = newValueString.mid(i, j == -1 ? j : j - i); if (!newValue.isEmpty()) { *it = newValue.toFloat(&ok); ++it; } i = j + 1; } // Set the new value. ///\todo use the exact count rather than just 4 values if needed. if (size == 16) { Ogre::Matrix4 matrix(newParamValue[0], newParamValue[1], newParamValue[2], newParamValue[3], newParamValue[4], newParamValue[5], newParamValue[6], newParamValue[7], newParamValue[8], newParamValue[9], newParamValue[10], newParamValue[11], newParamValue[12], newParamValue[13], newParamValue[14], newParamValue[15]); #if OGRE_VERSION_MINOR <= 6 && OGRE_VERSION_MAJOR <= 1 verPtr->_writeRawConstant(paramDef.physicalIndex, matrix); #else verPtr->_writeRawConstant(paramDef.physicalIndex, matrix, size); #endif } else { Ogre::Vector4 vector(newParamValue[0], newParamValue[1], newParamValue[2], newParamValue[3]); verPtr->_writeRawConstant(paramDef.physicalIndex, vector); } } } } } if (pass->hasFragmentProgram()) { // Fragment program const Ogre::GpuProgramPtr &fragProg = pass->getFragmentProgram(); if (!fragProg.isNull()) { Ogre::GpuProgramParametersSharedPtr fragPtr = pass->getFragmentProgramParameters(); if (!fragPtr.isNull()) { if (fragPtr->hasNamedParameters()) { // Named parameters (constants) Ogre::GpuConstantDefinitionIterator mapIter = fragPtr->getConstantDefinitionIterator(); while(mapIter.hasMoreElements()) { QString paramName(mapIter.peekNextKey().c_str()); const Ogre::GpuConstantDefinition ¶mDef = mapIter.getNext(); // Filter names that end with '[0]' if (paramName.lastIndexOf("[0]") != -1) continue; if (!paramDef.isFloat()) continue; size_t size = paramDef.elementSize * paramDef.arraySize; QVector<float> newParamValue; QVector<float>::iterator it; newParamValue.resize(size); // Find the corresponding property value. QVariant val = property(paramName.append(" FP").toLatin1()); if (!val.isValid() || val.isNull()) continue; TypeValuePair typeValuePair = val.toMap(); QString newValueString(typeValuePair.begin().value().toByteArray()); newValueString.trimmed(); // Fill the float vector with new values. it = newParamValue.begin(); int i = 0, j = 0; bool ok = true; while(j != -1 && ok) { j = newValueString.indexOf(' ', i); QString newValue = newValueString.mid(i, j == -1 ? j : j - i); if (!newValue.isEmpty()) { *it = *it = newValue.toFloat(&ok); ++it; } i = j + 1; } // Set the new value. ///\todo use the exact count rather than just 4 values if needed. if (size == 16) { Ogre::Matrix4 matrix(newParamValue[0], newParamValue[1], newParamValue[2], newParamValue[3], newParamValue[4], newParamValue[5], newParamValue[6], newParamValue[7], newParamValue[8], newParamValue[9], newParamValue[10], newParamValue[11], newParamValue[12], newParamValue[13], newParamValue[14], newParamValue[15]); #if OGRE_VERSION_MINOR <= 6 && OGRE_VERSION_MAJOR <= 1 fragPtr->_writeRawConstant(paramDef.physicalIndex, matrix); #else fragPtr->_writeRawConstant(paramDef.physicalIndex, matrix, size); #endif } else { Ogre::Vector4 vector(newParamValue[0], newParamValue[1], newParamValue[2], newParamValue[3]); fragPtr->_writeRawConstant(paramDef.physicalIndex, vector); } } } } } } Ogre::Pass::TextureUnitStateIterator texIter = pass->getTextureUnitStateIterator(); while(texIter.hasMoreElements()) { // Texture units Ogre::TextureUnitState *tu = texIter.getNext(); // Replace the texture name (uuid) with the new one QString tu_name(tu->getName().c_str()); QVariant val = property(tu_name.append(" TU").toLatin1()); if (!val.isValid() || val.isNull()) continue; TypeValuePair typeValuePair = val.toMap(); QString newValueString(typeValuePair.begin().value().toByteArray()); newValueString.trimmed(); tu->setTextureName(newValueString.toStdString()); /* //QString new_texture_name = iter->second; RexUUID new_name(iter->second); // If new texture is UUID-based one, make sure the corresponding RexOgreTexture gets created, // because we may not be able to load it later if load fails now if (RexUUID::IsValid(new_texture_name)) { RexUUID imageID(new_texture_name); if (!imageID.IsNull()) { image* image = imageList.getImage(imageID); if (image) { image->getOgreTexture(); } } } //tu->setTextureName(iter->second); */ } } } return matPtrClone; } matPtrClone.setNull(); return matPtrClone; }
CRosRttTexture::CRosRttTexture(unsigned width, unsigned height, Ogre::Camera * camera, bool isDepth /*= false*/ ) : m_materialName("MyRttMaterial") , width_(width) , height_(height) , frame_("/map") , m_bIsDepth( isDepth ) { assert( height > 0 && width > 0 ); { // Set encoding current_image_.encoding = ROS_IMAGE_FORMAT; // Set image size current_image_.width = width; current_image_.height = height; // Set image row length in bytes (row length * 3 bytes for a color) current_image_.step = width * BPP; #if OGRE_ENDIAN == ENDIAN_BIG current_image_.is_bigendian = true; #else current_image_.is_bigendian = false; #endif // Resize data current_image_.data.resize( width_ * height_ * BPP); } Ogre::TextureManager & lTextureManager( Ogre::TextureManager::getSingleton() ); Ogre::String textureName("RVIZ_CamCast_Texture"); bool lGammaCorrection( false ); unsigned int lAntiAliasing( 0 ); unsigned int lNumMipmaps( 0 ); if( isDepth ) { texture_ = lTextureManager.createManual(textureName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, width, height, lNumMipmaps, OGRE_DEPTH_TEXTURE_FORMAT, Ogre::TU_RENDERTARGET, 0, lGammaCorrection, lAntiAliasing); } else { texture_ = lTextureManager.createManual(textureName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, width, height, lNumMipmaps, OGRE_TEXTURE_FORMAT, Ogre::TU_RENDERTARGET, 0, lGammaCorrection, lAntiAliasing); } // Create render target Ogre::RenderTexture* lRenderTarget = NULL; Ogre::HardwarePixelBufferSharedPtr lRttBuffer = texture_->getBuffer(); lRenderTarget = lRttBuffer->getRenderTarget(); lRenderTarget->setAutoUpdated(true); // Create and attach viewport Ogre::Viewport* lRttViewport1 = lRenderTarget->addViewport(camera, 50, 0.00f, 0.00f, 1.0f, 1.0f); lRttViewport1->setAutoUpdated(true); Ogre::ColourValue lBgColor1(0.0,0.0,0.0,1.0); lRttViewport1->setBackgroundColour(lBgColor1); // create a material using this texture. //Get a reference on the material manager, which is a singleton. Ogre::MaterialManager& lMaterialManager = Ogre::MaterialManager::getSingleton(); Ogre::MaterialPtr lMaterial = lMaterialManager.create(m_materialName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); Ogre::Technique * lTechnique = lMaterial->getTechnique(0); Ogre::Pass* lPass = lTechnique->getPass(0); if( isDepth ) { lPass->setLightingEnabled(false); } Ogre::TextureUnitState* lTextureUnit = lPass->createTextureUnitState(); lTextureUnit->setTextureName(textureName); lTextureUnit->setNumMipmaps(0); lTextureUnit->setTextureFiltering(Ogre::TFO_BILINEAR); update(); }
Camera::Camera(Event::Lane& lane, GameHandle cameraHandle, Ogre::SceneNode* camNode, Ogre::RenderTarget* renderTarget, u32 width, u32 height, const v3& position, const qv4& orientation, GameHandle parent) : mSubLane(lane.createSubLane()), mCameraNode(camNode), mRenderTarget(renderTarget), mHandle(cameraHandle), mNodeCreated(false), mRenderTargetCreated(false) { Ogre::SceneManager* sceneMgr = Ogre::Root::getSingleton().getSceneManager(BFG_SCENEMANAGER); if (mCameraNode == NULL) // Create SceneNode { if (sceneMgr->hasSceneNode(stringify(mHandle))) { mCameraNode = sceneMgr->getSceneNode(stringify(mHandle)); } else { mCameraNode = sceneMgr->getRootSceneNode()->createChildSceneNode(stringify(mHandle)); mNodeCreated = true; } } mCameraNode->setOrientation(toOgre(orientation)); mCameraNode->setPosition(toOgre(position)); v3 target = toBFG(mCameraNode->getOrientation().zAxis()); norm(target); Ogre::Camera* cam; cam = sceneMgr->createCamera(stringify(mHandle)); cam->setFOVy(Ogre::Degree(60.0f)); cam->setNearClipDistance(0.1f); cam->setFarClipDistance(250000.0f); cam->lookAt(toOgre(target)*10); mCameraNode->attachObject(cam); infolog << "Camera: " << stringify(mHandle) << " created."; if (mRenderTarget == NULL) { // Create renderToTexture RenderTarget if (width == 0 || height == 0) { throw std::logic_error("Too few information to create a render target."); } cam->setAspectRatio((f32)width / (f32)height); Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().createManual ( stringify(mHandle), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, width, height, 0, Ogre::PF_R8G8B8, Ogre::TU_RENDERTARGET ); mRenderTarget = texture->getBuffer()->getRenderTarget(); prepareRenderTarget(); mRenderTarget->addViewport(cam); mRenderTarget->getViewport(0)->setClearEveryFrame(true); mRenderTarget->getViewport(0)->setBackgroundColour(Ogre::ColourValue::Black); mRenderTarget->getViewport(0)->setOverlaysEnabled(false); Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(stringify(mHandle)); if (mat.isNull()) { mat = Ogre::MaterialManager::getSingleton().create( stringify(mHandle), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); } Ogre::Technique* tech = mat->getTechnique(0); if (!tech) { tech = mat->createTechnique(); } Ogre::Pass* pass = tech->getPass(0); if (!pass) { pass = tech->createPass(); } pass->setLightingEnabled(false); if (pass->getNumTextureUnitStates() > 0) { Ogre::TextureUnitState* txState = NULL; txState = pass->getTextureUnitState(0); txState->setTextureName(stringify(mHandle)); } else { pass->createTextureUnitState(stringify(mHandle)); } mRenderTarget->setAutoUpdated(true); mRenderTargetCreated = true; infolog << "Rendertarget: " << stringify(mHandle) << " created."; } else { prepareRenderTarget(); f32 width = static_cast<f32>(mRenderTarget->getWidth()); f32 height = static_cast<f32>(mRenderTarget->getHeight()); cam->setAspectRatio(width / height); mRenderTarget->addViewport(cam); } // mSubLane->connect(ID::VE_UPDATE_POSITION, this, &Camera::updatePosition, mHandle); // mSubLane->connect(ID::VE_UPDATE_ORIENTATION, this, &Camera::updateOrientation, mHandle); mSubLane->connect(ID::VE_SET_CAMERA_TARGET, this, &Camera::onSetTarget, mHandle); if (parent != NULL_HANDLE) { onSetTarget(parent); } }
void RenderState::createScene() { ////////////////////// Volume texture // breadVolume.createTexture("media/fields/imagen3-1.field", "volumeTex"); // breadVolume.createTexture("media/fields/mengel3d.field", "volumeTex"); // breadVolume.createTexture("media/fields/3Dbread.256.field", "volumeTex"); breadDensityVolume.createTexture("media/fields/warped.field", "densityTex"); breadDensityTex = breadDensityVolume.getTexturePtr(); if (breadDensityTex.isNull()) { printf("Error generating density texture"); exit(); } breadCrustVolume.createTexture("media/fields/warpedC.field", "crustTex"); breadCrustTex = breadCrustVolume.getTexturePtr(); if (breadCrustTex.isNull()) { printf("Error generating crust texture"); exit(); } breadOcclusionVolume.createTexture("media/fields/warpedO.field", "occlusionTex"); breadOcclusionTex = breadOcclusionVolume.getTexturePtr(); if (breadOcclusionTex.isNull()) { printf("Error generating occlusion texture"); exit(); } ///////////////////// Volume bounding cubes breadVolumeBoundingCubes.create(breadDensityVolume, 32, 1, 255, _sceneMgr); //////////// Background color Ogre::Viewport* vp = OgreFramework::getSingletonPtr()->_viewport; vp->setBackgroundColour (ColourValue(0.1,0.1,0.1)); //////////// Light _sceneMgr->setAmbientLight(ColourValue(0.1,0.1,0.1)); light = _sceneMgr->createLight("Light"); // light->setType(Light::LT_POINT); light->setType(Light::LT_SPOTLIGHT); light->setPosition(100,100,100); light->setDirection(100,-100,100); light->setDiffuseColour(1,1,1); light->setSpecularColour(1.0,1.0,1.0); light->setSpotlightRange(Radian(M_PI/2), Radian(M_PI/3)); // light->setAttenuation(20, 0.5, 1, 1); //////////// Shadows // _sceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE); // _sceneMgr->setShadowTextureSettings( 256, 2); // _sceneMgr->setShadowTextureConfig( 0, 512, 512, PF_FLOAT16_R, 50 ); ////////////////////// BREAD breadEntity = _sceneMgr->createEntity("BreadEntity", "Cube01.mesh"); breadNode = _sceneMgr->getRootSceneNode()->createChildSceneNode("BreadNode"); breadNode->attachObject(breadEntity); breadNode->setOrientation(Quaternion::IDENTITY); breadNode->setPosition(Vector3(0, 0, 0)); breadNode->setScale(Vector3(20,20,20)); // breadEntity->setRenderQueueGroup(RENDER_QUEUE_8); breadEntity->setCastShadows(true); breadEntity->getSubEntity(0)->setMaterialName("Bread","General"); breadMat = breadEntity->getSubEntity(0)->getMaterial(); Ogre::Pass* breadPass = breadMat->getTechnique(0)->getPass(0); Ogre::TextureUnitState* posTU = breadPass->createTextureUnitState("rayPos"); Ogre::TextureUnitState* dirTU = breadPass->createTextureUnitState("rayDir"); posTU->setTextureName("rayPos"); dirTU->setTextureName("rayDir"); posTU->setTextureFiltering(TFO_NONE); dirTU->setTextureFiltering(TFO_NONE); posTU->setTextureAddressingMode(TextureUnitState::TAM_CLAMP); dirTU->setTextureAddressingMode(TextureUnitState::TAM_CLAMP); /////////////////////// TABLE tableEntity = _sceneMgr->createEntity("PlaneEntity", "Plane.mesh"); tableEntity->getSubEntity(0)->setMaterialName("Table","General"); tableEntity->setCastShadows(false); tableNode = _sceneMgr->getRootSceneNode()->createChildSceneNode("PlaneNode"); tableNode->attachObject(tableEntity); tableNode->setOrientation(Quaternion::IDENTITY); tableNode->setPosition(Vector3(0, 0, 0)); tableNode->setScale(Vector3(10,10,10)); /////////////////////// KNIFE knifeEntity = _sceneMgr->createEntity("KnifeEntity", "knife.mesh"); knifeEntity->getSubEntity(0)->setMaterialName("Knife","General"); knifeEntity->setCastShadows(false); knifeNode = _sceneMgr->getRootSceneNode()->createChildSceneNode("KnifeNode"); knifeNode->attachObject(knifeEntity); Quaternion ori(Radian(-0.5), Vector3(0,1,0)); knifeNode->setOrientation(ori); knifeNode->setPosition(Vector3(30, 1, -30)); knifeNode->setScale(Vector3(50,50,50)); // Create background rectangle covering the whole screen Rectangle2D* rect = new Rectangle2D(true); rect->setCorners(-1.0, 1.0, 1.0, -1.0); rect->setMaterial("Degrade"); rect->setCastShadows(false); // Render the background before everything else rect->setRenderQueueGroup(RENDER_QUEUE_BACKGROUND); // Use infinite AAB to always stay visible AxisAlignedBox aabInf; aabInf.setInfinite(); rect->setBoundingBox(aabInf); // Attach background to the scene backgroundNode =_sceneMgr->getRootSceneNode()->createChildSceneNode("Background"); backgroundNode->attachObject(rect); /////////////// Light obj // Create background rectangle covering the whole screen lightEntity = _sceneMgr->createEntity("LightEntity", "Cube01.mesh"); lightNode = _sceneMgr->getRootSceneNode()->createChildSceneNode("Light"); lightEntity->getSubEntity(0)->setMaterialName("White","General"); lightEntity->setCastShadows(false); lightNode->attachObject(lightEntity); lightNode->setPosition(light->getPosition()); lightNode->showBoundingBox(false); ///////////////////////// Set visibility masks for all entities lightEntity->setVisibilityFlags(RF_MAIN); rect->setVisibilityFlags(RF_MAIN); knifeEntity->setVisibilityFlags(RF_MAIN); tableEntity->setVisibilityFlags(RF_MAIN); breadEntity->setVisibilityFlags(RF_MAIN); }