Get light levels from a position

I thought I’d bump this topic after recently coming across it in my game development. It’s been a few years, so here’s a formal feature request with some previous replies considered:

Feature Request
As a Roblox developer, it is currently too hard to check light levels and color at a given position.

The only way to do this currently is through estimates, such as what @Maximum_ADHD’s 2015 module (as mentioned in the original post) does. This module checks the hue of light at a given position using cone math and raycasting. This is useful, but the module still has issues and an API method would be a large improvement.

Module Issues
  1. The module is outdated. It was created before FIB implementations, which means it doesn’t work as well with non-legacy lighting (especially shadows).

  2. It’s not as efficient as an internal API method could be. It has to iterate through the entire workspace to find point lights and calculate them. (Restatement from OP)

  3. Like @Defaultio said in the original post, it’s not very accurate. Here are three GIFs that show speific issues with the module, the cube represents the position input into the module and the bar at the bottom represents the result returned by the module:
    e3830bef0f80a82cb3280fcb13d18e05
    ad602f78240c298094bf03bbd5151db4
    916fa989dbcebdd28adc2e9a011776a4
    I believe the first two may be solvable with adjustments to the cone math & color lerping, however it still wouldn’t be as accurate as it could be. I can’t think of an accurate solution to the third shadow issue.

Methods:
Methods such as the proposed below could return info about lighting at a position, and could be easily accessible under a service such as Lighting.

Methods

A method to return the color at a position, returns a Color3.

game:GetService("Lighting"):GetLightHue(Vector3.new())

A method to return the brightness at a position, returns a number between 0 and 1.

game:GetService("Lighting"):GetLightValue(Vector3.new())

Or, the two methods compiled into one, returns a Color3 with both hue and brightness/value:

game:GetService("Lighting"):GetLightColor(Vector3.new())

It’d also be useful to know if the light is affected and/or produced by an artificial source instead of ambient lighting, but I can’t think of a method to do so. Maybe as a second value returned by the above methods?

Why is this useful?

@EchoReaper compiled a list of useful situations in post #4,

  • Having a light turn on when it becomes dark
  • Studio camera light that turns on when you’re in dark caves so you can see what you’re working with
  • Monster night vision that enables when it gets dark
  • Street lamps that come on when the area around them is dark
  • HUD that lights up in the dark (like your car’s dash when your lights turn on when it’s dark)
  • Vampire (or any other monster) damaged by sunlight
  • Spawn monsters in dark places
  • Detect how much a plant should grow based on its light level
  • Magic spells (light & dark) which require there to be a certain light level to cast

Issues
@zeuxcg responded in 2016 (in post #7) that this API could be problematic in the future due to planned implementation of GPU-only lighting calculation. Is there any chance has this changed since the release of shadowmap and FIB?

Any solutions/feedback/uses are all appreciated!

2 Likes

This topic was automatically closed after 1 minute. New replies are no longer allowed.

A post was merged into an existing topic: Get ambient light level at any point