Does this work by generating a shadow mesh every frame? How much of a performance hit would you say it causes?
Is it possible to have multiple “light sources”?
Is it possible (or automatic) to clip shadows? (Say I’m in a small circular room instead of a square one. Will the shadows spill over?)
Thanks for the comment
I understand for students and some indie developers it’s a bit too costly and unnecessary to have a Pro license, and especially I’m among them. So I always like plugins that work with Free version.
For the open source decision, I believe it may benefit me more than tagging a price for it. It’s a good way to improve the quality of the plugin, and also a good self introduction to the industry
It works by generating mesh when necessary. By “necessary”, I mean if the scene within the camera is dirty, like the light moved, or the obstacle moved.
Performance wise, I would say it’s acceptable, as you can adjust the precision of the lights (by adjusting degree step). Also, you can adjust the frequency of flashes of lights. Those lights offscreen will not be drawn.
Actually there are two types of lights available. One is radial light, that is what you can observe in the radial light (underwater) demo. For this type of lights, you can have multiple lights.
The other type is full screen light. It generates the mesh in a totally different way. So you can’t have more than 1 full screen light. However, with the full screen light, you can make something like visibility area like Monaco: Whate Yours Is Mine (but cannot render things on the shadow texture, that may require unity Pro licence).
For the radial light, it won’t. It’s bounded by obstacles. For full screen light, the shadow covers every parts that cannot be seen.
That is very very clever of you! And I completely understand what you mean with the PRO license, I’ve been around Unity for 4 years now and developing, yet I think that 1500$ is way too much for me. Good job!
Question: I’m turning the functionality on and off throughout the course of the game. Imagine “lights on” or “lights off”. When the lights are “off” I’m using the LOS system.
Here’s how I’m doing it now, is this the best (or only) way?
public class LightSwitch : MonoBehaviour {
static LOSLightBase[] lights;
void Awake() {
if (lights == null)
FindLights ();
}
//Public in case I add lights and want to update all my switches, or something.
static public void FindLights() {
lights = GameObject.FindObjectsOfType<LOSLightBase> ();
}
public void Toggle() {
LOSManager.instance.enabled = !LOSManager.instance.enabled;
foreach (var light in lights) {
light.renderer.enabled = LOSManager.instance.enabled;
}
}
}
I guess I’m asking if there’s already a method for this somewhere, or if I should also disable the colliders(obstacles) or LOSevents if they have some kind of overhead that would be unnecessary with the lights “on”.
Hi, I did not consider toggling the system on off in the current version, and I should have done that. Thanks for reminding me!!!
For your implementation, there is one thing can be adjusted a bit for better performance.
FindLights: the lights currently registered can be access through LOSManager.instance.lights, which can help save the time for finding the LOSLightBase.
Toggle: actually I should add an API in the LOSLightBase for toggling a particular light, and also an API in LOSManager for toggling all the lights. So I think I’m going to implement this in the next version.
For the event system, I did not consider toggling it on off either, so I’m also going to implement that in the next version. Currently, you can simply turn off the LOSEventManager, but this will leave every LOSEventTrigger in their current state. So if you need to clean their states, you can call myEventTrigger.NotTriggered().
Again, thanks for all the questions. They help me think deeper in terms of the use case of the plugin, which I believe can make it more user friendly
Hello. I have a few questions. First of all, how do you use the light trigger to actually impart a light gradient onto a sprite that is a certain distance away from a light source.
Additionally, there’s a glitch with the program in that when another object moves an obstacle, the object without an obstacle component imparts a shadow where it was colliding the other object with a component. How did you fix this?
Hi, thanks for the questions
For the first question, the event trigger has a TriggeredBySource function with the event source that is triggering it as parameter. And the event source has a reference to the LOSLightBase that it is attaching to. So if you are using LOSRadialLight, you can safely cast the LOSLightBase to LOSRadialLight, and use the radius property as the light strength.
For the second question, I’m not very sure if I understand you question. Could you describe more? Or attach a screenshot if possible?
Hey! I have a slight problem. I made a simple map with tiled and exported it to unity with Tiled2Unity with collision (Polygon Collider 2D). I get a strange problem with a simple + symbol, see the image below.
Hi, is it the polygon collider 2d used a concave polygon? For full screen light, concave polygon collider may have some issues currently, but it works fine with radial light, as they are using different algorithms to generate the meshes.
If you need to use full screen light, you can work around it by combining polygons to replace the concave polygon.
I am not sure what that even means, but if I understood the things google showed me, then yes. I tried the radial light and it indeed worked a little better, but I guess that the small plus symbols is not liked, if they are not a Box Collider
I changed the plus into octagon and at least the radial light worked without problems, so that’s all good. To be hones, I don’t think I will be using any plus symbols in my game anyways. Thank you for your help! I took some pictures too!