Terrain Detail Texture

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
IainC
Posts: 27
Joined: Tue Feb 24, 2004 5:55 pm
Location: Aberystwyth, UK
Contact:

Terrain Detail Texture

Post by IainC »

Hi folks,

I know I can do this:

terrain->setMaterialTexture(0, irr_driver()->getTexture("media/terrain-texture.jpg"));
terrain->setMaterialTexture(1, irr_driver()->getTexture("media/terrain-detailtexture.jpg"));

Already discovered the detail texture tiles automatically - But how can I get them to blend nicely? The following seems to have no effect:

terrain->setMaterialType(EMT_TRANSPARENT_ADD_COLOR);
www.coldcity.com|ninjastyle
Guest

Post by Guest »

SEARCH, THIS HAS BEEN DISCUSSED
IainC
Posts: 27
Joined: Tue Feb 24, 2004 5:55 pm
Location: Aberystwyth, UK
Contact:

Post by IainC »

Temper, temper. There's nothing of use on the first 3 pages of forum search results for "Terrain Detail Texture". I think my posts on this and other forums make it clear I generally do my homework before asking for help.

Any ideas?
www.coldcity.com|ninjastyle
Guest

Post by Guest »

I dont have a temper. I just like big font ;) Hopefully this will help you.
http://irrlicht.sourceforge.net/phpBB2/ ... light=tile
IainC
Posts: 27
Joined: Tue Feb 24, 2004 5:55 pm
Location: Aberystwyth, UK
Contact:

Post by IainC »

sorry for being snappy :)

That's not quite what I need. I can make a terrain texture tile, but I can't get a detail texture to blend with the terrain texture as in say this example, I can only see either base texture or detail texture, depending which I put in texture layer 0.

My card definately has two texture units, as I'm using the water effect described in Tutorial 8.
www.coldcity.com|ninjastyle
Guest

Post by Guest »

Dont be sorry. That one was my bad. I did not read your post carefully and I thought you wanted to know how to tile them (thats why I gave you that link) :oops: Sorry. Now that I have read it carefully, sorry dont know what the heck your talking about.
meatpuppet

Post by meatpuppet »

I also have had trouble blending 2 terrain textures to create a detail texture effect so my terrains look like something made about 7 or 8 years ago. Does anyone have any clue about how to do this or if irrlicht even supports this feature yet?
IainC
Posts: 27
Joined: Tue Feb 24, 2004 5:55 pm
Location: Aberystwyth, UK
Contact:

Post by IainC »

I've been researching this a bit more. From the API docs:

EMT_SOLID_2_LAYER - Solid material with 2 texture layers. The second is blended onto the first using the alpha value of the vertex colors. This material is currently not implemented in OpenGL, but it works with DirectX.

So this should work if the vertex alpha was 0.5:

Code: Select all

terrain->setMaterialTexture(0, driver->getTexture("media/terrain-texture.jpg"));
terrain->setMaterialTexture(1, driver->getTexture("media/terrain-detailtexture.jpg"));
terrain->setMaterialType(EMT_SOLID_2_LAYER);
... but it doesn't, cos it's not.

I really want to know if adding vertex.Color.setAlpha(0.5f); before pMeshBuffer->Vertices.push_back ( vertex ); in CTerrainSceneNode.cpp does the trick but my Irrlicht is uncompilable at the moment. :oops:
www.coldcity.com|ninjastyle
IainC
Posts: 27
Joined: Tue Feb 24, 2004 5:55 pm
Location: Aberystwyth, UK
Contact:

Post by IainC »

OK, getting there.

No need to recompile Irrlicht.

Code: Select all

terrain = irr_scenemgr()->addTerrainSceneNode("media/terrain-heightmap.bmp", 0, -1, vector3df(0, 0, 0), vector3df(0, 0, 0), vector3df(1.0f, 1.0f, 1.0f), SColor(127, 0, 0, 0));
terrain->setMaterialTexture(0, irr_driver()->getTexture("media/test.terrain-texture.jpg"));
terrain->setMaterialTexture(1, irr_driver()->getTexture("media/test.terrain-detailtexture.jpg"));
terrain->setMaterialType(EMT_SOLID_2_LAYER);
I have the two textures blending correctly, but I can't make the scaling work.

I have my main terrain texture @ 1024 x 1024. I don't want it to repeat, just drape over the whole terrain. Then I have my detail texture, 256x256, and I want it repeated about 100 times.

I'm just getting both textures repeating together; so by default they're both draped over the texture without repeating, and adding eg terrain->scaleTexture(100); makes them both repeat 100 times.

Can I repeat one and not the other?
www.coldcity.com|ninjastyle
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

To do this you need to change the code of the TerrainSceneNode....here's the code changes to apply to the scaleTexture function :

In ITerrainSceneNode.h, replace -

Code: Select all

virtual void scaleTexture(f32 scale = 1.0f, s32 textureNumber = 0 ) = 0;
In CTerrainSceneNode.h -

Code: Select all

virtual void scaleTexture(f32 scale = 1.0f, s32 textureNumber = 0 );
In CTerrainSceneNode.cpp -

Code: Select all

void CTerrainSceneNode::scaleTexture(f32 scale, s32 textureNumber )
{
	if( textureNumber >= 0 && textureNumber <= 2 )
	{
		video::S3DVertex2TCoords* vertices = (video::S3DVertex2TCoords*)Mesh.getMeshBuffer ( 0 )->getVertices ( );

		switch( textureNumber )
		{
			case 0:
			{
				int index = 0;
				int x = 0;
				int z = 0;

				for (x=0; x<TerrainData.Size; ++x)
				{
					for (z=0; z<TerrainData.Size; ++z)
					{
						index = x * TerrainData.Size + z;
						vertices[index].TCoords.X *= scale;
						vertices[index].TCoords.Y *= scale;						
						vertices[index].TCoords2.X *= scale;
						vertices[index].TCoords2.Y *= scale;
					}
				}
			}
			case 1:
			{
				int index = 0;
				int x = 0;
				int z = 0;

				for (x=0; x<TerrainData.Size; ++x)
				{
					for (z=0; z<TerrainData.Size; ++z)
					{
						index = x * TerrainData.Size + z;
						vertices[index].TCoords.X *= scale;
						vertices[index].TCoords.Y *= scale;					
					}
				}
			}
			case 2:
			{
				int index = 0;
				int x = 0;
				int z = 0;

				for (x=0; x<TerrainData.Size; ++x)
				{
					for (z=0; z<TerrainData.Size; ++z)
					{
						index = x * TerrainData.Size + z;
						vertices[index].TCoords2.X *= scale;
						vertices[index].TCoords2.Y *= scale;
					}
				}
			}
		}
	}
}
Hope this solves your problem... :D
Image
IainC
Posts: 27
Joined: Tue Feb 24, 2004 5:55 pm
Location: Aberystwyth, UK
Contact:

Post by IainC »

Spintz, that's great, many thanks :D

But um, I can't make it work :oops:

I recompiled Irrlicht fine but the below leaves both textures unrepeated:

Code: Select all

terrain->setMaterialTexture(0, irr_driver()->getTexture("media/terrain-texture.bmp"));
terrain->setMaterialTexture(1, irr_driver()->getTexture("media/terrain-detailtexture.jpg"));
terrain->scaleTexture(1.0f, 1);
terrain->scaleTexture(100.0f, 2);
Last edited by IainC on Fri Jul 15, 2005 3:02 pm, edited 1 time in total.
www.coldcity.com|ninjastyle
IainC
Posts: 27
Joined: Tue Feb 24, 2004 5:55 pm
Location: Aberystwyth, UK
Contact:

Post by IainC »

*bump* :oops:
www.coldcity.com|ninjastyle
Fred

Post by Fred »

Did you rebuild your program and are you definitely running with the updated version of the Irrlicht DLL (under Windows)?
IainC
Posts: 27
Joined: Tue Feb 24, 2004 5:55 pm
Location: Aberystwyth, UK
Contact:

Post by IainC »

Yes to both, I promise :)

FWIW I'm using terrain->setMaterialType(EMT_SOLID_2_LAYER) too.
www.coldcity.com|ninjastyle
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

try changing your material type to on of the lightmap material types and see what happens.
Image
Post Reply