From: Stuart Buchanan Date: Tue, 1 May 2012 21:35:42 +0000 (+0100) Subject: Emissive lighting for random buildings. Requires up to date fgdata. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e44eb390469b4a2f368291a9304877b7bc65a6fb;p=simgear.git Emissive lighting for random buildings. Requires up to date fgdata. --- diff --git a/simgear/scene/material/mat.cxx b/simgear/scene/material/mat.cxx index 2082fd47..6e149230 100644 --- a/simgear/scene/material/mat.cxx +++ b/simgear/scene/material/mat.cxx @@ -274,8 +274,15 @@ SGMaterial::read_properties(const SGReaderWriterOptions* options, if (building_texture.empty()) { SG_LOG(SG_GENERAL, SG_ALERT, "Cannot find texture \"" << bt); + } + + bt = props->getStringValue("building-lightmap", "Textures/buildings-lightmap.png"); + building_lightmap = SGModelLib::findDataFile(bt, options); + + if (building_lightmap.empty()) { + SG_LOG(SG_GENERAL, SG_ALERT, "Cannot find texture \"" << bt); } - + building_small_ratio = props->getDoubleValue("building-small-ratio", 0.8); building_medium_ratio = props->getDoubleValue("building-medium-ratio", 0.15); building_large_ratio = props->getDoubleValue("building-large-ratio", 0.05); diff --git a/simgear/scene/material/mat.hxx b/simgear/scene/material/mat.hxx index f607f7fb..a939be4b 100644 --- a/simgear/scene/material/mat.hxx +++ b/simgear/scene/material/mat.hxx @@ -172,6 +172,15 @@ public: * @return The texture for auto-generated buildings. */ inline std::string get_building_texture () const { return building_texture; } + + /** + * Get the building lightmap. + * + * This is the lightmap used for auto-generated buildings. + * + * @return The lightmap for auto-generated buildings. + */ + inline std::string get_building_lightmap () const { return building_lightmap; } // Ratio of the 3 random building sizes inline double get_building_small_fraction () const { return building_small_ratio / (building_small_ratio + building_medium_ratio + building_large_ratio); } @@ -384,8 +393,9 @@ private: // building spacing double building_spacing; - // building texture + // building texture & lightmap std::string building_texture; + std::string building_lightmap; // Ratio of the 3 random building sizes double building_small_ratio; diff --git a/simgear/scene/tgdb/SGBuildingBin.cxx b/simgear/scene/tgdb/SGBuildingBin.cxx index 72d9ec50..95494f14 100644 --- a/simgear/scene/tgdb/SGBuildingBin.cxx +++ b/simgear/scene/tgdb/SGBuildingBin.cxx @@ -611,9 +611,14 @@ osg::Group* createRandomBuildings(SGBuildingBinList buildings, const osg::Matrix SGPropertyNode_ptr effectProp = new SGPropertyNode; makeChild(effectProp, "inherits-from")->setStringValue("Effects/building"); SGPropertyNode* params = makeChild(effectProp, "parameters"); - // emphasize n = 0 + // Main texture - n=0 params->getChild("texture", 0, true)->getChild("image", 0, true) ->setStringValue(bin->texture); + + // Light map - n=1 + params->getChild("texture", 1, true)->getChild("image", 0, true) + ->setStringValue(bin->lightMap); + effect = makeEffect(effectProp, true, options); if (iter == buildingEffectMap.end()) buildingEffectMap.insert(EffectMap::value_type(bin->texture, effect)); @@ -639,34 +644,6 @@ osg::Group* createRandomBuildings(SGBuildingBinList buildings, const osg::Matrix ref_ptr group = quadbuilding.getRoot(); - /* - // Set up the stateset for this building bin and the texture to use. - osg::StateSet* stateSet = group->getOrCreateStateSet(); - const std::string texturename = bin->texture; - osg::Texture2D* texture = SGLoadTexture2D(texturename); - texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::CLAMP_TO_EDGE); - texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::CLAMP_TO_EDGE); - stateSet->setTextureAttributeAndModes(0, texture); - - osg::ShadeModel* shadeModel = new osg::ShadeModel; - shadeModel->setMode(osg::ShadeModel::FLAT); - stateSet->setAttributeAndModes(shadeModel); - stateSet->setMode(GL_LIGHTING, osg::StateAttribute::ON); - stateSet->setMode(GL_FOG, osg::StateAttribute::ON); - stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON); - stateSet->setMode(GL_CULL_FACE, osg::StateAttribute::ON); - stateSet->setMode(GL_BLEND, osg::StateAttribute::OFF); - stateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::OFF); - stateSet->setAttribute(new osg::CullFace(osg::CullFace::BACK)); - - osg::Material* material = new osg::Material; - material->setAmbient(osg::Material::FRONT, osg::Vec4(0.3,0.3,0.3,1.0)); - material->setDiffuse(osg::Material::FRONT, osg::Vec4(1.0,1.0,1.0,1.0)); - material->setSpecular(osg::Material::FRONT, osg::Vec4(0,0,0,1.0)); - material->setShininess(osg::Material::FRONT, 0.0); - material->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE); - stateSet->setAttribute(material); - */ mt->addChild(group); } diff --git a/simgear/scene/tgdb/SGBuildingBin.hxx b/simgear/scene/tgdb/SGBuildingBin.hxx index 9c6d2619..3dfb3c38 100644 --- a/simgear/scene/tgdb/SGBuildingBin.hxx +++ b/simgear/scene/tgdb/SGBuildingBin.hxx @@ -86,6 +86,7 @@ public: BuildingList buildings; std::string texture; + std::string lightMap; void insert(const Building& model) { diff --git a/simgear/scene/tgdb/obj.cxx b/simgear/scene/tgdb/obj.cxx index cff3356a..1c925709 100644 --- a/simgear/scene/tgdb/obj.cxx +++ b/simgear/scene/tgdb/obj.cxx @@ -496,6 +496,7 @@ struct SGTileGeometryBin { if (!found) { bin = new SGBuildingBin(); bin->texture = mat->get_building_texture(); + bin->lightMap = mat->get_building_lightmap(); SG_LOG(SG_INPUT, SG_DEBUG, "Building texture " << bin->texture); randomBuildings.push_back(bin); }