本文整理汇总了C++中ogre::TextureUnitState::setAlphaOperation方法的典型用法代码示例。如果您正苦于以下问题:C++ TextureUnitState::setAlphaOperation方法的具体用法?C++ TextureUnitState::setAlphaOperation怎么用?C++ TextureUnitState::setAlphaOperation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ogre::TextureUnitState
的用法示例。
在下文中一共展示了TextureUnitState::setAlphaOperation方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetTransparence
// 设置模型的透明度
// 0 -- 完全透明。
// 1 -- 不透明。
void CEditDobject_NT::SetTransparence(float Transparence)
{
int iCount = m_EntityList.size();
Ogre::Entity* pEntity = NULL;
for(int i = 0; i < iCount; i++)
{
pEntity = m_EntityList[i].pEntity;
if(pEntity)
{
Ogre::SubEntity* pSubEntiy = pEntity->getSubEntity(0);
if(pSubEntiy)
{
Ogre::MaterialPtr material1 = pSubEntiy->getMaterial();
Ogre::Technique* t1 = material1->getBestTechnique();
Ogre::Pass* p1 = t1->getPass(0);
p1->setSceneBlending(Ogre::SBT_ADD );
p1->setSceneBlending(Ogre::SBF_SOURCE_ALPHA , Ogre::SBF_ONE_MINUS_SOURCE_ALPHA );
Ogre::TextureUnitState* pTextureState = p1->getTextureUnitState(0);
pTextureState->setAlphaOperation(Ogre::LBX_MODULATE, Ogre::LBS_TEXTURE, Ogre::LBS_MANUAL, 1, Transparence, 1);
//Ogre::ColourValue color(1,0.0,0.0,0.1) ;
//pTextureState->setColourOperationEx(LBX_ADD , LBS_TEXTURE , LBS_MANUAL, color, color );
}
}
}
}
示例2: setMaterialAlpha
void gkHUDElement::setMaterialAlpha(float factor)
{
if (!m_element) return;
try
{
Ogre::MaterialPtr material = m_element->getMaterial();
Ogre::Pass* pass = material->getTechnique(0)->getPass(0);
if (m_alphaBlend > 1.f)
{
pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
m_alphaBlend = 1.f;
}
Ogre::TextureUnitState* tu = pass->getTextureUnitState(0);
if (tu)
{
factor = gkClamp(factor, 0.f, 1.f);
tu->setAlphaOperation(Ogre::LBX_SOURCE1, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, factor);
m_alphaBlend = factor;
}
}
catch (Ogre::Exception& e)
{
gkPrintf("HUD Error: %s", e.what());
}
}
示例3: AddMaterial
void TerrainProjectionMarker::AddMaterial(const string& matName)
{
// check if material is already added or there's no material
if( _targetMaterials.find(matName) != _targetMaterials.end() ||
matName.empty() )
{
return;
}
string matName2 = "StoreMat";
// get the material ptr
Ogre::MaterialPtr mat = (Ogre::MaterialPtr)Ogre::MaterialManager::getSingleton().getByName(matName);
// create a new pass in the material to render the decal
Ogre::Pass* pass = mat->getTechnique(0)->createPass();
// set up the decal's texture unit
Ogre::TextureUnitState *texState = pass->createTextureUnitState(GetTextureName());
texState->setProjectiveTexturing(true, _projectionFrustum);
texState->setTextureAddressingMode(Ogre::TextureUnitState::TAM_WRAP);
texState->setTextureFiltering(Ogre::FO_POINT, Ogre::FO_LINEAR, Ogre::FO_NONE);
texState->setAlphaOperation(Ogre::LBX_ADD);
// set our pass to blend the decal over the model's regular texture
pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
pass->setDepthBias(2.5f, 2.5f);
pass->setDepthCheckEnabled(false);
// set the decal to be self illuminated instead of lit by scene lighting
pass->setLightingEnabled(false);
// save pass in map
_targetMaterials[matName] = pass;
}
示例4: fade
void fade(Ogre::Real tpf) {
if (m_eFadeOperation != FADE_NONE && m_pTextUnitState) {
m_pTextUnitState->setAlphaOperation(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_TEXTURE, m_fAlpha);
if (m_eFadeOperation == FADE_IN) {
m_fCurrentDuration -= tpf;
m_fAlpha = m_fCurrentDuration / m_fTotalDuration;
if (m_fAlpha < 0.0) {
m_pOverlay->hide();
m_eFadeOperation = FADE_NONE;
if (m_pFaderCallback) {
m_pFaderCallback->fadeInCallback();
}
}
}
else if (m_eFadeOperation == FADE_OUT) {
m_fCurrentDuration += tpf;
m_fAlpha = m_fCurrentDuration / m_fTotalDuration;
if (m_fAlpha > 1.0) {
m_eFadeOperation = FADE_NONE;
if (m_pFaderCallback) {
m_pFaderCallback->fadeOutCallback();
}
}
}
}
#ifdef USE_SPRITE_SHADER
m_SpritePixelShaderParameters->setNamedConstant("colour", Ogre::ColourValue(1, 1, 1, m_fAlpha));
#endif
}
示例5: registerPass
void Decal::registerPass(Ogre::Pass* _Pass)
{
unregister();
_Pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
_Pass->setCullingMode(Ogre::CULL_NONE);
_Pass->setDepthBias(1,1);
_Pass->setLightingEnabled(false);
_Pass->setDepthWriteEnabled(false);
Ogre::TextureUnitState *DecalTexture = _Pass->createTextureUnitState(mTextureName);
DecalTexture->setProjectiveTexturing(true, mProjector);
DecalTexture->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
DecalTexture->setTextureFiltering(Ogre::FO_LINEAR, Ogre::FO_LINEAR, Ogre::FO_NONE);
DecalTexture->setAlphaOperation(Ogre::LBX_MODULATE, Ogre::LBS_TEXTURE, Ogre::LBS_MANUAL, 1.0, mTransparency);
mRegisteredPass = _Pass;
}
示例6: Update
bool LagomPlayerBase::Update(float time_elapsed)
{
_health += getIntFactory().HealthRegeneration*time_elapsed/1000.0f;
if(_health >= getIntFactory().Health)
_health = getIntFactory().Health;
_factoryHighlightRemaining -= time_elapsed;
if(_factoryHighlightRemaining < 0.0f)
_factoryHighlightRemaining = 0.0f;
float newCooldown = _buildCooldown - time_elapsed;
if( (newCooldown > 0.0f) != (_buildCooldown > 0.0f))
_factoryHighlightRemaining = getIntFactory().ConstructionHighlightTime;
_buildCooldown = newCooldown;
Ogre::ColourValue playerColor = Lagom::getSingleton().GetPlayerColor();
Ogre::ColourValue staticColor = playerColor*.05f + Ogre::ColourValue(.1,.1,.1,.0f);
Ogre::ColourValue pulseColor = playerColor * _state.GetPulsePower();
_materialInstance->setCustomParameter(0,Ogre::Vector4(staticColor.r,staticColor.g,staticColor.b,.0f));
_materialInstance->setCustomParameter(1,Ogre::Vector4(pulseColor.r,pulseColor.g,pulseColor.b,_state.GetPulseTime()));
if( _selectedActorFactory !=_actorFactories.end() && _selectedActorFactory->second != _constructionObject)
{
if(_constructionObject)
_sceneNode->removeChild(_constructionObject);
_constructionObject=_selectedActorFactory->second;
_constructionObject->setPosition(getIntFactory().ConstructionOffset);
if(_constructionObject)
_sceneNode->addChild(_constructionObject);
}
if(_constructionObject)
{
Ogre::ColourValue constructionColour(0.0f,0.0f,0.0f,0.0f);
float constructionAlpha = 1.0f;
if(_draggingConstruction)
{
if(checkConstructionRestriction(_selectedActorFactory->first,_currentDragLocation))
constructionColour=playerColor;
else
constructionColour=Ogre::ColourValue::Black;
}
else if(_buildCooldown <= 0.0f)
{
if(_hoverConstructing)
constructionColour = Ogre::ColourValue::White;
else if(_factoryHighlightRemaining>= 0.0f)
{
float highlight = _factoryHighlightRemaining / getIntFactory().ConstructionHighlightTime;
float rev_h = 1.0f - highlight;
constructionColour = Ogre::ColourValue(playerColor.r*rev_h + highlight,playerColor.g*rev_h + highlight,playerColor.b*rev_h + highlight,1.0f);
}
else
constructionColour=playerColor;
}
else
{
constructionAlpha = std::max(std::min(1.0f - _buildCooldown / _buildCooldownMax,1.0f),0.0f);
constructionAlpha *= getIntFactory().ConstructionAlphaFactor;
}
Ogre::MaterialPtr materialPtr = Ogre::MaterialManager::getSingleton().getByName(getIntFactory().ConstructingMaterial);
Ogre::TextureUnitState* ptus = materialPtr->getTechnique(0)->getPass(0)->getTextureUnitState(0); //1st pass, first texture unit
Ogre::TextureUnitState* ptus2 = materialPtr->getTechnique(0)->getPass(1)->getTextureUnitState(0); //2nd pass, first texture unit
ptus->setColourOperationEx(Ogre::LBX_SOURCE1, Ogre::LBS_MANUAL, Ogre::LBS_TEXTURE, constructionColour);
ptus->setAlphaOperation(Ogre::LBX_SOURCE1, Ogre::LBS_MANUAL, Ogre::LBS_TEXTURE, .25f * constructionAlpha);
ptus2->setColourOperationEx(Ogre::LBX_SOURCE1, Ogre::LBS_MANUAL, Ogre::LBS_TEXTURE, constructionColour);
ptus2->setAlphaOperation(Ogre::LBX_SOURCE1, Ogre::LBS_MANUAL, Ogre::LBS_TEXTURE, .25f* constructionAlpha);
if(!_draggingConstruction)
{
float rotation_speed = time_elapsed / 500.0f;
Ogre::Quaternion rot1;
rot1.FromAngleAxis(Ogre::Radian(rotation_speed), Ogre::Vector3( 0.0f , 1.0f, 0.0f).normalisedCopy() );
_constructionObject->rotate( rot1);
}
else
{
_constructionObject->setOrientation(1.0f,0.0f,0.0f,0.0f);
static_cast<Ogre::Entity*>(_constructionObject->getAttachedObject(0))->setMaterialName(getIntFactory().ConstructingMaterial);
}
}
_energy = 1000.0f;
if(_health <= 0.0f)
return false;
return true;
}
示例7: create
Ogre::MaterialPtr MaterialGenerator::create(bool renderCompositeMap, bool displayCompositeMap)
{
assert(!renderCompositeMap || !displayCompositeMap);
static int count = 0;
std::stringstream name;
name << "terrain/mat" << count++;
if (!mShaders)
{
Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create(name.str(),
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
Ogre::Technique* technique = mat->getTechnique(0);
technique->removeAllPasses();
if (displayCompositeMap)
{
Ogre::Pass* pass = technique->createPass();
pass->setVertexColourTracking(Ogre::TVC_AMBIENT|Ogre::TVC_DIFFUSE);
pass->createTextureUnitState(mCompositeMap)->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
}
else
{
assert(mLayerList.size() == mBlendmapList.size()+1);
std::vector<Ogre::TexturePtr>::iterator blend = mBlendmapList.begin();
for (std::vector<LayerInfo>::iterator layer = mLayerList.begin(); layer != mLayerList.end(); ++layer)
{
Ogre::Pass* pass = technique->createPass();
pass->setLightingEnabled(false);
pass->setVertexColourTracking(Ogre::TVC_NONE);
// TODO: How to handle fog?
pass->setFog(true, Ogre::FOG_NONE);
bool first = (layer == mLayerList.begin());
Ogre::TextureUnitState* tus;
if (!first)
{
pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
pass->setDepthFunction(Ogre::CMPF_EQUAL);
tus = pass->createTextureUnitState((*blend)->getName());
tus->setAlphaOperation(Ogre::LBX_BLEND_TEXTURE_ALPHA,
Ogre::LBS_TEXTURE,
Ogre::LBS_TEXTURE);
tus->setColourOperationEx(Ogre::LBX_BLEND_DIFFUSE_ALPHA,
Ogre::LBS_TEXTURE,
Ogre::LBS_TEXTURE);
tus->setIsAlpha(true);
tus->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
float scale = (16/(16.f+1.f));
tus->setTextureScale(1.f/scale,1.f/scale);
}
// Add the actual layer texture on top of the alpha map.
tus = pass->createTextureUnitState(layer->mDiffuseMap);
if (!first)
tus->setColourOperationEx(Ogre::LBX_BLEND_DIFFUSE_ALPHA,
Ogre::LBS_TEXTURE,
Ogre::LBS_CURRENT);
tus->setTextureScale(1/16.f,1/16.f);
if (!first)
++blend;
}
if (!renderCompositeMap)
{
Ogre::Pass* lightingPass = technique->createPass();
lightingPass->setSceneBlending(Ogre::SBT_MODULATE);
lightingPass->setVertexColourTracking(Ogre::TVC_AMBIENT|Ogre::TVC_DIFFUSE);
lightingPass->setFog(true, Ogre::FOG_NONE);
}
}
return mat;
}
#if TERRAIN_USE_SHADER
else
{
sh::MaterialInstance* material = sh::Factory::getInstance().createMaterialInstance (name.str());
material->setProperty ("allow_fixed_function", sh::makeProperty<sh::BooleanValue>(new sh::BooleanValue(false)));
if (displayCompositeMap)
{
sh::MaterialInstancePass* p = material->createPass ();
p->setProperty ("vertex_program", sh::makeProperty<sh::StringValue>(new sh::StringValue("terrain_vertex")));
p->setProperty ("fragment_program", sh::makeProperty<sh::StringValue>(new sh::StringValue("terrain_fragment")));
p->mShaderProperties.setProperty ("is_first_pass", sh::makeProperty(new sh::BooleanValue(true)));
p->mShaderProperties.setProperty ("render_composite_map", sh::makeProperty(new sh::BooleanValue(false)));
p->mShaderProperties.setProperty ("display_composite_map", sh::makeProperty(new sh::BooleanValue(true)));
p->mShaderProperties.setProperty ("num_layers", sh::makeProperty (new sh::StringValue("0")));
p->mShaderProperties.setProperty ("num_blendmaps", sh::makeProperty (new sh::StringValue("0")));
p->mShaderProperties.setProperty ("normal_map_enabled", sh::makeProperty (new sh::BooleanValue(false)));
p->mShaderProperties.setProperty ("parallax_enabled", sh::makeProperty (new sh::BooleanValue(false)));
p->mShaderProperties.setProperty ("normal_maps",
//.........这里部分代码省略.........
示例8: onInitialize
void CameraDisplay::onInitialize()
{
caminfo_tf_filter_ = new tf::MessageFilter<sensor_msgs::CameraInfo>(*vis_manager_->getTFClient(), "", 2, update_nh_);
bg_scene_node_ = scene_manager_->getRootSceneNode()->createChildSceneNode();
fg_scene_node_ = scene_manager_->getRootSceneNode()->createChildSceneNode();
{
static int count = 0;
UniformStringStream ss;
ss << "CameraDisplayObject" << count++;
//background rectangle
bg_screen_rect_ = new Ogre::Rectangle2D(true);
bg_screen_rect_->setCorners(-1.0f, 1.0f, 1.0f, -1.0f);
ss << "Material";
bg_material_ = Ogre::MaterialManager::getSingleton().create( ss.str(), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );
bg_material_->setDepthWriteEnabled(false);
bg_material_->setReceiveShadows(false);
bg_material_->setDepthCheckEnabled(false);
bg_material_->getTechnique(0)->setLightingEnabled(false);
Ogre::TextureUnitState* tu = bg_material_->getTechnique(0)->getPass(0)->createTextureUnitState();
tu->setTextureName(texture_.getTexture()->getName());
tu->setTextureFiltering( Ogre::TFO_NONE );
tu->setAlphaOperation( Ogre::LBX_SOURCE1, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, 0.0 );
bg_material_->setCullingMode(Ogre::CULL_NONE);
bg_material_->setSceneBlending( Ogre::SBT_REPLACE );
Ogre::AxisAlignedBox aabInf;
aabInf.setInfinite();
bg_screen_rect_->setRenderQueueGroup(Ogre::RENDER_QUEUE_BACKGROUND);
bg_screen_rect_->setBoundingBox(aabInf);
bg_screen_rect_->setMaterial(bg_material_->getName());
bg_scene_node_->attachObject(bg_screen_rect_);
bg_scene_node_->setVisible(false);
//overlay rectangle
fg_screen_rect_ = new Ogre::Rectangle2D(true);
fg_screen_rect_->setCorners(-1.0f, 1.0f, 1.0f, -1.0f);
fg_material_ = bg_material_->clone( ss.str()+"fg" );
fg_screen_rect_->setBoundingBox(aabInf);
fg_screen_rect_->setMaterial(fg_material_->getName());
fg_material_->setSceneBlending( Ogre::SBT_TRANSPARENT_ALPHA );
fg_screen_rect_->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY - 1);
fg_scene_node_->attachObject(fg_screen_rect_);
fg_scene_node_->setVisible(false);
}
setAlpha( 0.5f );
render_panel_ = new RenderPanel();
render_panel_->getRenderWindow()->addListener( this );
render_panel_->getRenderWindow()->setAutoUpdated(false);
render_panel_->getRenderWindow()->setActive( false );
render_panel_->resize( 640, 480 );
render_panel_->initialize(vis_manager_->getSceneManager(), vis_manager_);
WindowManagerInterface* wm = vis_manager_->getWindowManager();
if( wm )
{
panel_container_ = wm->addPane(name_, render_panel_);
}
render_panel_->setAutoRender(false);
render_panel_->setOverlaysEnabled(false);
render_panel_->getCamera()->setNearClipDistance( 0.01f );
caminfo_tf_filter_->connectInput(caminfo_sub_);
caminfo_tf_filter_->registerCallback(boost::bind(&CameraDisplay::caminfoCallback, this, _1));
vis_manager_->getFrameManager()->registerFilterForTransformStatusCheck(caminfo_tf_filter_, this);
if( panel_container_ )
{
// TODO: wouldn't it be better to connect this straight to the wrapper?
connect( panel_container_, SIGNAL( visibilityChanged( bool ) ), this, SLOT( setWrapperEnabled( bool )));
}
}
示例9: Display
CameraDisplaySave::CameraDisplaySave( const std::string& name, VisualizationManager* manager )
: Display( name, manager )
, transport_("raw")
, caminfo_tf_filter_(*manager->getTFClient(), "", 2, update_nh_)
, new_caminfo_(false)
, texture_(update_nh_)
, frame_(0)
, force_render_(false)
, render_listener_(this)
{
scene_node_ = scene_manager_->getRootSceneNode()->createChildSceneNode();
{
static int count = 0;
std::stringstream ss;
ss << "CameraDisplaySaveObject" << 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_TRANSPARENT_ALPHA );
material_->setDepthWriteEnabled(false);
material_->setReceiveShadows(false);
material_->setDepthCheckEnabled(false);
#if 1
material_->getTechnique(0)->setLightingEnabled(false);
Ogre::TextureUnitState* tu = material_->getTechnique(0)->getPass(0)->createTextureUnitState();
tu->setTextureName(texture_.getTexture()->getName());
tu->setTextureFiltering( Ogre::TFO_NONE );
tu->setAlphaOperation( Ogre::LBX_SOURCE1, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, 0.0 );
#else
material_->getTechnique(0)->setLightingEnabled(true);
material_->setAmbient(Ogre::ColourValue(0.0f, 1.0f, 1.0f, 1.0f));
#endif
material_->setCullingMode(Ogre::CULL_NONE);
Ogre::AxisAlignedBox aabInf;
aabInf.setInfinite();
screen_rect_->setBoundingBox(aabInf);
screen_rect_->setMaterial(material_->getName());
scene_node_->attachObject(screen_rect_);
}
setAlpha( 0.5f );
wxWindow* parent = 0;
WindowManagerInterface* wm = vis_manager_->getWindowManager();
if (wm)
{
parent = wm->getParentWindow();
}
else
{
frame_ = new wxFrame(0, wxID_ANY, wxString::FromAscii(name.c_str()), wxPoint(100,100), wxDefaultSize, wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxRESIZE_BORDER | wxCAPTION | wxCLIP_CHILDREN);
parent = frame_;
}
render_panel_ = new RenderPanel(parent, false);
render_panel_->SetSize(wxSize(640, 480));
if (wm)
{
wm->addPane(name, render_panel_);
}
render_panel_->createRenderWindow();
render_panel_->initialize(vis_manager_->getSceneManager(), vis_manager_);
render_panel_->setAutoRender(false);
render_panel_->getRenderWindow()->addListener(&render_listener_);
render_panel_->getViewport()->setOverlaysEnabled(false);
render_panel_->getViewport()->setClearEveryFrame(true);
render_panel_->getRenderWindow()->setActive(false);
render_panel_->getRenderWindow()->setAutoUpdated(false);
render_panel_->getCamera()->setNearClipDistance( 0.1f );
caminfo_tf_filter_.connectInput(caminfo_sub_);
caminfo_tf_filter_.registerCallback(boost::bind(&CameraDisplaySave::caminfoCallback, this, _1));
vis_manager_->getFrameManager()->registerFilterForTransformStatusCheck(caminfo_tf_filter_, this);
}
示例10: addPassToTechnique
//.........这里部分代码省略.........
// textureUnitState->setTextureAddressingMode(Ogre::TextureUnitState::TAM_WRAP);
// /* textureUnitState->setTextureCoordSet(0);*/
// textureUnitState->setTextureScale(0.025, 0.025);
// textureUnitState->setColourOperationEx(Ogre::LBX_BLEND_CURRENT_ALPHA, Ogre::LBS_TEXTURE, Ogre::LBS_CURRENT);
//
// /* Ogre::TextureUnitState * alphaTextureState= pass->createTextureUnitState();
// alphaTextureState->setTextureName(mTextureName);
// // alphaTextureState->setTextureName(splatTextureName);
// alphaTextureState->setTextureCoordSet(0);
// alphaTextureState->setTextureFiltering(Ogre::TFO_ANISOTROPIC);
// alphaTextureState->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
// alphaTextureState->setColourOperationEx(Ogre::LBX_BLEND_DIFFUSE_ALPHA, Ogre::LBS_CURRENT, Ogre::LBS_TEXTURE);
//
//
//
// // detailTextureState->setAlphaOperation(Ogre::LBX_SOURCE1, Ogre::LBS_TEXTURE, Ogre::LBS_TEXTURE);
// // detailTextureState->setColourOperationEx(Ogre::LBX_SOURCE1, Ogre::LBS_CURRENT, Ogre::LBS_CURRENT);
//
// Ogre::TextureUnitState * detailTextureState = pass->createTextureUnitState();
// detailTextureState ->setTextureName(splatTextureName);
// // detailTextureState ->setTextureName(mTextureName);
// detailTextureState ->setTextureAddressingMode(Ogre::TextureUnitState::TAM_WRAP);
// detailTextureState ->setTextureCoordSet(0);
// detailTextureState ->setTextureScale(0.01, 0.01);
// //detailTextureState ->setColourOperationEx(Ogre::LBX_BLEND_CURRENT_ALPHA, Ogre::LBS_TEXTURE, Ogre::LBS_CURRENT);*/
//
// }
//
Ogre::Pass* Simple::addPassToTechnique(const TerrainPageGeometry& geometry, Ogre::Technique* technique, const Layer& layer, std::set<std::string>& managedTextures) const
{
//check if we instead can reuse the existing pass
// if (technique->getNumPasses() != 0) {
// Ogre::Pass* pass = technique->getPass(technique->getNumPasses() - 1);
// if (4 - pass->getNumTextureUnitStates() >= 2) {
// //there's more than two texture units available, use those instead of creating a new pass
// S_LOG_VERBOSE("Reusing existing pass. ("<< pass->getNumTextureUnitStates() << " of "<< mNumberOfTextureUnitsOnCard << " texture unit used)");
// addTextureUnitsToPass(pass, splatTextureName);
// return pass;
// }
//
// }
const OgreImage& ogreImage = *layer.blendMap;
Ogre::Image image;
image.loadDynamicImage(const_cast<unsigned char*>(ogreImage.getData()), ogreImage.getResolution(), ogreImage.getResolution(), 1, Ogre::PF_A8);
std::stringstream splatTextureNameSS;
splatTextureNameSS << "terrain_" << mPage.getWFPosition().x() << "_" << mPage.getWFPosition().y() << "_" << technique->getNumPasses();
const Ogre::String splatTextureName(splatTextureNameSS.str());
Ogre::TexturePtr blendMapTexture;
if (Ogre::Root::getSingletonPtr()->getTextureManager()->resourceExists(splatTextureName)) {
blendMapTexture = static_cast<Ogre::TexturePtr>(Ogre::Root::getSingletonPtr()->getTextureManager()->getByName(splatTextureName));
blendMapTexture->loadImage(image);
Ogre::HardwarePixelBufferSharedPtr hardwareBuffer(blendMapTexture->getBuffer());
//blit the whole image to the hardware buffer
Ogre::PixelBox sourceBox(image.getPixelBox());
hardwareBuffer->blitFromMemory(sourceBox);
} else {
blendMapTexture = Ogre::Root::getSingletonPtr()->getTextureManager()->loadImage(splatTextureName, "General", image, Ogre::TEX_TYPE_2D, 0);
managedTextures.insert(blendMapTexture->getName());
}
//we need to create the image, update it and then destroy it again (to keep the memory usage down)
// if (layer->getBlendMapTextureName() == "") {
// //no texture yet; let's create one
// layer->createBlendMapImage();
// layer->updateBlendMapImage(geometry);
// layer->createTexture();
// } else {
// //a texture exists, so we just need to update the image
// layer->updateBlendMapImage(geometry); //calling this will also update the texture since the method will blit the image onto it
// }
Ogre::Pass* pass = technique->createPass();
pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
pass->setAmbient(1, 1, 1);
pass->setDiffuse(1, 1, 1, 1);
pass->setLightingEnabled(false);
Ogre::TextureUnitState * textureUnitState = pass->createTextureUnitState();
textureUnitState->setTextureName(layer.surfaceLayer.getDiffuseTextureName());
textureUnitState->setTextureAddressingMode(Ogre::TextureUnitState::TAM_WRAP);
textureUnitState->setTextureCoordSet(0);
textureUnitState->setTextureScale(1.0f / layer.surfaceLayer.getScale(), 1.0f / layer.surfaceLayer.getScale());
Ogre::TextureUnitState * textureUnitStateSplat = pass->createTextureUnitState();
textureUnitStateSplat->setTextureName(blendMapTexture->getName());
textureUnitStateSplat->setTextureCoordSet(0);
textureUnitStateSplat->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
textureUnitStateSplat->setTextureFiltering(Ogre::TFO_ANISOTROPIC);
// textureUnitStateSplat->setAlphaOperation(Ogre::LBX_SOURCE1, Ogre::LBS_TEXTURE, Ogre::LBS_TEXTURE);
textureUnitStateSplat->setAlphaOperation(Ogre::LBX_BLEND_DIFFUSE_COLOUR, Ogre::LBS_TEXTURE, Ogre::LBS_CURRENT);
textureUnitStateSplat->setColourOperationEx(Ogre::LBX_SOURCE1, Ogre::LBS_CURRENT, Ogre::LBS_CURRENT);
return pass;
}