Emissive lighting for random buildings. Requires up to date fgdata.
This commit is contained in:
@@ -276,6 +276,13 @@ SGMaterial::read_properties(const SGReaderWriterOptions* options,
|
|||||||
SG_LOG(SG_GENERAL, SG_ALERT, "Cannot find texture \"" << bt);
|
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_small_ratio = props->getDoubleValue("building-small-ratio", 0.8);
|
||||||
building_medium_ratio = props->getDoubleValue("building-medium-ratio", 0.15);
|
building_medium_ratio = props->getDoubleValue("building-medium-ratio", 0.15);
|
||||||
building_large_ratio = props->getDoubleValue("building-large-ratio", 0.05);
|
building_large_ratio = props->getDoubleValue("building-large-ratio", 0.05);
|
||||||
|
|||||||
@@ -173,6 +173,15 @@ public:
|
|||||||
*/
|
*/
|
||||||
inline std::string get_building_texture () const { return building_texture; }
|
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
|
// 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); }
|
inline double get_building_small_fraction () const { return building_small_ratio / (building_small_ratio + building_medium_ratio + building_large_ratio); }
|
||||||
inline double get_building_medium_fraction () const { return building_medium_ratio / (building_small_ratio + building_medium_ratio + building_large_ratio); }
|
inline double get_building_medium_fraction () const { return building_medium_ratio / (building_small_ratio + building_medium_ratio + building_large_ratio); }
|
||||||
@@ -384,8 +393,9 @@ private:
|
|||||||
// building spacing
|
// building spacing
|
||||||
double building_spacing;
|
double building_spacing;
|
||||||
|
|
||||||
// building texture
|
// building texture & lightmap
|
||||||
std::string building_texture;
|
std::string building_texture;
|
||||||
|
std::string building_lightmap;
|
||||||
|
|
||||||
// Ratio of the 3 random building sizes
|
// Ratio of the 3 random building sizes
|
||||||
double building_small_ratio;
|
double building_small_ratio;
|
||||||
|
|||||||
@@ -611,9 +611,14 @@ osg::Group* createRandomBuildings(SGBuildingBinList buildings, const osg::Matrix
|
|||||||
SGPropertyNode_ptr effectProp = new SGPropertyNode;
|
SGPropertyNode_ptr effectProp = new SGPropertyNode;
|
||||||
makeChild(effectProp, "inherits-from")->setStringValue("Effects/building");
|
makeChild(effectProp, "inherits-from")->setStringValue("Effects/building");
|
||||||
SGPropertyNode* params = makeChild(effectProp, "parameters");
|
SGPropertyNode* params = makeChild(effectProp, "parameters");
|
||||||
// emphasize n = 0
|
// Main texture - n=0
|
||||||
params->getChild("texture", 0, true)->getChild("image", 0, true)
|
params->getChild("texture", 0, true)->getChild("image", 0, true)
|
||||||
->setStringValue(bin->texture);
|
->setStringValue(bin->texture);
|
||||||
|
|
||||||
|
// Light map - n=1
|
||||||
|
params->getChild("texture", 1, true)->getChild("image", 0, true)
|
||||||
|
->setStringValue(bin->lightMap);
|
||||||
|
|
||||||
effect = makeEffect(effectProp, true, options);
|
effect = makeEffect(effectProp, true, options);
|
||||||
if (iter == buildingEffectMap.end())
|
if (iter == buildingEffectMap.end())
|
||||||
buildingEffectMap.insert(EffectMap::value_type(bin->texture, effect));
|
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();
|
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);
|
mt->addChild(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ public:
|
|||||||
BuildingList buildings;
|
BuildingList buildings;
|
||||||
|
|
||||||
std::string texture;
|
std::string texture;
|
||||||
|
std::string lightMap;
|
||||||
|
|
||||||
void insert(const Building& model)
|
void insert(const Building& model)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -496,6 +496,7 @@ struct SGTileGeometryBin {
|
|||||||
if (!found) {
|
if (!found) {
|
||||||
bin = new SGBuildingBin();
|
bin = new SGBuildingBin();
|
||||||
bin->texture = mat->get_building_texture();
|
bin->texture = mat->get_building_texture();
|
||||||
|
bin->lightMap = mat->get_building_lightmap();
|
||||||
SG_LOG(SG_INPUT, SG_DEBUG, "Building texture " << bin->texture);
|
SG_LOG(SG_INPUT, SG_DEBUG, "Building texture " << bin->texture);
|
||||||
randomBuildings.push_back(bin);
|
randomBuildings.push_back(bin);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user