Line of sight effect

Hey,
what would be the suggested way to implement line of sight effect?

I’ve got top-down view of 3D location and PC character within it, I would like to blacken the areas that area not visible from the point of view.

Something like that:
image

To approximate this I’ve tried using PointLight above the head of characater and casting shadows from such a light source.

The effects are really strange:

Is there an easy way to do that effect ?
I’m pretty sure the solution would be hard shadow cast without lighting the stuff with light that produces it. Question is can it be done easily?

1 Like

Using a point light and a shadow generator should work:

https://playground.babylonjs.com/#1Z71FW#139

Yes, but the light itself shines over the surface, what is needed is something that only blackens the area with shadow but does not brighten the visible area.

you can remove some of it by setting specular to 0,0,0 and reducing intensity
https://playground.babylonjs.com/#1Z71FW#144
i don’t know if you can get rid of all the “shine” with this method

You can use some custom code to achieve what you want to do:

https://playground.babylonjs.com/#1Z71FW#145

It works by computing a global shadow value: if this value is strictly less than 1, it means the pixel is at least partly in shadow and so will be displayed full black. You can change this color in line 49 if you want something a bit smoother.

Note that I have set the intensity of the point light to 0.

2 Likes

Hey it works fine but not for 4.2.

Out of curiosity:
Is there something, some shader include that would allow me to handle shadows for custom shader material (shadow receving not casting) quickly?

I mean i want to write my own shadow receiving material, reusing as much from StandardMaterial as possible.

It does work for me in 4.2 in the Playground.

You can use the CustomMaterial material if you want to extend the standard material with custom code, as I did in the PG. You can also use a node material created in the NME.

Another possibility is to simply use a ShadowDepthWrapper with any material you write: Custom shadows with ShadowDepthWrapper

That’s strange I’ve got 4.2 on my server straight from github repo and BABYLON.CustomMaterial is undefined.

To my understanding the whole ShadowDepthWrapper thing works for defining how shadows are casted, if you have a custom material.
Not in case when you want to have shadow received on a custom one.
I’ll recheck the things with the custom material

CustomMaterial is found in the materials library, it is not part of the core engine.

1 Like