ShaderTerrainMesh
from panda3d.core import ShaderTerrainMesh
- class ShaderTerrainMesh
Bases:
PandaNode
This class provides functionality to render heightfields of large sizes utilizing the GPU. Internally a quadtree is used to generate the LODs. The final terrain is then rendered using instancing on the GPU. This makes it possible to use very large heightfields (8192+) with very reasonable performance. The terrain provides options to control the LOD using a target triangle width, see ShaderTerrainMesh::set_target_triangle_width().
Because the Terrain is rendered entirely on the GPU, it needs a special vertex shader. There is a default vertex shader available, which you can use in your own shaders. IMPORTANT: If you don’t set an appropriate shader on the terrain, nothing will be visible.
Inheritance diagram
- __init__(*args, **kwargs)
- chunk_size
- generate()
C++ Interface: generate(const ShaderTerrainMesh self)
- /**
@brief Generates the terrain mesh
@details This generates the terrain mesh, initializing all chunks of the
internal used quadtree. At this point, a heightfield and a chunk size should
have been set, otherwise an error is thrown.
If anything goes wrong, like a missing heightfield, then an error is printed
and false is returned.
@return true if the terrain was initialized, false if an error occured
*/
- generate_patches
- getChunkSize()
C++ Interface: get_chunk_size(ShaderTerrainMesh self)
- /**
@brief Returns the chunk size
@details This returns the chunk size, previously set with set_chunk_size()
@return Chunk size
*/
- getClassType()
C++ Interface: get_class_type()
- getGeneratePatches()
C++ Interface: get_generate_patches(ShaderTerrainMesh self)
- /**
@brief Returns whether to generate patches
@details This returns whether patches are generated, previously set with
set_generate_patches()
@return Whether to generate patches
*/
- getHeightfield()
C++ Interface: get_heightfield(ShaderTerrainMesh self)
- /**
@brief Returns the heightfield
@details This returns the terrain heightfield, previously set with
set_heightfield()
@return Path to the heightfield
*/
- getTargetTriangleWidth()
C++ Interface: get_target_triangle_width(ShaderTerrainMesh self)
- /**
@brief Returns the target triangle width
@details This returns the target triangle width, previously set with
ShaderTerrainMesh::set_target_triangle_width()
@return Target triangle width
*/
- getUpdateEnabled()
C++ Interface: get_update_enabled(ShaderTerrainMesh self)
- /**
@brief Returns whether the terrain is getting updated
@details This returns whether the terrain is getting updates, previously set with
set_update_enabled()
@return Whether to update the terrain
*/
- get_chunk_size()
C++ Interface: get_chunk_size(ShaderTerrainMesh self)
- /**
@brief Returns the chunk size
@details This returns the chunk size, previously set with set_chunk_size()
@return Chunk size
*/
- get_class_type()
C++ Interface: get_class_type()
- get_generate_patches()
C++ Interface: get_generate_patches(ShaderTerrainMesh self)
- /**
@brief Returns whether to generate patches
@details This returns whether patches are generated, previously set with
set_generate_patches()
@return Whether to generate patches
*/
- get_heightfield()
C++ Interface: get_heightfield(ShaderTerrainMesh self)
- /**
@brief Returns the heightfield
@details This returns the terrain heightfield, previously set with
set_heightfield()
@return Path to the heightfield
*/
- get_target_triangle_width()
C++ Interface: get_target_triangle_width(ShaderTerrainMesh self)
- /**
@brief Returns the target triangle width
@details This returns the target triangle width, previously set with
ShaderTerrainMesh::set_target_triangle_width()
@return Target triangle width
*/
- get_update_enabled()
C++ Interface: get_update_enabled(ShaderTerrainMesh self)
- /**
@brief Returns whether the terrain is getting updated
@details This returns whether the terrain is getting updates, previously set with
set_update_enabled()
@return Whether to update the terrain
*/
- heightfield
- setChunkSize()
C++ Interface: set_chunk_size(const ShaderTerrainMesh self, int chunk_size)
- /**
@brief Sets the chunk size
@details This sets the chunk size of the terrain. A chunk is basically the
smallest unit in LOD. If the chunk size is too small, the terrain will
perform bad, since there will be way too many chunks. If the chunk size
is too big, you will not get proper LOD, and might also get bad performance.
For terrains of the size 4096x4096 or 8192x8192, a chunk size of 32 seems
to produce good results. For smaller resolutions, you should try out a
size of 16 or even 8 for very small terrains.
The amount of chunks generated for the last level equals to
(heightfield_size / chunk_size) ** 2. The chunk size has to be a power
of two.
@param chunk_size Size of the chunks, has to be a power of two
*/
- setGeneratePatches()
C++ Interface: set_generate_patches(const ShaderTerrainMesh self, bool generate_patches)
- /**
@brief Sets whether to generate patches
@details If this option is set to true, GeomPatches will be used instead of
GeomTriangles. This is required when the terrain is used with tesselation
shaders, since patches are required for tesselation, whereas triangles
are required for regular rendering.
If this option is set to true while not using a tesselation shader, the
terrain will not get rendered, or even produce errors. The same applies
when this is option is not set, but the terrain is used with tesselation
shaders.
@param generate_patches [description]
*/
- setHeightfield()
C++ Interface: set_heightfield(const ShaderTerrainMesh self, Texture heightfield)
- /**
@brief Sets the heightfield texture
@details This sets the heightfield texture. It should be 16bit
single channel, and have a power-of-two resolution greater than 32.
Common sizes are 2048x2048 or 4096x4096.
You should call generate() after setting the heightfield.
@param filename Heightfield texture
*/
- setTargetTriangleWidth()
C++ Interface: set_target_triangle_width(const ShaderTerrainMesh self, float target_triangle_width)
- /**
@brief Sets the desired triangle width
@details This sets the desired width a triangle should have in pixels.
A value of 10.0 for example will make the terrain tesselate everything
in a way that each triangle edge roughly is 10 pixels wide.
Of course this will not always accurately match, however you can use this
setting to control the LOD algorithm of the terrain.
@param target_triangle_width Desired triangle width in pixels
*/
- setUpdateEnabled()
C++ Interface: set_update_enabled(const ShaderTerrainMesh self, bool update_enabled)
- /**
@brief Sets whether to enable terrain updates
@details This flag controls whether the terrain should be updated. If this value
is set to false, no updating of the terrain will happen. This can be useful
to debug the culling algorithm used by the terrain.
@param update_enabled Whether to update the terrain
*/
- set_chunk_size()
C++ Interface: set_chunk_size(const ShaderTerrainMesh self, int chunk_size)
- /**
@brief Sets the chunk size
@details This sets the chunk size of the terrain. A chunk is basically the
smallest unit in LOD. If the chunk size is too small, the terrain will
perform bad, since there will be way too many chunks. If the chunk size
is too big, you will not get proper LOD, and might also get bad performance.
For terrains of the size 4096x4096 or 8192x8192, a chunk size of 32 seems
to produce good results. For smaller resolutions, you should try out a
size of 16 or even 8 for very small terrains.
The amount of chunks generated for the last level equals to
(heightfield_size / chunk_size) ** 2. The chunk size has to be a power
of two.
@param chunk_size Size of the chunks, has to be a power of two
*/
- set_generate_patches()
C++ Interface: set_generate_patches(const ShaderTerrainMesh self, bool generate_patches)
- /**
@brief Sets whether to generate patches
@details If this option is set to true, GeomPatches will be used instead of
GeomTriangles. This is required when the terrain is used with tesselation
shaders, since patches are required for tesselation, whereas triangles
are required for regular rendering.
If this option is set to true while not using a tesselation shader, the
terrain will not get rendered, or even produce errors. The same applies
when this is option is not set, but the terrain is used with tesselation
shaders.
@param generate_patches [description]
*/
- set_heightfield()
C++ Interface: set_heightfield(const ShaderTerrainMesh self, Texture heightfield)
- /**
@brief Sets the heightfield texture
@details This sets the heightfield texture. It should be 16bit
single channel, and have a power-of-two resolution greater than 32.
Common sizes are 2048x2048 or 4096x4096.
You should call generate() after setting the heightfield.
@param filename Heightfield texture
*/
- set_target_triangle_width()
C++ Interface: set_target_triangle_width(const ShaderTerrainMesh self, float target_triangle_width)
- /**
@brief Sets the desired triangle width
@details This sets the desired width a triangle should have in pixels.
A value of 10.0 for example will make the terrain tesselate everything
in a way that each triangle edge roughly is 10 pixels wide.
Of course this will not always accurately match, however you can use this
setting to control the LOD algorithm of the terrain.
@param target_triangle_width Desired triangle width in pixels
*/
- set_update_enabled()
C++ Interface: set_update_enabled(const ShaderTerrainMesh self, bool update_enabled)
- /**
@brief Sets whether to enable terrain updates
@details This flag controls whether the terrain should be updated. If this value
is set to false, no updating of the terrain will happen. This can be useful
to debug the culling algorithm used by the terrain.
@param update_enabled Whether to update the terrain
*/
- target_triangle_width
- update_enabled
- uvToWorld()
C++ Interface: uv_to_world(ShaderTerrainMesh self, const LPoint2f coord) uv_to_world(ShaderTerrainMesh self, float u, float v)
- /**
@see ShaderTerrainMesh::uv_to_world(LTexCoord)
*/
- /**
@brief Transforms a texture coordinate to world space
@details This transforms a texture coordinatefrom uv-space (0 to 1) to world
space. This takes the terrains transform into account, and also samples the
heightmap. This method should be called after generate().
@param coord Coordinate in uv-space from 0, 0 to 1, 1
@return World-Space point
*/
- uv_to_world()
C++ Interface: uv_to_world(ShaderTerrainMesh self, const LPoint2f coord) uv_to_world(ShaderTerrainMesh self, float u, float v)
- /**
@see ShaderTerrainMesh::uv_to_world(LTexCoord)
*/
- /**
@brief Transforms a texture coordinate to world space
@details This transforms a texture coordinatefrom uv-space (0 to 1) to world
space. This takes the terrains transform into account, and also samples the
heightmap. This method should be called after generate().
@param coord Coordinate in uv-space from 0, 0 to 1, 1
@return World-Space point
*/