eea

photograph

eea
Apr 23rd, 2022 (edited)
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.80 KB | None | 0 0
  1. wait(1)
  2. local Tool = Instance.new("Tool", owner.Backpack)
  3. Tool.Name = "Renderer"
  4. local handle = Instance.new("Part", Tool)
  5. handle.Name = "Handle"
  6. handle.Size = Vector3.new(1, 1, 1)
  7. local base = 15
  8. local height = 15
  9. local distance = 200
  10. local r_gradient = .15
  11. local size = Vector3.new(.1, .1, .01)
  12.  
  13. function Setvecmag(v, m)
  14.     return v*(m/v.Magnitude)
  15. end
  16.  
  17. function Reflect(pixel, ray, color, p, r)
  18.     if ray.Instance.Reflectance ~= 0 then
  19.         local dist = ray.Distance
  20.         local vec = (ray.Position - pixel)
  21.         local dir = vec - 2 * vec:Dot(ray.Normal) * ray.Normal
  22.         local r_ray = Raycast(ray.Position, dir.Unit*(distance-dist), p)
  23.         local r_ray_color
  24.         local r_color
  25.         if r_ray then
  26.             --local d = Instance.new("SpawnLocation", script:FindFirstChildOfClass("WorldModel"))
  27.             --d.Anchored = true
  28.             --d.Position = r_ray.Position
  29.             --d.Size = Vector3.new(1,1,1)
  30.             r_ray_color = r_ray.Instance.Color
  31.             r_color = ray.Instance.Color:Lerp(r_ray_color, ray.Instance.Reflectance)
  32.             if (r_ray.Instance.Reflectance ~= 0) then
  33.                 task.wait(.01)
  34.                 return Reflect(r_ray.Position, r_ray, r_color, p, r+1)
  35.             end
  36.             return r_ray, r_color, r
  37.         end
  38.         if r_ray == nil then
  39.             return ray, color, r
  40.         end
  41.     end
  42.     return ray, ray.Instance.Color, r
  43. end
  44.  
  45. function Shadow(ray, color, max)
  46.     max = max or 0
  47.     local sundir = game:GetService("Lighting"):GetSunDirection()
  48.     local shadowtest = Raycast(ray.Position, sundir*903249)
  49.     if shadowtest then
  50.         if not (ray.Instance == shadowtest.Instance) then
  51.             return Colormult(color, .5)
  52.         end
  53.     end
  54.     return Colormult(color, math.max(1-getVectorAngles(game:GetService("Lighting"):GetSunDirection(), ray.Normal)/math.pi, max))
  55. end
  56.  
  57. function clearRenders()
  58.     script:FindFirstChild("WorldModel"):Destroy()
  59. end
  60.  
  61. function getVectorAngles(v1, v2)
  62.     return math.acos(v1:Dot(v2)/(v1.Magnitude * v2.Magnitude))
  63. end
  64.  
  65. function Raycast(start, dir, p)
  66.     local ray = workspace:Raycast(start, dir, p)
  67.     if ray then
  68.         return ray
  69.     end
  70. end
  71.  
  72. function ColorLerp(c1, c2, t)
  73.     return c1:Lerp(c2, t)
  74. end
  75.  
  76. function Colormult(color, m)
  77.     return Color3.new(color.R*m, color.G*m, color.B*m)
  78. end
  79.  
  80. function makeBlock(x, y, parent)
  81.     local c_pixel = Instance.new("SpawnLocation", parent)
  82.     local pos = handle.CFrame:ToWorldSpace(CFrame.new(Vector3.new(x - base/2, y - 3.7, -.51)))
  83.     local params = RaycastParams.new()
  84.     params.FilterDescendantsInstances = {script}
  85.     params.FilterType = Enum.RaycastFilterType.Blacklist
  86.     local ray = Raycast(pos.Position, pos.LookVector*distance, params)
  87.     c_pixel.Size = size
  88.     c_pixel.Locked = true
  89.     c_pixel.CFrame = pos
  90.     c_pixel.Anchored = true
  91.     c_pixel.Enabled = false
  92.     if ray ~= nil then
  93.         local r_ray, r_color, reflections = Reflect(c_pixel.Position, ray, ray.Instance.Color, params, 1)
  94.         if r_ray == ray then
  95.             c_pixel.Color = Colormult(Shadow(ray, ray.Instance.Color:Lerp(Color3.new(.5, .5, 1), ray.Instance.Reflectance), .35), 1-reflections/20)
  96.             c_pixel.Material = "SmoothPlastic"
  97.         end
  98.         if r_ray ~= ray then
  99.             c_pixel.Color = Colormult(Shadow(r_ray, r_color, .35), 1-reflections/20)
  100.         end
  101.     else
  102.         c_pixel.Color = Color3.new(.5, .5, 1)
  103.         c_pixel.Material = "SmoothPlastic"
  104.     end
  105. end
  106.  
  107. function onClick()
  108.     local wmodel = Instance.new("WorldModel", script)
  109.     handle.Anchored = true
  110.     for x = 0, base, size.X do
  111.         for y = 0, height, size.Y do
  112.             local s, e = pcall(function() makeBlock(x, y, wmodel) end)
  113.             if e then
  114.                 wait(1)
  115.                 pcall(function() makeBlock(x, y, wmodel) end)
  116.             end
  117.         end
  118.         task.wait(0.05)
  119.     end
  120.     handle.Anchored = false
  121. end
  122.  
  123. Tool.Activated:Connect(onClick)
  124. owner.Chatted:Connect(function(msg)
  125.     if string.lower(msg) == "%clr" then
  126.         clearRenders()
  127.     end
  128. end)
Add Comment
Please, Sign In to add comment