]> git.mxchange.org Git - simgear.git/commitdiff
Emissive lighting for random buildings. Requires up to date fgdata.
authorStuart Buchanan <stuart_d_buchanan@yahoo.co.uk>
Tue, 1 May 2012 21:35:42 +0000 (22:35 +0100)
committerStuart Buchanan <stuart_d_buchanan@yahoo.co.uk>
Tue, 1 May 2012 21:35:42 +0000 (22:35 +0100)
simgear/scene/material/mat.cxx
simgear/scene/material/mat.hxx
simgear/scene/tgdb/SGBuildingBin.cxx
simgear/scene/tgdb/SGBuildingBin.hxx
simgear/scene/tgdb/obj.cxx

index 2082fd47e83d0485acd51ccad8d439fb51325e51..6e149230097b332446bf96c83c126c948bd1f0fb 100644 (file)
@@ -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);
index f607f7fb32a4805428e0ab27ca9fdc07c6dc5b69..a939be4baf53ea5b060f4297fec233c424370160 100644 (file)
@@ -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;
index 72d9ec50f653d8caa0782b258edc00e2bd2f6f22..95494f142ea522161bdc665c594671c1475c47f4 100644 (file)
@@ -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> 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);        
     }
     
index 9c6d261902955607e60e0abe360db791d683e871..3dfb3c38b7258a590a76153adeb0ba71db3c0817 100644 (file)
@@ -86,6 +86,7 @@ public:
   BuildingList buildings;
   
   std::string texture;
+  std::string lightMap;
 
   void insert(const Building& model)
   { 
index cff3356a01e73307e814c2030199937757101e9c..1c9257099b4ad82dde89674162a12a0517d20913 100644 (file)
@@ -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);
       }