Light detection OUT!

▄▀█ █▄░█ █▄░█ █▀█ █▄░█ █▀▀ █▀▄▀█ █▀▀ █▄░█ ▀█▀
█▀█ █░▀█ █░▀█ █▄█ █░▀█ █▄▄ █░▀░█ ██▄ █░▀█ ░█░

𝗜 𝗺𝗮𝗱𝗲 𝗮 𝗻𝗲𝘄 𝗺𝗼𝗱𝘂𝗹𝗲 𝘄𝗵𝗶𝗰𝗵 𝗶𝘀 𝘄𝗮𝘆 𝗺𝗼𝗿𝗲 𝗼𝗽𝘁𝗶𝗺𝗶𝘇𝗲𝗱 𝗮𝗻𝗱 𝗮𝗰𝗰𝘂𝗿𝗮𝘁𝗲 𝘀𝗼 𝗽𝗹𝗲𝗮𝘀𝗲 𝗴𝗼 𝗮𝗻𝗱 𝘂𝘀𝗲 𝘁𝗵𝗲 𝗻𝗲𝘄 𝗼𝗻𝗲, 𝗔𝗳𝘁𝗲𝗿 𝗮 𝘄𝗲𝗲𝗸 (𝟴.𝟲.𝟮𝟮) 𝗶 𝘄𝗶𝗹𝗹 𝗿𝗲𝗺𝗼𝘃𝗲 𝘁𝗵𝗲 𝗼𝗹𝗱 𝗼𝗻𝗲 𝗳𝗿𝗼𝗺 𝘁𝗵𝗲 toolbox

Link to new one Light detection revamp - Optimized and more accurate


Hello developers!!!

Last time I posted I’ve showed u my Light detection script (which was at alpha).
I’ve worked on it a bit more and I’ve made it into model

Showcase
https://i.gyazo.com/efb1cc025b9361fa4c66300cf223acda.mp4
https://i.gyazo.com/f6660d80f8371b5434d0b93c0c9f16c2.mp4
https://i.gyazo.com/9f3cbf3fcba7e9de514947458c05d5c1.mp4

How does it work?
Very simple!!
1.First u chose Server or local script

2.Require the Module Script
image

3.Call the function CheckLight from the model
image
to call it u need Basepart and boolValue
The Basepart is the part that u want to check if its in light
The boolValue is true or false and it FIlters a model if the base part is in one (if true it wont count it as invisible) – NOT REQUIRED

4.Return the function

Can I edit it?
Yes of course!
but u need basic understanding of (magnitude,Camera:GetPartsObscuringTarget and some math)

Where can i get it?
Here is the link for the module
NEW VERSION CHECK DESC FOR MORE INFO

Old ver

and here is the Test place

LightDetectionModules.rbxl (30.5 KB)

I will still update it a bit more since there are some bugs, but it wont have any big updates

75 Likes

I’m a bit curious, how do you know what is on a shadow or not? This seems pretty good.

1 Like

xdd im still curious how does it work and there arent any errors

2 Likes

What…? Is this somebody else’s system?

1 Like

No its all mine im just curious how i made it without any errors
normally my stuff are always broken

1 Like

He is probably doing a trick I learned from working with gpu coding. Basically we can represent “brightness” in a sense by treating it as a vector, where say we have a direction of our light and the brightness is the length of that vector. We can then compare the angles of those vectors (1 being the source of lights vector and the other being the “normal” of the face Graphing Calculator) and then from there seeing if the angle is some value, say 180 degrees (pitch black)

8 Likes

i do use vectors but no i dont do that
(which is good idea but the math is gona kill me)

It’s really simple man all you are doing is just checking their angle difference. Watch I know its swift code but it really gives a good explanation (this is where I learned it from)

6 Likes

i do check angle difference with the Surface and Spot light but i dont think its the same

but i will check that out thanks

Do you mean like just comparing its dot product to the other? Like in a sense transposing its “range” to the radian range of the dot product of them and seeing if its less than?

2 Likes

ok yea thats simple explained .I didnt understand it first time since I’m kind of dead brain but i do exactly that

1 Like

Very good! I’ll use it one day for something that I had in mind. Thanks for making it open-source, and sharing it with everybody. :smiley:

2 Likes

No problem i wasnt thinking of doing anything with it .I just saw people struggle with it so i made it

1 Like

Looks like this uses Cameras instead of rays. Unorthodox, but it works.

One critique is that there could be a memory leak if you call the CheckLight function on too many objects. You might consider having a single Heartbeat function that goes through a queue. Also, you probably don’t need to make a new SunPart for every object that you’re checking.

Apart from that, this is cool.
Still, I’d probably opt to use something shorter / more efficient.

oh thanks im gona fix it right now

How exactly does this work? I’m very curious.

Well first at all I get all the lights in workspace and put them in a tabel after that

I put a camera in the part that I want to check if it’s in light. Then I roll through the tabel with the lights and check the magnitude between them. If the light range is bigger than the magnitude then it check if there are parts on the way of the light to the part.For that I use camera and get the obstacles in the camera direction
. If there aren’t any then I return it true for point light only. For the other 2 lights I do the same thing but j also check the angle of the part and the light if its in this angle I return true. For the sun I make position which follows the sun and I detect if there is something in the way of the camera again. If the lights are set to cast shadow only then they just check the magnitude and the angle for the surface light and the other one (forgot the name).

(If there are mistakes sorry I’m on mobile)

Good Job! I didin’t even realised that this is a thing

Neat! I have a question for the third gif.
Is it possible to make something for the character to have, and when he has it, the light doesn’t detect him?

This is a super clever use of Camera:GetPartsObscuringTarget! :smile:
Very neat!

For anyone wanting an explanation, what this basically does is orient a camera at the source of each light, and then it checks if there is anything blocking that light from the target object. You could achieve the same effect with regular ray casts as these are what are used internally by GetPartsObscuringTarget afaik, but, this is a super clever way to go about it.

A simplified explanation is to think about what you see (what a camera sees). You are pretty much seeing any beams of light that enter your eyes, or enter the camera. So, if you do the opposite, and imagine your camera is the light source (imagine the beams of light travelling backwards), you can decide what things can “see” the camera (which is acting as the light source).

8 Likes