From 053bda26a43314a91b01b08cd4617da82f7ab807 Mon Sep 17 00:00:00 2001 From: Stuart Buchanan Date: Wed, 25 Sep 2019 21:53:19 +0100 Subject: [PATCH] Shader buildings - split wall and roof tex index Previously there was very limited texture variations as a given texture index was used for both the wall and ceiling. Now these can be specified separately, allowing for more variation in both STG defined and random buildings. --- simgear/scene/tgdb/SGBuildingBin.cxx | 100 ++++++++++++++++----------- simgear/scene/tgdb/SGBuildingBin.hxx | 27 ++++++-- 2 files changed, 80 insertions(+), 47 deletions(-) diff --git a/simgear/scene/tgdb/SGBuildingBin.cxx b/simgear/scene/tgdb/SGBuildingBin.cxx index 96465d89..5cd24dc3 100644 --- a/simgear/scene/tgdb/SGBuildingBin.cxx +++ b/simgear/scene/tgdb/SGBuildingBin.cxx @@ -104,7 +104,7 @@ struct MakeBuildingLeaf for (int i=0; i<4; ++i) { n->push_back( osg::Vec3(1, 0, 0) ); // normal - c->push_back( osg::Vec4(1, 0, 0, 0) ); // color - used to identify faces + c->push_back( osg::Vec4(1, 0, 0, 0) ); // color - used to differentiate wall from roof } // Left face @@ -115,7 +115,7 @@ struct MakeBuildingLeaf for (int i=0; i<4; ++i) { n->push_back( osg::Vec3(0, -1, 0) ); // normal - c->push_back( osg::Vec4(0, 1, 0, 0) ); // color - used to identify faces + c->push_back( osg::Vec4(1, 0, 0, 0) ); // color - used to differentiate wall from roof } // Back face @@ -126,7 +126,7 @@ struct MakeBuildingLeaf for (int i=0; i<4; ++i) { n->push_back( osg::Vec3(-1, 0, 0) ); // normal - c->push_back( osg::Vec4(1, 0, 0, 0) ); // color - used to identify faces + c->push_back( osg::Vec4(1, 0, 0, 0) ); // color - used to differentiate wall from roof } // Right face @@ -137,7 +137,7 @@ struct MakeBuildingLeaf for (int i=0; i<4; ++i) { n->push_back( osg::Vec3(0, 1, 0) ); // normal - c->push_back( osg::Vec4(0, 1, 0, 0) ); // color - used to identify faces + c->push_back( osg::Vec4(1, 0, 0, 0) ); // color - used to differentiate wall from roof } // MAIN BODY @@ -149,7 +149,7 @@ struct MakeBuildingLeaf for (int i=0; i<4; ++i) { n->push_back( osg::Vec3(1, 0, 0) ); // normal - c->push_back( osg::Vec4(1, 0, 0, 0) ); // color - used to identify faces + c->push_back( osg::Vec4(1, 0, 0, 0) ); // color - used to differentiate wall from roof } // Left face @@ -160,7 +160,7 @@ struct MakeBuildingLeaf for (int i=0; i<4; ++i) { n->push_back( osg::Vec3(0, -1, 0) ); // normal - c->push_back( osg::Vec4(0, 1, 0, 0) ); // color - used to identify faces + c->push_back( osg::Vec4(1, 0, 0, 0) ); // color - used to differentiate wall from roof } // Back face @@ -171,7 +171,7 @@ struct MakeBuildingLeaf for (int i=0; i<4; ++i) { n->push_back( osg::Vec3(-1, 0, 0) ); // normal - c->push_back( osg::Vec4(1, 0, 0, 0) ); // color - used to identify faces + c->push_back( osg::Vec4(1, 0, 0, 0) ); // color - used to differentiate wall from roof } // Right face @@ -182,7 +182,7 @@ struct MakeBuildingLeaf for (int i=0; i<4; ++i) { n->push_back( osg::Vec3(0, 1, 0) ); // normal - c->push_back( osg::Vec4(0, 1, 0, 0) ); // color - used to identify faces + c->push_back( osg::Vec4(1, 0, 0, 0) ); // color - used to differentiate wall from roof } // ROOF - assume pitched - will be flattened in shader if required. @@ -194,7 +194,7 @@ struct MakeBuildingLeaf for (int i=0; i<4; ++i) { n->push_back( osg::Vec3(0.707, 0, 0.707) ); // normal - c->push_back( osg::Vec4(0, 0, 1, 0) ); // color - used to identify faces + c->push_back( osg::Vec4(0, 1, 0, 0) ); // color - used to differentiate wall from roof } // Left pitched roof @@ -205,7 +205,7 @@ struct MakeBuildingLeaf for (int i=0; i<4; ++i) { n->push_back( osg::Vec3(0, -1, 0) ); // normal - c->push_back( osg::Vec4(0, 1, 0, 0) ); // color - used to identify faces + c->push_back( osg::Vec4(0, 1, 0, 0) ); // color - used to differentiate wall from roof } // Back pitched roof @@ -216,7 +216,7 @@ struct MakeBuildingLeaf for (int i=0; i<4; ++i) { n->push_back( osg::Vec3(-0.707, 0, 0.707) ); // normal - c->push_back( osg::Vec4(0, 0, 1, 0) ); // color - used to identify faces + c->push_back( osg::Vec4(0, 1, 0, 0) ); // color - used to differentiate wall from roof } // Right pitched roof @@ -227,7 +227,7 @@ struct MakeBuildingLeaf for (int i=0; i<4; ++i) { n->push_back( osg::Vec3(0, 1, 0) ); // normal - c->push_back( osg::Vec4(0, 1, 0, 0) ); // color - used to identify faces + c->push_back( osg::Vec4(0, 1, 0, 0) ); // color - used to differentiate wall from roof } // The 1024x1024 texture is split into 32x16 blocks. @@ -308,6 +308,7 @@ struct MakeBuildingLeaf geom->setVertexAttribArray(BUILDING_SCALE_ATTR, new osg::Vec3Array, Array::BIND_PER_VERTEX); geom->setVertexAttribArray(BUILDING_ROT_PITCH_TEX0X_ATTR, new osg::Vec3Array, Array::BIND_PER_VERTEX); geom->setVertexAttribArray(BUILDING_TEX0Y_TEX1X_TEX1Y_ATTR, new osg::Vec3Array, Array::BIND_PER_VERTEX); + geom->setVertexAttribArray(BUILDING_RTEX0X_RTEX0Y_ATTR, new osg::Vec3Array, Array::BIND_PER_VERTEX); geom->addPrimitiveSet( new osg::DrawArrays( GL_QUADS, 0, 48, 0) ); @@ -320,6 +321,7 @@ struct MakeBuildingLeaf ss->setAttributeAndModes(new osg::VertexAttribDivisor(BUILDING_SCALE_ATTR, 1)); ss->setAttributeAndModes(new osg::VertexAttribDivisor(BUILDING_ROT_PITCH_TEX0X_ATTR, 1)); ss->setAttributeAndModes(new osg::VertexAttribDivisor(BUILDING_TEX0Y_TEX1X_TEX1Y_ATTR, 1)); + ss->setAttributeAndModes(new osg::VertexAttribDivisor(BUILDING_RTEX0X_RTEX0Y_ATTR, 1)); LOD* result = new LOD; result->addChild(geode, 0, _range); @@ -342,15 +344,15 @@ struct AddBuildingLeafObject osg::Vec3Array* positions = static_cast (geom->getVertexAttribArray(BUILDING_POSITION_ATTR)); // (x,y,z) osg::Vec3Array* scale = static_cast (geom->getVertexAttribArray(BUILDING_SCALE_ATTR)); // (width, depth, height) - osg::Vec3Array* rot = static_cast (geom->getVertexAttribArray(BUILDING_ROT_PITCH_TEX0X_ATTR)); // (rotation, pitch height, texture x offset) - osg::Vec3Array* tex = static_cast (geom->getVertexAttribArray(BUILDING_TEX0Y_TEX1X_TEX1Y_ATTR)); // (texture y offset, texture x gain, texture y gain) + osg::Vec3Array* rot = static_cast (geom->getVertexAttribArray(BUILDING_ROT_PITCH_TEX0X_ATTR)); // (rotation, pitch height, wall texture x offset) + osg::Vec3Array* tex = static_cast (geom->getVertexAttribArray(BUILDING_TEX0Y_TEX1X_TEX1Y_ATTR)); // (wall texture y offset, wall/roof texture x gain, wall/roof texture y gain) + osg::Vec3Array* rtex = static_cast (geom->getVertexAttribArray(BUILDING_RTEX0X_RTEX0Y_ATTR)); // (roof texture x offset, roof texture y offset, unused) positions->push_back(building.position); scale->push_back(osg::Vec3(building.width, building.depth, building.height)); - rot->push_back(osg::Vec3(building.rotation, building.pitch_height, building.tex0.x())); - tex->push_back(osg::Vec3(building.tex0.y(), building.tex1.x(), building.tex1.y())); - - if ((building.tex0.y() > (1470.0f / 2048.0f)) && (building.tex1.x() > 0.25f)) cerr << "Building texture out of bounds " << building.tex0.y() << " " << building.tex1.x() << "\n"; + rot->push_back(osg::Vec3(building.rotation, building.pitch_height, building.walltex0.x())); + tex->push_back(osg::Vec3(building.walltex0.y(), building.tex1.x(), building.tex1.y())); + rtex->push_back(osg::Vec3(building.rooftex0.x(), building.rooftex0.y(), 0.0f)); DrawArrays* primSet = static_cast(geom->getPrimitiveSet(0)); primSet->setNumInstances(positions->size()); @@ -399,7 +401,7 @@ typedef QuadTreeBuilder> x >> y >> z >> r >> b >> w >> d >> h >> p >> s >> o >> f >> t; + int b, s, o, f, wt, rt; + in >> x >> y >> z >> r >> b >> w >> d >> h >> p >> s >> o >> f >> wt >> rt; //SG_LOG(SG_TERRAIN, SG_ALERT, "Building entry " << x << " " << y << " " << z << " " << b ); SGVec3f loc = SGVec3f(x,y,z); @@ -435,7 +438,7 @@ typedef QuadTreeBuilderget_building_large_pitch()) ? 3.0 : 0.0; } - insert(p, r, buildingtype, width, depth, height, pitch_height, floors, (int) (mt_rand(&seed) * 1000.0)); + insert(p, r, buildingtype, width, depth, height, pitch_height, floors, (int) (mt_rand(&seed) * 1000.0), (int) (mt_rand(&seed) * 1000.0)); } int SGBuildingBin::getNumBuildings() { diff --git a/simgear/scene/tgdb/SGBuildingBin.hxx b/simgear/scene/tgdb/SGBuildingBin.hxx index 67e94ce3..666a1f45 100644 --- a/simgear/scene/tgdb/SGBuildingBin.hxx +++ b/simgear/scene/tgdb/SGBuildingBin.hxx @@ -54,8 +54,9 @@ // these correspond to building.eff const int BUILDING_POSITION_ATTR = 10; // (x,y,z) const int BUILDING_SCALE_ATTR = 11; // (width, depth, height) -const int BUILDING_ROT_PITCH_TEX0X_ATTR = 12; // (rotation, pitch height, texture x offset) -const int BUILDING_TEX0Y_TEX1X_TEX1Y_ATTR = 13; // (texture y offset, texture x gain, texture y gain) +const int BUILDING_ROT_PITCH_TEX0X_ATTR = 12; // (rotation, pitch height, wall texture x offset) +const int BUILDING_TEX0Y_TEX1X_TEX1Y_ATTR = 13; // (wall texture y offset, texture x gain, texture y gain) +const int BUILDING_RTEX0X_RTEX0Y_ATTR = 14; // (roof texture x offset, roof texture y offset, unused) using namespace osg; @@ -90,14 +91,15 @@ public: LARGE }; struct BuildingInstance { - BuildingInstance(Vec3f p, float w, float d, float h, float ph, float r, Vec2f t0, Vec2f t1) : + BuildingInstance(Vec3f p, float w, float d, float h, float ph, float r, Vec2f wt0, Vec2f rt0, Vec2f t1) : position(p), width(w), depth(d), height(h), pitch_height(ph), rotation(r), - tex0(t0), + walltex0(wt0), + rooftex0(rt0), tex1(t1) { } @@ -108,7 +110,8 @@ public: height(b.height), pitch_height(b.pitch_height), rotation(b.rotation), - tex0(b.tex0), + walltex0(b.walltex0), + rooftex0(b.rooftex0), tex1(b.tex1) { } @@ -120,7 +123,8 @@ public: float pitch_height; float rotation; - Vec2f tex0; + Vec2f walltex0; + Vec2f rooftex0; Vec2f tex1; // References to allow the QuadTreeBuilder to work @@ -159,7 +163,16 @@ public: ~SGBuildingBin(); // Generate a building specifying the exact position, dimensions and texture index. - void insert(SGVec3f p, float r, BuildingType buildingtype, float width, float depth, float height, float pitch_height, int floors, int tex_index); + void insert(SGVec3f p, + float r, + BuildingType buildingtype, + float width, + float depth, + float height, + float pitch_height, + int floors, + int wall_tex_index, + int roof_tex_index); // Generate a building of a given type at a specified position, using the random building material definition to determine the dimensions and texture index. void insert(SGVec3f p, float r, BuildingType type);