Panda3D
 All Classes Functions Variables Enumerations
config_speedtree.cxx
1 // Filename: config_speedtree.cxx
2 // Created by: drose (30Sep10)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "config_speedtree.h"
16 #include "speedTreeNode.h"
17 #include "stBasicTerrain.h"
18 #include "stTerrain.h"
19 #include "stTree.h"
20 #include "loaderFileTypeSrt.h"
21 #include "loaderFileTypeStf.h"
22 #include "loaderFileTypeRegistry.h"
23 #include "dconfig.h"
24 
25 ConfigureDef(config_speedtree);
26 NotifyCategoryDef(speedtree, "");
27 
28 ConfigureFn(config_speedtree) {
29  init_libspeedtree();
30 }
31 
32 ConfigVariableString speedtree_license
33 ("speedtree-license", "",
34  PRC_DESC("Specify the license string to pass to SpeedTreeNode::authorize() by default."));
35 
36 #ifndef CPPPARSER
37 ConfigVariableFilename speedtree_shaders_dir
38 ("speedtree-shaders-dir", Filename(Filename::from_os_specific(SPEEDTREE_BIN_DIR), "Shaders"),
39  PRC_DESC("Specifies the directory in which to locate SpeedTree's system "
40  "shaders at runtime. If this is empty, the default is based on "
41  "SPEEDTREE_BIN_DIR, as provided at compile time."));
42 #endif // CPPPARSER
43 
44 ConfigVariableFilename speedtree_textures_dir
45 ("speedtree-textures-dir", "",
46  PRC_DESC("Specifies the directory in which to locate textures referenced "
47  "by SRT files at runtime. The default is to search in the same "
48  "directory as the SRT file itself. Unfortunately, the model-path "
49  "cannot be searched, because SpeedTree only provides a single "
50  "directory option."));
51 
52 ConfigVariableDouble speedtree_max_anisotropy
53 ("speedtree-max-anisotropy", 0.0,
54  PRC_DESC("Specifies the maximum anisotropy for SpeedTree textures."));
55 
56 ConfigVariableBool speedtree_horizontal_billboards
57 ("speedtree-horizontal-billboards", true,
58  PRC_DESC("Set this true to allow the use of horizontal billboards in "
59  "SpeedTree, or false to disallow them. Horizontal billboards "
60  "may be defined for some trees to provide a billboard LOD "
61  "when the tree is seen from above."));
62 
63 ConfigVariableDouble speedtree_alpha_test_scalar
64 ("speedtree-alpha-test-scalar", 0.57,
65  PRC_DESC("Undocumented speedtree config."));
66 
67 ConfigVariableBool speedtree_z_pre_pass
68 ("speedtree-z-pre-pass", false,
69  PRC_DESC("True if the SpeedTree renderer should perform a first pass "
70  "to fill the depth buffer before going back to draw pixels. "
71  "This can result in a cost savings if there is much overdraw and "
72  "if the pixel shader is particularly expensive, but in most cases "
73  "it will result in a cost penalty."));
74 
75 ConfigVariableInt speedtree_max_billboard_images_by_base
76 ("speedtree-max-billboard-images-by-base", 20,
77  PRC_DESC("Specifies the maximum number of billboard images used by any single "
78  "tree."));
79 
80 ConfigVariableDouble speedtree_visibility
81 ("speedtree-visibility", 1000.0,
82  PRC_DESC("Undocumented SpeedTree parameter."));
83 
84 ConfigVariableDouble speedtree_global_light_scalar
85 ("speedtree-global-light-scalar", 1.0,
86  PRC_DESC("Undocumented SpeedTree parameter."));
87 
88 ConfigVariableBool speedtree_specular_lighting
89 ("speedtree-specular-lighting", false,
90  PRC_DESC("True to enable specular lighting effects in SpeedTree."));
91 
92 ConfigVariableBool speedtree_transmission_lighting
93 ("speedtree-transmission-lighting", false,
94  PRC_DESC("True to enable transmission lighting effects in SpeedTree."));
95 
96 ConfigVariableBool speedtree_detail_layer
97 ("speedtree-detail-layer", false,
98  PRC_DESC("True to render the detail texture layer defined on tree and "
99  "terrain objects, false otherwise."));
100 
101 ConfigVariableBool speedtree_detail_normal_mapping
102 ("speedtree-detail-normal-mapping", false,
103  PRC_DESC("True to render the detail normal maps defined on tree and "
104  "terrain objects, false otherwise."));
105 
106 ConfigVariableBool speedtree_ambient_contrast
107 ("speedtree-ambient-contrast", false,
108  PRC_DESC("Undocumented SpeedTree parameter."));
109 
110 ConfigVariableDouble speedtree_transmission_scalar
111 ("speedtree-transmission-scalar", 1.0f,
112  PRC_DESC("Undocumented SpeedTree parameter."));
113 
114 ConfigVariableDouble speedtree_fog_distance
115 ("speedtree-fog-distance", "2500 5000",
116  PRC_DESC("Specifies the nearest and farthest distance of the fog on trees "
117  "and terrain."));
118 
119 ConfigVariableColor speedtree_fog_color
120 ("speedtree-fog-color", "1.0 1.0 1.0",
121  PRC_DESC("Specifies the r g b color of SpeedTree fog."));
122 
123 ConfigVariableColor speedtree_sky_color
124 ("speedtree-sky-color", "0.2 0.3 0.5",
125  PRC_DESC("Specifies the r g b color of the SpeedTree sky, when the sky "
126  "is enabled. Currently unused."));
127 
128 ConfigVariableDouble speedtree_sky_fog
129 ("speedtree-sky-fog", "-0.5 1.0",
130  PRC_DESC("Specifies the range of fog in the sky. -1 is down, 1 is up."));
131 
132 ConfigVariableColor speedtree_sun_color
133 ("speedtree-sun-color", "1.0 1.0 0.85",
134  PRC_DESC("Specifies the r g b color of the SpeedTree sun, when the sun "
135  "is enabled. Currently unused."));
136 
137 ConfigVariableDouble speedtree_sun_size
138 ("speedtree-sun-size", 0.001,
139  PRC_DESC("Undocumented SpeedTree parameter."));
140 
141 ConfigVariableDouble speedtree_sun_spread_exponent
142 ("speedtree-sun-spread-exponent", 200.0,
143  PRC_DESC("Undocumented SpeedTree parameter."));
144 
145 ConfigVariableDouble speedtree_sun_fog_bloom
146 ("speedtree-sun-fog-bloom", 0.0,
147  PRC_DESC("Undocumented SpeedTree parameter."));
148 
149 ConfigVariableColor speedtree_specular_color
150 ("speedtree-specular-color", "1 1 1",
151  PRC_DESC("Specifies the r g b color of the specular reflections on SpeedTree "
152  "surfaces."));
153 
154 ConfigVariableColor speedtree_emissive_color
155 ("speedtree-emissive-color", "0 0 0",
156  PRC_DESC("Specifies the r g b color of the emissive light effect on SpeedTree "
157  "surfaces."));
158 
159 ConfigVariableInt speedtree_shadow_map_resolution
160 ("speedtree-shadow-map-resolution", 0, //1024,
161  PRC_DESC("Specifies the resolution for rendering shadow maps. Should "
162  "be a power of 2. Specify 0 to disable shadowing in SpeedTree."));
163 
164 ConfigVariableDouble speedtree_cascading_shadow_splits
165 ("speedtree-cascading-shadow-splits", "200 400 600",
166  PRC_DESC("Specifies the shadow split distance, in spatial units, for "
167  "each shadow map to be rendered. The number of values also "
168  "implies the number of shadow maps, to a maximum value compiled "
169  "within SpeedTree (typically 4)."));
170 
171 ConfigVariableBool speedtree_smooth_shadows
172 ("speedtree-smooth-shadows", false,
173  PRC_DESC("True to enable a smoothing pass on the shadow maps."));
174 
175 ConfigVariableBool speedtree_show_shadow_splits_on_terrain
176 ("speedtree-show-shadow-splits-on-terrain", false,
177  PRC_DESC("Currently unsupported."));
178 
179 ConfigVariableBool speedtree_wind_enabled
180 ("speedtree-wind-enabled", true,
181  PRC_DESC("True to enable global wind in the SpeedTree world."));
182 
183 ConfigVariableBool speedtree_frond_rippling
184 ("speedtree-frond-rippling", true,
185  PRC_DESC("True to allow fronds to respond to the global wind."));
186 
187 ConfigVariableInt speedtree_terrain_num_lods
188 ("speedtree-terrain-num-lods", 5,
189  PRC_DESC("Specifies the number of different LOD stages to use in "
190  "rendering terrain. Each stage has 75% few polygons than the "
191  "stage before. Increasing this number decreases the total "
192  "number of polygons onscreen, at the cost of visual quality of "
193  "distant terrain."));
194 
195 ConfigVariableInt speedtree_terrain_resolution
196 ("speedtree-terrain-resolution", 33,
197  PRC_DESC("Specifies the number of vertices per edge of each terrain grid "
198  "cell at the highest LOD. This must be a power of two plus 1."));
199 
200 ConfigVariableInt speedtree_terrain_cell_size
201 ("speedtree-terrain-cell-size", 800,
202  PRC_DESC("Specifies the size in spatial units of one edge of a terrain "
203  "grid cell. This effects culling and resolution, but has nothing "
204  "to do with the scale of the heightmap or other maps."));
205 
206 ConfigVariableDouble speedtree_shadow_fade
207 ("speedtree-shadow-fade", 0.25,
208  PRC_DESC("Specifies the rate at which shadows fade to transparency in the "
209  "distance."));
210 
211 ConfigVariableBool speedtree_show_overlays
212 ("speedtree-show-overlays", false,
213  PRC_DESC("True to draw onscreen overlays showing the generated "
214  "shadow map(s)."));
215 
216 ConfigVariableInt speedtree_max_num_visible_cells
217 ("speedtree-max-num-visible-cells", 75,
218  PRC_DESC("Specifies the maximum number of cells in a single SpeedTree forest "
219  "frustum. This is used internally by SpeedTree's billboard system."));
220 
221 ConfigVariableDouble speedtree_cull_cell_size
222 ("speedtree-cull-cell-size", 1200,
223  PRC_DESC("Specifies the size of a single SpeedTree cull cell, in Panda "
224  "units. Increasing this number decreases the number of "
225  "individual calls that must be made to render geometry, "
226  "while increasing the number of trees that are rendered "
227  "per call."));
228 
229 ConfigVariableDouble speedtree_area_scale
230 ("speedtree-area-scale", 3280.839895013,
231  PRC_DESC("This is the factor by which the \"area\" value in a SpeedTree "
232  "terrain.txt file is scaled (after taking its square root) "
233  "when loading a new terrain. The default is about 3281, which "
234  "scales from kilometers to feet. You should set a different "
235  "scale if you use units other than feet."));
236 
237 ConfigVariableBool speedtree_follow_terrain
238 ("speedtree-follow-terrain", true,
239  PRC_DESC("Set this true to have trees automatically snap to the terrain "
240  "height when loaded into a SpeedTree node with a configured "
241  "terrain. If this is false, you may still call "
242  "SpeedTreeNode::snap_to_terrain() afterwards."));
243 
244 ConfigVariableInt speedtree_max_random_try_count
245 ("speedtree-max-random-try-count", 1000,
246  PRC_DESC("This is a cheesy limit to detect bad parameters passed to "
247  "SpeedTreeNode::add_random_instances(). If this number of attempts "
248  "to find a legal place for a tree fail in a row, the parameters "
249  "are deemed to be in error, and the function fails."));
250 
251 ConfigVariableBool speedtree_5_2_stf
252 ("speedtree-5-2-stf",
253 #if SPEEDTREE_VERSION_MAJOR > 5 || (SPEEDTREE_VERSION_MAJOR == 5 && SPEEDTREE_VERSION_MINOR >= 2)
254  true,
255 #else
256  false,
257 #endif
258  PRC_DESC("The format of the STF file changed in SpeedTree version 5.2. "
259  "Specify true here to read STF files in the new file format, or "
260  "false to read STF files in the pre-5.2 file format."));
261 
262 
263 ////////////////////////////////////////////////////////////////////
264 // Function: init_libspeedtree
265 // Description: Initializes the library. This must be called at
266 // least once before any of the functions or classes in
267 // this library can be used. Normally it will be
268 // called by the static initializers and need not be
269 // called explicitly, but special cases exist.
270 ////////////////////////////////////////////////////////////////////
271 void
272 init_libspeedtree() {
273  static bool initialized = false;
274  if (initialized) {
275  return;
276  }
277  initialized = true;
278 
279  SpeedTreeNode::init_type();
280  STBasicTerrain::init_type();
281  STTerrain::init_type();
282  STTree::init_type();
283  LoaderFileTypeSrt::init_type();
284  LoaderFileTypeStf::init_type();
285 
287 
291 }
292 
293 // We need a SpeedTree custom allocator to integrate with Panda's
294 // memory management.
295 class STCustomAllocator : public SpeedTree::CAllocator {
296 public:
297  void *Alloc(size_t block_size) {
298  return PANDA_MALLOC_ARRAY(block_size);
299  }
300 
301  void Free(void *block) {
302  if (block != NULL) {
303  PANDA_FREE_ARRAY(block);
304  }
305  }
306 };
307 
308 // Hook our custom allocator into SpeedTree.
309 #ifndef CPPPARSER
310 static STCustomAllocator custom_allocator;
311 static SpeedTree::CAllocatorInterface allocator_interface(&custom_allocator);
312 #endif // CPPPARSER
This is a convenience class to specialize ConfigVariable as a Filename type.
This is a convenience class to specialize ConfigVariable as a boolean type.
static LoaderFileTypeRegistry * get_global_ptr()
Returns a pointer to the global LoaderFileTypeRegistry object.
This is a convenience class to specialize ConfigVariable as a set of floating-point types representin...
void register_type(LoaderFileType *type)
Defines a new LoaderFileType in the universe.
This is a convenience class to specialize ConfigVariable as a floating-point type.
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
This is a convenience class to specialize ConfigVariable as a string type.
This class maintains the set of all known LoaderFileTypes in the universe.
This is a convenience class to specialize ConfigVariable as an integer type.
static void register_with_read_factory()
Tells the BamReader how to create objects of type SpeedTreeNode.
This defines the Loader interface to read SpeedTree STF files–a simple text file that describes a for...
This defines the Loader interface to read SpeedTree SRT files, which describe a single tree...
static Filename from_os_specific(const string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes, and no drive letter) based on the supplied filename string that describes a filename in the local system conventions (for instance, on Windows, it may use backslashes or begin with a drive letter and a colon).
Definition: filename.cxx:332