PnP TerrainCreator - Forum
http://forum.pnp-terraincreator.com/

Ogre3D 1.6 export with splatting shader
http://forum.pnp-terraincreator.com/viewtopic.php?f=15&t=454
Page 2 of 3

Author:  jacmoe [ Tue Jan 19, 2010 10:28 pm ]
Post subject:  Re: Ogre3D export with splatting shader

RAW is usually scaled by a factor, due to precision issues, isn't it?

The new Ogre terrain gladly takes an array of floats:
Code:
         /** Optional list of terrainSize * terrainSize floats defining the terrain.
            The list of floats wil be interpreted such that the first row
            in the array equates to the bottom row of vertices.
         */
         float* inputFloat;

In fact, that's the preferred way of providing heightmap data.
Image based, including RAW, is not recommended.
And even when you're extracting the float array from the RAW file, you have to know what to scale it with?
Or does PnP TerrainCreator spit it out in raw, unscaled form?

When I export to RAW, I need to know the bias and the scale factors.
Bias is the lowest point (for example '200') and scale is the scaling factor, maybe '2000'.

Maybe it's me who doesn't get it. :)
But it seems to me that just spitting out the array of floats is easier to export/import.

Author:  jacmoe [ Tue Jan 19, 2010 10:36 pm ]
Post subject:  Re: Ogre3D export with splatting shader

Right now, I use Float(4 byte), 1024 patch size, size + 1, Full Scale, Flip Y and Offset to Zero.

Code:
    mTerrain = OGRE_NEW Ogre::Terrain(sceneMgr);

    Ogre::Image img;
    Ogre::DataStreamPtr stream = Ogre::ResourceGroupManager::getSingleton().openResource("demoraw.raw", "General" );
    img.loadRawData( stream, 1025, 1025, Ogre::PF_FLOAT32_R );

    Ogre::Terrain::ImportData imp;
    imp.inputImage = &img;
    imp.terrainSize = 1025;
    imp.worldSize = 1024;
    imp.inputScale = 150;

    // textures
    imp.layerList.resize(5);
    imp.layerList[0].textureNames.push_back("gras.jpg");
    imp.layerList[1].textureNames.push_back("gras.jpg");
    imp.layerList[1].worldSize = 30;
    imp.layerList[2].textureNames.push_back("ground01.jpg");
    imp.layerList[2].worldSize = 30;
    imp.layerList[3].textureNames.push_back("schlamm_getrocknet2.jpg");
    imp.layerList[3].worldSize = 30;
    imp.layerList[4].textureNames.push_back("Boulder_Rocky_01_COL.dds");
    imp.layerList[4].worldSize = 30;
    mTerrain->prepare(imp);
    mTerrain->load();

    Ogre::String blendImages[4];
    blendImages[0] = "gras_00000_00000_000.PNG";
    blendImages[1] = "ground01_00000_00000_000.PNG";
    blendImages[2] = "schlamm_getrocknet2_00000_00000_000.PNG";
    blendImages[3] = "moos2_00000_00000_000.PNG";

    for(int j = 1;j < 5;j++)
    {
        Ogre::TerrainLayerBlendMap *blendmap = mTerrain->getLayerBlendMap(j);
        Ogre::Image img;
        img.load(blendImages[j-1],"General");
        int blendmapsize = mTerrain->getLayerBlendMapSize();
        if(img.getWidth() != blendmapsize)
            img.resize(blendmapsize, blendmapsize);

        float *ptr = blendmap->getBlendPointer();
        Ogre::uint8 *data = static_cast<Ogre::uint8*>(img.getPixelBox().data);
     
        for(int bp = 0;bp < blendmapsize * blendmapsize;bp++)
            ptr[bp] = static_cast<float>(data[bp]) / 255.0f;

        blendmap->dirty();
        blendmap->update();
    }
    mTerrain->freeTemporaryResources();
    mTerrain->setPosition(Ogre::Vector3(512,0,512));

Author:  Ralf [ Wed Jan 20, 2010 8:29 am ]
Post subject:  Re: Ogre3D export with splatting shader

If you use the "Heightmap to RAW" exporter from the group "Heightmap exporters" with the format "FLOAT (4 Byte)" a "Factor" of 1 and "Full scale" and "Offset to zero" unchecked, you'll get a 2d map with pure untransformed float. Exactly the height values as used/stored within TC.

The floats are given in metrical units. So there will be no need for any further transformations, I think.

Author:  jacmoe [ Wed Jan 20, 2010 5:14 pm ]
Post subject:  Re: Ogre3D export with splatting shader

Thanks, I'll try that. :)

Author:  jacmoe [ Wed Jan 20, 2010 7:53 pm ]
Post subject:  Re: Ogre3D export with splatting shader

Yes, it works:
Attachment:
heightmapExport.jpg
heightmapExport.jpg [ 13.64 KiB | Viewed 17677 times ]


This really simplifies a lot:
Code:
Ogre::DataStreamPtr stream = Ogre::ResourceGroupManager::getSingleton().openResource("demoraw.raw", "General" );
size_t size = stream.get()->size();
float* buffer = OGRE_ALLOC_T(float, size, Ogre::MEMCATEGORY_GENERAL);
stream->read(buffer, size);

Ogre::Terrain::ImportData imp;
imp.terrainSize = 1025;
imp.worldSize = 1024;
imp.inputFloat = buffer;

The only code which needs to be changed between terrains is the terrainSize parameter.
Neat. :wink:

I think I'll get this topic working with the old terrain, and update it.
And then create a new topic on the new Ogre terrain.
What do you think? :)

Author:  jacmoe [ Wed Jan 20, 2010 7:59 pm ]
Post subject:  Re: Ogre3D export with splatting shader

The only thing I can think of now, would be to allow the user to choose between origin of terrain at the corner, or at the centre.
It's aligned at the centre in the new Ogre terrain, but it's fairly simple to work around.
The Ogre scene exporter moves the positions by pagesize because Ogre used the upper left corner as origin where PnP TerrainCreator uses the lower left corner for the origin (or is it the other way 'round?).

I am not sure if I'm able to get hold of a Visual Studio Professional, so I can't fix this myself.
At least not now.

Author:  Ralf [ Thu Jan 21, 2010 9:39 am ]
Post subject:  Re: Ogre3D export with splatting shader

The template based scene exporter could be used to first) automated the execution of RAW and alphamap export and second) to create a scene file which correctly aligns the patches.

Author:  jacmoe [ Fri Jan 22, 2010 11:34 am ]
Post subject:  Re: Ogre3D export with splatting shader

This is the demoterrain in Ogre:
Attachment:
screenshot01222010_121921296.jpg
screenshot01222010_121921296.jpg [ 133.34 KiB | Viewed 1027 times ]


I figured out how to convert the base diffuse textures to the format the default Ogre material generator expects.

1) Get ShaderMap CL from http://www.shadermap.renderingsystems.com/
2) Create a bat file with the following contents:
Code:
CD "C:\Program Files\ShaderMap CL 1.2.2"

START /WAIT shadermap.exe cdiff "<texture_directory>\<texture_name>" -disp (60,100,12,xy) -norm (100,200,xy,0) -spec (100,-50,52,xy) -v


Replace the directory and texture name with what you want to generate maps for.

3) Generate the maps by running the bat script, once for each texture.

4) Use the following Ogre code to combine the images:
Code:
   Ogre::Image combined;

   combined.loadTwoImagesAsRGBA("moos1.jpg", "moos1_SPEC.bmp",
      Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::PF_BYTE_RGBA);
   combined.save("moos1_diffusespecular.png");

   combined.loadTwoImagesAsRGBA("moos1_NORM.tga", "moos1_DISP.bmp",
      Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::PF_BYTE_RGBA);
   combined.save("moos1_normalheight.png");


5) Get the nVidida texture tools (DDS Utilities) and convert the output textures to dds.

6) Done. :wink:

Author:  Ralf [ Fri Jan 22, 2010 11:59 am ]
Post subject:  Re: Ogre3D export with splatting shader

Great, this looks good.
Are you limited in the maximum number of textures in OGRE's current terrain system?
Which terrain system are you using PLSM?
Do you additionally use a scene format like dotScene?

Using this description, I could create an export plugin which combines all these steps so you can export everything with one click.
What do you think?

Author:  jacmoe [ Fri Jan 22, 2010 12:44 pm ]
Post subject:  Re: Ogre3D export with splatting shader

I think the limit is 9 layers.
This is the reason why I had to re-texture the demo.

This is the new Ogre terrain component, so it's going to be the default for Ogre now.

This is the new terrain topic in our forum:
http://www.ogre3d.org/forums/viewtopic.php?f=11&t=50674
Still a work in progress.

I am using an xml loader, so yes: dotscene.

Next up is loading several terrain pages.

So, if you can hold your horses a bit, I am able to tell you what a complete export would be. :)

Author:  jacmoe [ Fri Jan 22, 2010 1:05 pm ]
Post subject:  Re: Ogre3D export with splatting shader

I updated the first post with images as a working guide for exporting to Ogre versions up to and including 1.6

I'll create another topic on Ogre 1.7 :)

Author:  jacmoe [ Fri Jan 22, 2010 1:37 pm ]
Post subject:  Re: Ogre3D 1.6 export with splatting shader

Since Ogre is now licensed under the MIT license, it means that you can use it directly in PnP TC.
Would simplify the object loader a bit, as it can load a mesh and a material directly, instead of relying on converted xml and custom written pnptc materials.

Author:  Ralf [ Fri Jan 22, 2010 1:59 pm ]
Post subject:  Re: Ogre3D 1.6 export with splatting shader

great, good to hear that a powerful terrain system is now directly included in Ogre, without the need of installing additional PlugIns. But the PLSM was very powerful I think. I haven't followed its development during the last couple of months. There was an announcment of PLSM3 I think. Is it still work in progress, or is it canceled, or is the new default Ogre terrain system based on the PLSM core? So does it support pages?

For PLSM2 I had a modification which could load custom material files per page. So I could create those material files with the TC and by multipass rendering we were able to use an unlimited number of textures. Would that be possible too with the new default terrain system?

Author:  jacmoe [ Fri Jan 22, 2010 2:05 pm ]
Post subject:  Re: Ogre3D 1.6 export with splatting shader

Not much happening with PLSM2, unfortunately.
But the new terrain is more powerful and more flexible.

I think it would be possible to allow for multi-pass and unlimited textures.

Paging is actually a separate component, and Sinbad (Ogre lead developer) intends to make the terrain and the paging components cooperate.

So, yes: this is going to be way better than PLSM2, and part of the official Ogre distribution. :)

It is also possible to write custom material generators, I haven't looked into that just yet.

If you have any specific questions to ask, why not register at the Ogre forum and ask away there?
I am not the only one in need of a good toolchain
And you can pimp PnP TC while you're at it. :)

Author:  jacmoe [ Fri Jan 22, 2010 2:52 pm ]
Post subject:  Re: Ogre3D 1.6 export with splatting shader

I think the current limit is roughly 6 layers, if we're using lightmap and normal map:

Code:
   uint8 TerrainMaterialGeneratorA::SM2Profile::getMaxLayers(const Terrain* terrain) const
   {
      // count the texture units free
      uint8 freeTextureUnits = 16;
      // lightmap
      --freeTextureUnits;
      // normalmap
      --freeTextureUnits;
      // colourmap
      if (terrain->getGlobalColourMapEnabled())
         --freeTextureUnits;
      // TODO shadowmaps

      // each layer needs 2.25 units (1xdiffusespec, 1xnormalheight, 0.25xblend)
      return static_cast<uint8>(freeTextureUnits / 2.25f);
}


The good news is that it looks like you can set the layers per page.

Page 2 of 3 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/