PnP TerrainCreator - Forum

The PnP TerrainCreator Forum
It is currently Sat Oct 21, 2017 4:53 am

All times are UTC




Post new topic Reply to topic  [ 34 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Ogre3D 1.6 export with splatting shader
PostPosted: Sat Dec 27, 2008 7:27 pm 
Offline
User avatar

Joined: Mon Dec 22, 2008 8:24 pm
Posts: 64
Location: Denmark

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. :wink:

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
pnptc_terrain.jpg [ 101.44 KiB | Viewed 3755 times ]


Right.

In PnPTC, right-click the tile you want to export. Choose Export Heightmap:
Attachment:
export_heightmap.jpg
export_heightmap.jpg [ 25.65 KiB | Viewed 3645 times ]

Make sure your raw heightmap is setup like this:
Attachment:
heightmap_export.jpg
heightmap_export.jpg [ 13.39 KiB | Viewed 60211 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
export_alphamap.jpg [ 25.3 KiB | Viewed 3669 times ]

Again, be sure to set it up like this:
Attachment:
alphamap_export.jpg
alphamap_export.jpg [ 19.63 KiB | Viewed 60224 times ]

You might check the box 'Material files'.
It comes in handy when we set it up for Ogre3D. :wink:

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. :wink:


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/release


Now 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. :wink:


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
screenshot_1.png [ 989.34 KiB | Viewed 3674 times ]


The shader script lives on this page:
http://www.ogre3d.org/wiki/index.php/Terrain_Alpha_Splatting
Check for updates there.

Attached to this post is a zip with three files:
pnptc_ogre.cg
pnptc_ogre.material
pnptc_ogre.program


Attachments:
pnptc_tut.zip [3.08 KiB]
Downloaded 4031 times

_________________
/* when invited to a free lunch, you should not complain about the quality of the caviar */


Last edited by jacmoe on Fri Jan 22, 2010 1:54 pm, edited 9 times in total.
Top
 Profile  
 
 Post subject: Re: Ogre3D export with splatting shader
PostPosted: Sun Dec 28, 2008 12:01 pm 
Offline
Programmierdochfix
User avatar

Joined: Tue Apr 27, 2004 12:53 pm
Posts: 891
Location: Braunschweig
Very coool... Thanks a lot :)


Top
 Profile  
 
 Post subject: Re: Ogre3D export with splatting shader
PostPosted: Tue Dec 30, 2008 1:06 am 
Offline
User avatar

Joined: Mon Dec 22, 2008 8:24 pm
Posts: 64
Location: Denmark
Ralf wrote:
Very coool... Thanks a lot :)

I wished there were a tutorial like this a couple days ago!
Now there is. :)

PnPTC is a great program, and I want more fellow Ogre users using it. :wink:

_________________
/* when invited to a free lunch, you should not complain about the quality of the caviar */


Top
 Profile  
 
 Post subject: Re: Ogre3D export with splatting shader
PostPosted: Tue Jul 28, 2009 6:29 pm 
Offline

Joined: Tue Jul 28, 2009 6:20 pm
Posts: 1
Hi ,

Where are the images about how to config exports for heightmap e alphamap?

Thank you


Top
 Profile  
 
 Post subject: Re: Ogre3D export with splatting shader
PostPosted: Mon Dec 21, 2009 11:21 am 
Offline

Joined: Mon Dec 21, 2009 7:34 am
Posts: 2
Hi jacmoe thanx for sharing such a nice article, but where are the images? I dont understand how to config exports for heightmaps and for alphamaps? And one more thing i want to use this in my Ogre3D based application when i export only the heightmap to BMP exporter(pnptc) by using HeightMap Exporters it gives me a grayscale imgae and when i load this image in my terrain.cfg file my terrain not working properly, as from where i get the WorldTexture and DetailTexture images.

Waiting for ur kind reply, thanx in Advance.


Top
 Profile  
 
 Post subject: Re: Ogre3D export with splatting shader
PostPosted: Mon Jan 04, 2010 4:38 am 
Offline

Joined: Tue Dec 08, 2009 5:59 am
Posts: 7
isa wrote:
Hi jacmoe thanx for sharing such a nice article, but where are the images? I dont understand how to config exports for heightmaps and for alphamaps? And one more thing i want to use this in my Ogre3D based application when i export only the heightmap to BMP exporter(pnptc) by using HeightMap Exporters it gives me a grayscale imgae and when i load this image in my terrain.cfg file my terrain not working properly, as from where i get the WorldTexture and DetailTexture images.

Waiting for ur kind reply, thanx in Advance.


jacmoe's last post was a year before you posted, and they don't reply now. hence for your first question (terrain looks blocky).. during exporting in grayscale. try exporting in .raw it helps. check the following post
http://forum.pnp-terraincreator.com/viewtopic.php?f=2&t=883

and for world texture you can use texturemap exporters -> texture map to bmp exporter. you will get the full world texture. and for detail texture i am quite confused myself, working on it. will let you know if i done through it.

hope that helps..


Top
 Profile  
 
 Post subject: Re: Ogre3D export with splatting shader
PostPosted: Mon Jan 04, 2010 8:32 am 
Offline
Programmierdochfix
User avatar

Joined: Tue Apr 27, 2004 12:53 pm
Posts: 891
Location: Braunschweig
I already mailed jacmoe for sending me the images of his forum post. But I didn't get any response... sorry.


Top
 Profile  
 
 Post subject: Re: Ogre3D export with splatting shader
PostPosted: Mon Jan 04, 2010 10:24 am 
Offline

Joined: Tue Dec 08, 2009 5:59 am
Posts: 7
Yes Ralf, i pm'ed him through ogre forum, no response. I am not able to make the shaders work correctly, all i get is a white texture. thinking some problem with the detail textures, but i am rounding up at the same zero point, can't go past it. hope he returns to solve these problems.


Top
 Profile  
 
 Post subject: Re: Ogre3D export with splatting shader
PostPosted: Tue Jan 05, 2010 12:22 pm 
Offline

Joined: Tue Dec 08, 2009 5:59 am
Posts: 7
for detail texture you can use texturemap exporters -> texture map to bmp exporter, which use used for world texture. coz without detail texture you can't see what you exactly want. atlast i am done what i wanted to make. if you have any doubt pm me, if possible i'll help you guys.

@ Ralf, i found that flip y doesn't work during texture alphamap export in community edition. tried quite a few times, then used photoshop to flip vertically. 8)


Top
 Profile  
 
 Post subject: Re: Ogre3D export with splatting shader
PostPosted: Wed Jan 06, 2010 10:21 am 
Offline
User avatar

Joined: Mon Dec 22, 2008 8:24 pm
Posts: 64
Location: Denmark
Hi guys. :)
Sorry about the missing pictures - I am working on exporting for the new Ogre terrain component (Ogre 1.7).
I'll update this topic when I am done.

The exiting features of the new terrain, for Terrain Creator users, is that it supports paging.

_________________
/* when invited to a free lunch, you should not complain about the quality of the caviar */


Top
 Profile  
 
 Post subject: Re: Ogre3D export with splatting shader
PostPosted: Wed Jan 06, 2010 10:36 am 
Offline
Programmierdochfix
User avatar

Joined: Tue Apr 27, 2004 12:53 pm
Posts: 891
Location: Braunschweig
Welcome back :)

Please let me know, if I can do anything to support you for exporting terrains to the new Ogre terrain system.


Top
 Profile  
 
 Post subject: Re: Ogre3D export with splatting shader
PostPosted: Wed Jan 06, 2010 1:29 pm 
Offline

Joined: Tue Dec 08, 2009 5:59 am
Posts: 7
jacmoe wrote:
Hi guys. :)
Sorry about the missing pictures - I am working on exporting for the new Ogre terrain component (Ogre 1.7).
I'll update this topic when I am done.

The exiting features of the new terrain, for Terrain Creator users, is that it supports paging.


cool jacmoe...


Top
 Profile  
 
 Post subject: Re: Ogre3D export with splatting shader
PostPosted: Sat Jan 16, 2010 1:38 pm 
Offline
User avatar

Joined: Mon Dec 22, 2008 8:24 pm
Posts: 64
Location: Denmark
I think I am almost done.
Going to use the PnP TC demo terrain.

The Ogre terrain now has the origin at the centre of the terrain page, instead of at the corner.
So it would be good to take that into account: make it optional when doing a Ogre scene export.
It's not a problem, though.
Because you can position the terrain, which I did.

I am also not sure if the object placements will work with multiple terrain pages?

About the heightmap export:
Ogre is very happy to take raw, unscaled floats. :)
Much better than using image based heightmaps, such as raw or png.
An option of exporting those to a flat file would be appreciated.
With the flip y option, most probably.

Until later. :wink:


Top
 Profile  
 
 Post subject: Re: Ogre3D export with splatting shader
PostPosted: Sat Jan 16, 2010 3:16 pm 
Offline
User avatar

Joined: Mon Dec 22, 2008 8:24 pm
Posts: 64
Location: Denmark
An array of floats would be awesome, as we don't have to guess the scaling factor. :)

_________________
/* when invited to a free lunch, you should not complain about the quality of the caviar */


Top
 Profile  
 
 Post subject: Re: Ogre3D export with splatting shader
PostPosted: Sun Jan 17, 2010 10:53 pm 
Offline
Programmierdochfix
User avatar

Joined: Tue Apr 27, 2004 12:53 pm
Posts: 891
Location: Braunschweig
Isn't the output of the RAW exporter sufficient for this? You can export float values with it which actually results in a float array.
Or should I change/add anything to it?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 34 posts ]  Go to page 1, 2, 3  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron