ROAM terrain rendering, help us make spring much faster! - Page 3

ROAM terrain rendering, help us make spring much faster!

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Post Reply
User avatar
Beherith
Posts: 5145
Joined: 26 Oct 2007, 16:21

Re: ROAM terrain rendering, help us make spring much faster!

Post by Beherith »

EDIT: see the bottom of post!

Ok, I suspect your familiar with the first part, the optimal tesselation of the terrain into smaller and smaller tris while the screen error is above a certain metric defined by the distance from camera and your viewradius settings. If not, here is the 100% accurate review of how ROAM works, and how this implementation functions:
http://www.gamasutra.com/view/feature/3 ... etail_.php

This isnt the first stripping method we used. The first was pushing each tri as a separate primitive. Slow, clunky, excessive cpu overhead.

The second one stripped the tris based on neighbouring relationships, doing quasi random walks on the triangles. Canned due to avg only 16 tris per strip.

This third one uses a wholly different approach, illustrated by the following paint masterpiece:
Image

Each patch of terrain (128*128 hmap pixels) is split into 2 base triangles, one for top left, one for bottom right. The image above only contains top left, but the process is identical for bottom right.
All triangles created during tesselation are right angle tris, and there are no T junctions.
So I make a linked list, with the first element containing the bottom left coords of the base tri, and the second (and last) element contains the top right. Then I pass the link to first element to the recursive stripper. The recurse stripper then inserts the coords of the apex of the triangle after the link passed into the linked list. Then if the triangle is not a leaf node, then it passes the first link to the left child, and the apex link to the right child.

After the recursion finishes, I read out the corresponding vertexes from the list into an array, and store the array as only the array needs to be pushed when when the cam isnt changed. This is also the part that seems to introduce the flickering bug. If I read out the list, and push the read, it doesnt flicker, If i just push the read array, it flickers.

This solution results in 2n+2 vertexes for the n tris in a single strip.
The ugly hack part of the solution is the following:
This algo does not do proper winding of triangles, so approx 50% of tris end up facing the other side. So I do a glDisable(GL_CULL_FACE) before the rendering, and enable it back after map render is complete.
The reason I still chose this method, is that it generates only 2 strips per patch, and is linear time.

For me, it results in correct stripping:
Image

But your GPU seems to discard or cull tris differently, since i can see from your screenies that you have tris that arent right angled tris.

My screenshot of the wiremap when turning backface culling on is this:
Image

All of my tris are right angled tris.


Here is the code for stripping a half triangle of a patch:

Code: Select all

void Patch::RecursRender2(TriTreeNode *tri, int leftX, int leftY, int rightX,
		int rightY, int apexX, int apexY, int n, int insertafterthis, bool dir)
{
		lstrip[lend].x=apexX;
		lstrip[lend].y=apexY;
		lstrip[lend].next=lstrip[insertafterthis].next;;
		lstrip[insertafterthis].next=lend;
		lend++;

	if (tri->LeftChild) // All non-leaf nodes have both children, so just check for one
	{
		int centerX = (leftX + rightX) >> 1; // Compute X coordinate of center of Hypotenuse
		int centerY = (leftY + rightY) >> 1; // Compute Y coord...

			int tmp=lstrip[insertafterthis].next;
			if(rightX==lstrip[insertafterthis].x&&rightY==lstrip[insertafterthis].y){
				RecursRender2(tri->RightChild, rightX, rightY, apexX, apexY, centerX,centerY, n,insertafterthis,dir);
				RecursRender2(tri->LeftChild, apexX, apexY, leftX, leftY, centerX,	centerY, n,tmp,dir);
			}else if(apexX==lstrip[lstrip[insertafterthis].next].x&&apexY==lstrip[lstrip[insertafterthis].next].y){
				RecursRender2(tri->RightChild, rightX, rightY, apexX, apexY, centerX,centerY, n,tmp,dir);
				RecursRender2(tri->LeftChild, apexX, apexY, leftX, leftY, centerX,	centerY, n,insertafterthis,dir);
			
		}
	}
}

EDIT: Fixed the flickering! Please pull from git again! (caused by a badly passed pointer) May have also caused the bad stripping seen by Kloot.
User avatar
Beherith
Posts: 5145
Joined: 26 Oct 2007, 16:21

Re: ROAM terrain rendering, help us make spring much faster!

Post by Beherith »

Ok, fixed the bad rendering for ppl not compiling with VS. Now it should really work for everyone! Did you know VS and mingw post increment i++ in a different order? Fuckem!

github link: http://github.com/Beherith/spring/tree/roam

Drop in exe (DLL files included, dont overwrite old DLLs, just let it pop in the ones you dont have) http://beherith.eat-peet.net/stuff/springroam.7z
User avatar
hunterw
Posts: 1838
Joined: 14 May 2006, 12:22

Re: ROAM terrain rendering, help us make spring much faster!

Post by hunterw »

this is win as fuck

last time i remember seeing this sort of optimization was making ut99 terrains with bryce
SirMaverick
Posts: 834
Joined: 19 May 2009, 21:10

Re: ROAM terrain rendering, help us make spring much faster!

Post by SirMaverick »

For smaller view radius Roam creates more details, that's why I actually have lower fps than with the current algorithm (I play on quite low settings). On higher view radius Roam gets better fps.

What I like about it is that the details don't change too much when camera position changes. The current algorithm produces more details for the terrain directly under the camera - a bit fail, because normally the view angle isn't 90┬░. This leads to the situation that with low view radius the terrain (cliffs/mountains) changes when scrolling around.
User avatar
Gota
Posts: 7151
Joined: 11 Jan 2008, 16:55

Re: ROAM terrain rendering, help us make spring much faster!

Post by Gota »

So is there like a bundled update including the latest stable spring with fixes and Roam?
zerver
Spring Developer
Posts: 1358
Joined: 16 Dec 2006, 20:59

Re: ROAM terrain rendering, help us make spring much faster!

Post by zerver »

I agree this is kick ass stuff, particularly if it means we get better looking terrain with less or same system load.

However, you should keep in mind that terrain rendering is a fairly constant load throughout the game. Even if the cost for terrain rendering was reduced to zero, it would still only raise the notch slightly in terms of how many units a specific system can handle.

I'm looking forward to seeing ROAM in action.
User avatar
hughperkins
AI Developer
Posts: 836
Joined: 17 Oct 2006, 04:14

Re: ROAM terrain rendering, help us make spring much faster!

Post by hughperkins »

Well, it would presumably open the door to more detailed landscapes?

Number of units is essentially determined by the pathfinder I think?
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: ROAM terrain rendering, help us make spring much faster!

Post by Tobi »

I tried this today and noticed two issues. I think the first one is already known / or maybe caused by just broken shadow rendering code. That is, shadows are weird when using roam branch. The second one is that selection rectangles seem not to work anymore in this branch.

Good work either way :-)
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: ROAM terrain rendering, help us make spring much faster!

Post by Argh »

@Tobi: the shadowmaps are borked, not because of the new format, but because the new format doesn't play nicely with the horrible kludges in the current implementation.
User avatar
Beherith
Posts: 5145
Joined: 26 Oct 2007, 16:21

Re: ROAM terrain rendering, help us make spring much faster!

Post by Beherith »

If you compiled latest commit, then shadows are implemented (with roam renderer), although they are still a tad buggy, i have a clue on where to look, but ill have to check further. I didnt test selection boxes, but there really isnt any reason why it shouldnt be working, ill go check that.
User avatar
TheFatController
Balanced Annihilation Developer
Posts: 1177
Joined: 10 Dec 2006, 18:46

Re: ROAM terrain rendering, help us make spring much faster!

Post by TheFatController »

I noticed a bit of unit animation stuttering despite FPS being fine with this branch.

Just by loading a new game and walking a commander around, the com would jerk and miss some frames as if FPS was low while it was hovering around 60
User avatar
Beherith
Posts: 5145
Joined: 26 Oct 2007, 16:21

Re: ROAM terrain rendering, help us make spring much faster!

Post by Beherith »

Still some more bugs to be fixed, I have no clue what causes the no selection boxes bug, like absolutely no clue :(
But there is an even worse one, and its only apparent when you look at DSD cliffs zoomed in, but it causes multiple tris being overlayed when diamond shapes are formed in tri stripping, and therefore causes Z-fighting with shadows (shadows are currently ROAMed as well)

Vid of the tri stripping bug (1MB):
http://beherith.eat-peet.net/stuff/roambug.avi
User avatar
Beherith
Posts: 5145
Joined: 26 Oct 2007, 16:21

Re: ROAM terrain rendering, help us make spring much faster!

Post by Beherith »

So, the shadows are fixed now.
Git repo updated.

Stuff left to do:
Cap roam resolution, allow more config options.
Add mapdamage.
Add reflections.
Add optimal cam based retesselation.
Fix selection boxes
User avatar
Beherith
Posts: 5145
Joined: 26 Oct 2007, 16:21

Re: ROAM terrain rendering, help us make spring much faster!

Post by Beherith »

Left a huge bug in shadow code, causing me to render shadows 5 times per frame. Now shadows work, and are super fast, and no flicker either.
Git repo updated, I can supply a test exe if anyone wants to try without compiling.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: ROAM terrain rendering, help us make spring much faster!

Post by Argh »

Are the shadowmap projections still really horribly distorted, though?

I would like to test an exe, definitely, if you really fixed the shadows then you're my hero forever.
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: ROAM terrain rendering, help us make spring much faster!

Post by Forboding Angel »

I would like an exe as well please :-)
User avatar
Beherith
Posts: 5145
Joined: 26 Oct 2007, 16:21

Re: ROAM terrain rendering, help us make spring much faster!

Post by Beherith »

Exe, with dlls included. Dont overwrite your old stuff when unzipping, and launch springroam.exe. I switched to newer compiler, so please report bugs!

http://beherith.eat-peet.net/stuff/springroam.7z

Mapdamage is still not implemented, and rotating the cam isnt calced in yet(trivial). Try Rot overhead cam to see what i mean :)
Setting viewradius still works, but you have to move the camera to apply the settings.

Edit: new bug- only water 0 works with shadows.
User avatar
Beherith
Posts: 5145
Joined: 26 Oct 2007, 16:21

Re: ROAM terrain rendering, help us make spring much faster!

Post by Beherith »

Link updated, git repo too. More speed improvements.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: ROAM terrain rendering, help us make spring much faster!

Post by Argh »

Tested. The projections are still borked. My guess: the matrix being used is always being derived from a vector 0,1,0 (and maybe even a fixed height) and needs to be positioned / rotated properly with the camera.

Here are two examples of what's happening:

In this first example, I am changing the position of the camera in the Y axis:

Image

Image
Attachments
shadowmap_distortion02.jpg
(239.76 KiB) Downloaded 147 times
shadowmap_distortion01.jpg
(138.9 KiB) Downloaded 146 times
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: ROAM terrain rendering, help us make spring much faster!

Post by Argh »

In the second example, I am moving the camera along the X axis.

Oh, and btw, if anybody says it's my GLSL, they're completely wrong. These distortions are 100% the same with the shader off.

Image
Image
Attachments
shadowmap_distortion04.jpg
(172.64 KiB) Downloaded 151 times
shadowmap_distortion03.jpg
(104.15 KiB) Downloaded 149 times
Post Reply

Return to “Engine”