Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local remote = Instance.new("RemoteEvent", owner.Character)
- remote.Name = "t"
- local module = {}
- function module:NewRender(base: number, height: number, resolution: Vector2, start: CFrame, maxdist: number, params: RaycastParams, fov: number?, handle: Part, maxr: number)
- local renderinfo = {}
- renderinfo[1] = base
- renderinfo[2] = height
- renderinfo[3] = resolution or Vector2.new(.5, .5)
- renderinfo[4] = start
- renderinfo[5] = maxdist or 100
- renderinfo[6] = params
- renderinfo[7] = {}
- renderinfo[8] = math.rad(fov or 90)
- renderinfo[9] = handle
- renderinfo[10] = maxr or 10
- return renderinfo
- end
- function module:GetReflected(origin: Vector3, point: Vector3, normal: Vector3)
- local vec = point - origin
- local dir = vec - 2 * vec:Dot(normal) * normal
- return dir
- end
- function module:Shadow(ray: RaycastResult, color: Color3, p: RaycastParams, max: number, shadowdef: number)
- if (ray.Instance.Transparency < 1) then
- max = max or 0
- local sundir = game:GetService("Lighting"):GetSunDirection()
- local shadowtest = module:Raycast(ray.Position, sundir*12345678, p)
- local m = math.max(1-module:GetVectorAngles(sundir, ray.Normal)/math.pi, max)
- local s_color = module:C_mult(color, m)
- if shadowtest ~= nil then
- if shadowtest.Instance ~= ray.Instance and (shadowtest.Instance.Transparency < 1) then
- return module:C_mult(s_color, shadowdef)
- end
- end
- return s_color, m
- end
- return color
- end
- function module:GetVectorAngles(a: Vector3, b: Vector3)
- return math.acos(a:Dot(b)/(a.Magnitude*b.Magnitude))
- end
- function module:ReflectRay(render, pixel: Vector3, ray: RaycastResult, color: Color3, r: number, s)
- if ray.Instance.Reflectance ~= 0 and r < render[10] then
- local dir = module:GetReflected(pixel, ray.Position, ray.Normal)
- local r_ray = module:Raycast(ray.Position, dir.Unit*render[5], render[6])
- if r_ray ~= nil then
- local t_color = r_ray.Instance.Color:Lerp(color, 1-ray.Instance.Reflectance)
- if r_ray.Instance.Reflectance ~= 0 then
- task.wait(.01)
- return module:ReflectRay(render, ray.Position, r_ray, t_color, r+1, s)
- end
- return r_ray, t_color, r+1
- end
- if r_ray == nil then
- return ray, s, r+1
- end
- end
- return ray, color, r
- end
- function makePart(a, p, s, pa)
- local par
- local s, e = pcall(function()
- par = Instance.new("Part", pa)
- par.Anchored = a
- par.Position = p
- par.Size = s
- end)
- if e then
- if par ~= nil then
- par:Destroy()
- par = nil
- end
- task.wait(2)
- return trymakePart(a, p, s, pa)
- end
- if (not e) and (par ~= nil) then
- return par
- end
- end
- function module:Raycast(start: Vector3, dir: Vector3, p: RaycastParams)
- return workspace:Raycast(start, dir, p or nil)
- end
- function module:C_mult(color: Color3, scalar: number)
- return Color3.new(color.R*scalar, color.G*scalar, color.B*scalar)
- end
- function module:C_mult2(color: Color3, color2: Color3)
- return Color3.new(color.R*color2.R, color.B*color2.B, color.G*color2.G)
- end
- function lerp(min, max, t)
- return (max-min)*t + min
- end
- function module:Render(render)
- local xit = math.floor(render[1] / render[3].X)
- local yit = math.floor(render[2] / render[3].Y)
- local seed = math.random()*1000000
- local sky = Color3.new(0, 0.6, 1)
- local max_r = render[10]
- local stc = render[9]
- for x = 0,xit do
- render[7][x] = {}
- for y = 0, yit do
- local fov = render[8]
- local left = CFrame.Angles(0, fov/2, 0)
- local right = CFrame.Angles(0, -fov/2, 0)
- local bottom = CFrame.Angles(-fov/2, 0, 0)
- local top = CFrame.Angles(fov/2, 0, 0)
- local forward = Vector3.new(0, 0, -1)
- local xpos = lerp(left.LookVector, right.LookVector, x/xit)
- local ypos = lerp(top.LookVector, bottom.LookVector, y/yit)
- local dir = CFrame.new(xpos.X, ypos.Y, -1).LookVector
- --makePart(true, (stc * relpos).Position, Vector3.new(.01, .01, .01), workspace)
- local ray = module:Raycast(stc.Position, dir, render[6])
- local clouds = math.clamp((math.noise(x*render[3].X/7+seed, y*render[3].Y/7+seed)+.5)^2, 0, 1)
- local sky_c = sky:Lerp(Color3.new(1,1,1), clouds)
- --task.wait(.2)
- --print(math.deg(module:GetVectorAngles(xpos, forward)))
- if ray ~= nil then
- local r_ray, r_color, r = module:ReflectRay(render, stc.Position, ray, ray.Instance.Color, 0, sky_c)
- local r_ray_shadow, m = module:Shadow(r_ray, r_color, render[6], .3, .5)
- --makePart(true, r_ray.Position, Vector3.new(render[3].X, render[3].Y, 0.01), script)
- if (r_ray == ray) then
- render[7][x][y] = r_ray_shadow:Lerp(Color3.new(), math.clamp(r/max_r, 0, 1))
- end
- if r_color == sky then
- render[7][x][y] = sky_c:Lerp(Color3.new(), math.clamp(r/max_r, 0, 1))
- end
- if r_ray ~= ray then
- if m then
- render[7][x][y] = module:C_mult(r_ray_shadow:Lerp(Color3.new(), math.clamp(r/max_r, 0, 1)), m)
- else
- render[7][x][y] = r_ray_shadow:Lerp(Color3.new(), math.clamp(r/max_r, 0, 1))
- end
- --local pos = Instance.new("SpawnLocation", workspace)
- --pos.Position = r_ray.Position
- --pos.Anchored = true
- end
- else
- render[7][x][y] = sky_c
- end
- end
- if x % 20 == 0 then
- task.wait()
- end
- end
- end
- ---------------------------------------------------------------------------------------------------
- NLS([[
- local fps = 2
- local f = 0
- while task.wait(1/fps) do
- local cc = workspace.CurrentCamera
- script.Parent.t:FireServer({cc.CFrame, cc.ViewportSize, cc.FieldOfView, f})
- f = f + 1
- end
- ]], owner.Character)
- local sg = Instance.new("ScreenGui", owner.PlayerGui)
- sg.DisplayOrder = -1
- sg.IgnoreGuiInset = true
- local fin
- remote.OnServerEvent:Connect(function(player, cam)
- local xsize = cam[2].X
- local ysize = cam[2].Y
- local size = Vector2.new(38, 38)
- local rm = module
- function printmatrix(m)
- print("rows: "..#m)
- print("cols: "..#m[1])
- for x = 1,#m do
- local str = "{"
- for y = 1,#m[x] do
- str = str..tostring(m[x][y])..","
- end
- str = string.sub(str, 1, #str-1)
- str = str.."}"
- print(x, str)
- end
- end
- if cam[4] == 0 and fin == nil then
- local star = rm:NewRender(xsize, ysize, size, false, 1000, false, cam[3], cam[1], 5)
- rm:Render(star)
- for x = 1,#star[7]+1 do
- for y = 1,#star[7][x-1]+1 do
- local nf = Instance.new('Frame', sg)
- nf.Size = UDim2.new(0, size.X, 0, size.Y)
- nf.Position = UDim2.new(0, (x-1) * size.X, 0, (y-1) * size.Y)
- nf.BackgroundColor3 = star[7][x-1][y-1]
- nf.BorderSizePixel = 0
- nf.Name = tostring(x)..tostring(x+y)..tostring(y)
- end
- end
- fin = true
- end
- if cam[4] ~= 0 and fin == true then
- local newr = rm:NewRender(xsize, ysize, size, false, 1000, false, cam[3], cam[1], 5)
- rm:Render(newr)
- for x = 1,#newr[7]+1 do
- for y = 1,#newr[7][x-1]+1 do
- local c_f = sg:FindFirstChild(tostring(x)..tostring(x+y)..tostring(y))
- c_f.BackgroundColor3 = newr[7][x-1][y-1]
- end
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement