Grass Node v0.3.x

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
etcaptor
Posts: 871
Joined: Fri Apr 09, 2004 10:32 pm
Location: Valhalla
Contact:

Post by etcaptor »

Great!
I think that your node not needs any editor :D
ImageImage
Site development -Rock and metal online
--- etcaptor.com ------freenetlife.com
zenoid
Posts: 40
Joined: Wed Jul 20, 2005 1:16 pm
Location: france
Contact:

Post by zenoid »

wonderfull ! I'am trying to integrate it in my project but it's not working correctly yet. Does it run using irr 0.12 ?
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

etcaptor- since it can load or create procedurally, i'd go for procedural when you're in the wilderness, but have it load exclusion zones around houses and hand made flowerbeds. for editor options, i guess box/circle select and delete, scale, and change sprite is all it will need.

zenoid- Thanks for the heightmap code, its about 10,000X faster than using a triangle selector! It should work in old irrlicht versions, but it needs camera->getViewFrustrum()->getBoundingBox() which was introduced in either 0.10 or 0.11
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
needforhint
Posts: 322
Joined: Tue Aug 30, 2005 10:34 am
Location: slovakia

Post by needforhint »

cool,,,, I will add a fog in distance so it will hide the being-created particles and terrain interpolating better...(an eye is sensitive to these contrasts on horizont )I got 40fps with maxed distance 2500 and density 1500!..... i have an intel 2,4, ATI radeon 9600agp126mb, sooooo, this is so cool, ....... I am on my way for a TES 5: irrlichtion....vzzzzzssschh :lol:
what is this thing...
needforhint
Posts: 322
Joined: Tue Aug 30, 2005 10:34 am
Location: slovakia

Post by needforhint »

bool CGrassPatchSceneNode::Create(bool save) doesn't return a value.... shouldn't be?
.... anyways I have compiled the source successfuly
what is this thing...
Pazystamo
Posts: 115
Joined: Sat Dec 03, 2005 5:56 pm
Location: Lithuania
Contact:

Post by Pazystamo »

Some time ago i thought about grass. You coud create grass not only from highmap,but from highmap and grass map. for grass map create texture with color coded grass type, example: black color - no grass,red-low grass,blue-flowers,green-2 types mixed grass and so on. After checking grass map,read highmap and set grass high pos.
Good luck.
etcaptor
Posts: 871
Joined: Fri Apr 09, 2004 10:32 pm
Location: Valhalla
Contact:

Post by etcaptor »

Yes, this is and my point of view about this.
ImageImage
Site development -Rock and metal online
--- etcaptor.com ------freenetlife.com
zenoid
Posts: 40
Joined: Wed Jul 20, 2005 1:16 pm
Location: france
Contact:

Post by zenoid »

yes I was about to proposed that also.
Klasker
Posts: 230
Joined: Thu May 20, 2004 8:53 am
Contact:

Post by Klasker »

bitplane, if you want dynamic wind you can use this simple wind generator I wrote by experimenting with perlin noise.
It's not very fast, but it's not too slow either (it works for me).
Just keep in mind that if lights are supposed to work properly you need to update the vertex normals every time you skew the top of the grass.

Anyway, if you (or anyone else) is interested here is the wind generator. (Sorry for making such a tall post, I don't know where else to post it)
IWindGenerator.h

Code: Select all

#ifndef IWINDGENERATOR_H_INCLUDED
#define IWINDGENERATOR_H_INCLUDED

#include <irrlicht.h>

namespace irr
{
namespace scene
{

class IWindGenerator : public IUnknown
{
public:
  virtual void setStrength( f32 strength ) = 0;
  virtual void setRegularity( f32 regularity ) = 0;
  virtual core::vector2df getWind( const core::vector3df& position, s32 timeMs ) = 0;
};

IWindGenerator* createWindGenerator(f32 strength=3.0f, f32 regularity=1.0f);

}
}  

#endif
CWindGenerator.cpp

Code: Select all

#include "IWindGenerator.h"

namespace irr
{
namespace scene
{

class CWindGenerator : public IWindGenerator
{
private:
  f32 Strength;
  f32 Regularity;
  
public:
  void setStrength( f32 strength );
  void setRegularity( f32 regularity );
  core::vector2df getWind( const core::vector3df& position, s32 timeMs );
};  

void CWindGenerator::setStrength( f32 strength )
{ 
  Strength = strength;
}
void CWindGenerator::setRegularity( f32 regularity )
{
  Regularity = regularity;
}

inline f32 rndGenerator(s32 x)			 
{
  x = (x<<13) ^ x;
  return ( 1.0 - ( (x * (x * x * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0);    
}
inline f32 cosInterpolater(f32 a, f32 b, f32 x)
{
	f32 ft = x * 3.1415927;
	f32 f = (1 - cos(ft)) * .5;

	return  a*(1-f) + b*f;
}
inline f32 windSmoother(s32 x)
{
  return rndGenerator(x)/2  +  rndGenerator(x-1)/4  +  rndGenerator(x+1)/4;
}
inline f32 noiseInterpolate( f32 x )
{
  s32 intX = (int)(x);
  f32 fracX = x - intX;

  f32 v1 = windSmoother(intX);
  f32 v2 = windSmoother(intX + 1);

  return cosInterpolater(v1 , v2 , fracX);
}
inline f32 noise( f32 x )
{
  f32 total = 0;
  f32 p = 0.50;
  
  s32 n = 4;
  
  f32 frequency = 1;
  f32 amplitude = 1;
  
  for ( s32 i=0; i<n; i++ )
  {    
    total += noiseInterpolate(x * frequency) * amplitude;
    
    frequency = frequency + frequency;
    amplitude *= p;
  }
  
  return total;
}


core::vector2df CWindGenerator::getWind( const core::vector3df& position, s32 timeMs )
{
  f32 seed = (timeMs + position.X*7*cos(timeMs/120000.0f) + position.Z*7*sin(timeMs/120000.0f))/ 1000.0f;
  f32 dir = 2*core::PI*noise( seed / Regularity );
  f32 amp = Strength*sin( seed );
  
  return core::vector2df( amp*cos(dir), amp*sin(dir) );
}  

IWindGenerator* createWindGenerator( f32 strength, f32 regularity )
{
  CWindGenerator* wind = new CWindGenerator();
  wind->setStrength(strength);
  wind->setRegularity(regularity);
  return wind;
}  

}

}
You can look at the demo program I wrote using that wind generator to see how it looks. You'll probably get bad FPS in the demo but that's I was in a hurry and there was little point in optimizing the grass rendering since that's what bitplane is trying to do.
http://www.wc3jass.com/files/WindDemo.rar - Download there
krama757
Posts: 451
Joined: Sun Nov 06, 2005 12:07 am

Post by krama757 »

Klasker your wind example isnt working, you sure you included everything needed in that rar file?
Klasker
Posts: 230
Joined: Thu May 20, 2004 8:53 am
Contact:

Post by Klasker »

Hmm... what happens when you try to start the program?
The only file I didn't include was Irrlicht.dll, so if it's not in the same folder or in your system32 folder, that might be why (Use the dll from irrlicht 1.4).

I use Windows XP so I dont know if it works in Linux.
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

wow that rocks. I'll definately add this in, thank you :)
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

okay, small update with the new wind. Wind is a CPU killer when applied to each blade, but pretty fast if done to a whole area. Also I think wind looks better on billboards, but hey too late for that now. I changed the CWindGenerator.cpp to .h, since most of the functions were inline anyway.
I've not done the generation from image thing yet, expect that next release (0.3) :)

edit: oh yeah i'm not fixing the normals at all :. light is not supported. where should a quad's normal point to? should I be using twice as many vertices so each side has its own normals?

i've also been thinking about the grass map thing.. hows about this- alpha = density, brightness = height, colour balance = diversity.

edit2: update 0.2.2
i'm now making a grid of current windspeeds instead of calculating for each blade, and only updating it if 30ms have passed. I'm doing the same with the mesh too, fps++
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

wind should prolly be done on a shader. . .
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

hmm yeah you're right but i'm still scared of shaders. any volunteers?

and an update screenie. no texture generation yet, but i did add grass lightmap thingy-
Image
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Post Reply