Greetings!
I’m trying to create Global Illumination with the follow code and I need help on reflecting the rays when hit and stopping once they reach the max bounce limit!
local config = {};
config.MaxBounce = 5;
for i,v in pairs(workspace:GetDescendants()) do
if v:IsA("Light") then
local part = v.Parent;
local orig = part.Position;
local dir = part.CFrame.LookVector*5000;
local ray = Ray.new(orig, dir);
local hitPart, hitPosition = workspace:FindPartOnRay(ray)
if hitPart then
local p = Instance.new('Part')
p.Transparency = 1
p.CastShadow = false
p.CanCollide = false
p.Anchored = true
p.Position = hitPosition
p.CFrame = CFrame.new(hitPosition, part.Position)
local x = Instance.new('SpotLight')
x.Parent = p
p.Parent = workspace.GI
else
print('no hit')
end
end
end
Thanks!