Jump to content
Eternal Lands Official Forums
Wytter

Optimizing The Renderer

Recommended Posts

Seems to be working all right, apart from that I had to include SDL_opengl.h in global.h to get it to compile. The spread in FPS seems a bit wild, though, i can get 34 FPS and the next instance 178.

Share this post


Link to post
Share on other sites

glClipPlane() and Nvidia==teh sukc.

Nvidia should actually implement it in hardware. I don't know what other options there are.

Share this post


Link to post
Share on other sites

Well... A time ago I've downloaded programs from http://delphi3d.net...

There's a program under Download>Special Effects>texreflect.zip that does exactly what you want...

But I don't know how it works... I've just downloaded the programs and then I executed them...

But maybe you will find something in the sourcecode?

Share this post


Link to post
Share on other sites

Here's a new patch - hopefully it will help making the FPS less jumpy.

 

http://wytter.tfm.ro/elc/opt2.diff

 

It's creating an array of the nearest 2d objects and a linear tree of the nearest 3d objects (ordered by distance from the camera) when the camera moves/you go to a new map/an object is added etc. These objects are then rendered, hence it aims at giving a somewhat better CPU/GPU load.

 

But what we really need is a better way to determine which objects are visible.

Edited by Wytter

Share this post


Link to post
Share on other sites

User clip planes are evil. Not only they slow rendering down, but they are reported to even screw up texture coordinates and other stuff. Personally, I've never been able to even use them when to programmable pipeline is on.

 

An excellent alternative is oblique frustum planes by Eric Lengyel, which basically modifies the projection matrix and maps the near plane into an arbitrary user-defined plane. Of course it's accelerated in all 3D hardware, since it just uses the projection matrix. One drawback is some loss in depth precision while rendering the reflected scene, but in EL it shouldn't be a problem.

 

Here's a link: http://www.terathon.com/code/oblique.html

 

Unfortunately, the source code on this example assumes we're dealing with a perspective projection, and not orthographic. But I strongly suggest to switch to perspective projection(not to be confused with first-person view) anyway. Apart from the fact it's better looking, having a view frustum instead of a box will help with various things like visibility determination, shadowmaps, LOD... It's no big deal, actually in the client I'm working on for Cal3D I've already modified the projection to perspective without any problems at all. It still looks *like* isometric, but with perspective.

 

Also, about the FPS jumps: It might have a thing to do with how you actually calculate and display FPS. In each frame, you calculate:

 

if ((cur_time-last_time)) fps = 1000 / (cur_time-last_time);

 

which is supposed to give you the FPS in that instance. And every 10 frames, you average all the fps and print the result.

 

The thing is, you should never calculate fps every instance, because in such small timings the clock is never completely accurate. Also note that fps is an (int), so whatever rounding is accumulated.

 

Instead, you should calculate the fps in fixed intervals, say every second:

 


float dt;
int fps;
int frame_count;
start_interval=GetTick();

while (PlayGame)
{
   end_interval=GetTick();
   if (end_interval-start_interval>1000)
       {
         dt=(end_interval-start_interval)/1000.0;//milliseconds to seconds
         fps=(int)(frame_count/dt);
         PRINT(fps)
         start_interval=end_interval;
       }
   DrawFrame();
   ++frame_count;
}




Edited by mikeman

Share this post


Link to post
Share on other sites

Using a perspective view would need just slow things down (more objects displayed) and would also increase the bandwidth requirements (as the players need to be sent to each client from further away).

Share this post


Link to post
Share on other sites

******

Quote:

Using a perspective view would need just slow things down (more objects displayed) and would also increase the bandwidth requirements (as the players need to be sent to each client from further away).

******

 

Actually, no. Just look at the picture:

 

el5ab.jpg

 

It is taken from the modified client with perspective projection. I have mady *no* changes at all except setting up the projection and the modelview matrix. The camera rotates/tilts as always. As you can see, it covers exactly the same area as with ortho projection. I've tested it, no players or objects pop in/out. If coded correctly to render only objects that are inside the frustum(which is actually smaller from the bounding box of ortho projection), it can actually speed things up.

Edited by mikeman

Share this post


Link to post
Share on other sites

Hmm...

Based on my testings, it looked quite different. Maybe your perspective is very close to isometric?

Can you please post the perspective screenshot and isometric screenshot (of the same scene, same position) side by side?

Share this post


Link to post
Share on other sites

One of the slowest parts of the main display loop was the mouse-object intersection tests. Taking out the tests entirely gets you a nice chunk of "free" FPS. At some point, someone made a test to see if the mouse was in a bounding box around a 3d object, but no test was ever made for actors (this was about the time cal3d development was starting). You could probably get some decent performance gains by creating bounding boxes or even a bounding hierarchy for all actors and objects, and maybe try to find a faster and better method for testing the intersection than reading pixels from the back buffer (slow).

 

 

 

Now that I finally know enough about graphics to make some good improvements, I have absolutely no free time :P

Share this post


Link to post
Share on other sites

That looks really impressive ;)

Great job :o

If you finish it prior to the update, we should include an option on having perspective view or isometric (some people might like isometric better).

 

Cicero: When you'll have some free time, feel free to come back.

Share this post


Link to post
Share on other sites

Hm..it's pretty interesting and neat. I'm not sure which I like better really... maybe it just takes some getting used to. Is there a bug that you can no longer rotate the camera up and down, or is it limited to this range only?

 

The rain is really nice too :)

Share this post


Link to post
Share on other sites

Most likely there are problems because that's a TEST client only.

As for the server sending what kind of rain, it's possible, but not a priority

Share this post


Link to post
Share on other sites

Did anyone notice problems with the patch ? Otherwise I'll commit it...

Share this post


Link to post
Share on other sites

Wytter, since you're working on this, perhaps you should also try to use Display Lists. It might seem strange at first(because DL are old feature), but I've heard from several sources that many times DL are even faster than VBOs, since the geometry is completely static, and you can compile state changes too. See this thread for a little more insight:

 

http://www.gamedev.net/community/forums/to...topic_id=320627

Edited by mikeman

Share this post


Link to post
Share on other sites

Actually, I tried the DLs in the beginning, and they were SLOWER than the immediate mode.

And no, I didn't compile them every time, they were compiled only once (and released if out of the screen for too long).

Besides, the DLs are implementation dependent, some drivers/manufacturers implement them differently.

VBOs are standard, and should be hardware accelerated all the time.

Share this post


Link to post
Share on other sites

Added to CVS. Please tell me if you get any problems with it.

Share this post


Link to post
Share on other sites

I downloaded from CVS and compiled and it runs nice on my linux box. :(

 

The fps rate increase is really significative. It has come from about 16-18 in my gForce2 up to 28-35. And the best for me: the cpu usage during the game has droppen from 97-99% to an average that goes from 6 to 10%, that really makes a difference. Good work! ;)

Share this post


Link to post
Share on other sites

Well, +3 approx. FPS, -9% CPU, and a lot smoother rendering - nice :P

Share this post


Link to post
Share on other sites

I found a bug that will be fixed as soon as I commit the spell quickbar :)

Share this post


Link to post
Share on other sites

Right, can I get a list of people who are actually testing this?

 

Radu keeps telling me that his client is crashing, but I cannot reproduce the bugs he's been telling me about - it's 100% stable here with VBO's. So please, tell me if anyone is experiencing crashes - I'm especially interested in the people running on Windows.

Share this post


Link to post
Share on other sites

I am running it, and so are everyone running the TC client, so we have 100 or so guinea pigs out there, all running various Windows versions :)

 

Any bugs so far have been mainly my code, apart from the glitches like buildings just suddenly appearing from nowhere after a few seconds or so.. I will keep you informed of the bug reports I get.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×