Jump to content

Create light for flashlight


naitro
 Share

Recommended Posts

Hi, here the situation - for example I have some third-person game(camera in sky) there player walk in full darkness across the rooms with flashlight, so if he direct flashlight on the wall into the room then only this wall and space front have to be highlighted, but all over still have to be in darkness include space behind this wall.

here simple scene: http://jsfiddle.net/QZD4w/ in this scene only big right box have to be highlighted and ground before, can I do it in any case? I can't use shadows cause then I have to use directional light and in this case all rooms will be highlighted.. mb exist some over way to do this? For example mb just don't render mesh which are out of view.. but in this case problem still will be with ground..

Link to comment
Share on other sites

space front have to be highlighted, but all over still have to be in darkness include space behind this wall.

 

Naitro, well one thing you can try is setting the range value for the spotlight. If you wall thickness is greater than the range then no light will show on the other side.

 

Try adding this to your script :

light.range = 150; 

By the way, welcome to the babylon forum.

 

cheers, gryff :)

Link to comment
Share on other sites

Inserting "light.range = 300;" at line 15 did have the effect of working.  Probably good to set a range anyway, since a flashlight does not have infinite range.  Does not all solve the problem though, unless the range is less than the depth of the smallest box, but even then the flashlight would have to right up to the wall to be seen on the other side.

Link to comment
Share on other sites

Yeah I tried add range, but there is no solution for me.

Here little bit more complex example: http://jsfiddle.net/EjTh9/ in this example left wall have to be highlighted, but corridor not.

Actually in my case I wanna did it not like exactly flashlight, but mostly like view of character, so if character staying at one side of the room, he have to see all room, but not what behind the walls.. mb light not perfect solution for it? Any solution I can do it with lights or anything?

Link to comment
Share on other sites

Hi!  http://www.babylonjs.com/playground/#2HQ0M0  I thought maybe... if we could push all the wall boxes into a ShadowGenerator, maybe the wall would cast shadows, which would make the light act correctly.  But I failed.  The ShadowGenerator is being grumpy... maybe because I tried to push 51 boxes into its renderList.

 

Its all there, remarked-out.  Maybe somebody else can figure out what's wrong with the shadow generator.  Adjust things, hit Run, over and over, as wanted.  Good luck.

 

Shadows tutorial - https://github.com/BabylonJS/Babylon.js/wiki/17-Shadows

Playground Shadows demo - http://www.babylonjs.com/playground/?15

Link to comment
Share on other sites

so if character staying at one side of the room, he have to see all room

 

Naitro, I set the range to 140 and just the room gets illuminated.

 

But I suspect that is not what you want. If the character starts to move, eventually he will be close enough to a wall that the spotlight will "shine through a wall". And once the character moves out into a corridor, you may have a spotlight cone size problem as well.

 

You could make the range less than the thickness of the wall, but then it will not meet your criterion of "he have to see all room". But as JCP says "a flashlight does not have infinite range".

 

Maybe there is someway of detecting the closest wall in the direction the flashlight is pointing and adjusting the range dynamically - but that is above my scripting grade ;-)

 

cheers, gryff :)

Link to comment
Share on other sites

 

 

Maybe there is someway of detecting the closest wall in the direction the flashlight is pointing and adjusting the range dynamically 

 

it's sounds like option, but partly - for example, character staying in the corner of the room and look at opposite corner in this case closest wall will be closest then that corner and range will be not enough.. and also I don't know how exactly I can calculate that range, cause all that splashes on the floor, but it's ok :)

 

 

 

maybe somebody else can figure out what's wrong with the shadow generator

 

I wrote above about shadows, it's works only for directional light which are not suitable for me

 

Maybe someone have another decision in this situation instead use light? .. I start thinking about just hide all object which are not line of sight, but I think it will not be a beautiful solution..

Link to comment
Share on other sites

for example, character staying in the corner of the room and look at opposite corner in this case closest wall will be closest then that corner and range will be not enough

 

That is why I said "in the direction the light is pointing" - not just the closest wall.

 

cheers, gryff :)

Link to comment
Share on other sites

 

 

That is why I said "in the direction the light is pointing" - not just the closest wall.

 

if we will take closest in direction, then also we will have extra highlighted spaces behind walls:

 

Ikgmrxh.jpg

in a word I wanna achieve effect similar to this: http://ncase.me/sight-and-light/ but in 3d and in best way object in darkness should not rendered.. little bit later I will try this method, but afraid it can be very hurt for fps.. and mb not so beautiful..

Link to comment
Share on other sites

Wingnut is on the right path... you have to use a per-pixel light source and shadows to keep the light from spilling over. This may be a limitation of Babylon currently.

 

With that though the shadow would nullify the additional light. My other question would be how are you seeing the light on the other side of the wall. In most cases It shouldn't be in the visible frame anyway if we're talking about a wall blocking it.

Link to comment
Share on other sites

Sure, but you could still have a ceiling. Most of the time the camera uses the ceiling as the height limit in 3rd person games. You usually don't clip through walls.

 

Only other way to solve this if you really want to not have ceilings, then you'll need a shadow.

Link to comment
Share on other sites

Other idea:

 

Using shadows and directional lights but use the wonderful light.excludedMeshes feature :)

 

You can play with this array to add a list of meshes you do not want to be lighted by the light. Sounds like a good way to solve your issue

 

Yeah, thanks, that's sounds great)

 

here is little example of this idea(with hardcoded elements):

http://www.babylonjs.com/playground/#22SCRP

I have artifacts with too clear boundary between light and dark on off elements, but I will play with it and mb it's no so big problem for me, guess I will add second light with shadows etc.. only believe it's will be hard calculate these elements for moving character)

Link to comment
Share on other sites

I finally found some time for trying it and have some troubles, here is example: http://jsfiddle.net/3nDPd/

As you can see walls getting is ok, but ground not.. my rays lie in one plane with ground, so why they don't intersects? I tried send them with little angle in y, but that not particularly helped(

Any solution how can I get ground blocks before walls?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...