AxisRenderable::AxisRenderable(int lineCount,Ogre::Camera* camera,Ogre::Viewport* viewport) { // Disable cast shadows by default mCastShadows = false; mPrevAxisGizmoSelAxis = -1; mCamera = camera; mViewport = viewport; m_max_line_count = m_line_count = lineCount; m_line_count = 0; mLength = 200; mProjectDistance = mCamera->getFarClipDistance(); m_local = false; m_locked_data = 0; //m_locked_buffer = 0; mRenderOp.vertexData = new Ogre::VertexData(); m_radius = 0; mRenderOp.indexData = 0; mRenderOp.vertexData->vertexCount = m_line_count*2; mRenderOp.vertexData->vertexStart = 0; mRenderOp.operationType = Ogre::RenderOperation::OT_LINE_LIST; mRenderOp.useIndexes = false; Ogre::VertexDeclaration* decl = mRenderOp.vertexData->vertexDeclaration; Ogre::VertexBufferBinding* bind = mRenderOp.vertexData->vertexBufferBinding; decl->addElement(0, 0, Ogre::VET_FLOAT3, Ogre::VES_POSITION); decl->addElement(0, 3*sizeof(Ogre::Real), Ogre::VET_COLOUR, Ogre::VES_DIFFUSE); Ogre::HardwareVertexBufferSharedPtr vbuf = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer( decl->getVertexSize(0), 2*m_max_line_count, Ogre::HardwareBuffer::HBU_WRITE_ONLY); bind->setBinding(0, vbuf); // Obtain the pure colour material Ogre::MaterialPtr pureColourMaterial = createPureColourMaterial(Ogre::ColourValue(1,1,0)); Ogre::String realName = pureColourMaterial->getName() + "_NoDepthBuffer"; Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName(realName); if (material.isNull()) { // Clone to avoid confuse somewhere else that using the same material material = pureColourMaterial->clone(realName); material->setDepthCheckEnabled(false); material->setDepthWriteEnabled(false); } setMaterial(material->getName()); mBox.setExtents(-10,-10,-10,10,10,10); setQueryFlags(0); }
Ogre::MaterialPtr IntersectGrid::_createIntersectGridMaterial(void) { String name = "IntersectGridMaterial"; Ogre::ResourcePtr res = Ogre::MaterialManager::getSingleton().getByName(name); if (!res.isNull()) return res; Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create(name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); material->setLightingEnabled(false); material->setSceneBlending(Ogre::SBF_SOURCE_ALPHA, Ogre::SBF_ONE_MINUS_SOURCE_ALPHA); material->setDepthWriteEnabled(false); // Use wireframe polygon mode material->getTechnique(0)->getPass(0)->setPolygonMode(Ogre::PM_WIREFRAME); return material; }
void gkMaterialLoader::loadSubMeshMaterial(gkSubMesh* mesh, const gkString& group) { using namespace Ogre; gkMaterialProperties& gma = mesh->getMaterial(); if (gma.m_name.empty()) gma.m_name = "<gkBuiltin/DefaultMaterial>"; Ogre::MaterialPtr oma = Ogre::MaterialManager::getSingleton().getByName(gma.m_name.c_str(), group); if (!oma.isNull()) return; oma = Ogre::MaterialManager::getSingleton().create(gma.m_name, group); if (gma.m_mode & gkMaterialProperties::MA_INVISIBLE) { // disable writing to this material oma->setReceiveShadows(false); oma->setColourWriteEnabled(false); oma->setDepthWriteEnabled(false); oma->setDepthCheckEnabled(false); oma->setLightingEnabled(false); return; } if (gma.m_mode & gkMaterialProperties::MA_TWOSIDE) { oma->setCullingMode(Ogre::CULL_NONE); oma->setManualCullingMode(Ogre::MANUAL_CULL_NONE); } // apply lighting params bool enableLights = (gma.m_mode & gkMaterialProperties::MA_LIGHTINGENABLED) != 0; oma->setReceiveShadows((gma.m_mode & gkMaterialProperties::MA_RECEIVESHADOWS) != 0); oma->setLightingEnabled(enableLights); if (enableLights) { gkColor emissive, ambient, specular, diffuse; emissive = gma.m_diffuse * gma.m_emissive; ambient = gma.m_diffuse * gma.m_ambient; specular = gma.m_specular * gma.m_spec; diffuse = gma.m_diffuse * (gma.m_emissive + gma.m_refraction); emissive.a = ambient.a = specular.a = 1.f; oma->setSelfIllumination(emissive); oma->setAmbient(ambient); oma->setSpecular(specular); oma->setDiffuse(diffuse); oma->setShininess(gma.m_hardness); } Ogre::Pass* pass = oma->getTechnique(0)->getPass(0); bool matBlending = gkEngine::getSingleton().getUserDefs().matblending; if (matBlending && (gma.m_mode & gkMaterialProperties::MA_HASRAMPBLEND)) { switch (gma.m_rblend) { case GK_BT_MULTIPLY: pass->setSceneBlending(SBT_MODULATE); break; case GK_BT_SUBTRACT: pass->setSceneBlending(SBF_ONE_MINUS_SOURCE_COLOUR, SBF_ONE); break; case GK_BT_DARKEN: pass->setSceneBlendingOperation(SBO_MIN); pass->setSceneBlending(SBF_ONE, SBF_ONE); break; case GK_BT_LIGHTEN: pass->setSceneBlendingOperation(SBO_MAX); pass->setSceneBlending(SBF_ONE, SBF_ONE); break; case GK_BT_SCREEN: pass->setSceneBlending(SBF_ONE_MINUS_DEST_COLOUR, SBF_ONE); break; case GK_BT_ADDITIVE: pass->setSceneBlending(SBT_ADD); break; case GK_BT_MIXTURE: default: pass->setSceneBlending(SBF_ONE, SBF_ZERO); break; } } bool hasNormap = false; bool rtss = gkEngine::getSingleton().getUserDefs().rtss; for (int i = 0; i < gma.m_totaltex; ++i) { gkTextureProperties& gte = gma.m_textures[i]; #ifdef OGREKIT_USE_RTSHADER_SYSTEM if (gte.m_mode & gkTextureProperties::TM_NORMAL) { hasNormap = true; continue; } #endif Ogre::TextureUnitState* otus = pass->createTextureUnitState(gte.m_name, gte.m_layer); LayerBlendOperationEx op = LBX_MODULATE; switch (gte.m_blend) { case GK_BT_ADDITIVE: op = LBX_ADD; break; case GK_BT_SUBTRACT: op = LBX_SUBTRACT; break; case GK_BT_DARKEN: case GK_BT_LIGHTEN: case GK_BT_SCREEN: case GK_BT_COLOR: //break; TODO: support more mode case GK_BT_MULTIPLY: case GK_BT_MIXTURE: default: op = LBX_MODULATE; break; } if (i == 0) otus->setColourOperationEx(op, LBS_DIFFUSE, LBS_TEXTURE); else otus->setColourOperationEx(op); otus->setTextureScale(gte.m_scale[0],gte.m_scale[1]); } if (gma.m_mode & gkMaterialProperties::MA_ALPHABLEND) { pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA); pass->setDepthWriteEnabled(false); } if (gma.m_mode & gkMaterialProperties::MA_ALPHACLIP) { pass->setAlphaRejectSettings(Ogre::CMPF_GREATER_EQUAL, 254); } #ifdef OGREKIT_USE_RTSHADER_SYSTEM if (rtss) { //pass->setSpecular(ColourValue::Black); //pass->setShininess(0.0); RTShader::RenderState* rs = 0; RTShader::ShaderGenerator* sg = Ogre::RTShader::ShaderGenerator::getSingletonPtr(); bool ok = sg->createShaderBasedTechnique(gma.m_name, group, Ogre::MaterialManager::DEFAULT_SCHEME_NAME, Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME); if (ok && hasNormap) { rs = sg->getRenderState(RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME, gma.m_name, 0); rs->reset(); for (int i = 0; i < gma.m_totaltex; ++i) { gkTextureProperties& gte = gma.m_textures[i]; if (gte.m_mode & gkTextureProperties::TM_NORMAL) { GK_ASSERT(rs); RTShader::SubRenderState* srs= sg->createSubRenderState(RTShader::NormalMapLighting::Type); RTShader::NormalMapLighting* nsrs = static_cast<RTShader::NormalMapLighting*>(srs); if (gte.m_texmode & gkTextureProperties::TX_OBJ_SPACE) nsrs->setNormalMapSpace(RTShader::NormalMapLighting::NMS_OBJECT); else nsrs->setNormalMapSpace(RTShader::NormalMapLighting::NMS_TANGENT); nsrs->setNormalMapTextureName(gte.m_name); nsrs->setTexCoordIndex(gte.m_layer); rs->addTemplateSubRenderState(srs); } } sg->invalidateMaterial(RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME, gma.m_name); } } #endif }
void AerialMapDisplay::assembleScene() { if (!dirty_) { return; // nothing to update } dirty_ = false; if (!loader_) { return; // no tiles loaded, don't do anything } // get rid of old geometry, we will re-build this clearGeometry(); // iterate over all tiles and create an object for each of them const double resolution = loader_->resolution(); const std::vector<TileLoader::MapTile> &tiles = loader_->tiles(); for (const TileLoader::MapTile &tile : tiles) { const int w = tile.image().width(); const int h = tile.image().height(); // we here assume that the tiles are uniformly sized... const double tileW = w * resolution; const double tileH = h * resolution; const double origin_x = -loader_->originX() * tileW; const double origin_y = -(1 - loader_->originY()) * tileH; // determine location of this tile const double x = (tile.x() - loader_->tileX()) * tileW + origin_x; const double y = -(tile.y() - loader_->tileY()) * tileH + origin_y; // don't re-use any ids const std::string name_suffix = std::to_string(tile.x()) + "_" + std::to_string(tile.y()) + "_" + std::to_string(map_id_) + "_" + std::to_string(scene_id_); Ogre::TexturePtr tex; if (tile.hasImage()) { // one material per texture std::string matName = "material_" + name_suffix; Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create( matName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); material->setReceiveShadows(false); material->getTechnique(0)->setLightingEnabled(false); material->setDepthBias(-16.0f, 0.0f); /// @todo: what the f**k does this do? material->setCullingMode(Ogre::CULL_NONE); material->setDepthWriteEnabled(false); // create textureing unit Ogre::Pass *pass = material->getTechnique(0)->getPass(0); Ogre::TextureUnitState *tex_unit = NULL; if (pass->getNumTextureUnitStates() > 0) { tex_unit = pass->getTextureUnitState(0); } else { tex_unit = pass->createTextureUnitState(); } // only add if we have a texture for it tex = textureFromImage(tile.image(), "texture_" + name_suffix); ROS_INFO("Rendering with texture: %s", tex->getName().c_str()); tex_unit->setTextureName(tex->getName()); tex_unit->setTextureFiltering(Ogre::TFO_BILINEAR); // create an object const std::string obj_name = "object_" + name_suffix; Ogre::ManualObject *obj = scene_manager_->createManualObject(obj_name); scene_node_->attachObject(obj); // configure depth & alpha properties if (alpha_ >= 0.9998) { material->setDepthWriteEnabled(!draw_under_); material->setSceneBlending(Ogre::SBT_REPLACE); } else { material->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA); material->setDepthWriteEnabled(false); } if (draw_under_) { obj->setRenderQueueGroup(Ogre::RENDER_QUEUE_4); } else { obj->setRenderQueueGroup(Ogre::RENDER_QUEUE_MAIN); } tex_unit->setAlphaOperation(Ogre::LBX_SOURCE1, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, alpha_); // create a quad for this tile obj->begin(material->getName(), Ogre::RenderOperation::OT_TRIANGLE_LIST); // bottom left obj->position(x, y, 0.0f); obj->textureCoord(0.0f, 0.0f); obj->normal(0.0f, 0.0f, 1.0f); // top right obj->position(x + tileW, y + tileH, 0.0f); obj->textureCoord(1.0f, 1.0f); obj->normal(0.0f, 0.0f, 1.0f); // top left obj->position(x, y + tileH, 0.0f); obj->textureCoord(0.0f, 1.0f); obj->normal(0.0f, 0.0f, 1.0f); // bottom left obj->position(x, y, 0.0f); obj->textureCoord(0.0f, 0.0f); obj->normal(0.0f, 0.0f, 1.0f); // bottom right obj->position(x + tileW, y, 0.0f); obj->textureCoord(1.0f, 0.0f); obj->normal(0.0f, 0.0f, 1.0f); // top right obj->position(x + tileW, y + tileH, 0.0f); obj->textureCoord(1.0f, 1.0f); obj->normal(0.0f, 0.0f, 1.0f); obj->end(); if (draw_under_property_->getValue().toBool()) { // render under everything else obj->setRenderQueueGroup(Ogre::RENDER_QUEUE_4); } MapObject object; object.object = obj; object.texture = tex; object.material = material; objects_.push_back(object); } } scene_id_++; }