Will it be possible to measure the brightness in S&Box?

Hello, I recently wondered whether it is possible to measure the brightness in S&Box?
With such a function you could e.g. create addon like Minecraft monsters or stuff like that, what does also spawn only in dark areas, as soon as the brightness falls below a certain level in certain areas.
The tool with which you can measure this in C# should have to take into account the prefabricated lights of the map and individually placed lights that can be placed from players.

Personally, I would want to use this function to: program the Keter class: “SCP-835-JP”. This SCP would teleport from shadow to shadow and would try to stab the player as soon as he moves careless into darker areas…

1 Like

You could calculate it based off the distance to the nearest light source entity.
Shouldn’t be too hard

you can make lights brighter and darker and put the radius small or large. it should work with the from players placed realtime lights and with the baked lights from the map.
I would therefore like to have a function with which one can measure the current brightness at a point in the room in order to e.g. To tell an NPC that he can walk there or whether he should stay away from it because the light there is still too bright.

But there is probably no other way how to do it. I think shaders can get the light intensity or whatever, but that’s run completely seperately from the scripting environment (it is run on the GPU), so you can’t really use that.

The easiest way is to do what I described, you just need some math to make it work. Check the Unity forums for example - there is a lot of content on that.

What I was getting at was whether Facepunch could not incorporate such a function because it would also be an advantage for many workshop creators, e.g. To make realistic Minecraft monsters that burn as soon as it’s too bright or something.

Yeah not a bad idea, to be able to sample the average lighting at any point. Just querying the surrounding lights should be enough for what you want to do too

8 Likes

This sounds like a pretty helpful thing to have for mappers too, for lighting consistency, debugging, etc.

3 Likes

Would be a nice feature.

Worst things worst, you can pair a raycast and a distance check and that’ll work too.

How is that supposed to work with the Enviromentlight because it illuminates everything on the surface with light?
The NPC is supposed to stay and walk only in the dark areas on every map.
And it should disappear when a player lights up his surroundings because the NPC should avoids the light.

Really there is no way to do this effectively. You can manually specify dark areas but really in this case you should not really be working with an environment light anyway. At least not a bright one. I mean I feel like that would destroy most if not all of your ability for the AI to move anyway

I don’t know if this is still the case in source2 but I know that in Source the navmesh stored light intensity. If that’s still the case you could probably make use of it.

1 Like

A raycast would work mostly.

The hardest thing to account for is inditect lighting (like sunlight reflected from a white wall into a dark room), it’s usually baked and I dunno if there are lighting voxels or something in source 2 to get this information from

That would make no sence if the NPC ignores the sun but fears the light.

It would make no sense to place your AI in a bright environment as your AI would significantly try and avoid it.

Things spawn where you look and if you look in a bright environment, I can make the AI not spawn until you look into a dark area, or the AI spawns somewhere on the map in a dark environment. But if the map doesn’t have a single dark spot, an error message would appear on the screen that the AI has not found a dark place to spawn.

However, I would have to deal more closely with the technical possibilities, which in my current state is not possible without access to the game to test the AI and above all without source code information because the official wiki page is still not yet accessible …

1 Like

Look at what Layla added:

  • Add LightQuery.GetLightForPoint (calculates light at a single point)

However I’m not sure if this includes dynamic lights.

If you consider that players often expand their worlds with lamps and lights (with the toolgun), real-time lighting should hopefully also be included. otherwise it would be nothing half and nothing whole …

Good idea using light source distance, but also you need to take account environmental lightning too!

Though, I believe if the engine needs to calculate lightning, maybe isn’t that hard to detect brightness.

I think this would be very hard if even impossible, if there are no sourcecode fuctions from facepunch or Valve to read it out. And I think valve did not make a fuction because they did’nt needed it for Half Life Alyx.