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
|
local win = require("window")
local color = require("color")
local world = require("world")
local shim = require("shader_shim")
local numstars = 500 -- we might have as many as 4 over
local genned_stars = 0
local period_x = 3
local period_y = 3
local stars = {}
local tries = 0
aspect = win.width / win.height
while genned_stars < numstars and tries < 100000 do
local rngx = math.random()
local xpos = rngx * win.width --* (period_x - 1)
local rngy = math.random()
local ypos = rngy * win.height --* (period_y - 1)
local blinks = math.random() > 0.3 and (math.random() * 2 * math.pi) or 0
--if math.distance(vec2(rngx,rngy), vec2(0.53,0.5)) > 0.5 then
local off = vec2(math.abs(rngx - 0.50) * aspect, math.abs(rngy-0.5))
if math.length(off) > 0.5 then
stars[#stars+1] = vec3(xpos, ypos, blinks)
genned_stars = genned_stars + 1
if xpos < win.width then
-- duplicate on the last screen
stars[#stars+1] = vec3(xpos + (win.width * (period_x-2)), ypos, blinks)
genned_stars = genned_stars + 1
end
if ypos < win.height then
stars[#stars+1] = vec3(xpos, ypos + (win.height * (period_y-2)), blinks)
genned_stars = genned_stars + 1
end
if xpos < win.width and ypos < win.height then
stars[#stars+1] = vec3(xpos + (win.width * (period_x-2)), ypos+(win.height * (period_y-2)),blinks)
genned_stars = genned_stars + 1
end
end
tries = tries + 1
end
assert(genned_stars == numstars, "Failed to generate stars")
local node = am.blend("premult") ^ shim.stars
^ am.bind({
MV = mat4(
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
(-win.width / 2), (-win.height/2), 0, 1
),
color = color.am_color.highlight,
stars = am.vec3_array(stars),
world_x = am.current_time(),
world_x_period = (period_x - 2) * win.width,
world_y = am.current_time(),
world_y_period = (period_y - 2) * win.height,
time = am.current_time(),
lamp1 = vec3(0),
lamp2 = vec3(0),
lamp3 = vec3(0),
lamp4 = vec3(0),
lamp5 = vec3(0),
lamp6 = vec3(0),
lamp7 = vec3(0),
lamp8 = vec3(0)
})
^ am.draw("points")
node:action(function(self)
self("bind").time = am.current_time()
self("bind").world_x = world.world_x
self("bind").world_y = world.world_y
local lamps = world.level.lamps_on_screen()
for i,v in pairs(lamps) do
print("Setting lamp", i, "to", v)
self("bind")["lamp" .. tostring(i)] = v
end
end)
return node
|