Terrain Detail Texture
Terrain Detail Texture
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);
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
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?
Any ideas?
www.coldcity.com|ninjastyle
-
Guest
I dont have a temper. I just like big font
Hopefully this will help you.
http://irrlicht.sourceforge.net/phpBB2/ ... light=tile
http://irrlicht.sourceforge.net/phpBB2/ ... light=tile
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.
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
-
meatpuppet
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:
... 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.
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);
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.
www.coldcity.com|ninjastyle
OK, getting there.
No need to recompile Irrlicht.
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?
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 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
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 -
In CTerrainSceneNode.h -
In CTerrainSceneNode.cpp -
Hope this solves your problem... 
In ITerrainSceneNode.h, replace -
Code: Select all
virtual void scaleTexture(f32 scale = 1.0f, s32 textureNumber = 0 ) = 0;
Code: Select all
virtual void scaleTexture(f32 scale = 1.0f, s32 textureNumber = 0 );
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;
}
}
}
}
}
}

Spintz, that's great, many thanks 
But um, I can't make it work
I recompiled Irrlicht fine but the below leaves both textures unrepeated:
But um, I can't make it work
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
-
Fred
Yes to both, I promise 
FWIW I'm using terrain->setMaterialType(EMT_SOLID_2_LAYER) too.
FWIW I'm using terrain->setMaterialType(EMT_SOLID_2_LAYER) too.
www.coldcity.com|ninjastyle