Light detection OUT!

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

2 Likes

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:

1 Like

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

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

The detector is fine but the Output is very annoying…

1 Like

Oh uh I did recently an update and didn’t test it out my bad

(Also that seems like a typo in your script)

2 Likes

i maded a modification
i deleted the configuration function and added a simply table for better custom
i changed .DetectLight() for :DetectLight()
i added a color misc. when detect light of a color the color misc changes to that color. if theres much light colors then misc all the colors and returns a misc color. if a light is brighter then the result is an approximation
of that color

my version

3 Likes