Panda3D
|
00001 // Filename: config_speedtree.cxx 00002 // Created by: drose (30Sep10) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "config_speedtree.h" 00016 #include "speedTreeNode.h" 00017 #include "stBasicTerrain.h" 00018 #include "stTerrain.h" 00019 #include "stTree.h" 00020 #include "loaderFileTypeSrt.h" 00021 #include "loaderFileTypeStf.h" 00022 #include "loaderFileTypeRegistry.h" 00023 #include "dconfig.h" 00024 00025 ConfigureDef(config_speedtree); 00026 NotifyCategoryDef(speedtree, ""); 00027 00028 ConfigureFn(config_speedtree) { 00029 init_libspeedtree(); 00030 } 00031 00032 ConfigVariableString speedtree_license 00033 ("speedtree-license", "", 00034 PRC_DESC("Specify the license string to pass to SpeedTreeNode::authorize() by default.")); 00035 00036 #ifndef CPPPARSER 00037 ConfigVariableFilename speedtree_shaders_dir 00038 ("speedtree-shaders-dir", Filename(Filename::from_os_specific(SPEEDTREE_BIN_DIR), "Shaders"), 00039 PRC_DESC("Specifies the directory in which to locate SpeedTree's system " 00040 "shaders at runtime. If this is empty, the default is based on " 00041 "SPEEDTREE_BIN_DIR, as provided at compile time.")); 00042 #endif // CPPPARSER 00043 00044 ConfigVariableFilename speedtree_textures_dir 00045 ("speedtree-textures-dir", "", 00046 PRC_DESC("Specifies the directory in which to locate textures referenced " 00047 "by SRT files at runtime. The default is to search in the same " 00048 "directory as the SRT file itself. Unfortunately, the model-path " 00049 "cannot be searched, because SpeedTree only provides a single " 00050 "directory option.")); 00051 00052 ConfigVariableDouble speedtree_max_anisotropy 00053 ("speedtree-max-anisotropy", 0.0, 00054 PRC_DESC("Specifies the maximum anisotropy for SpeedTree textures.")); 00055 00056 ConfigVariableBool speedtree_horizontal_billboards 00057 ("speedtree-horizontal-billboards", true, 00058 PRC_DESC("Set this true to allow the use of horizontal billboards in " 00059 "SpeedTree, or false to disallow them. Horizontal billboards " 00060 "may be defined for some trees to provide a billboard LOD " 00061 "when the tree is seen from above.")); 00062 00063 ConfigVariableDouble speedtree_alpha_test_scalar 00064 ("speedtree-alpha-test-scalar", 0.57, 00065 PRC_DESC("Undocumented speedtree config.")); 00066 00067 ConfigVariableBool speedtree_z_pre_pass 00068 ("speedtree-z-pre-pass", false, 00069 PRC_DESC("True if the SpeedTree renderer should perform a first pass " 00070 "to fill the depth buffer before going back to draw pixels. " 00071 "This can result in a cost savings if there is much overdraw and " 00072 "if the pixel shader is particularly expensive, but in most cases " 00073 "it will result in a cost penalty.")); 00074 00075 ConfigVariableInt speedtree_max_billboard_images_by_base 00076 ("speedtree-max-billboard-images-by-base", 20, 00077 PRC_DESC("Specifies the maximum number of billboard images used by any single " 00078 "tree.")); 00079 00080 ConfigVariableDouble speedtree_visibility 00081 ("speedtree-visibility", 1000.0, 00082 PRC_DESC("Undocumented SpeedTree parameter.")); 00083 00084 ConfigVariableDouble speedtree_global_light_scalar 00085 ("speedtree-global-light-scalar", 1.0, 00086 PRC_DESC("Undocumented SpeedTree parameter.")); 00087 00088 ConfigVariableBool speedtree_specular_lighting 00089 ("speedtree-specular-lighting", false, 00090 PRC_DESC("True to enable specular lighting effects in SpeedTree.")); 00091 00092 ConfigVariableBool speedtree_transmission_lighting 00093 ("speedtree-transmission-lighting", false, 00094 PRC_DESC("True to enable transmission lighting effects in SpeedTree.")); 00095 00096 ConfigVariableBool speedtree_detail_layer 00097 ("speedtree-detail-layer", false, 00098 PRC_DESC("True to render the detail texture layer defined on tree and " 00099 "terrain objects, false otherwise.")); 00100 00101 ConfigVariableBool speedtree_detail_normal_mapping 00102 ("speedtree-detail-normal-mapping", false, 00103 PRC_DESC("True to render the detail normal maps defined on tree and " 00104 "terrain objects, false otherwise.")); 00105 00106 ConfigVariableBool speedtree_ambient_contrast 00107 ("speedtree-ambient-contrast", false, 00108 PRC_DESC("Undocumented SpeedTree parameter.")); 00109 00110 ConfigVariableDouble speedtree_transmission_scalar 00111 ("speedtree-transmission-scalar", 1.0f, 00112 PRC_DESC("Undocumented SpeedTree parameter.")); 00113 00114 ConfigVariableDouble speedtree_fog_distance 00115 ("speedtree-fog-distance", "2500 5000", 00116 PRC_DESC("Specifies the nearest and farthest distance of the fog on trees " 00117 "and terrain.")); 00118 00119 ConfigVariableDouble speedtree_fog_color 00120 ("speedtree-fog-color", "1.0 1.0 1.0", 00121 PRC_DESC("Specifies the r g b color of SpeedTree fog.")); 00122 00123 ConfigVariableDouble speedtree_sky_color 00124 ("speedtree-sky-color", "0.2 0.3 0.5", 00125 PRC_DESC("Specifies the r g b color of the SpeedTree sky, when the sky " 00126 "is enabled. Currently unused.")); 00127 00128 ConfigVariableDouble speedtree_sky_fog 00129 ("speedtree-sky-fog", "-0.5 1.0", 00130 PRC_DESC("Specifies the range of fog in the sky. -1 is down, 1 is up.")); 00131 00132 ConfigVariableDouble speedtree_sun_color 00133 ("speedtree-sun-color", "1.0 1.0 0.85", 00134 PRC_DESC("Specifies the r g b color of the SpeedTree sun, when the sun " 00135 "is enabled. Currently unused.")); 00136 00137 ConfigVariableDouble speedtree_sun_size 00138 ("speedtree-sun-size", 0.001, 00139 PRC_DESC("Undocumented SpeedTree parameter.")); 00140 00141 ConfigVariableDouble speedtree_sun_spread_exponent 00142 ("speedtree-sun-spread-exponent", 200.0, 00143 PRC_DESC("Undocumented SpeedTree parameter.")); 00144 00145 ConfigVariableDouble speedtree_sun_fog_bloom 00146 ("speedtree-sun-fog-bloom", 0.0, 00147 PRC_DESC("Undocumented SpeedTree parameter.")); 00148 00149 ConfigVariableDouble speedtree_specular_color 00150 ("speedtree-specular-color", "1 1 1", 00151 PRC_DESC("Specifies the r g b color of the specular reflections on SpeedTree " 00152 "surfaces.")); 00153 00154 ConfigVariableDouble speedtree_emissive_color 00155 ("speedtree-emissive-color", "0 0 0", 00156 PRC_DESC("Specifies the r g b color of the emissive light effect on SpeedTree " 00157 "surfaces.")); 00158 00159 ConfigVariableInt speedtree_shadow_map_resolution 00160 ("speedtree-shadow-map-resolution", 0, //1024, 00161 PRC_DESC("Specifies the resolution for rendering shadow maps. Should " 00162 "be a power of 2. Specify 0 to disable shadowing in SpeedTree.")); 00163 00164 ConfigVariableDouble speedtree_cascading_shadow_splits 00165 ("speedtree-cascading-shadow-splits", "200 400 600", 00166 PRC_DESC("Specifies the shadow split distance, in spatial units, for " 00167 "each shadow map to be rendered. The number of values also " 00168 "implies the number of shadow maps, to a maximum value compiled " 00169 "within SpeedTree (typically 4).")); 00170 00171 ConfigVariableBool speedtree_smooth_shadows 00172 ("speedtree-smooth-shadows", false, 00173 PRC_DESC("True to enable a smoothing pass on the shadow maps.")); 00174 00175 ConfigVariableBool speedtree_show_shadow_splits_on_terrain 00176 ("speedtree-show-shadow-splits-on-terrain", false, 00177 PRC_DESC("Currently unsupported.")); 00178 00179 ConfigVariableBool speedtree_wind_enabled 00180 ("speedtree-wind-enabled", true, 00181 PRC_DESC("True to enable global wind in the SpeedTree world.")); 00182 00183 ConfigVariableBool speedtree_frond_rippling 00184 ("speedtree-frond-rippling", true, 00185 PRC_DESC("True to allow fronds to respond to the global wind.")); 00186 00187 ConfigVariableInt speedtree_terrain_num_lods 00188 ("speedtree-terrain-num-lods", 5, 00189 PRC_DESC("Specifies the number of different LOD stages to use in " 00190 "rendering terrain. Each stage has 75% few polygons than the " 00191 "stage before. Increasing this number decreases the total " 00192 "number of polygons onscreen, at the cost of visual quality of " 00193 "distant terrain.")); 00194 00195 ConfigVariableInt speedtree_terrain_resolution 00196 ("speedtree-terrain-resolution", 33, 00197 PRC_DESC("Specifies the number of vertices per edge of each terrain grid " 00198 "cell at the highest LOD. This must be a power of two plus 1.")); 00199 00200 ConfigVariableInt speedtree_terrain_cell_size 00201 ("speedtree-terrain-cell-size", 800, 00202 PRC_DESC("Specifies the size in spatial units of one edge of a terrain " 00203 "grid cell. This effects culling and resolution, but has nothing " 00204 "to do with the scale of the heightmap or other maps.")); 00205 00206 ConfigVariableDouble speedtree_shadow_fade 00207 ("speedtree-shadow-fade", 0.25, 00208 PRC_DESC("Specifies the rate at which shadows fade to transparency in the " 00209 "distance.")); 00210 00211 ConfigVariableBool speedtree_show_overlays 00212 ("speedtree-show-overlays", false, 00213 PRC_DESC("True to draw onscreen overlays showing the generated " 00214 "shadow map(s).")); 00215 00216 ConfigVariableInt speedtree_max_num_visible_cells 00217 ("speedtree-max-num-visible-cells", 75, 00218 PRC_DESC("Specifies the maximum number of cells in a single SpeedTree forest " 00219 "frustum. This is used internally by SpeedTree's billboard system.")); 00220 00221 ConfigVariableDouble speedtree_cull_cell_size 00222 ("speedtree-cull-cell-size", 1200, 00223 PRC_DESC("Specifies the size of a single SpeedTree cull cell, in Panda " 00224 "units. Increasing this number decreases the number of " 00225 "individual calls that must be made to render geometry, " 00226 "while increasing the number of trees that are rendered " 00227 "per call.")); 00228 00229 ConfigVariableDouble speedtree_area_scale 00230 ("speedtree-area-scale", 3280.839895013, 00231 PRC_DESC("This is the factor by which the \"area\" value in a SpeedTree " 00232 "terrain.txt file is scaled (after taking its square root) " 00233 "when loading a new terrain. The default is about 3281, which " 00234 "scales from kilometers to feet. You should set a different " 00235 "scale if you use units other than feet.")); 00236 00237 ConfigVariableBool speedtree_follow_terrain 00238 ("speedtree-follow-terrain", true, 00239 PRC_DESC("Set this true to have trees automatically snap to the terrain " 00240 "height when loaded into a SpeedTree node with a configured " 00241 "terrain. If this is false, you may still call " 00242 "SpeedTreeNode::snap_to_terrain() afterwards.")); 00243 00244 ConfigVariableInt speedtree_max_random_try_count 00245 ("speedtree-max-random-try-count", 1000, 00246 PRC_DESC("This is a cheesy limit to detect bad parameters passed to " 00247 "SpeedTreeNode::add_random_instances(). If this number of attempts " 00248 "to find a legal place for a tree fail in a row, the parameters " 00249 "are deemed to be in error, and the function fails.")); 00250 00251 ConfigVariableBool speedtree_5_2_stf 00252 ("speedtree-5-2-stf", 00253 #if SPEEDTREE_VERSION_MAJOR > 5 || (SPEEDTREE_VERSION_MAJOR == 5 && SPEEDTREE_VERSION_MINOR >= 2) 00254 true, 00255 #else 00256 false, 00257 #endif 00258 PRC_DESC("The format of the STF file changed in SpeedTree version 5.2. " 00259 "Specify true here to read STF files in the new file format, or " 00260 "false to read STF files in the pre-5.2 file format.")); 00261 00262 00263 //////////////////////////////////////////////////////////////////// 00264 // Function: init_libspeedtree 00265 // Description: Initializes the library. This must be called at 00266 // least once before any of the functions or classes in 00267 // this library can be used. Normally it will be 00268 // called by the static initializers and need not be 00269 // called explicitly, but special cases exist. 00270 //////////////////////////////////////////////////////////////////// 00271 void 00272 init_libspeedtree() { 00273 static bool initialized = false; 00274 if (initialized) { 00275 return; 00276 } 00277 initialized = true; 00278 00279 SpeedTreeNode::init_type(); 00280 STBasicTerrain::init_type(); 00281 STTerrain::init_type(); 00282 STTree::init_type(); 00283 LoaderFileTypeSrt::init_type(); 00284 LoaderFileTypeStf::init_type(); 00285 00286 SpeedTreeNode::register_with_read_factory(); 00287 00288 LoaderFileTypeRegistry *reg = LoaderFileTypeRegistry::get_global_ptr(); 00289 reg->register_type(new LoaderFileTypeSrt); 00290 reg->register_type(new LoaderFileTypeStf); 00291 } 00292 00293 // We need a SpeedTree custom allocator to integrate with Panda's 00294 // memory management. 00295 class STCustomAllocator : public SpeedTree::CAllocator { 00296 public: 00297 void *Alloc(size_t block_size) { 00298 return PANDA_MALLOC_ARRAY(block_size); 00299 } 00300 00301 void Free(void *block) { 00302 if (block != NULL) { 00303 PANDA_FREE_ARRAY(block); 00304 } 00305 } 00306 }; 00307 00308 // Hook our custom allocator into SpeedTree. 00309 #ifndef CPPPARSER 00310 static STCustomAllocator custom_allocator; 00311 static SpeedTree::CAllocatorInterface allocator_interface(&custom_allocator); 00312 #endif // CPPPARSER