Roads, water and splatting

sjcomp

29-03-2006 18:41:47

I have a conceptual question. I would like to have roads, grass areas and water on my terrain. Heightmap gives me terrain, while I can use texture information to set the type of the surface. As I understand, splatting takes care of the type of a surface when the surface is close to the camera. Can I assign texture according to the type of the surface?

Crashy

29-03-2006 19:01:59

For road, I use an alpha map on the base texture, and in the shader I replace "natural" zones with alpha by road. But for the moment I can only use 1 road texture at once(even if I've a little idea to use more).

Falagard

29-03-2006 19:47:41

Wow, I don't understand that Crashy.

In the alpha channel of the base texture you have your road. I understand that, sorta, but what do you mean by "in the shader I replace "natural" zones with alpha by road"?

In the pixel shader you ... do what?

sjcomp

29-03-2006 19:49:52

For road, I use an alpha map on the base texture, and in the shader I replace "natural" zones with alpha by road. But for the moment I can only use 1 road texture at once(even if I've a little idea to use more).
Thanks for the quick response! Can you explain a little bit more? I have a hieght map and a texture. MapSplitter generates Base and 4 Alpha textures. Should I modify them?

Thaks.

Crashy

29-03-2006 21:08:05

Sorry, I wasn't clear :D

Here is how I proceed:
I've my base texture in png format, so with an alpha layer: No other maps than the base texture and the heightmap!

In the Pixel Shader I do this:

oColor=lerp(pathColor,worldColor,worldColor.a);

Where pathColor=tex2D(myPathTextureSampler, texcoord)
and worldColor=grass+rock splatted.

I think it is now understandable :)

sjcomp

29-03-2006 21:41:00


I've my base texture in png format, so with an alpha layer: No other maps than the base texture and the heightmap!

Got it. I am taking my base texture and in alpha channel I make roads. So everything is 1, while roads are 0. Is it correct?

In the Pixel Shader I do this:

Is it in SplatShader.cg? There are vp and fp functions. Where should I change it? Time for me to read more about cg.
I think it is now understandable :)
Your explanations were good from the start, it is that my level of knowledge is insufficient yet.

Thanks.

Crashy

30-03-2006 16:14:42

Got it. I am taking my base texture and in alpha channel I make roads. So everything is 1, while roads are 0. Is it correct?
yes.

Is it in SplatShader.cg? There are vp and fp functions. Where should I change it? Time for me to read more about cg.

PixelShader=Fragment Program, so it is mainfp, or main_fp. It depends.

sjcomp

31-03-2006 00:28:23

PixelShader=Fragment Program, so it is mainfp, or main_fp. It depends.
Could you provide me with more explanation about which Fragment Program I should use. I could not find any information about how to control splatting in PLSM2. Any pointers for me? Thanks.

Falagard

31-03-2006 01:31:30

It depends on your texture format setting in the terrain config file, and what you're doing with your terrain.

Find out your texture format, then look into the .cpp file in the Paging Landscape Scene Manager plugin for the corresponding texture format file, such as Splatting2 or SplattingShader or InstantBaseTexture and look in the Load function, you'll see that it's dynamically creating a clone of a material. That material is the one you need to look into to find what shader is being used, so go to the corresponding Media\paginglandscape2\materials\scripts folder and find that .material file. Then find out if it's using a fragment program, and the name of the program in the .material file. Then you can find the corresponding program under the \materials\programs folder. It's possible your texture format doesn't even use a shader, such as Splatting2, so you'll need to switch to a different texture format that does use a shader.

You're on your own here for the most part, so do some investigation, read the Ogre manual if you're stuck on scripts. Ogre has an amazing material and shader system, but you have to spend the time learning it.

Also read through the PLM2 source code and track down your own answers, everyone else has :-) It's the best way to learn.

sjcomp

31-03-2006 04:56:20

look into the .cpp file in the Paging Landscape Scene Manager plugin for the corresponding texture format file, such as Splatting2 or SplattingShader or InstantBaseTexture and look in the Load function, you'll see that it's dynamically creating a clone of a material.

TextureFormat in .cfg file sets the format. Image is used.
Next: PagingLandScapeTemplate.material has PagingLandScape.Template.VertexPixelShaded
Next: fragment_program_ref DecompressVertex/FP
Next: source DecompressVertex.cg
Next: DecompressVertex.cg with entry_point main_fp

I suppose this the point when I want to introduce Crashy's code. The original code is:

void main_fp
(
float2 worldTextureCoord : TEXCOORD0,
float2 detailTextureCoord : TEXCOORD1,
float distancedetailFact : TEXCOORD2,
out float4 oColor : COLOR,
uniform sampler2D worldTexture: TEXUNIT0,
uniform sampler2D detailTexture: TEXUNIT1
)
{
float4 worldColor = tex2D( worldTexture, worldTextureCoord.xy );
float4 detailColor = tex2D( detailTexture, detailTextureCoord );

float distanceFact = distancedetailFact.x;

// Sample the texture to get the output colour
oColor.rgb = (worldColor.rgb + lerp( worldColor.rgb, detailColor.rgb, distanceFact )) * 0.5f;
oColor.a = 1.0f;
}

That is what I did:

// Fragment program for automatic terrain texture generation
void main_fp
(
float2 worldTextureCoord : TEXCOORD0,
float2 detailTextureCoord : TEXCOORD1,
float distancedetailFact : TEXCOORD2,

out float4 oColor : COLOR,

uniform sampler2D worldTexture: TEXUNIT0,
uniform sampler2D detailTexture: TEXUNIT1
)
{
// from http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=812

float4 worldColor = tex2D( worldTexture, worldTextureCoord.xy );
float4 detailColor = tex2D( detailTexture, detailTextureCoord );
oColor.rgb=lerp(detailColor.rgb,worldColor.rgb,worldColor.a);
oColor.a = 1.0f;
}

as I understand detailTexture gets texture from the second texture_unit in material PagingLandScape.Template.VertexPixelShaded. I changed texture there to a dirt.jpg.

I expected to see dirt texture where I put strips of 0 alpha in my texture. I saw no effect. Which brings me to a question where in the texture generated by MapSplitter I should see the effects of what I did with alpha channel? I only see it in *Texture.Small.png. Shouldn't I see something in *.Alpha.X.0.0.png files?

Thanks.

tuan kuranes

31-03-2006 09:00:23

You need to use a splatting texturemode. "Image" isn't.

using latest SDK or CVS, change

SplatFilename0=splatting_sand.png
SplatFilename1=splatting_grass.png
SplatFilename2=splatting_rock.png
SplatFilename3=splatting_snow.png


one of those for your own "splatting_road.png".
You should see it on screen on any splatting texture mode.

Say you choose to replace "SplatFilename1=splatting_grass.png"
by "SplatFilename1=splatting_road.png" you have to modify Alpha
*.Alpha.1.X.X.png files to make you road.

To "draw the splat", add a white stroke on that file.

(Ideally you should generate all alpha maps togheter to make sure all alpha factor summed = 1, but now mapsplitter doesn't handle this case.)

sjcomp

31-03-2006 16:23:49

You need to use a splatting texturemode. "Image" isn't.
Got it. I am using Splatting4 and after modifications of *.Aplha.1.* I got what I was looking for without modifications of the fragment program.

Splatting works slow though :(. Is it possible to have more detailed texture for the center of the terrain? for example if I split terrain into 513x513 pages, can I substitute 513 texture with 1024? This would allow me to have roads using Image TextureFormat.

sjcomp

31-03-2006 16:29:15

Clarification: When I want to substitute textures I want to change them only for a few pages and leave the rest of the pages at is at low resolution.

tuan kuranes

03-04-2006 08:28:12

You can do that using material lod in material script.

sjcomp

03-04-2006 22:49:54

You can do that using material lod in material script.
Let's say I have a texture 1024x1024 and in the center of this texture I have an area 256x256, which I want to be of a high resolution. I am making pages with the size 128x128. After I ran MapSplitter I have 64 page textures with the resolution 128x128. I want to change textures for pages 4.4 4.5 5.4 and 5.5 with textures with the size 1024x1024. Should I do something to material for that?
Thanks.

tuan kuranes

04-04-2006 08:24:14

Should I do something to material for that?
Yes.
Edit it and change actual LOD to your needed LOD.

example, after distance 280000 from camera, second lod will be used.

material BaseMaterial
{
lod_distances 280000
technique
{
lod_index 0
pass
{
texture_unit
{
texture myNearTexture.png
}
}
}
technique
{
lod_index 1
pass
{
texture_unit
{
texture my_distant_texture.png
}
}
}
}

sjcomp

07-04-2006 15:42:29

but does not it mean that all pages should have two textures?

tuan kuranes

07-04-2006 15:54:11

yes, all pages should have one distant and one near.
But each will only be used if near/distant from camera respectively.

sjcomp

28-06-2006 03:35:54

yes, all pages should have one distant and one near.
But each will only be used if near/distant from camera respectively.

If I have a material with two textures for different lods, I assume both materials will be loaded into memory? Is it right?
I would like to have alow res texture for far away tiles and hires for the closest tile. Given that only few hires textures are used at any single time GPU should have enough memory. When textures are loaded in the GPU and when are they loaded into the memory? How can I control that only required materials are in the GPU memory? Or I do not have such a control?
Thanks.

Falagard

28-06-2006 03:42:00

AFAIK Ogre loads all supported techniques, passes in those techniques, and texture units in those passes when the material is first used.

You can look at the code from Material::loadImpl through to all the techniques, passes, texture units, etc. yourself if you wish.

However, that's loading them into system memory. They'll only be uploaded to video memory when needed.

sjcomp

28-06-2006 13:15:20

However, that's loading them into system memory. They'll only be uploaded to video memory when needed.
Thanks, Falagard! What about unloading from the video memory? I can understand how ogre knows that it is time to load a texture. But if I am moving over the terrain and I am leaving the page, when actuall unloading of the texture from video memory happnes?

Thanks.

syedhs

29-06-2006 05:56:28


can understand how ogre knows that it is time to load a texture. But if I am moving over the terrain and I am leaving the page, when actuall unloading of the texture from video memory happnes?

If I get you correctly, i think you can take a look at various listener delegates as in the PLSM2 sample application.

sjcomp

29-06-2006 13:03:12

If I get you correctly, i think you can take a look at various listener delegates as in the PLSM2 sample application.
Delegates should allow me to perform this task manually, so my question is should I do it? Should I look into implementation of PLSM2 for these details?
Thanks.