naitro Posted July 16, 2014 Share Posted July 16, 2014 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.. Quote Link to comment Share on other sites More sharing options...
gryff Posted July 16, 2014 Share Posted July 16, 2014 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 Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted July 16, 2014 Share Posted July 16, 2014 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. Quote Link to comment Share on other sites More sharing options...
naitro Posted July 17, 2014 Author Share Posted July 17, 2014 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? Quote Link to comment Share on other sites More sharing options...
Wingnut Posted July 17, 2014 Share Posted July 17, 2014 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-ShadowsPlayground Shadows demo - http://www.babylonjs.com/playground/?15 Quote Link to comment Share on other sites More sharing options...
gryff Posted July 17, 2014 Share Posted July 17, 2014 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 naitro 1 Quote Link to comment Share on other sites More sharing options...
Temechon Posted July 17, 2014 Share Posted July 17, 2014 Hey Wingy, look what I found in the wiki Only directional lights can cast shadows We are using a spotlight here, so no shadows. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
naitro Posted July 17, 2014 Author Share Posted July 17, 2014 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.. Quote Link to comment Share on other sites More sharing options...
gryff Posted July 17, 2014 Share Posted July 17, 2014 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 Quote Link to comment Share on other sites More sharing options...
naitro Posted July 17, 2014 Author Share Posted July 17, 2014 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: 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.. Quote Link to comment Share on other sites More sharing options...
reddozen Posted July 17, 2014 Share Posted July 17, 2014 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. Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted July 17, 2014 Share Posted July 17, 2014 reddozen, Way at the beginning he said it was a third person "camera in the sky", which is why the problem would be in the frame. Quote Link to comment Share on other sites More sharing options...
reddozen Posted July 17, 2014 Share Posted July 17, 2014 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. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 17, 2014 Share Posted July 17, 2014 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 naitro and Temechon 2 Quote Link to comment Share on other sites More sharing options...
Temechon Posted July 17, 2014 Share Posted July 17, 2014 But the directional light cannot act like a flashlight, am i right ? The light comes from an infinite distance, not like a flashlight. Quote Link to comment Share on other sites More sharing options...
naitro Posted July 18, 2014 Author Share Posted July 18, 2014 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/#22SCRPI 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) Quote Link to comment Share on other sites More sharing options...
naitro Posted July 25, 2014 Author Share Posted July 25, 2014 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? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 25, 2014 Share Posted July 25, 2014 Your rays are perfectly parallel with the ground so they cannot intersect Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.