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 / DBPro's lights and shadows

Author
Message
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 15th Jul 2010 16:24 Edited at: 15th Jul 2010 16:47
Hi all,

I'm currently trying out the default lights and shadows that DBPro has but I'm having a problem.

There was an example code around this forums that showed multiple pillars projecting shadows from a moving light source. It ran smoothly on my computer at 60fps.

So I thought I'd try it. I applied the necessary lines of code for my light and "ONE" object in my world. My world, is very small with the object being a 5x5x5 cube. It isn't even a "busy" world. Anyway, when I run the lights, it goes fine.

However, when I added a "light switch", it lags like crazy. Basically, I start off with the light off and when you press the return key, it toggles the lights.

I really apologize but I can't seem to find that thread with the example (and I can't remember the commands exactly), butdoes anyone have any idea why it lags down to 0 fps when I toggle the shadows on and off?

It works fine if I don't toggle it and just leave the shadows on.

In the mean time, I'll try to find that thread again.

The only part I remember is this inside my do loop:



Where object 2 moves around. The mode is -1 because I was reading it and from what I understand, -1 allows you to "move" the light and not sit at a default area?

EDIT: I found it! This is the link:

http://forum.thegamecreators.com/?m=forum_view&t=108890&b=1

So using his example, I basically done this:



This is the important parts of the code. If I took out that light switch, and just leave the shadows permanently on, the game runs fine. But the moment I give it a light switch and turn the shadow shading on/off, it lags.

In particular, when the shadow is turned on, my game drops down to 0fps. And remember, this is on just ONE object. I wish I can upload my code, but it's a project I'm working on and it's pretty big. HOWEVER, the level itself is not "busy". You rarely see more than 20-25 objects on screen. Which I don't think is a lot no?
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 15th Jul 2010 16:32
Probably best to post the whole source code - there might be something causing the slowdown that you can easily fix. I don't think it could be a shadow command itself, at least not if your using the shader version of the shadow effect. The geometric version is much slower, and might just cause issues when switched off and on.


Health, Ammo, and bacon and eggs!
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 15th Jul 2010 16:44
Quote: " I don't think it could be a shadow command itself"

I agree. Make the simplest program using only two objects, 1 light, and cast a shadow from object1 on to object2 and see if your problem still exists. If so, post that. You may be doing something wrong in implimentation or it may be the other parts that are slowing it down. Either way, the simple program will narrow it down.

The fastest code is the code never written.
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 15th Jul 2010 17:03
Wow, you're right.

I just made a simple code:


And it works fine. Must be my code then. I wonder what could be affecting it. Maybe because I have 4 dbpro lights? .X objects?

I'm still pretty sure I shouldn't post my code. It's around 3500 lines long XD

By the way, what do you mean the geometric version? Anyway, the code I posted is the same method I used.
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 15th Jul 2010 17:13
Back when DBPro first came out, the shadow commands only used the geometry mode, so the shadow would actually be a 3D object, made from polygons. Then a couple of years ago TGC added a shadow shader as standard, which gives much faster results. When you initiate the shadows, you can specify whether it uses the shader, or the geometry - one of the flags, don't remember which.


Health, Ammo, and bacon and eggs!
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 15th Jul 2010 17:22 Edited at: 15th Jul 2010 17:28
I see...

It didn't specify the modes in the help, but I tried 0, 1 and 2 and they all lag still o.O

This isn't good =/

I was reading the help files more though and it mentioned something about boned mesh.

So... I added a 3D object with bones and animations on it (replacing object 1) and noticed that when you turn on the light, it lags a bit before the shadow is projected and the game runs smoothly again.

Then I just realized. Almost everything in my game uses .X objects. Maybe that's why it lags?
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 15th Jul 2010 17:27
Quote: "Everything in my game uses .X objects. Maybe that's why it lags?"

I see no reason why that would be the case..... .x objects are the same type of object once loaded as any other object.... The vertex processing is done by the GPU (unless you can specify DX to do it). Skin meshes are slightly different than regular meshes, but the render process is the same.

The fastest code is the code never written.
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 15th Jul 2010 17:31
Hmm... I wonder what could be causing it then.

My game has nothing special in it (like shaders, fx etc.). It is entirely made up of some default objects and .x objects with a couple of them having animations.

I'll have to test around with stuff in my game then.
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 15th Jul 2010 17:39
Yes. Minimize. Minimize. Minimize. Until you find what the problem is, that's the best solution. Remove objects one at a time or in groups to see where the holdup is-- I don't think it's your objects though. Can you give some psudo-code of the layout of your routines. Like:
set display
load objects
do
check input
loop
blah, blah, blah.....

The fastest code is the code never written.
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 15th Jul 2010 17:53
Yeah right now I'm breaking down my code and commenting out stuff like lights. But so far still laggy. Although, I do notice slightly that when I took out all but 1 light, the game ran slightly faster. I.E. the lag for the shadow appearing doens't take as long.

Umm... I have a lot of setting up in the beginning.

setup display
setup camera
setup main menu (sprites, textures)
setup player (objects, textures)
setup level (tons of objects and a few repetitive textures)
setup lights (4 so far)
setup sparky's collision
do
functions
sync
loop
functions and gosubs

That's basically it. the functions and gosubs make the game work like "physics", controls, "AI", interactive objects and the background (an ocean made of 10 plains).
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 15th Jul 2010 18:08
First take out sparky's. See if that helps.
The repetitive textures part-- Are you loading the same texture multiple times? I think the default render method for DBP is by a texture loop: Each active texture is looped and the meshes associated to that texture are rendered. The GPU can handle only 8 textures at one time and these stages are for blending (usually). So that means that the program loads a new texture each "texture loop" to the GPU (which takes time). If you are using the same texture for different objects, just reference that texture, don't make a new one:

Not


The fastest code is the code never written.
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 15th Jul 2010 18:26 Edited at: 15th Jul 2010 18:29
I found the problem...

It's my player. I have around 20 different files for every time I did a major change to my game and the moment I uploaded my player.x, the game lags when the shadows are turned on.

To really test this. I got my latest code, took out this line:



And replaced it with a default sphere and the shadows work PERFECTLY (at least on this single object).

So there's my problem and I have no idea why. Because before on the test code that I uploaded here, I loaded the player object to see if it was the .x file and the shadow turned on fine. But remember that I did mention that the shadow appearing had a delay because of a slight lag. So it was the player.x file after all.

But the thing is, I haven't changed anything on it. The same .x file I used in the test is the exact same file as the one used in the latest file code.

Thoughts?

EDIT: Oh and yeah, that's how I texture. I said repetitive meaning that I use the same texture to texture multiple objects.

Well I'm going to sleep and will investigate this more tomorrow. If anyone has ideas as to why my player.x is causing the lag, please share them ^^
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 15th Jul 2010 18:43
How many polly's do you have on player.x? Hi-res polly's suck for shadow casting (and render speed in general). If it is hi-res, then maybe you could make a lo-res version and use that for shadow casting-- just hide it so it doesn't render.

The fastest code is the code never written.
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 16th Jul 2010 03:32
All my models are low poly.

My character has 1388 polys according to 3Ds Max. I'm sure that isn't too high right?

I mean it only consist of 1 mesh and bones.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 16th Jul 2010 16:23
Exporting two sided faces can double your poly count but even so it would only be 2776 poly, not much really. What size is the object texture?

Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 16th Jul 2010 17:08
Export your mesh without animation and load it into your game to test it. Don't export it with the same name as your character, use something like "test.x". Take the character out of the loop and put the "test" in it's place (remember, no animation). If you still have the same problem, try making a VERY lo-polly version and repeat. If you don't find the solution on your own soon, make a simplified version that gives the same problem, and post it with source, meshes, and textures.... Someone WILL figure it out.

The fastest code is the code never written.
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 16th Jul 2010 17:37
baxslash:

the texture size is 1024x1024. Pretty standard I think.

Hawkblood:

Alright, I'll try that tomorrow. It's late here and I'm tired lol

It would kinda suck if the animation was the problem since I need him to have animation. But I do want to know what's causing it. I'll post again with results tomorrow.
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 17th Jul 2010 07:39
Hmm...

I used a version of my character where it's just the mesh and texture. No bones, no animations.

It doesn't lag, but the shadow is wonky.

As in, when I turn shadows on, the shadow isn't touching the player's feet. It starts off a few feet from him and it's very VERY skinny. I used the exact same code as before. Also, the shadow doesn't move in regards to the light's position.

So I got the next model I had (thank goodness I always save after major changes XD). This one is the exact same setup except that it is rigged, ready for animating.

And you guessed it! It lags! But the shadow is still imperfect. Doesn't attach to the player's feet (he is on the ground) and it's skinny and it doesn't reposition.
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 17th Jul 2010 19:52
Ok. Make a SIMPLE example that shows your problem and upload it.

The fastest code is the code never written.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Jul 2010 21:11
I think this illustrates the problem DB_Newbie is talking about - look at the shadows for the ellipsoid.



It might be something to do with minor inaccuracies in the shader calculations. Not sure though. Need to delve into the shader code.
DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 18th Jul 2010 06:27 Edited at: 18th Jul 2010 06:28
Hawkblood:

I think the problem is the combination of the rigged/animated character combined with the contents of my game. Because when I use the character with bone and animations in an empty world, the shadows work fine, if not perfectly. It's only when I do it in my current game that it lags.

I can make a simple code, but it will probably work fine since it won't contain the contents of my game in it. I'm not trying to sound stubborn about posting an example code, mind you.

Green Gandalf:

Yeah that's the problem I'm having.

Annyways. If this helps, here is Green Gandalf's code except I placed my character in it (attached). As you can see, it works fine with no lag (this character has bones and animations), which I think is because it is an empty world.



I think it's something else in the world combining with my character that is making it lag.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 18th Jul 2010 12:36 Edited at: 18th Jul 2010 12:40
I'm not convinced the shadow positioning fault here is the same problem. Your character isn't quite standing on the ground. Here's a partial screenshot taken by placing the camera at ground level, i.e. by changing



to



If I change the character's position to



then the boy is standing on the ground and the shadow seems to line up correctly. I don't know what's causing your lagging problem though - unless it's the poly count of the rest of your level.

DB_Newbie
16
Years of Service
User Offline
Joined: 4th Aug 2009
Location:
Posted: 18th Jul 2010 15:20
Yeah, no surprise there. That's something I can easily fix in my code.

But as for the lagging, me neither. The player has the most poly counts out of all the objects in my world.

If this continues, I guess I'll just use a shader instead. Thanks for the help guys.

Login to post a reply

Server time is: 2026-07-25 04:55:04
Your offset time is: 2026-07-25 04:55:04