PDA

View Full Version : Terrain Editing - once again



Brainer
26-08-2007, 06:05 AM
System: Windows XP, Pentium D 805 2,8 GHz, GeForce 7600 GS
Compiler/IDE: Delphi 2005 for Win32
API: OpenGL
---

Hello :!:

I've written a post before, but it has been deleted due to breaking the rules. This time it should not happen again. :)

But to the point. Together with my group we've decided to make a terrain editor for our game. I got stuck with the editor, because I don't really know how to optimize the rendering of it. When I use heightmap which is 64x64, everything works fine and the framerate is pretty decent. When the heightmap is 512x512, the framerate goes down drastically. :(

Have you got any ideas :?: It'd be nice if you sent me some code. If you want, I can send you my code. I have nothing to hide from you. ;)

Regards :!:

Andreaz
26-08-2007, 06:40 AM
First, how are you rendering the terrain ? Using intermediate mode or vertex arrays ? The latter are alot faster. (Terrains of 512x512 are no big deal in a editor and current hardware)

Secondly to optimize it further look up geometrical mipmapping, forget everything about ROAM and similar technices, todays gpu's is fast enough to use the easier geomipmaps.

http://wiki.delphigl.com/index.php/Geometrical_Mipmapping

And as a third thing, use frustrum culling on the terrain chunks to only render what's visible

Brainer
26-08-2007, 07:20 AM
This is the code I use:
http://www.glsoftworks.pastebin.com/f29375c3d

Can you help me out now? :)

Andreaz
26-08-2007, 08:21 AM
This is the code I use:
http://www.glsoftworks.pastebin.com/f29375c3d

Can you help me out now? :)

What do you want help with? You asked for ideas of how to improve the speed of the terrain rendering. Doesnt geomipmaps help ? Or the frustrum culling ?

I saw in your source that you where using vertex buffers, that's good. But just a node, drop the displaylists, they just dont gonna do it.

However it seems strange that you're experiensing fps problems with no larger then 512x512 terrain.

Found the doc that i used when writing my terrain renderer; http://www.flipcode.com/articles/article_geomipmaps.pdf

User137
26-08-2007, 11:33 AM
Seeing the code, this is the only render call i found:

glDrawElements(GL_TRIANGLE_STRIP, FIndices.Count, GL_UNSIGNED_INT, FIndices.List);

So it is no wonder it gets slow... You couldn't edit world like 2000x2000 with system like this, view must be restricted some way.

Brainer
26-08-2007, 01:38 PM
Found the doc that i used when writing my terrain renderer; http://www.flipcode.com/articles/article_geomipmaps.pdf


Man, what is that? I can't understand even a word. :roll:



Seeing the code, this is the only render call i found:

glDrawElements(GL_TRIANGLE_STRIP, FIndices.Count, GL_UNSIGNED_INT, FIndices.List);

So it is no wonder it gets slow... You couldn't edit world like 2000x2000 with system like this, view must be restricted some way.


You mean using f.i. octree? I've seen somewhere few Delphi implementations. Maybe I should try it? What do you think?

User137
26-08-2007, 03:50 PM
Checked wiki :P Quadtree might be good way with possibly frustum culling... Quadtree would simply mean dividing the map in many small maps, where frustum culling would tell which of the small maps are visible. Still trying to avoid too many frustum checks or it lose its purpose (speed). Because of heightmap i would make frustum checks 2 dimensional if at all (if camera is always top-view there's no need for frustum).

I only learned more about vertex arrays little while ago so haven't tried making this all that optimal, but i would imagine this needing several dynamic vertex arrays.

Brainer
26-08-2007, 07:25 PM
I have figured out another way of doing it. I dunno it's the correct one, but I think it's good to let you know more about it. :)

Suppose I've got a heightmap, which dimensions are 512x512. Rendering goes very well when the heightmap is 64x64, so I could divide my heightmap into eight smaller parts (64x64 each). Then I could calculate a bounding box for each parts and check whether the cursor is inside or not. If it's outside, I'll use a display list. Otherwise, I'll disable the display list and render the geometry without it. Do you get what I mean? What do you think of that idea?

User137
26-08-2007, 08:10 PM
That's close to quadtree approach, still, if part of map is not on the screen it shouldn't be rendered at all even if it's a displaylist. My tests ( http://www.pascalgamedevelopment.com/viewtopic.php?t=4785 ) rendered vertexarray faster than displaylist but that's thing to be experimented if you like, i could be wrong :)

VBO's might speed it up too for you but it's taken from same memory that textures use, becoming more hardware dependant so not my favorite...

Brainer
26-08-2007, 08:15 PM
Thanks for useful hints. I'm going to write some code now using your and mine ideas. I'll let you know later about the result - I'll post the code then. :)

.: EDIT !! :.
I did some changes, but I don't know why my "favorite" error occurs (line 268). :?
http://www.glsoftworks.pastebin.com/f5051d109

Andreaz
27-08-2007, 05:03 AM
Thanks for useful hints. I'm going to write some code now using your and mine ideas. I'll let you know later about the result - I'll post the code then. :)

.: EDIT !! :.
I did some changes, but I don't know why my "favorite" error occurs (line 268). :?
http://www.glsoftworks.pastebin.com/f5051d109

Most likely it's related to
Data.Heights[X, Y]

And as i said, displaylist doesnt gonna help you, especially when you're goint to edit the terrain, displaylists is static by nature. Use vertex arrays as in you last code instead.

User137
27-08-2007, 08:20 AM
Forgot to create DisplayList first?

DisplayList:=glGenLists(1);
glNewList(DisplayList, GL_COMPILE);
...

Brainer
27-08-2007, 06:53 PM
Thanks, User137. :) Here is the newest try. This time nothing gets rendered. I dunno why. Could you take a look at the code? Sorry for my lame questions, but I'm not that advanced and I'd like to learn more by asking as much as possible. :(
http://www.glsoftworks.pastebin.com/d69ddc039

User137
27-08-2007, 09:06 PM
I don't see anything odd, i trust you've tested all the numeric things to work before, and couldn't help there without testing in delphi. But as perfectionist as i can be, there is something :P

1.GL_COMPILE_AND_EXECUTE could be used to replace GL_COMPILE + glCallList as it's also faster way and simplify code.

2.procedure TCell.RenderCell; creates displaylist but does not render it. Without seeing the main program this would explain the non showing only if render was not in loop (but i guess you got a timer so this point is non valid...).

3.Extra variables controlling other variables sometimes make a mess. glGenLists(1) results a number that is always > 0, so uninitialized list would result 0.
if GotDisplayList then
// means the same as
if DisplayList>0 then

Brainer
27-08-2007, 09:21 PM
Thank you for your tips! I'll do the changes you mentioned tomorrow and let you know. :)