Emissive lighting for random buildings. Requires up to date fgdata.

This commit is contained in:
Stuart Buchanan
2012-05-01 22:35:42 +01:00
parent ab7d2a4bcc
commit e44eb39046
5 changed files with 27 additions and 31 deletions

View 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);

View 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;

View 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);
}

View File

@@ -86,6 +86,7 @@ public:
BuildingList buildings;
std::string texture;
std::string lightMap;
void insert(const Building& model)
{

View 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);
}