Begin work on improving runway lighting infrastructure.
This commit is contained in:
parent
e74c4d9437
commit
f54302e9e9
5 changed files with 99 additions and 50 deletions
|
@ -106,8 +106,9 @@ static int gen_test_light_map() {
|
|||
}
|
||||
|
||||
|
||||
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;
|
||||
|
@ -142,6 +143,49 @@ static int gen_light_map() {
|
|||
}
|
||||
|
||||
|
||||
// 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 ) {
|
||||
|
||||
|
@ -191,23 +235,40 @@ 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();
|
||||
// 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
|
||||
|
||||
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 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;
|
||||
}
|
||||
|
|
|
@ -1390,7 +1390,6 @@ bool fgBinObjLoad( const string& path, const bool is_base,
|
|||
int_list tex_index;
|
||||
|
||||
group_list::size_type i;
|
||||
bool is_lighting = false;
|
||||
|
||||
// generate points
|
||||
string_list const& pt_materials = obj.get_pt_materials();
|
||||
|
@ -1403,6 +1402,7 @@ bool fgBinObjLoad( const string& path, const bool is_base,
|
|||
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 );
|
||||
|
@ -1426,12 +1426,12 @@ bool fgBinObjLoad( const string& path, const bool is_base,
|
|||
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
|
||||
|
|
|
@ -30,7 +30,8 @@
|
|||
|
||||
|
||||
// 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;
|
||||
|
@ -96,7 +97,7 @@ ssgLeaf *gen_directional_light( sgVec3 pt, sgVec3 dir, sgVec3 up ) {
|
|||
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() );
|
||||
|
||||
|
@ -136,6 +137,7 @@ ssgBranch *gen_directional_lights( const point_list &nodes,
|
|||
const point_list &normals,
|
||||
const int_list &pnt_i,
|
||||
const int_list &nml_i,
|
||||
const string &material,
|
||||
sgVec3 up )
|
||||
{
|
||||
ssgBranch *result = new ssgBranch;
|
||||
|
@ -150,7 +152,7 @@ ssgBranch *gen_directional_lights( const point_list &nodes,
|
|||
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 );
|
||||
|
|
|
@ -103,6 +103,7 @@ ssgBranch *gen_directional_lights( const point_list &nodes,
|
|||
const point_list &normals,
|
||||
const int_list &pnt_i,
|
||||
const int_list &nml_i,
|
||||
const string &material,
|
||||
sgVec3 up );
|
||||
|
||||
|
||||
|
|
|
@ -807,32 +807,17 @@ void FGTileEntry::prep_ssg_node( const Point3D& p, sgVec3 up, float vis) {
|
|||
|
||||
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 );
|
||||
|
@ -1105,7 +1090,7 @@ bool FGTileEntry::obj_load( const std::string& path,
|
|||
}
|
||||
}
|
||||
|
||||
return (NULL != geometry);
|
||||
return (geometry != NULL);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1170,7 +1155,7 @@ FGTileEntry::load( const SGPath& base, bool is_base )
|
|||
}
|
||||
} 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;
|
||||
|
|
Loading…
Add table
Reference in a new issue