GeoMipMapped Terrain Scene Node ( UPDATED 3/3/05 )

A forum to store posts deemed exceptionally wise and useful
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

A brand new sample application, showing the use of the new triangle selector I've added today!!!! It's just like the Collision example, in that it draws a line from the camera to where the camera's looking at and draws a then draws a red triangle over the triangle where the line intersects with the geomipmapscenenode.

http://www.spintz.com/irrlicht/geomipma ... st2Exe.zip
http://www.spintz.com/irrlicht/geomipma ... st2Exe.rar

Same commands as last example -

* [F1] toggles the debug window
* [F2] toggles the patch visible window
* [1] makes wireframe
* [2] makes textured
* [~] takes screenshot ( screenshots are saved in the local directory, you can take as many as you'd like, they create a new filename each time you take one )

The sample heightmap for this one is 128x128. You can select DirectX 8 or 9 or OpenGL, the software renderer will not work with this with my engine ( I haven't updated code to the software renderer ).

Here's 2 screenshots of this demo application -

Image
Image
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

deprecated,

are you sure you added the #include "IGeoMipMapSceneNode.h" to the Irrlicht.h file???
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

I updated the above GeoMipMapTest2 files, there's a bug I found which I noticed in that version, when using a patch size that is too small. I made the patch size larger, but will look into the bug. Not a crash, just misses some triangles at low patch sizes in comparison to the heightmap size.
Captain_Kill
Posts: 124
Joined: Sun Jun 27, 2004 11:02 am
Contact:

Post by Captain_Kill »

Hey Spintz, awesome demos BUT i can't get the code to work! :( It compiles ok and i applied those 32-16bit changes but it still doesn't work... It seems to be that rather than running the terrain strips parallel, it just sticks em on top of each other :?

I was using 0.6 but i switched because i thought it was the problem and the same thing happens with 0.7.1 :cry: I've got an ATI Radeon 9600XT and i'm using .net 2003 and i've tried *all* driver options yet there's no difference... See further down for my test app's main function (it uses the textures from your demos cause i wanted to make sure it all worked) If you want i can also upload my engine source somewhere too (or parts of it)

This is annoying me because i really do want to use this terrain system because it's so damn good! I could use LibMini but it'd be better to get this one working...

PS. I have added other addons to my irrlicht's source. (RTS camera, MD3 loader and skydome support)

Code: Select all

#include <irrlicht.h>

using namespace irr;

#pragma comment(lib, "Irrlicht.lib")

int main()
{
	IrrlichtDevice *device =
		createDevice(video::EDT_DIRECTX9, core::dimension2d<s32>(640, 480),32);

	video::IVideoDriver* driver = device->getVideoDriver();
	scene::ISceneManager* smgr = device->getSceneManager();

//	driver->setTextureCreationFlag(video::ETCF_OPTIMIZED_FOR_QUALITY,true ); 

	scene::IGeoMipMapSceneNode *node = smgr->addGeoMipMapSceneNode(0,-1,5,17, 
		core::vector3df ( 0.0f, 0.0f, 0.0f ), 
		core::vector3df ( 0.0f, 0.0f, 0.0f ), 
		core::vector3df ( 100.0f, 0.0f, 100.0f ));

	node->LoadHeightMap("freeworld04.bmp");
	node->setMaterialTexture(0,driver->getTexture("grassdetail.bmp"));
	node->setMaterialTexture(1,driver->getTexture("freeworld04_lightmap.bmp"));

	node->setMaterialFlag(video::EMF_LIGHTING,false);
//	node->setMaterialFlag(video::EMF_WIREFRAME,true);
	node->setMaterialType(video::EMT_LIGHTMAP); 

	scene::ITriangleSelector *selector = smgr->createTriangleSelector(node);
	node->setTriangleSelector(selector);
	selector->drop(); 

	scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();

	device->getCursorControl()->setVisible(false);

	int lastFPS = -1;

	video::SMaterial material;
	material.Texture1 = 0;
	material.Lighting = false;

	while(device->run())
	{
		driver->beginScene(true, true, video::SColor(0,100,100,100));
		smgr->drawAll();

		core::line3d<f32> line;
		line.start = camera->getPosition();
		line.end = line.start + (camera->getTarget() - line.start).normalize() * 1000.0f;

		core::vector3df intersection;
		core::triangle3df tri;

		if (smgr->getSceneCollisionManager()->getCollisionPoint(line, selector, intersection, tri))
		{
			driver->setTransform(video::ETS_WORLD, core::matrix4());
			driver->setMaterial(material);
			driver->draw3DTriangle(tri, video::SColor(0,255,0,0));
		}

		driver->endScene();

		int fps = driver->getFPS();

		if (lastFPS != fps)
		{
			wchar_t tmp[1024];
			swprintf(tmp, 1024, L"Terrain Example - Irrlicht Engine (fps:%d) Triangles:%d", 
				fps, driver->getPrimitiveCountDrawn());

			device->setWindowCaption(tmp);
			lastFPS = fps;
		}
	}

	device->drop();
	
	return 0;
}
It seems weird that the demos work fine yet my compiled versions f00k :(
2.8GHz P4 with HT - 512MB DDR - ATI Radeon 9600XT 256MB - Windows XP - VC++ 6 and VC++ 2003

Dark Reign 3 Home Page: http://darkreign3.notwhatyouthink.org/
Dark Reign 3 Forums: http://notwhatyouthink.org/darkreign3bb/
Guest

Post by Guest »

For me, all examples using DirectX doesn't work. Only OpenGL, if menu is available.
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

Captain_Kill, increase you camera's far plane. You're scaling the terrain by 100 units in each direction. Since the heightmap you're using is 512x512, you're terrain, in Irrlicht units is 51200x51200. Thh default far plane for the camera scene node is 2000.0f, so you'd barely see anything.

Also, make the line that you are passing to your selector much longer as well, I'd recommend something like this -

Code: Select all

line.end = line.start + (camera->getTarget() - line.start).normalize() * 100000.0f;
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

Another note, backface culling is enabled, so if you are under the terrain, you won't see anything, however, in your application Captain_Kill, if the line you're passing to the collision test is long enough, you should see the red triangle, even if you're under the terrain.

I'm going to try my changes myself with the original Irrlicht 0.7.1 and see how they work. Maybe there are issues, I really should've done this in the first place. I'll post here and update the directions if I find anything amiss.
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

Ok, I found some mistakes and things I left out on the webpage as far as adding the code to the engine goes, I'm going to fix them asap. However, the problem you're having, since you've gotten it working ( and I had the same problem with the base Irrlicht engine ) is that the terrain is so large, it's generating indices larger than the u16 can handle, if you use a smaller heightmap, like 128x128, as opposed to the 512x512, you'll see the node working properly.

I'm thinking people using this need to also upgrade the engine to support 32 bit indices. The simple fix for now, would be to re-write the GeoMipMap code to use it's own mesh buffer, so you could have u32 indices and then show patches to upgrade the drawPrimitive calls to support u32 indices. For now, you'll just have to use a smaller terrain until we can do that.
Guest

Post by Guest »

so can you tell me how to edit the engine to use 32 bit indices ? :) i have no clue.

i really like your demo of the wireframe terrain, really kicks some ass. hope that i can use it soon, too. :D
Guest

Post by Guest »

ok now i changed to u16 but i get following errors:

Code: Select all

CGeoMipMapSceneNode.cpp: In member function `virtual void 
   irr::scene::CGeoMipMapSceneNode::OnPreRender()':
CGeoMipMapSceneNode.cpp:256: error: `abs' undeclared (first use this function)
CGeoMipMapSceneNode.cpp:256: error: (Each undeclared identifier is reported 
   only once for each function it appears in.)

make.exe: *** [CGeoMipMapSceneNode.o] Error 1
i use irrlicht 7.1 and DevC++, any suggestion :) ?
Guest

Post by Guest »

IT WORKS !!

i had to change:
1.CGeoMipMapSceneNode.cpp:256: "abs" to "fabs"
2.include math.h

works great now! :)

edit: how can i resize the terrain? the 7th value seem to does not work.
Last edited by Guest on Sat Jan 22, 2005 3:31 pm, edited 1 time in total.
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

Awesome! In order to explain how to change the whole engine to use 32 bit indices, is a bit much, I think I'm going to just make a version that maintains it's own vertices and indices and then how to add the drawPrimitive functions for 32 bit indices.

Using 32 bit indices is much, much better, because you can use huge terrains. Like I've said, I'vesuccesfully loaded and ran a hieghtmap that was 4096x4096!!! And still got pretty decent framereates considering the size, it was on a high end machine though. It'll take some time for that, I'll post here and update the code when I get this done.
Guest

Post by Guest »

cool man! i really have to thank you for making this! i guess this was much needed since now we can use terrain that runs pretty damn fast :) i feel like i have to hug you :shock:

a last question: are you going to implement detail maps?
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

Eventually, yes, detail maps will be implemented, good idea! :)

I just started working on this like 3 weeks ago, so pretty good so far. I need to work on the algorithm more, as well as I really want to implement quad tree technology into the scene node as well.
deprecated
Posts: 62
Joined: Fri Jan 07, 2005 4:37 pm
Location: California

Post by deprecated »

Ok, my problem was that the headers were old and the new headers here not being found... fixed...

now, using the map provided, i keep getting seg. faults....

spintz, could the seg. faults have to do with the 16bit indices ???


anyways, nice screenshots, keep up the good work... The one thing that is really holding me (and probably more people) back from cool apps, is the lack of a good terrain engine in irrlicht...
Post Reply