Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Yet another question about advanced lighting (sorry)

Author
Message
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 15th Sep 2011 02:56
So as you've all probably figured out by now I've been having a merry old time playing around with advanced lighting, and I have a new question of a more technical nature.

When things get memory intensive in a program, they tend to make it slow down between syncs, making the program appear as if it's running in slow-motion. This is well known and is usually dealt with using a combination of better syncing routines, better memory management, frustrum culling, etc, etc.

HOWEVER, in the game I'm making, as soon as I get more than one enemy on the screen (and I've got all my fancy Evolved Advanced Lighting happening) things start slowing down and I'd like to know if anyone knows the specifics of WHY so that I can better memory manage my game to reduce the slowing.

More specifically, what part of advanced lighting takes up the most memory when processing? At it's peak, my game is displaying around 35,000 polys on the screen at any given time (most of the time it's around 12,000) and I've already used frustrum culling to reduce that number as much as possible. If I remove enemies from my game, or there are no enemies around the player, things run VERY smoothly. I'm getting upwards of 55 fps and it's wonderful, but as soon as the enemies start piling up, things start turning a bit sour and I drop down to around 7 fps, but I'd like to improve that, so here's what I've done so far:

- I've tried excluding the enemies from the shadow-casting routine, which didn't REALLY help much.
- I've tried excluding the enemies from the advanced lighting routine, but that makes them look really weird and out of place.

Lights in the game are still able to cast shadows ONTO enemies, which might be causing the slow, since they're relatively high poly (between 3000 and 4000 each. I'm using one of the FPS Creator X10 model packs) but that's really what I'm asking... What part of advanced lighting uses the most resources? Is it the casting of shadows? Is it the receiving of shadows? Is it the animation of objects under the influence of advanced lighting?

Any help would be awesome.

Oh, and P.S. Revenant Chaos, you probably want to kill me by now Sorry about that! Once I'm done I should really go through and write a thorough help file for Advanced Lighting!

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 15th Sep 2011 03:20 Edited at: 15th Sep 2011 03:21
In my program, I noticed a slow down the higher the number is for this..

"set global shadow shades 2"

I set it to 1 and it speeds up. I set it to 2 or higher and the slower my computer gets. Its all to do with REAL TIME shadowing.

So on objects that get set the shadow once, make sure you preset it up first. Cast it on to an image first then paste image to object. Whatever works for you. But it all boils down to shading and shadowing. Its what I am also working on for mine.

"Life is like a box of chocolates.. eat it before it melts."
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 15th Sep 2011 03:36
Thanks JackDawson, but I'm using the Advanced Lighting shaders from Evolved Software, which don't make use of standard lighting commands

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 15th Sep 2011 03:39
Ahh my bad. Sorry I couldn't help.

"Life is like a box of chocolates.. eat it before it melts."
SH4773R
16
Years of Service
User Offline
Joined: 18th Jan 2010
Location: AMERICA!!!
Posted: 15th Sep 2011 04:04 Edited at: 15th Sep 2011 04:11
Advanced lighting is not really resource friendly in any form. are you using any of the particle commands? Or any other things like terrain? Try it without those if you are.

Ps. Darkbasic pro already has frustrum culling, I suggest looking into occlusion culling
I have some code I could give you for culling if you want

CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 15th Sep 2011 04:13
Hi SH4773R, I'm not using particles or terrain. Just the lighting, really. As I said, it works really efficiently when the poly count is lower, but yeah... Strange...

If you have some fancier culling code, I'd love to see it! Currently I'm using the advanced lighting system's frustrum culling as well as my own system that culls according to player viewing angle and distance, however, it's not hiding objects that are behind other objects, which would seriously bump up my optimisation if you've got something! I have a feeling it'd involve some raycasting...

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame
revenant chaos
DBPro Master
19
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 15th Sep 2011 04:16
Hello once again CumQuaT.
Though I am not sure exactly what causes it, I have run into that problem myself. I do know that extra slowdown comes from advanced lighting's multiple renders, but it seems like each model's animation frame needs to be recalculated for each camera render.

Since I got the Enhanced Animations plugin I rarely use the built in commands, as it is quite a bit quicker and uses less memory. I know its not the most favorable solution but it is worth looking into.

Quote: "More specifically, what part of advanced lighting takes up the most memory when processing?"
I would say your media probabaly takes up the most memory, but the slowest parts of Advanced lighting are the many cameras involved.

Quote: "Is it the casting of shadows?"

Rendering the shadow maps can be quite slow (especially point lights and the directional light), but the screen's resolution and your total object QT have quite an impact as well.

Make sure your animated models are using shaders from the "AdvancedLighting\Shaders\Animation\" folder. Those shaders are setup to offload the animations to the GPU which usually speeds things up a bit.

If you aren't already, look into combining your scenery objects to reduce the number of drawing calls required.

In my game engine I am using a modified version of the old deferred shading (before it was called Advanced lighting). I added the abillity to mask objects out of the main render while still casting shadows. That combined with frustum culling seems to have sped things up quite a bit.

Quote: "Oh, and P.S. Revenant Chaos, you probably want to kill me by now Sorry about that!"
That's quite alright, I would like to see Malevolence up and running.

Quote: "Darkbasic pro already has frustrum culling"
It does, but it doesn't seem to be the most efficient.
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 15th Sep 2011 05:22
Some interesting points there, Revenant! Glad to hear you're not sick of me yet!

A better culling method I think still wouldn't go astray. Something along the lines of hiding objects that are in screen but behind other objects, like using raycasting... I'll have to look into it as I've not done it before. Currently I'm just hiding objects not in the screen or past a certain distance from the camera.

Also a better exclusion method for the monster objects would help a lot I think... Excluding them from casting shadows has helped, but they are still receiving shadows. The effect being used on them is the Parallax Mapping effect that comes with the advanced lighting, but to be honest, they don't really need it as they look great on their own, so perhaps replacing that effect with an "empty" effect would keep them in the lighting system but use far less memory... Thoughts?

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame
SH4773R
16
Years of Service
User Offline
Joined: 18th Jan 2010
Location: AMERICA!!!
Posted: 15th Sep 2011 06:40
Yeah ill post some occlusion culling code as soon as I get it packed up into functions, and yes it does use ray casts but in a very special way...

CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 15th Sep 2011 06:42
I like the cut of your jib, SH4773R. If it works well, let me know what you'd like to be credited as and I'll make sure you're in the credits! Feel free to email the stuff to me, as well, at [email protected]

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame
SH4773R
16
Years of Service
User Offline
Joined: 18th Jan 2010
Location: AMERICA!!!
Posted: 15th Sep 2011 07:21
Sounds awesome! Ill be sure to polish the code as much as possible before I give it to you expect it somtime in the afternoon tomorrow.

CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 15th Sep 2011 07:23
You're a gentleman.

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame
revenant chaos
DBPro Master
19
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 15th Sep 2011 07:59
If by "empty effect" you mean a look similar to dbpro's standard lighting, then you could try the "Diffuse" version(s) of the advanced lighting shaders. They don't require anything but a diffuse texture.

I really don't think the speed issue is memory related, but rather that it is CPU intensive and is in addition to an already cycle hungry system. Have you gotten a chance to try the "Animation" shaders? I would imagine that a animation shader + no shadows should get you something workable.

With Advanced lighting, culling can get you some cycles back but you still have to be careful of the total number of objects that you have created at once. Even if objects are excluded/hidden they still slow down DBPro's rendering, which becomes even more apparent when using Advanced Lighting. I think even the highest object ID which is used has an effect on the rendering speed.
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 15th Sep 2011 08:04
Interesting points... The only reason I thought it was due to culling is that the game runs fine when the total visible object poly count was around the 10000-15000 mark. All of the models that "slow it down" are still loaded, but they are hidden. Once they become un-hidden it starts cranking over...

Animation Shaders are new to me and I've never actually seen them... If you point me in the right direction I'll definitely have a read of that! Also, thank you for the tip about diffuse shaders! I'll give that a try and see what happens

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame
revenant chaos
DBPro Master
19
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 15th Sep 2011 08:33
I meant the shaders which can be found in "AdvancedLighting\Shaders\Animation\"
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 15th Sep 2011 08:48
How exactly do they work? I noticed that there isn't an example for them in the Advanced lighting pack... Or are they just normal shaders that work better on animated models?

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame
revenant chaos
DBPro Master
19
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 15th Sep 2011 09:13
Quote: "Or are they just normal shaders that work better on animated models?"
Yep, they are used exactly like the other shaders.
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 15th Sep 2011 12:05
I know what I'M trying next!!!

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 15th Sep 2011 14:21
WOW! Revenant Chaos, the animation shaders make a MASSIVE difference to the framerate! Thank you so much for the tip!

SH4773R, I'm still keen to see the cull code though. You can never make a game engine too efficient!

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame
SH4773R
16
Years of Service
User Offline
Joined: 18th Jan 2010
Location: AMERICA!!!
Posted: 16th Sep 2011 03:59
Good to hear In my attempt to fix it all up I managed to break something. Working hard to fix it!

CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 16th Sep 2011 05:11
Hahaha these things happen!

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame
revenant chaos
DBPro Master
19
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 16th Sep 2011 06:19
Hi CumQuaT, I just took a look through advanced lighting and have just realized how many modifications evolved has really made.

It seems that Evolved has also added a way to exclude objects from the main screen render(s) while still allowing them to cast shadows. To remove/re-add objects to the main render, just call:

That can be used for culled objects which are still casting a visable shadow.

I also notice that the Object() array isn't being sorted in any way, and that the object-array lookups could be sped up with binary searches.

I see a lot of unneeded looping, for example:

could be changed to:


Almost all of the "Object_..()" functions make a call to Object_FindArray() which means alot of unneeded searches. That could be optimized by editing the functions to accept the object's array index, so you can call Object_FindArray() yourself and avoid the extra searches. That would mean that the function could be farther re-written to:


Nearly every function starts off with "if AdvancedLightingEnabled=1" which could be removed since you should know yourself weather or not it has been setup. It is good practice (even more so when releasing libraries to others) but it means performing alot of worthless checks.

Alot of this stuff doesn't make much of a difference until your ObjectQT gets up there, but it just seems like a good idea to leave as much time for your game logic as possible.
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 16th Sep 2011 06:50
Wow, you are the epitome of thoroughness, Revenant Chaos!

I think people would get a lot more use out of this system if it was re-written to be as efficient as possible and turned into a new plugin for DBpro...

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame
SH4773R
16
Years of Service
User Offline
Joined: 18th Jan 2010
Location: AMERICA!!!
Posted: 16th Sep 2011 08:02
Hey CumQuaT, sorry I was unable to get the culling code up here, life got in the way. I can't really afford to prioritize programming over school work right now. I'm sure you'll understand

CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 16th Sep 2011 08:51
Totally I'm not going anywhere!

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame

Login to post a reply

Server time is: 2026-07-10 08:39:33
Your offset time is: 2026-07-10 08:39:33