Light goes through walls/models

In my game, I have a spotlight attached to the gun in the bottom right hand corner of the camera which faces the direction of the camera. This spotlight, seems to go through walls. I know this is just the way the spotlight shader works, cast a cone and shade pixels contatined in the cone, but is it possible to make it not go through walls? I thought of casting a ray in the update and make the spotlight only last until the closest collision but that would be very CPU intensive, any ideas would be greatly appreciated.



You’ll have to use a shadow Processor, look at BasicShadowRenderer.

I’ve had a look and it seems to me that it uses a set direction and that the shadow is only set for those directions, I also had a look at the PssmShadowRenderer which gave me the same results

yes, set the same direction as the light

in your update loop do shadowRenderer.setDirection(light.getDirection());

Im no expert but wont that be extremely heavy on the CPU?

It won’t…just 3 floats assignment…it can handle it…

But what about the constant shadow mapping??? I dont know, Im not a dev :stuck_out_tongue:

I tried what you suggested although the light still shines through walls, the shadows only made the game look weird. So the shadow renderer doesnt work. Any other ideas?

ironeye42 said:
But what about the constant shadow mapping??? I dont know, Im not a dev :P

oh sorry i thought you were talking about the direction assignment.
It's more heavy than not casting shadows for sure.....but it cast shadows, and since it's what your looking for, i'm afraid there is no other way.

ironeye42 said:
I tried what you suggested although the light still shines through walls, the shadows only made the game look weird. So the shadow renderer doesnt work. Any other ideas?

What's weird....could you elaborate...maybe a screen shot?

By weird I just meant not what I wanted, it looks like I have the sun attached to my head but nothing out of the norm. Still I have been unable to find a fix for this. So again suggestions would be great.

I have no more suggestion than casting shadows…

What you suggested in the first post is incorrect, and would look wrong on the floor for example…

THE way to do this is to cast shadows. Now there might be something wrong in the shadow processor that makes it work bad with the spotlight, and that’s why I want you to elaborate,or give a screenshot if you don’t like long posts, or maybe a testcase, so I could fix it.

Hey all,



I am having the same problem but from a top-down perspective. I have a spotlight coming from the PC that follows the mouse pointer. Naturally this spotlight goes through meshes as if they were glass…understandable.



I have tried using the BasicShadowRenderer as described above (setting it’s direction to the same direction the spotlight is facing) and got some strange results (my guess is that this is what happened with @ironeye42 ). It’s probably something I’ve done wrong here, my setup is as follows:



rootNode shadowmode: Off

|_walls shadowmode: CastAndReceive

|_floors shadowmode: Receive



Is this right??



In the video below, you can see that to start with the problem of the light passing through walls still exists. Also there are weird moments where everything gets lighter, now I believe this is a problem with my mouse picking (as it happens when we mouse over the top of the walls) when getting a direction to face, but it’s still strange.



The other issue is that when I move the mouse around on the floor (so as to ignore the mouse picking issues above), the shadows still look strange. For example at 15 seconds in when I pan the view round above the character, the corridor behind him to the right lights up.



Also I cannot use the Pssm shadows as my laptop can’t handle any clever buffering, but that’s another issue entirely :S.



http://www.youtube.com/watch?v=sBhpERf4HKA

I think that with the shadow processor, since it isn’t a positional light or anything with stuff like spotlights and pointlights, if they are in an enclosed boundary the shadows are only global, if you get what I mean?

I’m not sure I do understand sorry. I’ve never really looked at shadows before this case to be honest.

Currently the shadow filters only support directional lights. Adding support for point/spot lights is planned in the future

Oh right ok, thanks for the help :). Do you know what sort of timeline we’re talking, or should I try and find another way?

No idea. I can only say it won’t be before the beta release.