ShiVa3D
Sample for Shadow detection
Sample for Shadow detection
by FF.Fan » 12 May 2012, 13:18
Hi ShiVa3D Community !
All the last contributions from other great members from the forum has put me in good mood lately, and I still believe we can share & do some cool things all together.
I also noticed that until now I just answered some questions & tried to help if I was able to but I never gave something myself to the Community.
So i'll try to post more stuff now if I think it can be usefull for the Community
Stop the talk and here is my little contribution :
What it is :
Its a sample that shows how to detect shadows/light in a scene, both with Directionnal Light than Point Light. It can be used as a base to make a cool stealth game for example.
What you can do with :
You can do what you want with this sample ! If you use it somewhere, I'll be very happy if you post something here to show what you did with and of course, if you improve it, please be sure to share with the others
How it works :
Basicly it just work with sensors, raycast, and involve some trivial math.
The idea is to see if a raycast fired from the light to the player hit actually the player or something else.
If it hit him, then, the player is in the light, otherwise he is hidden in the shadow.
Get the ste and you should understand pretty well, as i tried to comment a lot.
There is 2 AIModel. One that can be used for Point Light, and the other for Directionnal Light.
Indeed :
The dection occurs at the center of the sphere the player is controlling in point light detection.
Means if the center of sphere is in the shade, the whole sphere is considered as in the shadow.
In directionnal one, the point of reference is the point at the intersection of center of sphere and light direction (good old math formula from college
)
Keyboard commands :
If you have questions or something just post here please.
I agree that the scene is very not optimized.
Beware also that sensor & raycast everywhere can be performance eating, but i couldn't find any other way to do so, with less calcul power.
Screenshots :
point light in the light:

point light in the shadow:

directionnal light in the light:

directionnal light in the shadow:

In "Textured Display Mode" you'll be able to see a debug line showing the raycast direction :
here for point light :

here for directionnal one, note how parallel the line and the directionnal light are (same direction) :

Hope it will be usefull to somebody
Sorry but because of file limitation (256kb !?) i had to split in 2 part, just rename them in "Stealth.zip.001" and "Stealth.zip.002" respectively and extract as usual.
All the last contributions from other great members from the forum has put me in good mood lately, and I still believe we can share & do some cool things all together.
I also noticed that until now I just answered some questions & tried to help if I was able to but I never gave something myself to the Community.
So i'll try to post more stuff now if I think it can be usefull for the Community
Stop the talk and here is my little contribution :
What it is :
Its a sample that shows how to detect shadows/light in a scene, both with Directionnal Light than Point Light. It can be used as a base to make a cool stealth game for example.
What you can do with :
You can do what you want with this sample ! If you use it somewhere, I'll be very happy if you post something here to show what you did with and of course, if you improve it, please be sure to share with the others
How it works :
Basicly it just work with sensors, raycast, and involve some trivial math.
The idea is to see if a raycast fired from the light to the player hit actually the player or something else.
If it hit him, then, the player is in the light, otherwise he is hidden in the shadow.
Get the ste and you should understand pretty well, as i tried to comment a lot.
There is 2 AIModel. One that can be used for Point Light, and the other for Directionnal Light.
Indeed :
- if it's Point Light, just fire a raycast from light to player and see if it touches it => simple as that
- if it's Directionnal Light, it's a little bit different as the light has a direction (no seriously ?!
) and so it's coming from everywhere from that direction.
So in this case, you have to fire a raycast from player (watch out if you take center, you'll be firing raycast from "inside" the player and will always hit himself, so you have to offset the start raycast position!) to the direction of light ! (screens help understand)
The dection occurs at the center of the sphere the player is controlling in point light detection.
Means if the center of sphere is in the shade, the whole sphere is considered as in the shadow.
In directionnal one, the point of reference is the point at the intersection of center of sphere and light direction (good old math formula from college
Keyboard commands :
- Use the "L" key to switch from Point Light to Directionnal Light system
- Use the arrows keys to move the ball in the scene
If you have questions or something just post here please.
I agree that the scene is very not optimized.
Beware also that sensor & raycast everywhere can be performance eating, but i couldn't find any other way to do so, with less calcul power.
Screenshots :
point light in the light:

point light in the shadow:

directionnal light in the light:

directionnal light in the shadow:

In "Textured Display Mode" you'll be able to see a debug line showing the raycast direction :
here for point light :

here for directionnal one, note how parallel the line and the directionnal light are (same direction) :

Hope it will be usefull to somebody
Sorry but because of file limitation (256kb !?) i had to split in 2 part, just rename them in "Stealth.zip.001" and "Stealth.zip.002" respectively and extract as usual.
- Attachments
-
Stealth002.zip- a renommer en Stealth.zip.002
- (131.72 KiB) Downloaded 41 times
-
Stealth001.zip- a renommer en Stealth.zip.001
- (249.02 KiB) Downloaded 43 times
-

FF.Fan - Gold Boarder

- Posts: 265
- Location: France
Re: Sample for Shadow detection
by broozar » 13 May 2012, 09:40
very cool!
did you have a look at the the CarGame sample that comes with ShiVa? Shadow Volumes there are defined using sensor boxes. But your method is easier to set up, and it has the advantage of being really dynamic. well done!
would you allow us to host your STE on the ShiVa download page?
did you have a look at the the CarGame sample that comes with ShiVa? Shadow Volumes there are defined using sensor boxes. But your method is easier to set up, and it has the advantage of being really dynamic. well done!
would you allow us to host your STE on the ShiVa download page?
-

giggsy - Platinum Boarder

- Posts: 1019
- Location: Austria
Re: Sample for Shadow detection
by FF.Fan » 13 May 2012, 10:25
broozar wrote:... would you allow us to host your STE on the ShiVa download page?
of course, please do so ! thanks
-

FF.Fan - Gold Boarder

- Posts: 265
- Location: France
Re: Sample for Shadow detection
by broozar » 13 May 2012, 10:32
awesome! thanks. http://www.stonetrip.com/developer/download
Re: Sample for Shadow detection
by juaxix » 13 May 2012, 11:43
Amazing,...i can see a metal gear solid emerging from this tutorial?

Re: Sample for Shadow detection
by Fraser » 13 May 2012, 13:17
Great work ff.fan, nice share.
This could be used for some great dramatic looking games. I just got my son a tiny solar powered car for 1 euro. Watching it speed along and stop in the shadows this morning gave me an idea of something anyone could do with your code:
A hero droid recharges his batteries via solar panel in lit areas.
Hero then has to navigate through the shadows (perhaps with headlights on more powerful devices) as quickly as possible to get to the next lit area.
Moving and weapons drain the battery.
upgrades: +panel, +battery, +weapons, +motors
This could be used for some great dramatic looking games. I just got my son a tiny solar powered car for 1 euro. Watching it speed along and stop in the shadows this morning gave me an idea of something anyone could do with your code:
A hero droid recharges his batteries via solar panel in lit areas.
Hero then has to navigate through the shadows (perhaps with headlights on more powerful devices) as quickly as possible to get to the next lit area.
Moving and weapons drain the battery.
upgrades: +panel, +battery, +weapons, +motors
Fraser,
http://www.silicondroid.com
http://www.silicondroid.com
Re: Sample for Shadow detection
by FF.Fan » 13 May 2012, 13:26
nice game design idea Fraser !
it would be great if we users, make something like a community game to promote ShiVa3D, and it may be integrated as an official sample like "The Hunt" in the end if its really nice crafted.
everybody may improve it little by little using a repository.
Just my idea
it would be great if we users, make something like a community game to promote ShiVa3D, and it may be integrated as an official sample like "The Hunt" in the end if its really nice crafted.
everybody may improve it little by little using a repository.
Just my idea
-

FF.Fan - Gold Boarder

- Posts: 265
- Location: France
Re: Sample for Shadow detection
by Fraser » 13 May 2012, 16:25
It's a nice idea ff.fan, it would be alot of work and require a project coordinator to make an impressive game. LUA does have OOP traits so handing off black box AIs to developers would be possible to an extent.
Alot of people on this board are working toward generating an income and coding hours can be difficult to come by. That's pretty much me at the moment but I try to help others having probs if I can, trying to give back because most of my time on this board has been spent reading and harvesting information.
But if anyone is working toward building skills in order to land a job then it could be dynamite, it would prove you enjoy working in a team, very important to recruiters.
One wacky idea to encourage developers to contribute would be to release the game for free with in game ads (using deveoper owned adserver). the seperate developers could then promote their existing or future software in the free game (pro-rata depending on contribution). A good game (if free) would get millions of installs. It would also cut out the adserver middlemen.
Alot of people on this board are working toward generating an income and coding hours can be difficult to come by. That's pretty much me at the moment but I try to help others having probs if I can, trying to give back because most of my time on this board has been spent reading and harvesting information.
But if anyone is working toward building skills in order to land a job then it could be dynamite, it would prove you enjoy working in a team, very important to recruiters.
One wacky idea to encourage developers to contribute would be to release the game for free with in game ads (using deveoper owned adserver). the seperate developers could then promote their existing or future software in the free game (pro-rata depending on contribution). A good game (if free) would get millions of installs. It would also cut out the adserver middlemen.
Fraser,
http://www.silicondroid.com
http://www.silicondroid.com
Re: Sample for Shadow detection
by juaxix » 14 May 2012, 17:17
Can you create a shape around a model with this technique?
I mean, a shape over the other objects, ...here:
http://www.youtube.com/watch?v=kFWqf9zKugk
minute 4:30...
could you do something like that?!
it's like a cell shading but it is drawing over all the other objects with the shape of the char...
I mean, a shape over the other objects, ...here:
http://www.youtube.com/watch?v=kFWqf9zKugk
minute 4:30...
could you do something like that?!
it's like a cell shading but it is drawing over all the other objects with the shape of the char...
Re: Sample for Shadow detection
by FF.Fan » 14 May 2012, 20:57
juaxix wrote:Can you create a shape around a model with this technique?
I mean, a shape over the other objects, ...here:
http://www.youtube.com/watch?v=kFWqf9zKugk
minute 4:30...
could you do something like that?!![]()
it's like a cell shading but it is drawing over all the other objects with the shape of the char...
I'm afraid it's not possible for the moment
I think that you need to sort the rendering order of the z-buffer, which is actually impossible, unfortunately.
check here : http://www.stonetrip.com/developer/forum/viewtopic.php?f=28&t=23370&start=0
-

FF.Fan - Gold Boarder

- Posts: 265
- Location: France
13 posts
• Page 1 of 1

