Advertisement
eea

see

eea
Jul 31st, 2022 (edited)
1,525
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.02 KB | None | 0 0
  1. local remote = Instance.new("RemoteEvent", owner.Character)
  2. remote.Name = "t"
  3. local module = {}
  4.  
  5. function module:NewRender(base: number, height: number, resolution: Vector2, start: CFrame, maxdist: number, params: RaycastParams, fov: number?, handle: Part, maxr: number)
  6.     local renderinfo = {}
  7.     renderinfo[1] = base
  8.     renderinfo[2] = height
  9.     renderinfo[3] = resolution or Vector2.new(.5, .5)
  10.     renderinfo[4] = start
  11.     renderinfo[5] = maxdist or 100
  12.     renderinfo[6] = params
  13.     renderinfo[7] = {}
  14.     renderinfo[8] = math.rad(fov or 90)
  15.     renderinfo[9] = handle
  16.     renderinfo[10] = maxr or 10
  17.     return renderinfo
  18. end
  19.  
  20. function module:GetReflected(origin: Vector3, point: Vector3, normal: Vector3)
  21.     local vec = point - origin
  22.     local dir = vec - 2 * vec:Dot(normal) * normal
  23.     return dir
  24. end
  25.  
  26. function module:Shadow(ray: RaycastResult, color: Color3, p: RaycastParams, max: number, shadowdef: number)
  27.     if (ray.Instance.Transparency < 1) then
  28.         max = max or 0
  29.         local sundir = game:GetService("Lighting"):GetSunDirection()
  30.         local shadowtest = module:Raycast(ray.Position, sundir*12345678, p)
  31.         local m = math.max(1-module:GetVectorAngles(sundir, ray.Normal)/math.pi, max)
  32.         local s_color = module:C_mult(color, m)
  33.         if shadowtest ~= nil then
  34.             if shadowtest.Instance ~= ray.Instance and (shadowtest.Instance.Transparency < 1) then
  35.                 return module:C_mult(s_color, shadowdef)
  36.             end
  37.         end
  38.         return s_color, m
  39.     end
  40.     return color
  41. end
  42.  
  43. function module:GetVectorAngles(a: Vector3, b: Vector3)
  44.     return math.acos(a:Dot(b)/(a.Magnitude*b.Magnitude))
  45. end
  46.  
  47. function module:ReflectRay(render, pixel: Vector3, ray: RaycastResult, color: Color3, r: number, s)
  48.     if ray.Instance.Reflectance ~= 0 and r < render[10] then
  49.         local dir = module:GetReflected(pixel, ray.Position, ray.Normal)
  50.         local r_ray = module:Raycast(ray.Position, dir.Unit*render[5], render[6])
  51.         if r_ray ~= nil then
  52.             local t_color = r_ray.Instance.Color:Lerp(color, 1-ray.Instance.Reflectance)
  53.             if r_ray.Instance.Reflectance ~= 0 then
  54.                 task.wait(.01)
  55.                 return module:ReflectRay(render, ray.Position, r_ray, t_color, r+1, s)
  56.             end
  57.             return r_ray, t_color, r+1
  58.         end
  59.         if r_ray == nil then
  60.             return ray, s, r+1
  61.         end
  62.     end
  63.     return ray, color, r
  64. end
  65.  
  66. function makePart(a, p, s, pa)
  67.     local par
  68.     local s, e = pcall(function()
  69.         par = Instance.new("Part", pa)
  70.         par.Anchored = a
  71.         par.Position = p
  72.         par.Size = s
  73.     end)
  74.     if e then
  75.         if par ~= nil then
  76.             par:Destroy()
  77.             par = nil
  78.         end
  79.         task.wait(2)
  80.         return trymakePart(a, p, s, pa)
  81.     end
  82.    
  83.     if (not e) and (par ~= nil) then
  84.         return par
  85.     end
  86. end
  87.  
  88. function module:Raycast(start: Vector3, dir: Vector3, p: RaycastParams)
  89.     return workspace:Raycast(start, dir, p or nil)
  90. end
  91.  
  92. function module:C_mult(color: Color3, scalar: number)
  93.     return Color3.new(color.R*scalar, color.G*scalar, color.B*scalar)
  94. end
  95.  
  96. function module:C_mult2(color: Color3, color2: Color3)
  97.     return Color3.new(color.R*color2.R, color.B*color2.B, color.G*color2.G)
  98. end
  99.  
  100. function lerp(min, max, t)
  101.     return (max-min)*t + min
  102. end
  103.  
  104. function module:Render(render)
  105.     local xit = math.floor(render[1] / render[3].X)
  106.     local yit = math.floor(render[2] / render[3].Y)
  107.     local seed = math.random()*1000000
  108.     local sky = Color3.new(0, 0.6, 1)
  109.     local max_r = render[10]
  110.     local stc = render[9]
  111.     for x = 0,xit do
  112.         render[7][x] = {}
  113.         for y = 0, yit do
  114.             local fov = render[8]
  115.             local left = CFrame.Angles(0, fov/2, 0)
  116.             local right = CFrame.Angles(0, -fov/2, 0)
  117.             local bottom = CFrame.Angles(-fov/2, 0, 0)
  118.             local top = CFrame.Angles(fov/2, 0, 0)
  119.             local forward = Vector3.new(0, 0, -1)
  120.             local xpos = lerp(left.LookVector, right.LookVector, x/xit)
  121.             local ypos = lerp(top.LookVector, bottom.LookVector, y/yit)
  122.             local dir = CFrame.new(xpos.X, ypos.Y, -1).LookVector
  123.           --makePart(true, (stc * relpos).Position, Vector3.new(.01, .01, .01), workspace)
  124.             local ray = module:Raycast(stc.Position, dir, render[6])
  125.             local clouds = math.clamp((math.noise(x*render[3].X/7+seed, y*render[3].Y/7+seed)+.5)^2, 0, 1)
  126.             local sky_c = sky:Lerp(Color3.new(1,1,1), clouds)
  127.           --task.wait(.2)
  128.           --print(math.deg(module:GetVectorAngles(xpos, forward)))
  129.            
  130.             if ray ~= nil then
  131.                 local r_ray, r_color, r = module:ReflectRay(render, stc.Position, ray, ray.Instance.Color, 0, sky_c)
  132.                 local r_ray_shadow, m = module:Shadow(r_ray, r_color, render[6], .3, .5)
  133.                 --makePart(true, r_ray.Position, Vector3.new(render[3].X, render[3].Y, 0.01), script)
  134.                
  135.                 if (r_ray == ray) then
  136.                     render[7][x][y] = r_ray_shadow:Lerp(Color3.new(), math.clamp(r/max_r, 0, 1))
  137.                 end
  138.  
  139.                 if r_color == sky then
  140.                     render[7][x][y] = sky_c:Lerp(Color3.new(), math.clamp(r/max_r, 0, 1))
  141.                 end
  142.                
  143.                 if r_ray ~= ray then
  144.                     if m then
  145.                        render[7][x][y] = module:C_mult(r_ray_shadow:Lerp(Color3.new(), math.clamp(r/max_r, 0, 1)), m)
  146.                     else
  147.                        render[7][x][y] = r_ray_shadow:Lerp(Color3.new(), math.clamp(r/max_r, 0, 1))
  148.                     end
  149.                     --local pos = Instance.new("SpawnLocation", workspace)
  150.                     --pos.Position = r_ray.Position
  151.                     --pos.Anchored = true
  152.                 end
  153.             else
  154.                 render[7][x][y] = sky_c
  155.             end
  156.         end
  157.         if x % 20 == 0 then
  158.             task.wait()
  159.         end
  160.     end
  161. end
  162. ---------------------------------------------------------------------------------------------------
  163. NLS([[
  164. local fps = 2
  165. local f = 0
  166. while task.wait(1/fps) do
  167.     local cc = workspace.CurrentCamera
  168.     script.Parent.t:FireServer({cc.CFrame, cc.ViewportSize, cc.FieldOfView, f})
  169.     f = f + 1
  170. end
  171. ]], owner.Character)
  172.  
  173. local sg = Instance.new("ScreenGui", owner.PlayerGui)
  174. sg.DisplayOrder = -1
  175. sg.IgnoreGuiInset = true
  176. local fin
  177. remote.OnServerEvent:Connect(function(player, cam)
  178.     local xsize = cam[2].X
  179.     local ysize = cam[2].Y
  180.     local size = Vector2.new(38, 38)
  181.     local rm = module
  182.  
  183.     function printmatrix(m)
  184.         print("rows: "..#m)
  185.         print("cols: "..#m[1])
  186.         for x = 1,#m do
  187.             local str = "{"
  188.             for y = 1,#m[x] do
  189.                 str = str..tostring(m[x][y])..","
  190.             end
  191.             str = string.sub(str, 1, #str-1)
  192.             str = str.."}"
  193.             print(x, str)
  194.         end
  195.     end
  196.     if cam[4] == 0 and fin == nil then
  197.         local star = rm:NewRender(xsize, ysize, size, false, 1000, false, cam[3], cam[1], 5)
  198.         rm:Render(star)
  199.  
  200.         for x = 1,#star[7]+1 do
  201.             for y = 1,#star[7][x-1]+1 do
  202.                 local nf = Instance.new('Frame', sg)
  203.                 nf.Size = UDim2.new(0, size.X, 0, size.Y)
  204.                 nf.Position = UDim2.new(0, (x-1) * size.X, 0, (y-1) * size.Y)
  205.                 nf.BackgroundColor3 = star[7][x-1][y-1]
  206.                 nf.BorderSizePixel = 0
  207.                 nf.Name = tostring(x)..tostring(x+y)..tostring(y)
  208.             end
  209.         end
  210.         fin = true
  211.     end
  212.     if cam[4] ~= 0 and fin == true then
  213.         local newr = rm:NewRender(xsize, ysize, size, false, 1000, false, cam[3], cam[1], 5)
  214.         rm:Render(newr)
  215.         for x = 1,#newr[7]+1 do
  216.             for y = 1,#newr[7][x-1]+1 do
  217.                 local c_f = sg:FindFirstChild(tostring(x)..tostring(x+y)..tostring(y))
  218.                 c_f.BackgroundColor3 = newr[7][x-1][y-1]
  219.             end
  220.         end
  221.     end
  222. end)
  223.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement