}
-static int gen_light_map() {
- static const int env_tex_res = 32;
+// generate the directional white light environment texture map
+static int gen_white_light_map() {
+ const int env_tex_res = 32;
int half_res = env_tex_res / 2;
unsigned char env_map[env_tex_res][env_tex_res][4];
GLuint tex_name;
}
+// generate the directional vasi light environment texture map
+static int gen_vasi_light_map() {
+ const int env_tex_res = 256;
+ int half_res = env_tex_res / 2;
+ unsigned char env_map[env_tex_res][env_tex_res][4];
+ GLuint tex_name;
+
+ for ( int i = 0; i < env_tex_res; ++i ) {
+ for ( int j = 0; j < env_tex_res; ++j ) {
+ double x = (i - half_res) / (double)half_res;
+ double y = (j - half_res) / (double)half_res;
+ double dist = sqrt(x*x + y*y);
+ if ( dist > 1.0 ) { dist = 1.0; }
+ double bright = cos( dist * SGD_PI_2 );
+
+ // top half white, bottom half red
+ env_map[i][j][0] = 255;
+ if ( i < half_res ) {
+ env_map[i][j][1] = 255;
+ env_map[i][j][2] = 255;
+ } else {
+ env_map[i][j][1] = 0;
+ env_map[i][j][2] = 0;
+ }
+ env_map[i][j][3] = (int)(bright * 255);
+ }
+ }
+
+ glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
+ glGenTextures( 1, &tex_name );
+ glBindTexture( GL_TEXTURE_2D, tex_name );
+
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
+ glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, env_tex_res, env_tex_res, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, env_map);
+
+ return tex_name;
+}
+
+
// Load a library of material properties
bool FGMaterialLib::load( const string& mpath ) {
gnd_lights->disable( GL_LIGHTING );
matlib["GROUND_LIGHTS"] = new FGNewMat(gnd_lights);
- // hard coded runway light state
- ssgSimpleState *rwy_lights = new ssgSimpleState();
- rwy_lights->ref();
-
- rwy_lights->disable( GL_LIGHTING );
- rwy_lights->enable ( GL_CULL_FACE ) ;
- rwy_lights->enable( GL_TEXTURE_2D );
- rwy_lights->enable( GL_BLEND );
- rwy_lights->enable( GL_ALPHA_TEST );
- rwy_lights->enable( GL_COLOR_MATERIAL );
- rwy_lights->setMaterial ( GL_AMBIENT, 1.0, 1.0, 1.0, 1.0 );
- rwy_lights->setMaterial ( GL_DIFFUSE, 1.0, 1.0, 1.0, 1.0 );
- rwy_lights->setMaterial ( GL_SPECULAR, 0.0, 0.0, 0.0, 0.0 );
- rwy_lights->setMaterial ( GL_EMISSION, 0.0, 0.0, 0.0, 0.0 );
-
- rwy_lights->setTexture( gen_light_map() );
- matlib["RUNWAY_LIGHTS"] = new FGNewMat(rwy_lights);
+ // hard coded runway white light state
+ ssgSimpleState *rwy_white_lights = new ssgSimpleState();
+ rwy_white_lights->ref();
+ rwy_white_lights->disable( GL_LIGHTING );
+ rwy_white_lights->enable ( GL_CULL_FACE ) ;
+ rwy_white_lights->enable( GL_TEXTURE_2D );
+ rwy_white_lights->enable( GL_BLEND );
+ rwy_white_lights->enable( GL_ALPHA_TEST );
+ rwy_white_lights->enable( GL_COLOR_MATERIAL );
+ rwy_white_lights->setMaterial ( GL_AMBIENT, 1.0, 1.0, 1.0, 1.0 );
+ rwy_white_lights->setMaterial ( GL_DIFFUSE, 1.0, 1.0, 1.0, 1.0 );
+ rwy_white_lights->setMaterial ( GL_SPECULAR, 0.0, 0.0, 0.0, 0.0 );
+ rwy_white_lights->setMaterial ( GL_EMISSION, 0.0, 0.0, 0.0, 0.0 );
+ rwy_white_lights->setTexture( gen_white_light_map() );
+ matlib["RWY_WHITE_LIGHTS"] = new FGNewMat(rwy_white_lights);
+ // For backwards compatibility ... remove someday
+ matlib["RUNWAY_LIGHTS"] = new FGNewMat(rwy_white_lights);
+ // end of backwards compatitibilty
+
+ // hard coded runway vasi light state
+ ssgSimpleState *rwy_vasi_lights = new ssgSimpleState();
+ rwy_vasi_lights->ref();
+ rwy_vasi_lights->disable( GL_LIGHTING );
+ rwy_vasi_lights->enable ( GL_CULL_FACE ) ;
+ rwy_vasi_lights->enable( GL_TEXTURE_2D );
+ rwy_vasi_lights->enable( GL_BLEND );
+ rwy_vasi_lights->enable( GL_ALPHA_TEST );
+ rwy_vasi_lights->enable( GL_COLOR_MATERIAL );
+ rwy_vasi_lights->setMaterial ( GL_AMBIENT, 1.0, 1.0, 1.0, 1.0 );
+ rwy_vasi_lights->setMaterial ( GL_DIFFUSE, 1.0, 1.0, 1.0, 1.0 );
+ rwy_vasi_lights->setMaterial ( GL_SPECULAR, 0.0, 0.0, 0.0, 0.0 );
+ rwy_vasi_lights->setMaterial ( GL_EMISSION, 0.0, 0.0, 0.0, 0.0 );
+ rwy_vasi_lights->setTexture( gen_vasi_light_map() );
+ matlib["RWY_VASI_LIGHTS"] = new FGNewMat(rwy_vasi_lights);
return true;
}
int_list tex_index;
group_list::size_type i;
- bool is_lighting = false;
// generate points
string_list const& pt_materials = obj.get_pt_materials();
sgSetVec3( up, center->x(), center->y(), center->z() );
ssgBranch *branch = gen_directional_lights( nodes, normals,
pts_v[i], pts_n[i],
+ pt_materials[i],
up );
float ranges[] = { 0, 12000 };
branch->setCallback( SSG_CALLBACK_PREDRAW, runway_lights_predraw );
ssgBranch * random_object_branch = 0;
if (use_random_objects) {
float ranges[] = { 0, 20000 }; // Maximum 20km range for random objects
- ssgRangeSelector * object_lod = new ssgRangeSelector;
- object_lod->setRanges(ranges, 2);
- object_lod->setName("random-models");
- geometry->addKid(object_lod);
- random_object_branch = new ssgBranch;
- object_lod->addKid(random_object_branch);
+ ssgRangeSelector * object_lod = new ssgRangeSelector;
+ object_lod->setRanges(ranges, 2);
+ object_lod->setName("random-models");
+ geometry->addKid(object_lod);
+ random_object_branch = new ssgBranch;
+ object_lod->addKid(random_object_branch);
}
// generate triangles
// Generate a directional light
-ssgLeaf *gen_directional_light( sgVec3 pt, sgVec3 dir, sgVec3 up ) {
+ssgLeaf *gen_directional_light( sgVec3 pt, sgVec3 dir, sgVec3 up,
+ const string &material ) {
// calculate a vector perpendicular to dir and up
sgVec3 perp;
ssgLeaf *leaf =
new ssgVtxTable ( GL_TRIANGLES, vl, nl, NULL, cl );
- FGNewMat *newmat = material_lib.find( "RUNWAY_LIGHTS" );
+ FGNewMat *newmat = material_lib.find( material );
// FGNewMat *newmat = material_lib.find( "IrrCropPastureCover" );
leaf->setState( newmat->get_state() );
const point_list &normals,
const int_list &pnt_i,
const int_list &nml_i,
+ const string &material,
sgVec3 up )
{
ssgBranch *result = new ssgBranch;
nodes[pnt_i[i]][2] );
sgSetVec3( normal, normals[nml_i[i]][0], normals[nml_i[i]][1],
normals[nml_i[i]][2] );
- ssgLeaf *light = gen_directional_light( pt, normal, nup );
+ ssgLeaf *light = gen_directional_light( pt, normal, nup, material );
result->addKid( light );
// light = gen_normal_line( pt, normal, nup );
// result->addKid( light );
SetOffset( p );
-// #define USE_UP_AND_COMING_PLIB_FEATURE
-#ifdef USE_UP_AND_COMING_PLIB_FEATURE
terra_range->setRange( 0, SG_ZERO );
terra_range->setRange( 1, vis + bounding_radius );
if ( gnd_lights_range ) {
- gnd_lights_range->setRange( 0, SG_ZERO );
- gnd_lights_range->setRange( 1, vis * 1.5 + bounding_radius );
+ gnd_lights_range->setRange( 0, SG_ZERO );
+ gnd_lights_range->setRange( 1, vis * 1.5 + bounding_radius );
}
if ( rwy_lights_range ) {
- rwy_lights_range->setRange( 0, SG_ZERO );
- rwy_lights_range->setRange( 1, vis * 1.5 + bounding_radius );
+ rwy_lights_range->setRange( 0, SG_ZERO );
+ rwy_lights_range->setRange( 1, vis * 1.5 + bounding_radius );
}
-#else
- float ranges[2];
- ranges[0] = SG_ZERO;
- ranges[1] = vis + bounding_radius;
- terra_range->setRanges( ranges, 2 );
- if ( gnd_lights_range ) {
- ranges[1] = vis * 1.5 + bounding_radius;
- gnd_lights_range->setRanges( ranges, 2 );
- }
- if ( rwy_lights_range ) {
- ranges[1] = vis * 1.5 + bounding_radius;
- rwy_lights_range->setRanges( ranges, 2 );
- }
-#endif
+
sgVec3 sgTrans;
sgSetVec3( sgTrans, offset.x(), offset.y(), offset.z() );
terra_transform->setTransform( sgTrans );
}
}
- return (NULL != geometry);
+ return (geometry != NULL);
}
}
} else if ( token == "OBJECT" ) {
in >> name >> ::skipws;
- SG_LOG( SG_TERRAIN, SG_DEBUG, "token = " << token
+ SG_LOG( SG_TERRAIN, SG_INFO, "token = " << token
<< " name = " << name );
SGPath custom_path = tile_path;