Rigs of Rods 2026.01
Soft-body Physics Simulation
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | Friends
Forests::GrassLayer Class Reference

Description

A data structure giving you full control over grass properties.

Grass is added to the scene through GrassLoader::addLayer(). Through this class you can configure your grass layer any way you like - size, density, render technique, animation, etc. Simply call the appropriate "set" member function to set the desired property.

Remember that you cannot create or delete layers directly. Layers can only be created with GrassLoader::addLayer(), and may not be deleted manually (they will be deleted when the associated GrassLoader is deleted).

Definition at line 228 of file GrassLoader.h.

Public Member Functions

void setMaterialName (const Ogre::String &matName)
 
void setMinimumSize (float width, float height)
 
void setMaximumSize (float width, float height)
 
void setDensity (float density)
 
void setHeightRange (float minHeight, float maxHeight=0)
 
void setMaxSlope (const float maxSlopeRatio)
 
void setMaxSlope (Ogre::Radian maxSlopeAngle)
 
Ogre::Real getMaxSlope () const
 
void setDensityMap (const Ogre::String &mapFile, MapChannel channel=CHANNEL_COLOR)
 
void setDensityMap (Ogre::TexturePtr map, MapChannel channel=CHANNEL_COLOR)
 
void setDensityMapFilter (MapFilter filter)
 
void setColorMap (const Ogre::String &mapFile, MapChannel channel=CHANNEL_COLOR)
 
void setColorMap (Ogre::TexturePtr map, MapChannel channel=CHANNEL_COLOR)
 
void setColorMapFilter (MapFilter filter)
 
void setMapBounds (const TBounds &bounds)
 
DensityMap * getDensityMap () const
 
ColorMap * getColorMap () const
 
bool getBlendValue () const
 
GrassLoader * getParentGrassLoader () const
 
bool getLightingEnabled () const
 
const TBounds & getMapBounds () const
 
void setRenderTechnique (GrassTechnique style, bool blendBase=false)
 
void setFadeTechnique (FadeTechnique style)
 
void setAnimationEnabled (bool enabled)
 
void setLightingEnabled (bool enabled)
 
void setSwayLength (Ogre::Real mag)
 
void setSwaySpeed (Ogre::Real speed)
 
void setSwayDistribution (Ogre::Real freq)
 

Private Member Functions

 GrassLayer (PagedGeometry *geom, GrassLoader *ldr)
 
 ~GrassLayer ()
 
void _updateShaders ()
 
unsigned int _populateGrassList_Uniform (PageInfo page, float *posBuff, unsigned int grassCount)
 
unsigned int _populateGrassList_UnfilteredDM (PageInfo page, float *posBuff, unsigned int grassCount)
 
unsigned int _populateGrassList_BilinearDM (PageInfo page, float *posBuff, unsigned int grassCount)
 

Private Attributes

GrassLoader * parent
 
Ogre::MaterialPtr material
 
Ogre::Real density
 
Ogre::Real minWidth
 
Ogre::Real maxWidth
 
Ogre::Real minHeight
 
Ogre::Real maxHeight
 
Ogre::Real minY
 
Ogre::Real maxY
 
Ogre::Real maxSlope
 
FadeTechnique fadeTechnique
 
GrassTechnique renderTechnique
 
TBounds mapBounds
 
DensityMap * densityMap
 
MapFilter densityMapFilter
 
ColorMap * colorMap
 
MapFilter colorMapFilter
 
bool animate
 
bool blend
 
bool lighting
 
bool shaderNeedsUpdate
 
Ogre::Real animMag
 
Ogre::Real animSpeed
 
Ogre::Real animFreq
 
Ogre::Real waveCount
 
PagedGeometry * geom
 

Friends

class GrassLoader
 

Constructor & Destructor Documentation

◆ GrassLayer()

Forests::GrassLayer::GrassLayer ( PagedGeometry *  geom,
GrassLoader *  ldr 
)
private

Do not create a GrassLayer directly - use GrassLoader->addLayer()

Definition at line 724 of file GrassLoader.cpp.

◆ ~GrassLayer()

Forests::GrassLayer::~GrassLayer ( )
private

Do not delete a GrassLayer yourself - the GrassLoader will do this automatically when it's deleted.

Definition at line 751 of file GrassLoader.cpp.

Member Function Documentation

◆ _populateGrassList_BilinearDM()

unsigned int Forests::GrassLayer::_populateGrassList_BilinearDM ( PageInfo  page,
float *  posBuff,
unsigned int  grassCount 
)
private

Definition at line 987 of file GrassLoader.cpp.

◆ _populateGrassList_UnfilteredDM()

unsigned int Forests::GrassLayer::_populateGrassList_UnfilteredDM ( PageInfo  page,
float *  posBuff,
unsigned int  grassCount 
)
private

Definition at line 914 of file GrassLoader.cpp.

◆ _populateGrassList_Uniform()

unsigned int Forests::GrassLayer::_populateGrassList_Uniform ( PageInfo  page,
float *  posBuff,
unsigned int  grassCount 
)
private

Definition at line 846 of file GrassLoader.cpp.

◆ _updateShaders()

void Forests::GrassLayer::_updateShaders ( )
private

Definition at line 1090 of file GrassLoader.cpp.

◆ getBlendValue()

bool Forests::GrassLayer::getBlendValue ( ) const
inline

Gives back the value of blending.

Definition at line 412 of file GrassLoader.h.

◆ getColorMap()

ColorMap * Forests::GrassLayer::getColorMap ( ) const
inline

Gets a pointer to the color map being used.

You can use this function to access the internal color map object used by the GrassLoader. Through this object you can directly manipulate the pixels of the color map, among other things.

Note that although you can edit the color map in real-time through this class, the changes won't be uploaded to your video card until you call PagedGeometry::reloadGeometry(). If you don't, the grass you see will remain unchanged.

Definition at line 409 of file GrassLoader.h.

◆ getDensityMap()

DensityMap * Forests::GrassLayer::getDensityMap ( ) const
inline

Gets a pointer to the density map being used.

You can use this function to access the internal density map object used by the GrassLoader. Through this object you can directly manipulate the pixels of the density map, among other things.

Note that although you can edit the density map in real-time through this class, the changes won't be uploaded to your video card until you call PagedGeometry::reloadGeometry(). If you don't, the grass you see will remain unchanged.

Definition at line 398 of file GrassLoader.h.

◆ getLightingEnabled()

bool Forests::GrassLayer::getLightingEnabled ( ) const
inline

Gives back if lighting is enabled for grass.

Definition at line 418 of file GrassLoader.h.

◆ getMapBounds()

const TBounds & Forests::GrassLayer::getMapBounds ( ) const
inline

Gets the map bounds.

Definition at line 421 of file GrassLoader.h.

◆ getMaxSlope()

Ogre::Real Forests::GrassLayer::getMaxSlope ( ) const
inline

Get the maximum slope a grass blade can be placed on (as set by setMaxSlope()).

Returns
The currently set maximum slope ratio value (not an angle).

This returns the currently set maximum slope which is used to determine what ground is too steep for grass to be placed on. Note that this returns the slope as a slope ratio, not an angle. If you need an angle value, convert with ATan() (maxSlopeAngle = ATan(maxSlopeRatio)).

Definition at line 286 of file GrassLoader.h.

◆ getParentGrassLoader()

GrassLoader * Forests::GrassLayer::getParentGrassLoader ( ) const
inline

Gets the parent grassLoader of this layer.

Definition at line 415 of file GrassLoader.h.

◆ setAnimationEnabled()

void Forests::GrassLayer::setAnimationEnabled ( bool  enabled)

Enables/disables animation on this layer.

Always use this function to disable animation, rather than setting SwayLength or SwaySpeed to 0. This function will use a different vertex shader which means improved performance when animation is disabled.

Definition at line 803 of file GrassLoader.cpp.

◆ setColorMap() [1/2]

void Forests::GrassLayer::setColorMap ( const Ogre::String &  mapFile,
MapChannel  channel = CHANNEL_COLOR 
)

Sets the color map used for this grass layer.

Parameters
mapFileThe color map image
channelThe color channel(s) to from the image to use

A color map is simply a texture that allows you to vary the color and shading of grass across your world for a more realistic look. For example, adding a dark spot to the center of your color map will make grass near the center of your terrain look darker, as long as you have the color map aligned to your terrain (see setMapBounds()).

The channel parameter allows you to extract the color information from the image's red, green, blue, alpha, or color values. For example, you may store the desired shade of your grass in the red channel of an image, in which case you would use CHANNEL_RED (when you choose a single channel, it is converted to a greyscale color). By default, CHANNEL_COLOR is used, which uses the full color information available in the image.

Remember that GrassLayer by default has no idea of your terrain/world boundaries, so you must specify a rectangular/square area of your world that is affected by density/color maps. To do this, use the setMapBounds() function. Normally this is set to your terrain's bounds so the density/color map is aligned to your heightmap, but you could apply it anywhere you want.

◆ setColorMap() [2/2]

void Forests::GrassLayer::setColorMap ( Ogre::TexturePtr  map,
MapChannel  channel = CHANNEL_COLOR 
)

Sets the color map used for this grass layer.

Overloaded to accept a Texture object. See the original setColorMap() documentation above for more detailed information on color maps.

Note
The texture data you provide is copied into RAM, so you can delete the texture after calling this function without risk of crashing.

◆ setColorMapFilter()

void Forests::GrassLayer::setColorMapFilter ( MapFilter  filter)

Sets the filtering mode used for color maps.

This function can be used to set the filtering mode used for your color map when generating grass. By default, bilinear filtering is used (MAPFILTER_BILINEAR). If you disable filtering by using MAPFILTER_NONE, the resulting grass coloration may appear slightly pixelated, depending on the resolution of your color map.

MAPFILTER_NONE is slightly faster than MAPFILTER_BILINEAR, so use it if you don't notice any considerable pixelation.

Definition at line 1083 of file GrassLoader.cpp.

◆ setDensity()

void Forests::GrassLayer::setDensity ( float  density)
inline

Sets the maximum density (measured in grass quads/billboards per square unit) of grass.

Definition at line 241 of file GrassLoader.h.

◆ setDensityMap() [1/2]

void Forests::GrassLayer::setDensityMap ( const Ogre::String &  mapFile,
MapChannel  channel = CHANNEL_COLOR 
)

Sets the density map used for this grass layer.

Parameters
mapFileThe density map image
channelThe color channel(s) to from the image to interpret as density

A density map is simply a greyscale image, similar to a heightmap, that specifies the grass density on your map. Full pixel intensity indicates that grass should be fully dense at that point (the maximum density is specified by GrassLayer::setDensity()), while no pixel intensity indicates that no grass should appear at that location.

The channel parameter allows you to extract the density information from the image's red, green, blue, alpha, or color values. For example, you may store density values in the alpha channel, in which case you would use CHANNEL_ALPHA. By default, CHANNEL_COLOR is used, which means the image color is converted to greyscale internally and used as a density map.

Note that GrassLayer by default has no idea of your terrain/world boundaries, so you must specify a rectangular/square area of your world that is affected by density/color maps. To do this, use the setMapBounds() function. Normally this is set to your terrain's bounds so the density/color map is aligned to your heightmap, but you could apply it anywhere you want.

◆ setDensityMap() [2/2]

void Forests::GrassLayer::setDensityMap ( Ogre::TexturePtr  map,
MapChannel  channel = CHANNEL_COLOR 
)

Sets the density map used for this grass layer.

Overloaded to accept a Texture object. See the original setDensityMap() documentation above for more detailed information on density maps.

Note
The texture data you provide is copied into the GrassLayer's own memory space, so you can delete the texture after calling this function without risk of crashing.

◆ setDensityMapFilter()

void Forests::GrassLayer::setDensityMapFilter ( MapFilter  filter)

Sets the filtering mode used for density maps.

This function can be used to set the filtering mode used for your density map when generating grass. By default, bilinear filtering is used (MAPFILTER_BILINEAR). If you disable filtering by using MAPFILTER_NONE, the resulting layout of your grass may look square and blocky, depending on the resolution of your density map.

MAPFILTER_NONE is slightly faster than MAPFILTER_BILINEAR, so use it if you don't notice any considerable blockiness.

Definition at line 839 of file GrassLoader.cpp.

◆ setFadeTechnique()

void Forests::GrassLayer::setFadeTechnique ( FadeTechnique  style)

Sets the technique used when fading out distant grass.

Parameters
styleThe FadeTechnique style used to fade grass.

This "style" setting allows you to choose from various fade techniques. Depending on your scene, certain techniques may look better than others. The most compatible method is FADETECH_ALPHA (used by default), although better results can usually be achieved with other methods. See the FadeTechnique documentation for more information.

Definition at line 795 of file GrassLoader.cpp.

◆ setHeightRange()

void Forests::GrassLayer::setHeightRange ( float  minHeight,
float  maxHeight = 0 
)
inline

Sets a minimum / maximum height where grass may appear.

Parameters
minHeightSets the minimum height grass may have. 0 = no minimum
maxHeightSets the maximum height grass may have. 0 = no maximum

By default grass appears at all altitudes. You can use this function to restrict grass to a certain height range. For example, if sea level is at 100 units Y, you might restrict this layer to display only above 100 units (so your grass doesn't grow under water).

It's possible to use density maps (see setDensityMap()) to achieve similar results, but if your density map is extremely low resolution, this function may be the only practical option to prevent grass from growing under water (when used in combination with your density map).

Setting minHeight to 0 means grass has no minimum height - it can grow as low as necessary. Similarly, setting maxHeight to 0 means grass has no maximum height - it can grow as high as necessary.

Definition at line 258 of file GrassLoader.h.

◆ setLightingEnabled()

void Forests::GrassLayer::setLightingEnabled ( bool  enabled)

Enables/disables lighting on this layer.

Definition at line 811 of file GrassLoader.cpp.

◆ setMapBounds()

void Forests::GrassLayer::setMapBounds ( const TBounds &  bounds)
inline

Sets the boundaries of the density/color maps.

Parameters
boundsThe map boundary

By default, the GrassLayer has no knowledge of your terrain/world boundaries, so you must use this function to specify a rectangular/square area of your world, otherwise density/color maps won't work properly. The boundary given to this function defines the area where density/color maps take effect. Normally this is set to your terrain's bounds so the density/color map is aligned to your heightmap, but you could apply it anywhere you want.

Note
The grass system is infinite, so there's no need to worry about using too expansive boundaries. This setting simply configures the behavior of density and color maps.

Definition at line 384 of file GrassLoader.h.

◆ setMaterialName()

void Forests::GrassLayer::setMaterialName ( const Ogre::String &  matName)

Sets the material that is applied to all grass billboards/quads.

Definition at line 759 of file GrassLoader.cpp.

◆ setMaximumSize()

void Forests::GrassLayer::setMaximumSize ( float  width,
float  height 
)

Sets the maximum size that grass quads/billboards will be.

Definition at line 775 of file GrassLoader.cpp.

◆ setMaxSlope() [1/2]

void Forests::GrassLayer::setMaxSlope ( const float  maxSlopeRatio)
inline

Set the maximum slope a grass of blade can be placed on.

Parameters
maxSlopeRatioThe maximum slope (h/w ratio) a grass blade is allowed to be placed on.

This function can be used to set the maximum slope you want your grass to be placed on (although it doesn't work for sprite grass). By default grass is allowed on any slope.

This version of setMaxSlope() accepts a slope ratio value, where ATan(maxSlopeRatio) = maxSlopeAngle. If you wish to provide a maximum slope as an angle, either use the other overload of this function, or convert your angle to a slope ratio first with Tan().

Definition at line 269 of file GrassLoader.h.

◆ setMaxSlope() [2/2]

void Forests::GrassLayer::setMaxSlope ( Ogre::Radian  maxSlopeAngle)
inline

Definition at line 271 of file GrassLoader.h.

◆ setMinimumSize()

void Forests::GrassLayer::setMinimumSize ( float  width,
float  height 
)

Sets the minimum size that grass quads/billboards will be.

Definition at line 769 of file GrassLoader.cpp.

◆ setRenderTechnique()

void Forests::GrassLayer::setRenderTechnique ( GrassTechnique  style,
bool  blendBase = false 
)

Sets the technique used to render this grass layer.

Parameters
styleThe GrassTechnique style used to display grass.
blendBaseWhether or not grass base blending is enabled.

The "style" setting allows you to choose from various construction methods, such as sprite-style grass quads, plain 3D quads, etc. See the GrassTechnique documentation for more information about this option. GRASSTECH_QUAD is used by default.

Setting "blendBase" to true will enable grass base blending, a technique which helps reduce the unnatural flat appearance of grass quads near the camera. Since the flatness is most obvious where the grass intersects the terrain, this technique attempts to smoothly blend the base of near-by grass into the terrain.

Note
Base blending does not work well with alpha-rejected textures.

Definition at line 784 of file GrassLoader.cpp.

◆ setSwayDistribution()

void Forests::GrassLayer::setSwayDistribution ( Ogre::Real  freq)
inline

Sets the smooth distribution (positional phase shift) of the grass swaying animation.

If you set this to 0, grass animation will look very unnatural, since all the grass sway motions will be in perfect synchronization (everything sways to the right, then everything sways to the left, etc.) This sets the "positional phase shift", which gives the grass a "wave" like phase distribution. The higher this value is, the more "chaotic" the wind will appear. Lower values give a smoother breeze appearance, but values too high can look unrealistic.

Definition at line 480 of file GrassLoader.h.

◆ setSwayLength()

void Forests::GrassLayer::setSwayLength ( Ogre::Real  mag)
inline

Sets how far grass should sway back and forth.

Note
Since this is measured in world units, you may have to adjust this depending on the size of your grass as set by setMinimumSize() and setMaximumSize().

Definition at line 467 of file GrassLoader.h.

◆ setSwaySpeed()

void Forests::GrassLayer::setSwaySpeed ( Ogre::Real  speed)
inline

Sets the sway speed of the grass (measured in "sways-per-second")

Definition at line 470 of file GrassLoader.h.

Friends And Related Symbol Documentation

◆ GrassLoader

friend class GrassLoader
friend

Definition at line 483 of file GrassLoader.h.

Field Documentation

◆ animate

bool Forests::GrassLayer::animate
private

Definition at line 531 of file GrassLoader.h.

◆ animFreq

Ogre::Real Forests::GrassLayer::animFreq
private

Definition at line 532 of file GrassLoader.h.

◆ animMag

Ogre::Real Forests::GrassLayer::animMag
private

Definition at line 532 of file GrassLoader.h.

◆ animSpeed

Ogre::Real Forests::GrassLayer::animSpeed
private

Definition at line 532 of file GrassLoader.h.

◆ blend

bool Forests::GrassLayer::blend
private

Definition at line 531 of file GrassLoader.h.

◆ colorMap

ColorMap* Forests::GrassLayer::colorMap
private

Definition at line 527 of file GrassLoader.h.

◆ colorMapFilter

MapFilter Forests::GrassLayer::colorMapFilter
private

Definition at line 528 of file GrassLoader.h.

◆ density

Ogre::Real Forests::GrassLayer::density
private

Definition at line 511 of file GrassLoader.h.

◆ densityMap

DensityMap* Forests::GrassLayer::densityMap
private

Definition at line 524 of file GrassLoader.h.

◆ densityMapFilter

MapFilter Forests::GrassLayer::densityMapFilter
private

Definition at line 525 of file GrassLoader.h.

◆ fadeTechnique

FadeTechnique Forests::GrassLayer::fadeTechnique
private

Definition at line 518 of file GrassLoader.h.

◆ geom

PagedGeometry* Forests::GrassLayer::geom
private

Definition at line 537 of file GrassLoader.h.

◆ lighting

bool Forests::GrassLayer::lighting
private

Definition at line 531 of file GrassLoader.h.

◆ mapBounds

TBounds Forests::GrassLayer::mapBounds
private

Definition at line 522 of file GrassLoader.h.

◆ material

Ogre::MaterialPtr Forests::GrassLayer::material
private

Definition at line 510 of file GrassLoader.h.

◆ maxHeight

Ogre::Real Forests::GrassLayer::maxHeight
private

Definition at line 513 of file GrassLoader.h.

◆ maxSlope

Ogre::Real Forests::GrassLayer::maxSlope
private

Definition at line 516 of file GrassLoader.h.

◆ maxWidth

Ogre::Real Forests::GrassLayer::maxWidth
private

Definition at line 512 of file GrassLoader.h.

◆ maxY

Ogre::Real Forests::GrassLayer::maxY
private

Definition at line 515 of file GrassLoader.h.

◆ minHeight

Ogre::Real Forests::GrassLayer::minHeight
private

Definition at line 513 of file GrassLoader.h.

◆ minWidth

Ogre::Real Forests::GrassLayer::minWidth
private

Definition at line 512 of file GrassLoader.h.

◆ minY

Ogre::Real Forests::GrassLayer::minY
private

Definition at line 515 of file GrassLoader.h.

◆ parent

GrassLoader* Forests::GrassLayer::parent
private

Definition at line 507 of file GrassLoader.h.

◆ renderTechnique

GrassTechnique Forests::GrassLayer::renderTechnique
private

Definition at line 519 of file GrassLoader.h.

◆ shaderNeedsUpdate

bool Forests::GrassLayer::shaderNeedsUpdate
private

Definition at line 531 of file GrassLoader.h.

◆ waveCount

Ogre::Real Forests::GrassLayer::waveCount
private

Definition at line 535 of file GrassLoader.h.


The documentation for this class was generated from the following files: