Terrain + vertex colors possible[Solved+screenshot]

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.
Post Reply
X_for_Extra
Posts: 69
Joined: Mon May 23, 2005 4:42 pm

Terrain + vertex colors possible[Solved+screenshot]

Post by X_for_Extra »

Hey, I've been trying to set vertex colors on a terrain, but it goes all funky and wonky no matter what I do.

Clues?

here is my latest attempt:

Code: Select all

    
ITerrainSceneNode* terrain = smgr->addTerrainSceneNode("media/h_map.bmp");

    terrain->setScale(core::vector3df(15, 2.0f, 15));
    terrain->setMaterialFlag(video::EMF_LIGHTING, false);

    
    s32 iCount = ((terrain->getMesh())->getMeshBuffer(0))->getVertexCount();
    S3DVertex * verts = (S3DVertex *) ((terrain->getMesh())->getMeshBuffer(0))->getVertices();
    S3DVertex tmp;
    for(s32 i = 0; i < iCount; i++){
       tmp =  verts[i];   
       tmp.Color.setRed(100);
       verts[i] = tmp;      
    }
    
I've tried like 100 variations on this theme, but it seems that as soon as I alter th color of a vert in the array, hijinks ensue.
Last edited by X_for_Extra on Tue Jul 26, 2005 12:39 am, edited 1 time in total.
Should put something witty here I suppose.
X_for_Extra
Posts: 69
Joined: Mon May 23, 2005 4:42 pm

Post by X_for_Extra »

Alternately, if someone knows how to load a height map as a static octtree, I would settle for that, because I cant get the LOD-popping under control anyway.
Should put something witty here I suppose.
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

Your problem is you're casting the vertices to the wrong type.

They should be casted to video::S3DVertex2TCoords
Image
X_for_Extra
Posts: 69
Joined: Mon May 23, 2005 4:42 pm

Post by X_for_Extra »

Oh, cool! And, duh, I should have known. It just didnt occur to me for some reason. Cheers.

This means I can dispense with the colormap texture and save a texture layer.
Should put something witty here I suppose.
X_for_Extra
Posts: 69
Joined: Mon May 23, 2005 4:42 pm

Post by X_for_Extra »

Here is a screenshot of the result. Vertex colors and detail texture in OpenGL:

Image
Should put something witty here I suppose.
etcaptor
Posts: 871
Joined: Fri Apr 09, 2004 10:32 pm
Location: Valhalla
Contact:

Post by etcaptor »

How do you implement detail texture?
ImageImage
Site development -Rock and metal online
--- etcaptor.com ------freenetlife.com
Guest

Post by Guest »

I think the detail texture is just one of the normal texture layers?

But how did you get the shadowing? If you enable vertex lights the colors are overwritten.
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

Very nice, I like to see pretty screenshots of terrain!!! :D
Image
X_for_Extra
Posts: 69
Joined: Mon May 23, 2005 4:42 pm

Post by X_for_Extra »

Yes, the detail texture is just a regular texture, although it mipmaps exceptionally well. The shadows are in the color map.


Here is the code:

Code: Select all

	
ITerrainSceneNode* terrain = smgr->addTerrainSceneNode("media/h_map.bmp");
    terrain->setScale(core::vector3df(15, 3.0f, 15));
    terrain->setMaterialFlag(video::EMF_LIGHTING, false);

	terrain->setMaterialTexture(0, driver->getTexture("media/dirt.jpg"));
	terrain->scaleTexture(16.0f);
   
    IImage* colormap = driver->createImageFromFile("media/c_map.bmp");
    
    s32 iCount = ((terrain->getMesh())->getMeshBuffer(0))->getVertexCount();
    S3DVertex2TCoords * verts = (S3DVertex2TCoords *) ((terrain->getMesh())->getMeshBuffer(0))->getVertices();
    S3DVertex2TCoords tmp; s32 y, x; 
    
    for(s32 i = 0; i < iCount; i++){
       tmp =  verts[i];
       x = s32(tmp.Pos.X / 15); 
       y = s32(tmp.Pos.Z / 15);  
       tmp.Color = colormap->getPixel(x,y);
       verts[i] = tmp;     
    } 
I suppose I could apply the colormap before scaling to avoid the "/ 15" and posibly get more acurate results.
It looks good though.
Should put something witty here I suppose.
Post Reply