Frame rate drop when lights are turned on

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
AndreaJens
Posts: 4
Joined: Mon May 23, 2016 10:48 pm

Frame rate drop when lights are turned on

Post by AndreaJens »

This is my first post here, so first of all... hi everyone!

I'm building a 3D fighting game using irrlicht 1.8.3 and I've stumbled into a not-so-nice issue.
In my scene, I'm rendering two animated characters (IAnimatedMeshNode) with approx. 7000-8000 polygons each, inside an arena (I've used the Quake arena included in the engine, just to test it), with two lights and soft shadows (XEffects-Reloaded, you can find it here).

The problem is, that the frame rate drops really badly when switching lights on.
More precisely:
  • first character rendered alone -> 400 fps,
  • both characters rendered -> 140 fps,
  • characters + arena -> 115 fps,
  • lights on -> 24-28 fps
Just to understand... the transition between the last two points is from this:

Image

... to this:

Image

Now, I have a good-to-advanced knowledge in C++, but I lack experience on shaders and GPU programming in general.
Can just adding lights and shadows cause a severe frame drop like this? Is the renderer using too much time to render the models? Should I reduce the poly count?

I was wondering if there could be a solution to get the same effect without the excessive frame rate drop.

Additional information:
  • My meshs are fairly middle-poly (8000 tris), and have bone/skeletal animations (.x mesh). Both meshs contain about 250 animation frames.
  • I have tried excluding all the game logic and build a minimal program with only the models, but the final result doesn't change (at least, now I'm sure that the FPS drop is not due to other routines, like the physics engine).
  • Interestingly enough, if I add any post-processing shader, the frame rate doesn't drop anymore - it's all due to the lights, apparently, but I could be wrong.
  • I've run the program using a Geforce 740M graphic card, processor Intel i7, 8 GB RAM.
  • I'm currently working on a Windows 10 computer with Visual Studio 2013.
Any hint is kindly appreciated, if I've missed some critical piece of information, just let me know and I will update my post :)

Thanks in advance,

~ Andrea Jens
Last edited by AndreaJens on Tue May 24, 2016 12:06 am, edited 1 time in total.
"Thorns are the rose's sweetest essence"
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Frame rate drop when lights are turned on

Post by mongoose7 »

For XEffects, there are two renders per light plus some postprocessing. You could try turning off soft shadows but I have no other ideas.
AndreaJens
Posts: 4
Joined: Mon May 23, 2016 10:48 pm

Re: Frame rate drop when lights are turned on

Post by AndreaJens »

Thanks for the hint!
Reducing the number of lights from 2 to 1 actually boosted my frame rate quite higher (almost double, 40-45 fps) :)
It looks like I will have to try some tricks to make it even better (for example, reducing the poly count, although is already fairly low).
Removing the shadows obviously solves the problems but destroys the nice effect :')
Just as an information... is there any alternative to XEffects which uses GPU instead of CPU calculations to create soft shadows?
"Thorns are the rose's sweetest essence"
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Re: Frame rate drop when lights are turned on

Post by devsh »

XEffects does use the GPU

Your problem might be a too-high resolution shadow map (to get the shadows you have to render the scene again for each shadow view)

The other problem with XEffects is that it draws its lights additively in multiple passes, so basically it blends the lights+shadow pixel contributions on top of each other instead of drawing the ambient and lights+shadows in one draw call.

So in all, you may be having your scene rendered FIVE TIMES OVER (which would actually account for the FPS drop from 115 to 24.

But most probably what is killing your perf is the fact that irrlicht models are skinned using the CPU, so all these 8000*3 ~ 24000 vertices per character are getting animated by the CPU maybe 5x or 1x as many times.

Also since they are animated on the CPU they sit in CPU-side arrays so the GPU can't draw them as fast (unless you have a Intel GPU which uses system RAM as VRAM), but maybe you could set the DYNAMIC mesh storage hint?


IMHO you have three options:
1) Hack away at XEffects and write your own shadows+lighting
2) Switch to SVN irrlicht and use the shader pipeline for hardware skinning
3) Wait 3 weeks for my newest irrlicht commit and use my branch while doing (1)
AndreaJens
Posts: 4
Joined: Mon May 23, 2016 10:48 pm

Re: Frame rate drop when lights are turned on

Post by AndreaJens »

devsh wrote: But most probably what is killing your perf is the fact that irrlicht models are skinned using the CPU, so all these 8000*3 ~ 24000 vertices per character are getting animated by the CPU maybe 5x or 1x as many times.
Yes, this was one of my thoughts. I have tried to use this hardware skinning plugin by christianclavet, but with bad results. My mesh got severely deformed and they were not considered while lighting the scene.
devsh wrote: Also since they are animated on the CPU they sit in CPU-side arrays so the GPU can't draw them as fast (unless you have a Intel GPU which uses system RAM as VRAM), but maybe you could set the DYNAMIC mesh storage hint?
I've not fully understood what do you mean with "dynamic mesh storage hint". Can you explain it a bit?
devsh wrote: IMHO you have three options:
1) Hack away at XEffects and write your own shadows+lighting
2) Switch to SVN irrlicht and use the shader pipeline for hardware skinning
3) Wait 3 weeks for my newest irrlicht commit and use my branch while doing (1)
I have a complete lack of experience in shaders, so this is not a viable solution (at the moment). I will definitely start studying GLSL and HLSL, after all one has to start from somewhere, right? ;)

Anyway, thanks a lot ;)
"Thorns are the rose's sweetest essence"
Post Reply