Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- @ CloneTrooper1019, 2019
- local Players = game:GetService("Players")
- local Lighting = game:GetService("Lighting")
- local RunService = game:GetService("RunService")
- local player = Players.LocalPlayer
- local up = Vector3.new(0, 1, 0)
- local function getBrightness(color)
- local h, s, v = Color3.toHSV(color)
- return v
- end
- local function computeOcclusion(origin, dir)
- local occlusion = 0
- local ray = Ray.new(origin, dir.Unit * 5000)
- local ignoreList = {player.Character}
- while occlusion < 1 do
- local hit = workspace:FindPartOnRayWithIgnoreList(ray, ignoreList, false, true)
- if not hit then
- break
- end
- if hit.Transparency < 0.95 and hit.CastShadow then
- local opacity = math.clamp(1 - hit.Transparency, 0, 1)
- local blockDepth = (hit.Size.Magnitude * opacity) / 20
- occlusion = math.min(1, occlusion + blockDepth)
- end
- table.insert(ignoreList, hit)
- end
- return occlusion
- end
- local function update(deltaTime)
- local camera = workspace.CurrentCamera
- if not camera then
- return
- end
- local origin = camera.CFrame.Position
- local sunDir = Lighting:GetSunDirection()
- local dayLight = math.clamp(sunDir.Y * 10, -0.5, 1)
- if dayLight < 0 then
- sunDir = Lighting:GetMoonDirection()
- end
- local indoorLevel = computeOcclusion(origin, up)
- local sunOcclusion = computeOcclusion(origin, sunDir)
- local indoorLight = getBrightness(Lighting.Ambient)
- local outdoorLight = getBrightness(Lighting.OutdoorAmbient)
- local strength = 1 - (outdoorLight + ((indoorLight - outdoorLight) * indoorLevel))
- local target = sunOcclusion * strength * dayLight * 3
- local current = Lighting.ExposureCompensation
- if (current < target) then
- current = math.min(target, current + deltaTime)
- elseif (current > target) then
- current = math.max(target, current - (deltaTime * 2))
- end
- Lighting.ExposureCompensation = current
- end
- RunService:BindToRenderStep("AutoExposure", 201, update)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement