Enough of that chit-chat, let's show it in action
FPS: 41

That's right, it can render so much grass with so high FPS.
Now some example code, to demonstrate how easy it is to use
Code: Select all
grassManager grass(smgr);
grass.setTerrain(terrain);
grass.setParametres(150, 6, 5);
grass.setLighting(false);
grass.addGrassPlaneTemplate(video->getTexture("media/grass.png"));
grass.makeReady();
//somewhere in main loop..
grass.doGrassStuff(camera->getPosition());1. grassManager grass(smgr); -- I think that's clear
2. grass.setTerrain(terrain); -- set terrain on which the grass will be placed
3. grass.setParametres(150, 6, 5); -- sets a bunch of parametres, which are: distance, in which the grass is visible
how many irrlicht units are between the grass planes
Y resolution of a plane
4. grass.setLighting(false); -- clear, hopefully
5. grass.addGrassPlaneTemplate(video->getTexture("media/grass.png")); -- add a plane template, takes texture as a parameter, basically sets the texture of grass
6. grass.makeReady(); -- does some stuff, you should do this as the last thing
7. grass.doGrassStuff(camera->getPosition()); -- takes the center around which the grass will be planted.
DOWNLOAD HERE(source and precompiled binary)
http://www.megaupload.com/?d=B6ANNU8F
DOCUMENTATION
Changes in 1.2
-- the constructor now takes ISceneManager* as argument
-- the struct was renamed to grassManager
New since 1.11:
void setNoGrassFadeOut(float newNoGrassZoneFadeOut)
-- this number sets how much is the blending zone between no grass
-- and grass bigger then the no grass zone.
-- So, if the no grass zone is 10x10 irrlicht units big and you set this to
-- 0.5, the blending zone will be from 10x10 to 15x15.
-- Set it to 0 to disable the blending zone.
New since 1.1:
void setAnisoFiltering(bool newAniso)
-- sets whether anisotropic and trillinear filtering are on
void setFog(bool newFof)
-- sets whether fog is on
void addNoGrassZone(aabbox3d<f32> newNoGrassZone)
-- adds a zone, in which grass does not grow
Since 1.0:
grassManager(ISceneManager* newSmgr)
-- constructor
int getCount()
-- returns how many planes with grass texture are currently there
void setSmgr(ISceneManager* newSmgr)
-- sets scene manager, which will be used to do drawing etc.
-- DEPRECATED
void setParametres(int newDistance, int newDensity=3, int newPlaneSize= 5)
-- sets some parametres which are:
---- newDistance, in which is grass visible
---- newDensity, means how many space is between the grass planes, in irrlicht units
---- newPlaneSize, Y resolution of a grass plane.
void setTerrain(ITerrainSceneNode* newTerrain)
--sets terrain, on which the grass will be drawn
void setTexturesPerPlane(int newTexturesPerPlane= 2)
-- how many grass textures are there per plane
-- this is very cool for optimization, set it to like 4 and decrease density 4 times and
-- the result will be almost the same as it was, but with much lower fps.
-- what it does: by setting this to value higher as 1, the grass texture on
-- planes will be tiled. You do not have to worry about the X resolution of
-- the grass planes, it will be calculated from the Y resolution you provided
void setLighting(bool newLighting)
-- sets EMF_LIGHTING material flag of grass planes
void addGrassPlaneTemplate(ITexture* newTexture, int newProbability= 100, float newYTranslation= 0.5, int newMinHeight= -99999, int newMaxHeight= 99999)
-- adds a new grass plane template, arguments:
---- newTexture - the texture which will be used
---- newProbability - probability of this type of plane being planted
---- newYTranslation - the translation on Y axis, provided for situation
---- when the grass would be floating over the terrain or below the ground
---- newMinHeight and newMaxHeight - interval, in which this grass type
---- will be planted. If you set it to like 10, 20, then this type of grass can
---- be found only on that height 10 to 20 of terrrain.
void makeReady()
-- needs to be called after all other stuff like setting parametres, add
-- grass plane templates, etc.
void doGrassStuff(vector3df center)
-- call this somewhere in main loop to make everything work
Example for using multiple grass templates
Code: Select all
//white grass with a few greens level
//3% probability, grows from -99 to 30
grass.addGrassPlaneTemplate(video->getTexture("media/grassGreen.png"), 3, 0.75, -99, 30);
//97% probability, grows from -99 to 30
grass.addGrassPlaneTemplate(video->getTexture("media/grassWhite.png"), 100, 0.75, -99, 30);
//blending level
//50% probability, grows from 30 to 45
grass.addGrassPlaneTemplate(video->getTexture("media/grassGreen.png"), 50, 0.75, 30, 45);
//50% probability, grows from 30 to 45
grass.addGrassPlaneTemplate(video->getTexture("media/grassWhite.png"), 100, 0.75, 30, 45);
//green with a few whites level
//3% probability, grows from 45 to 60
grass.addGrassPlaneTemplate(video->getTexture("media/grassWhite.png"), 3, 0.75, 45, 60);
//97% probability, grows from 45 to 60
grass.addGrassPlaneTemplate(video->getTexture("media/grassGreen.png"), 100, 0.75, 45, 60);
So, if you want to have 3 types of grass, with 25%, 25%, 50% probability, you would set it like this: 25, 50, 100
Also, be sure to always have the probability for one level increasing, not decreasing, so 25, 50, 100 is ok but 100, 50, 25 is not as the first type will be planted everywhere because it has 100%
A few more screens with different configuration
FPS: 36

FPS: 116

FPS: 111

