-
Notifications
You must be signed in to change notification settings - Fork 9
/
Functions.lua
116 lines (69 loc) · 2.3 KB
/
Functions.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
module("shadows.Functions", package.seeall)
Shadows = require("shadows")
Shaders = require("shadows.Shaders")
local sqrt = math.sqrt
local min = math.min
local max = math.max
function Shadows.Normalize(v)
local LengthFactor = 1 / sqrt( v[1] * v[1] + v[2] * v[2] )
return {
v[1] * LengthFactor,
v[2] * LengthFactor
}
end
function Shadows.PointInPolygon(x, y, Vertices)
local Intersects = false
local j = #Vertices - 1
for i = 1, #Vertices, 2 do
if Vertices[i + 1] < y and Vertices[j + 1] >= y or Vertices[j + 1] < y and Vertices[i + 1] >= y then
if Vertices[i] + ( y - Vertices[i + 1] ) / (Vertices[j + 1] - Vertices[i + 1]) * (Vertices[j] - Vertices[i]) < x then
Intersects = not Intersects
end
end
j = i
end
return Intersects
end
function Shadows.insertionSort(Table)
local Length = #Table
for j = 2, Length do
local Aux = Table[j]
local i = j - 1
while i > 0 and Table[j] > Aux do
Table[i + 1] = Table[i]
i = i - 1
end
Table[i + 1] = Aux
end
end
function Shadows.Insert(Table, Index, Value)
if Value then
for i = #Table, Index, -1 do
Table[i + 1] = Table[i]
end
Table[Index] = Value
else
Table[#Table + 1] = Index
end
end
function Shadows.newDropshadowsFromImageData(ImageData, LightX, LightY, LightZ, LightRadius, TextureZ, LightRadiusMult)
local width, height = ImageData:getDimensions()
local scale = LightZ / ( LightZ - TextureZ )
local canvasWidth = math.ceil( width * scale )
local canvasHeight = math.ceil( height * scale )
local canvas = love.graphics.newCanvas( canvasWidth, canvasHeight )
Shaders.DropShadows:send("lightPosition", { LightX, LightY, LightZ })
Shaders.DropShadows:send("lightRadius", LightRadius)
Shaders.DropShadows:send("lightRadiusMult", LightRadiusMult or 2)
Shaders.DropShadows:send("texure", love.graphics.newImage(ImageData))
Shaders.DropShadows:send("textureSize", { width - 0.5, height - 0.5 })
Shaders.DropShadows:send("textureZ", TextureZ)
love.graphics.setCanvas(canvas)
love.graphics.clear(0, 0, 0, 0)
love.graphics.setColor(1, 1, 1, 1)
love.graphics.setShader(Shaders.DropShadows)
love.graphics.rectangle("fill", 0, 0, canvasWidth, canvasHeight)
love.graphics.setCanvas()
love.graphics.setShader()
return canvas
end