Is there any way to get the brightness value at a position?

  1. What do you want to achieve?
    I want to have my ViewportFrame affected by the brightness of the area that the player is in. My lighting setup is that I have a higher outdoor ambient than background ambient, as well as the player has a faint light that activates as they descend farther. The calculation for outdoor ambient is the one I would want to match more accurately, and ideally without spamming raycasts. The reason I want to have the belt be SurfaceGui is to have more custom control of its position and orientation, and not have to worry about it clipping through objects

  2. What is the issue?
    Here is the image showing the issue with clashing brightness. I would like this to feel less out of place:

  3. What solutions have you tried so far?
    I’ve looked into the API for Terrain, Lighting, Workspace, and Camera for functions that let me get back a brightness value, and I wasn’t able to find any. With the way voxel lighting handles brightness, as well as Roblox detecting outdoor/not, I would think that there should be an exposed function where I can pass a Vector3 as a parameter to get accurate lighting data, but I just can’t find it.

3 Likes

Nope.

Wanted to make a Thief type stealth game a few years back and it wasn’t a thing back then. AFAIK there’s nothing new on that front and there’s nothing on the roadmap Roblox Platform High-Level Roadmap

1 Like

As far as I am aware of, this is not possible at the moment. However, there’s some workaround that you could use to achieve similar effect, for example, turning the brightness down when the part is in contact with any light from the sun: Touching areas that would be in contact with the sun's light - #17 by TaaRt

2 Likes

one way you can kinda do it is

lets say your using PointLights

https://developer.roblox.com/en-us/api-reference/class/PointLight

you would loop all pointlights position
and then check the magnitude to the position you want to know the brightness to

if you want to check for shadows you would also raycast

while this might not be 100% the correct brightness value it should be good enough

i have not tested this code

local target = mouse.Hit.Position
local totalBrightness = 0

for i, pointLight in ipairs(game.Workspace.Lights) do
    local position = pointLight.Parent.Position
    local direction = target - position

    local brightness = 1 - direction.Magnitude / pointLight.Range

    -- if the point light is out of range skip this light
    if brightness <= 0 then
        continue
    end

    -- if the point light has shadows lets make sure the target is not under a shadow
    if pointLight.Shadows == true then
        -- you might not need to do this but maybe we should reduce the direction by a small amount to make sure it does not hit the mouse.target
        direction = direction.Unit * (direction.Magnitude - 1) -- remove this line if you dont need it

        -- raycast from the light to the target
        local raycastResult = workspace:Raycast(position, direction)

        if raycastResult ~= nil then
            -- the ray hit something this position is in shadow to the light so lets skip it
            continue
        end
    end

    -- add this lights brightness to the totalBrightness
    totalBrightness += brightness * pointLight.Brightness
end

-- print the brightness of the target position
print(totalBrightness)
1 Like

The guy above who made a code is going in the right direction, but what if you have surface light sources for example? So that’s why the code above might be too hard to implement. What I can suggest is to build regions and whenever a player touches, do stuff. Probably the best you can do here