This tutorial is for Ogre version up to 1.6. See this tutorial for Ogre 1.7.
This is a small tutorial about using PnP TerrainCreator with
Ogre3D.

You will see how to export from PnPTC and submit the exported files - a raw heightmap and one or two RGBA alphamaps - to a CG splatting shader for use with the standard Ogre3D terrain scenemanager.

Achtung: You cannot use more than 8 (eight) textures with the attached shader, so it wont work with any of the demomaps without modification!This is the terrain we want to export:
Attachment:
pnptc_terrain.jpg [ 101.44 KiB | Viewed 59 times ]
Right.
In PnPTC, right-click the tile you want to export. Choose Export Heightmap:
Attachment:
export_heightmap.jpg [ 25.65 KiB | Viewed 51 times ]
Make sure your raw heightmap is setup like this:
Attachment:
heightmap_export.jpg [ 13.39 KiB | Viewed 2420 times ]
Format: WORD (2byte)
Full scale : yes
Flip Y : yes
Size + 1 : yes
The standard terrain scenemanager in Ogre does not support higher than two byte raw heightmap sources.
Choose Export Alphamap:
Attachment:
export_alphamap.jpg [ 25.3 KiB | Viewed 44 times ]
Again, be sure to set it up like this:
Attachment:
alphamap_export.jpg [ 19.63 KiB | Viewed 2420 times ]
You might check the box 'Material files'.
It comes in handy when we set it up for Ogre3D.

Alright.
We should have one or two alphamaps and one heightmap.
Rename the alphamaps to
alphamap1 and
alphamap2, and give the heightmap a good name, if you haven't already.
Find Ogre3D, go the the media folder and put the textures in where the textures are. Usually in
media/materials/textures.
Don't forget to copy the terrain textures over! Otherwise we would have nothing to splat on the terrain.

Download the pnptc_tut.zip from this topic (it's attached) and unpack it.
You should have three files.
Put
pnptc_ogre.cg and
pnptc_ogre.program in
media/materials/programs.
And
pnptc_ogre.material in
media/materials/scripts.
Edit
pnptc_ogre.program and change the name of the cg script to
pnptc_ogre.cg.
I forgot to change it before I uploaded. Sorry.We are getting closer!

Now we need a
terrain.cfg file, which is a terrain scenemanager configuration file.
Here's one:
Code:
# The main world texture (if you wish the terrain manager to create a material for you)
WorldTexture=cooltex.jpg
# The detail texture (if you wish the terrain manager to create a material for you)
#DetailTexture=terrain_texture.jpg
#number of times the detail texture will tile in a terrain tile
DetailTile=3
# Heightmap source
PageSource=Heightmap
# Heightmap-source specific settings
Heightmap.image=demoraw.raw
# If you use RAW, fill in the below too
# RAW-specific setting - size (horizontal/vertical)
Heightmap.raw.size=1025
# RAW-specific setting - bytes per pixel (1 = 8bit, 2=16bit)
Heightmap.raw.bpp=2
# How large is a page of tiles (in vertices)? Must be (2^n)+1
PageSize=1025
# How large is each tile? Must be (2^n)+1 and be smaller than PageSize
TileSize=65
# The maximum error allowed when determining which LOD to use
MaxPixelError=3
# The size of a terrain page, in world units
PageWorldX=1024
PageWorldZ=1024
# Maximum height of the terrain
MaxHeight=150
# Upper LOD limit
MaxMipMapLevel=5
VertexNormals=yes
#VertexColors=yes
#UseTriStrips=yes
# Use vertex program to morph LODs, if available
VertexProgramMorph=no
# The proportional distance range at which the LOD morph starts to take effect
# This is as a proportion of the distance between the current LODs effective range,
# and the effective range of the next lower LOD
LODMorphStart=0.2
# This following section is for if you want to provide your own terrain shading routine
# Note that since you define your textures within the material this makes the
# WorldTexture and DetailTexture settings redundant
# The name of the vertex program parameter you wish to bind the morph LOD factor to
# this is 0 when there is no adjustment (highest) to 1 when the morph takes it completely
# to the same position as the next lower LOD
# USE THIS IF YOU USE HIGH-LEVEL VERTEX PROGRAMS WITH LOD MORPHING
#MorphLODFactorParamName=morphFactor
# The index of the vertex program parameter you wish to bind the morph LOD factor to
# this is 0 when there is no adjustment (highest) to 1 when the morph takes it completely
# to the same position as the next lower LOD
# USE THIS IF YOU USE ASSEMBLER VERTEX PROGRAMS WITH LOD MORPHING
#MorphLODFactorParamIndex=4
CustomMaterialName=DemoSplatTerrainShader
It should be fairly self-explanatory.
PageSize and TileSize are familiar to PnPTC users. Those values +1 are used in the configuration file.
WorldTexture is not relevant in our case, since we are going to let a nice shader texture our terrain.
Notice how we at the end of the config file gives our terrain a custom material, entitled
'DemoSplatTerrainShader'.
Create a file, copy the above code into it and save it as
terrain.cfg.
Place the file in
samples/common/bin/releaseNow we are ready to tweak the material file a bit!

Find
pnptc_ogre.material from
ogre/samples/media/materials/scripts and open it in your favourite text editor.
In the section entitled
vertex_program_ref AlphaSplatTerrain/VP there is a list of parameters passed to the vertex shader.
We might want to tweak a few of them.
materialDiffuse and
materialAmbient are RGBA values which controls how bright diffuse and ambient textures are going to be.
pageSize should match your pagesize. (doh).
textureTileSize controls how big the splat textures are scaled. Smaller values, smaller splats.
Next section is
fragment_program_ref AlphaSplatTerrain/FP, which passes two parameters to the pixel shader.
alpha0Mask and
alpha1Mask are RGBA values which determines which channels of your alphamaps are used.
In this case, only the three first channels of the first alphamap is used, and set to '1'.
Therefore the rest of the values are set to '0'.
If you are using all 8 textures, do set all values to '1' - otherwise it won't work.

OK. So far, so good.

Remember the Material files exported from PnPTC?
Find them (or it) now, and open it in your editor, while still keeping the material file open.
Here's what mine looks like:
Code:
<coveragemaps sector_x="0" sector_y="0" patch_x="0" patch_y="0">
<coveragemap alphamap_texture="alphamap_00000_00000_000_0.PNG">
<alphamap channel="R" detail_texture="gras.jpg" />
<alphamap channel="G" detail_texture="moos2.jpg" />
<alphamap channel="B" detail_texture="schlamm_getrocknet2.jpg" />
</coveragemap>
</coveragemaps>
This tells us that we're using three textures:
gras.jpg in the red channel (R), moos2.jpg in the green channel (G) and schlamm_getrocknet2.jpg in the blue channel (B). Nothing in the alpha channel.
We have no second alphamap.
Armed with that knowledge, we are ready to make the final adjustment to our material script.
Navigate to the bottom, line 115, to the section named
material DemoSplatTerrainShader : AlphaSplatTerrain
.
It's a material inheriting from our main AlphaSplatTerrain material.
In it, all the texture aliases are resolved.
We need to edit the image files to match what we've got.
Code:
material DemoSplatTerrainShader : AlphaSplatTerrain
{
set_texture_alias AlphaMap1 alphamap1.png
set_texture_alias AlphaMap2 black.png
set_texture_alias Splat1 gras.jpg
set_texture_alias Splat2 moos2.jpg
set_texture_alias Splat3 schlamm_getrocknet1.jpg
The first five textures are mapped.
We set alphamap 1 to point to our alphamap, alphamap1.png.
The second alphamap is empty, and set to a completely black (all channels) png.
Then follows the splatting textures.
The rest of the splat texture entries are not relevant to us, as we're not using them (in this example).
Code:
set_texture_alias Detail Detail3.jpg
set_texture_alias Fallback cooltex.jpg
The two last textures are the detail texture, which gets splatted on top of the other textures to give it some detail look, hence the name, and the something_is_wrong texture, which could be anything.
It will only render if your card doesn't handle the shader.
That's it.
It should work in the default Ogre terrain demo.

Attachment:
screenshot_1.png [ 989.34 KiB | Viewed 117 times ]
The shader script lives on this page:
http://www.ogre3d.org/wiki/index.php/Terrain_Alpha_SplattingCheck for updates there.
Attached to this post is a zip with three files:
pnptc_ogre.cg
pnptc_ogre.material
pnptc_ogre.program