Proland Documentation - Forest Plugin
The forest plugin provides a task to draw instantiated trees or other objects on a terrain. This plugin does not depend on any other plugin.
The above task uses a producer that generates a set of points per terrain quad, based on data produced by other producers. The points are generated by removing points from precomputed point patterns, and by computing attributes for the remaining points (such as an elevation, using an external elevation producer, a normal, using an external normal producer, etc). The decision to keep or remove a point being made based on a density map, using an external ortho producer.
During rendering, the union of the point sets for all the visible leaf quads is drawn with a single draw call, with a shader that can then generate camera facing quads from these points, place them on the terrain, and finally texture and shade them.
The main classes of this module are the following:
- the proland::PlantProducer is the producer that generates the point sets for each terrain quad. The produced points are stored in a tile storage based on a vertex buffer object, which can be retrieved with proland::PlantProducer::getPlantsMesh. The subparts of this buffer corresponding to the generated points for the currently visible leaf quads are given by the proland::PlantProducer::offsets, proland::PlantProducer::sizes and proland::PlantProducer::count fields, updated by the proland::PlantProducer::produceTiles method.
- the proland::DrawPlantsShadowTask is a task that calls the above proland::PlantProducer::produceTiles method. It can then, optionnaly, draw these points in a cascaded shadow map. For this, this task first computes the shadow frustums based on the bounding boxes of the leaf terrain quads, and then draws the point with a shader that can then generate light facing quads from these points, place them on the terrain, and finally texture them.
- the proland::DrawPlantTask is the task that draws the points on screen. It is intended to be used with a shader that generates camera facing quads from these points, places them on the terrain, and finally textures and shades them.
- the position of each generated point is computed relatively to a given reference point. When the camera moves too far away from this reference point, all the generated points are recomputed relatively to a new reference, equal to the current camera position. We do this to ensure that the point coordinates remain small, in order to avoid numerical precision problems. Like for the ocean case, all computations are done in a local reference frame moving with the camera. Shaders have access to the position of the current reference point in this moving frame in order to transform the generated points in screen space in a correct way.
The "trees1" example illustrates how these tasks can be used, without shadow maps, and on a flat terrain. The "earth" examples show how they can be used with cascaded shadow maps, on a spherical terrain.