[SOLVED] Bug fix: random grass loader positioning

syedhs

29-11-2007 14:57:14

JohnJ,

I faced this problem quite sometime but only now managed to investigate :wink: and able to solve it.

Basically I feed the grass loader the density map, and the bug will be this.. *drum roll*.. a number of grass (which is very very few) will appear on the area where density map = rgb(0,0,0). This is irritating especially if the grass grows on the road :wink:. I checked thoroughly the density map, it is exactly rgb(0,0,0) ie pure black not rgb(0,1,0) or something like that.

So I think the problem lies with this line ( I am using MAPFILTER_NONE):-

GrassLayer::_populateGrassList_UnfilteredDM(...)
..
..
//Determine whether this grass will be added based on the local density.
//For example, if localDensity is .32, grasses will be added 32% of the time.
float density = densityMap->_getDensityAt_Unfiltered(x, z);
if (density > 1e-3) {

So basically I add extra checking which is if density is too small, then no tree is added at all. I suspect the bug lies with random value generated which can be very small and satisfies with density at that particular point.

Or maybe the bug is somewhere else: density values generated from the density image file which can be very small (but non zero) so there is still a possibility tree to be generated there.

Btw, originally I used the default map filtering which is bilinear, and then changed it no-filter but the grass still appear on the road.

JohnJ

29-11-2007 15:27:17

I checked GrassLoader, and found something interesting:
if (Math::UnitRandom() <= densityMap->_getDensityAt_Bilinear(x, z)){
The "<=" might be causing some grass to appear in black density map areas, since when UnitRandom() is 0 and the density is 0, the condition is met and grass will be added. It should be "<"; in this case there's no way UnitRandom() could return a value less than a density of 0.

I uploaded my changes to CVS, so you can download them or simply change the "<="s to "<"s yourself.

So basically I add extra checking which is if density is too small, then no tree is added at all. I suspect the bug lies with random value generated which can be very small and satisfies with density at that particular point.
I guess that's possible, but at most the density should never be less than 0, and neither should the UnitRandom(), so hopefully the "<" test above will solve the problem.

syedhs

01-12-2007 04:56:40

I redownloaded the CVS version, and therefore overriding my 'hacky' changes earlier and it is now okay (so far). But I would say it is more or less solved. Thanks!