[SOLVED] Grass density map gets rotated 45 degrees

CheeseSucker

13-11-2009 12:01:03

I am not sure if this is a problem with Python-Ogre or PagedGeometry, so I will post it in both forums:
Python-Ogre forum: http://www.ogre3d.org/addonforums/viewtopic.php?f=3&t=11603

I have tried to create a grass map for a terrain, however, the density map appears to be rotated 45 degrees when PagedGeometry parses it.

Python-Ogre version: 1.6.4
Problematic module: ogre.addons.forests

Density map:


Result (wireframe mode):


Code used to create grass:

def createGrass(self):
# Grass
self.grass = forests.PagedGeometry()
self.grass.setCamera(self.camera)
self.grass.setPageSize(self.grassPageSize)
self.grass.addDetailLevelGrassPage(2000)

self.grassLoader = forests.GrassLoader(self.grass)
self.grass.setPageLoader(self.grassLoader)
self.grassLoader.setHeightFunction(self.HeightFunction, "getTerrainHeight")

grassLayer = self.grassLoader.addLayer("grass")

#grassLayer.setAnimationEnabled(True)
#grassLayer.setSwaySpeed(0.5)
#grassLayer.setSwayLength(0.05)
#grassLayer.setSwayDistribution(10.0)

grassLayer.setDensity(0.1)

#grassLayer.setColorMap("terrain_texture2_grass.jpg")
#grassLayer.setColorMapFilter(forests.MAPFILTER_BILINEAR)

grassLayer.setDensityMap("grassmap.png")
grassLayer.setDensityMapFilter(forests.MAPFILTER_NONE)

grassLayer.setMapBounds(self.foliageRect)

grassLayer.setMinimumSize(0.5,0.5)
grassLayer.setMaximumSize(10, 10)

#grassLayer.setFadeTechnique(forests.FADETECH_GROW)


Any way I can fix this?

CheeseSucker

13-11-2009 12:37:12

It appears the density map size has to be a power of two plus one just like the ogre terrain heightmaps.

513x513px and 257x257px worked fine, while 512x512px and 256x256px gave a distorted image.
400x400px simply crashed the program ...

tdev

27-03-2010 16:36:03

we certainly need to add checks for this :-\

patches welcome ;)

Worthis

22-10-2012 22:33:55

I have the same problem? How fix this?
Terrain size - 1025x1025. Looks like the problem occurs with any sizes of density map: 1024x1024, 1025x1025, 513x513..
Used: ogre-paged-1.1.4, OgreSDK_vc10_v1-7-4
:(
//Create and configure a new PagedGeometry instance for grass
mGrass = new PagedGeometry(camera, 100);
mGrass->addDetailLevel<GrassPage>(500); //1500
//Create a GrassLoader object
GrassLoader *grassLoader = new GrassLoader(mGrass);
mGrass->setPageLoader(grassLoader); //Assign the "treeLoader" to be used to load geometry for the PagedGeometry instance

//Supply a height function to GrassLoader so it can calculate grass Y values
//HeightFunction::initialize(mSceneMgr);
grassLoader->setHeightFunction(&HeightFunction::getTerrainHeight);
//Add some grass to the scene with GrassLoader::addLayer()
GrassLayer *l = grassLoader->addLayer(tGrassMat);
//Configure the grass layer properties (size, density, animation properties, fade settings, etc.)
l->setMinimumSize(2.0f, 2.0f);
l->setMaximumSize(4.5f, 4.5f);

if(mDef->hasVertexProgram)
{
l->setAnimationEnabled(true); //Enable animations
l->setSwayDistribution(10.0f);
l->setSwayLength(0.7f); //Sway back and forth 0.5 units in length
l->setSwaySpeed(0.5f); //Sway 1/2 a cycle every second
}
l->setDensity(0.400);
l->setRenderTechnique(GRASSTECH_QUAD);
l->setFadeTechnique(FADETECH_GROW); //Distant grass should slowly raise out of the ground when coming in range
if(mDef->hasFragmentProgram)l->setColorMap(tGrassColourMap);
l->setDensityMap(tGrassMap);
l->setMapBounds(TBounds(0, 0, worldSize.x, worldSize.y));

Worthis

31-10-2012 20:08:17

Problem occurs only with OpenGL Rendering System, with DirectX all fine :)

gacamp

14-06-2014 16:59:27

Looks like PagedGeometry is trying to work around a bug that I guess has been fixed in later versions of Ogre.
This workaround causes the maps to not align correctly.

PropertyMaps.cpp has two source blocks like this one:
#if OGRE_PLATFORM != OGRE_PLATFORM_APPLE
// Patch incorrect PixelBox::getWidth() in OpenGL mode
if (Root::getSingleton().getRenderSystem()->getName() == "OpenGL Rendering Subsystem")
--mapWidth;
#endif //OGRE_PLATFORM_APPLE

Commenting them out seems to solve the problem for me (Ogre 1.9)

e.g.
#if OGRE_PLATFORM != OGRE_PLATFORM_APPLE
//Patch incorrect PixelBox::getWidth() in OpenGL mode
//if (Root::getSingleton().getRenderSystem()->getName() == "OpenGL Rendering Subsystem")
// --mapWidth;
#endif //OGRE_PLATFORM_APPLE