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