]> git.mxchange.org Git - flightgear.git/commitdiff
Added support for specifying light coverage on a per material basis in the
authorcurt <curt>
Tue, 5 Dec 2000 20:53:14 +0000 (20:53 +0000)
committercurt <curt>
Tue, 5 Dec 2000 20:53:14 +0000 (20:53 +0000)
materials file (contributed by David Megginson.)

src/Objects/newmat.cxx
src/Objects/newmat.hxx
src/Objects/obj.cxx

index 696de0c30421dae58968a23bccd0e2eae7b67cc5..3f11930726725c5979cc4eabdb507e2e6c0eb9be 100644 (file)
@@ -42,6 +42,7 @@
 FGNewMat::FGNewMat ( void ) {
     wrapu = wrapv = 1;
     mipmap = 1;
+    light_coverage = -1.0;
 }
 
 
@@ -65,6 +66,7 @@ FGNewMat::FGNewMat ( const string &mat_name, const string &tex_name )
     diffuse[0]  = diffuse[1]  = diffuse[2]  = diffuse[3]  = 1.0;
     specular[0] = specular[1] = specular[2] = specular[3] = 1.0;
     emission[0] = emission[1] = emission[2] = emission[3] = 1.0;
+    light_coverage = -1.0;
 }
 
 
@@ -237,6 +239,8 @@ operator >> ( istream& in, FGNewMat& m )
            } else {
                FG_LOG( FG_TERRAIN, FG_INFO, "Bad alpha value " << token );
            }
+       } else if ( token == "light-coverage" ) {
+           in >> token >> m.light_coverage;
        } else if ( token[0] == '}' ) {
            break;
        }
index dc13a5507752673fad1703a205ae9430fc7245e0..f8cb93cc9be801e1278416fce373ed80d61396d4 100644 (file)
@@ -79,6 +79,13 @@ private:
     // use mipmapping?
     int mipmap;
 
+    // coverage of night lighting.  This number is specifically the
+    // amount of area coverage we give a single light.  The size of a
+    // triangle is divided by this number and that is the number of
+    // lights assigned to that triangle.  Lower numbers mean more
+    // dense light ocverage.
+    double light_coverage;
+
     // material properties
     sgVec4 ambient, diffuse, specular, emission;
 
@@ -119,6 +126,11 @@ public:
     inline void set_specular( sgVec4 s ) { sgCopyVec4( specular, s ); }
     inline void set_emission( sgVec4 e ) { sgCopyVec4( emission, e ); }
 
+    inline double get_light_coverage () const { return light_coverage; }
+    inline void set_light_coverage (double coverage) {
+       light_coverage = coverage;
+    }
+
     inline ssgStateSelector *get_state() const { return state; }
 
     void dump_info();
index 6d3336b54141801f273d93e0334bb497261e13c8..001c55fb67431c94310771554ec0b15e762a418e 100644 (file)
@@ -373,8 +373,9 @@ static void gen_random_surface_points( ssgLeaf *leaf, ssgVertexArray *lights,
 ssgBranch *fgObjLoad( const string& path, FGTileEntry *t,
                      ssgVertexArray *lights, const bool is_base)
 {
-    FGNewMat *newmat;
+    FGNewMat *newmat = NULL;
     string material;
+    float coverage = -1;
     Point3D pp;
     // sgVec3 approx_normal;
     // double normal[3], scale = 0.0;
@@ -560,11 +561,14 @@ ssgBranch *fgObjLoad( const string& path, FGTileEntry *t,
                    tex_width = newmat->get_xsize();
                    tex_height = newmat->get_ysize();
                    state = newmat->get_state();
+                   coverage = newmat->get_light_coverage();
                    // cout << "(w) = " << tex_width << " (h) = " 
                    //      << tex_width << endl;
+               } else {
+                   coverage = -1;
                }
            } else {
-               // unknown comment, just gobble the input untill the
+               // unknown comment, just gobble the input until the
                // end of line
 
                in >> skipeol;
@@ -773,39 +777,49 @@ ssgBranch *fgObjLoad( const string& path, FGTileEntry *t,
                tile->addKid( leaf );
 
                if ( is_base ) {
-                   // generate lighting
-                   if ( material == "Urban" || material == "BuiltUpCover" ) {
-                       gen_random_surface_points( leaf, lights, 100000.0 );
-                   } else if ( material == "EvergreenBroadCover" ||
-                               material == "Default" || material == "Island" ||
-                               material == "SomeSort" ||
-                               material == "DeciduousBroadCover" ||
-                               material == "EvergreenNeedleCover" ||
-                               material == "DeciduousNeedleCover" ) {
-                       gen_random_surface_points( leaf, lights, 10000000.0 );
-                   } else if ( material == "MixedForestCover" ) {
-                       gen_random_surface_points( leaf, lights, 5000000.0 );
-                   } else if ( material == "WoodedTundraCover" ||
-                               material == "BareTundraCover" ||
-                               material == "HerbTundraCover" ||
-                               material == "MixedTundraCover" ||
-                               material == "Marsh" ||
-                               material == "HerbWetlandCover" ||
-                               material == "WoodedWetlandCover" ) {
-                       gen_random_surface_points( leaf, lights, 20000000.0 );
-                   } else if ( material == "ShrubCover" ||
-                               material == "ShrubGrassCover" ) {
-                       gen_random_surface_points( leaf, lights, 4000000.0 );
-                   } else if ( material == "GrassCover" ||
-                               material == "SavannaCover" ) {
-                       gen_random_surface_points( leaf, lights, 4000000.0 );
-                   } else if ( material == "MixedCropPastureCover" ||
-                               material == "IrrCropPastureCover" ||
-                               material == "DryCropPastureCover" ||
-                               material == "CropGrassCover" ||
-                               material == "CropWoodCover" ) {
-                       gen_random_surface_points( leaf, lights, 2000000.0 );
+                   if ( coverage > 0.0 ) {
+                       if ( coverage < 10000.0 ) {
+                           FG_LOG(FG_INPUT, FG_ALERT, "Light coverage is "
+                                  << coverage << ", pushing up to 10000");
+                           coverage = 10000;
+                       }
+                       gen_random_surface_points(leaf, lights, coverage);
                    }
+//                 // generate lighting
+//                 if ( material == "Urban" || material == "BuiltUpCover" ) {
+//                     gen_random_surface_points( leaf, lights, 100000.0 );
+//                 } else if ( material == "EvergreenBroadCover" ||
+//                             material == "Default" || material == "Island" ||
+//                             material == "SomeSort" ||
+//                             material == "DeciduousBroadCover" ||
+//                             material == "EvergreenNeedleCover" ||
+//                             material == "DeciduousNeedleCover" ) {
+//                     gen_random_surface_points( leaf, lights, 10000000.0 );
+//                 } else if ( material == "Road") {
+//                     gen_random_surface_points( leaf, lights,  10000.0);
+//                 } else if ( material == "MixedForestCover" ) {
+//                     gen_random_surface_points( leaf, lights, 5000000.0 );
+//                 } else if ( material == "WoodedTundraCover" ||
+//                             material == "BareTundraCover" ||
+//                             material == "HerbTundraCover" ||
+//                             material == "MixedTundraCover" ||
+//                             material == "Marsh" ||
+//                             material == "HerbWetlandCover" ||
+//                             material == "WoodedWetlandCover" ) {
+//                     gen_random_surface_points( leaf, lights, 20000000.0 );
+//                 } else if ( material == "ShrubCover" ||
+//                             material == "ShrubGrassCover" ) {
+//                     gen_random_surface_points( leaf, lights, 4000000.0 );
+//                 } else if ( material == "GrassCover" ||
+//                             material == "SavannaCover" ) {
+//                     gen_random_surface_points( leaf, lights, 4000000.0 );
+//                 } else if ( material == "MixedCropPastureCover" ||
+//                             material == "IrrCropPastureCover" ||
+//                             material == "DryCropPastureCover" ||
+//                             material == "CropGrassCover" ||
+//                             material == "CropWoodCover" ) {
+//                     gen_random_surface_points( leaf, lights, 2000000.0 );
+//                 }
                }
            } else {
                FG_LOG( FG_TERRAIN, FG_WARN, "Unknown token in "