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 / Real time Flashlight trick

Author
Message
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 11th Aug 2014 19:58 Edited at: 12th Aug 2014 16:06
Hi there.

Looking the capability of other engines to make realtime flashlights, I make a funny way to get something decent. It could be good for small levels as it use native commands for shadow shading, and slows down a bit. This is what I have so far.





I'm not a grumpy grandpa
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 11th Aug 2014 21:38 Edited at: 13th Aug 2014 01:34
Does this make it any faster?



I just jiggled it a bit, trying to reduce the amount of work in the main loop.

Formerly OBese87.
RonsWare
15
Years of Service
User Offline
Joined: 5th Sep 2010
Location: Netherlands
Posted: 11th Aug 2014 21:46
@Chafari
Amazing coding

@Libervurto
Very nice

Cheers

Programming is learning
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 11th Aug 2014 21:55 Edited at: 11th Aug 2014 22:01
Doesn't work for me. I wonder what's gone wrong? The light seems to be in the wrong place and there's no flashlight effect.

I'll investigate later this evening.

Edit Which DBPro update are you using? I'm using U77RC7.



Powered by Free Banners
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 11th Aug 2014 22:16
Quote: "Does this make it any faster?"

In my Laptop my code runs up to 234 FPS, with yours, it runs to 272, but a bit jiggled as you comented.


@RonsWare Thanks.

Quote: "Edit Which DBPro update are you using? I'm using U77RC7."

This is going to be the problem, I'm using old 1.074

Here's an exe if you want to test.

Cheers.

I'm not a grumpy grandpa
wattywatts
17
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 11th Aug 2014 22:21 Edited at: 11th Aug 2014 22:23
I seem to remember something about the native shadow shading not working correctly in the newest build. Specifically, setting the use shader option to 1.

Edit
The exe looks very nice though! Good work!
Derek Darkly
14
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 11th Aug 2014 22:32 Edited at: 11th Aug 2014 22:33
Quote: "GG: Doesn't work for me. I wonder what's gone wrong? The light seems to be in the wrong place and there's no flashlight effect."


I thought it wasn't working at first - I had to turn on the ambient light to get my bearings. It does appear to work, though. The target area is slightly to the right.

@Chafari:
Neat trick! So you are casting a light from light zero onto a cylinder object, which then in turn casts a shadow all around the outer edges of the screen?

Also, for my own clarification, SET SHADOW POSITION is the exact same thing as POSITION LIGHT 0?

666GO†O666
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 11th Aug 2014 22:35 Edited at: 11th Aug 2014 22:48
Quote: "I seem to remember something about the native shadow shading not working correctly in the newest build. Specifically, setting the use shader option to 1.
"


That's why I'm using old version, as lots of my old programs doesn't work correctly from 1.074 ahead.

Thanks for your comments.

Edited

Quote: "Neat trick! So you are casting a light from light zero onto a cylinder object, which then in turn casts a shadow all around the outer edges of the screen?"


Yeah, but I had to make a cylinder with some object because cylinder primitive doesn't seem to work.

Quote: "SET SHADOW POSITION is the exact same thing as POSITION LIGHT 0?"


I'm not completly sure

I'm not a grumpy grandpa
wattywatts
17
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 11th Aug 2014 22:51
I think I'm going to install 1.074, I'm getting almost 1k fps on my laptop and I always liked the stencil shadows.
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 11th Aug 2014 23:46
7.62 here and it runs at 450~[+/-40] fps average on an HD 4200 on my surface Pro 2

Very neat trick! thank you for sharing and maybe I can find a use for it, but that cell shading, I really want to use!

chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 11th Aug 2014 23:48
Quote: "It does appear to work, though. The target area is slightly to the right."


We have to put the camera slightly on one side to be capable to see the shadows...if it is the same target camera + light, we won't see shadows, because shadows will be right behind the objects.

Here's the same example with a level.

I'm not a grumpy grandpa
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th Aug 2014 01:14 Edited at: 12th Aug 2014 01:15
Quote: "Here's an exe if you want to test."


Yes, that was better but still some glitches - the basic idea is very neat though.

Here's a glitch:





Powered by Free Banners
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 12th Aug 2014 01:30
Quote: "Here's a glitch:"


I can understand about glitch, that the camera doesn't go smooth ?...have you seen the example with the level ?

I'm not a grumpy grandpa
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th Aug 2014 01:43
Quote: "have you seen the example with the level ? "


Will try to remember to check that tomorrow.



Powered by Free Banners
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 12th Aug 2014 01:48 Edited at: 12th Aug 2014 01:52
Quote: "Will try to remember to check that tomorrow"


In real life, we don't have to see the illuminated area exactly like a circle. When we carry a flashlight, and we project it to the walls it should look something like this:



Otherwise, it would seem that we are using a mask of light. So that depends on where are the walls.

I'm not a grumpy grandpa
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 12th Aug 2014 13:49 Edited at: 12th Aug 2014 15:52
Quote: "Very neat trick! thank you for sharing and maybe I can find a use for it, but that cell shading, I really want to use!"


@MrValentine
I hadn't see your post sorry . Thanks for testing.


In first attempts, I made a poor cone projection just to show the results, now I improved the code, instead of rotate object and set camera orientation to that object, I rotate both camera & object, and it looks to be smoother. We just need ajust the power light/fog/ambient light that we desire .



Cheers.

I'm not a grumpy grandpa
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th Aug 2014 14:06
Quote: "Otherwise, it would seem that we are using a mask of light. So that depends on where are the walls."


No, that's not the glitch I was referring to. I meant the box in front of the flashlight that should have been lit but isn't.



Powered by Free Banners
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 12th Aug 2014 14:38 Edited at: 12th Aug 2014 16:07
@GG

Yeah ...l see, but that just need to adjust the light position, as the light is into a cylinder to get the effect...we could make the cylinder a bit shorter and less diameter to help it.

EDITED. GG you were right about the camera glitch. It was the camera height...now is corrected.

Cheers.

I'm not a grumpy grandpa
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 12th Aug 2014 17:11
Tested this out.. using DBP U77RC7.

I love it. Pretty slick. I will have to add a sleep DLL routine I use into it to prevent it from over driving my CPU / GPU though. Over 3K in frames is cool and all, but also is rough on the CPU or GPU, depending which one your using. I usually limit the frames to about 60 or 120 depending.

chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 12th Aug 2014 19:39
Quote: "Tested this out.. using DBP U77RC7."

@JackDawson Thanks for testing.
I see that you have a fast CPU, but I can't see the shadow shading working Don't you see the flashlight illuminated area ?

I'm not a grumpy grandpa
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 12th Aug 2014 23:39 Edited at: 12th Aug 2014 23:45
I don't get the shadow shading nor the "flash light" effect. I have a good graphics card too.

NVidia GTX 660Ti with 3 Gigs ram on the video card.

It's a beast and plays games like Star Citizen just awesome. So I know its not the card itself.

My System Ram is 8 Gigs

CPU = Quad i5-2500K @ 3.3 GigHertz per core
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 13th Aug 2014 00:05
@JackDawson
I added an exe above compiled with 1.074 if you want to test. I think the problems is in the new version that you are using like Green Gandalf.

Cheers.

I'm not a grumpy grandpa
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 13th Aug 2014 00:57
I get 4300 fps with chafari's code and 4200 with Libervurto.

chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 13th Aug 2014 01:09
Quote: "I get 4300 fps with chafari's code and 4200 with Libervurto."


Thanks for testing Phaelax.
Can you see the flash light effect ? or you see the image completly flat ?

The code was made for Dbpro 1.074

I'm not a grumpy grandpa
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 13th Aug 2014 01:36
I changed move object 2, updn*0.1 back to two If statements. For some reason I thought multiplication would be faster.

Formerly OBese87.
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 13th Aug 2014 03:23 Edited at: 13th Aug 2014 03:26
Quote: "Chafari
@JackDawson
I added an exe above compiled with 1.074 if you want to test. I think the problems is in the new version that you are using like Green Gandalf.

Cheers."


Yea I tried your EXE and my frame rates plummeted to the 800s. But at least there was a flash light effect. Still no shadows though.

And I lost all the nice shading too. It looks bland. So with the loss of more visually, with only the benefit of the flashlight effect, you would think my frame rates would go up, not down.


chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 13th Aug 2014 03:46
Quote: " at least there was a flash light effect. Still no shadows though."


Yes there are shadows if we go close to the corners. In this example, you can see better, how shadows project on othere objects and on the walls.

Example attached.

I'm not a grumpy grandpa
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 13th Aug 2014 17:38 Edited at: 13th Aug 2014 17:40
Chafari, I got my full speed back and I have everything you spoke about in that example. What source code you use and what compiler ? and did you install any plugins for this ?

EDIT UPDATE : And please ignore the quality of this picture. I had to resize it down for this forum. That was taken at full screen 1920x1080.


chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 13th Aug 2014 19:33
@JackDawson
Now you can see the shadows!!
Quote: " What source code you use and what compiler ? and did you install any plugins for this ?"


The source code is the first post in this thread above.. the compiler is the old 1.074, cuz I have refused to use last versions for lots of problems in my old codes. I didn't use any plug-in.

The whole black area is a shadow, because I put the main light into a cylinder to get this effect. This object is hidden, and depending on the camera hight, we can see better or worst shadows. It was just a trick to use a flashlight in our games. The bland level above was just to see the effect, but we can play with with fog and other lights.

Cheers.

I'm not a grumpy grandpa

Login to post a reply

Server time is: 2026-07-05 17:32:12
Your offset time is: 2026-07-05 17:32:12