grassManager v 1.2

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
Post Reply

How do you like it?

I like it.
20
80%
I really don't care.
0
No votes
I don't like it.
5
20%
 
Total votes: 25

ent1ty
Competition winner
Posts: 1106
Joined: Sun Nov 08, 2009 11:09 am

grassManager v 1.2

Post by ent1ty »

Hi, this provides a struct reeealy easy to use for doing grass stuff. I tried to optimize it as much as I could.
Enough of that chit-chat, let's show it in action :) (my graphic card is GT9500 512MB)
FPS: 41
Image
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());
Ok, so let's see what I did.
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);
As you can see, the probability is not really in %, it is like intervals. So its 0-3 -> 3% and 3-100 -> 97% (or 4% and 97%, I cant remember now whether also 0 is counted)
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
Image
FPS: 116
Image
FPS: 111
Image
Last edited by ent1ty on Mon Apr 12, 2010 12:56 pm, edited 7 times in total.
irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps

Step back! I have a void pointer, and I'm not afraid to use it!
netpipe
Posts: 670
Joined: Fri Jun 06, 2008 12:50 pm
Location: Edmonton, Alberta, Canada
Contact:

Post by netpipe »

its very cool, thanks for sharing. here's a smaller example , had to rename grass.cpp to grass.h to compile it on gcc also added a cb project.
http://www.xup.in/dl,11117192/grassManager.7z/
ent1ty
Competition winner
Posts: 1106
Joined: Sun Nov 08, 2009 11:09 am

Post by ent1ty »

Added documentation.

As for the .cpp, I did not want to split this into 2 files. If the .cpp is problem, I will rename it to .h for next release.
Thanks for support anyway :)
irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps

Step back! I have a void pointer, and I'm not afraid to use it!
ent1ty
Competition winner
Posts: 1106
Joined: Sun Nov 08, 2009 11:09 am

Post by ent1ty »

Hi, new version is out, adds options to enable anisotropic filtering and fog and most importantly ability to add no grass zones, in which the grass does not grow. For details, check the first post for download and new documentation.
Also, I cleared the example project a bit.

showing a no grass zone:
Image
(click to increase size)
irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps

Step back! I have a void pointer, and I'm not afraid to use it!
ent1ty
Competition winner
Posts: 1106
Joined: Sun Nov 08, 2009 11:09 am

Post by ent1ty »

Added link to patch 1.11, makes the no grass zones less uniform, check documentation for more info.
irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps

Step back! I have a void pointer, and I'm not afraid to use it!
ent1ty
Competition winner
Posts: 1106
Joined: Sun Nov 08, 2009 11:09 am

Post by ent1ty »

New version available in the first post. The main improvements are even better optimization and linear(hopefully) fading of the grass in the distance.
Oh, and the grass is less uniform.
irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps

Step back! I have a void pointer, and I'm not afraid to use it!
Post Reply