summaryrefslogtreecommitdiff
path: root/src/shaders/stars.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/shaders/stars.lua')
-rw-r--r--src/shaders/stars.lua76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/shaders/stars.lua b/src/shaders/stars.lua
new file mode 100644
index 0000000..111bef8
--- /dev/null
+++ b/src/shaders/stars.lua
@@ -0,0 +1,76 @@
+local win = require("window")
+local color = require("color")
+local world = require("world")
+local numstars = 400 -- we might have as many as 4 over
+local genned_stars = 0
+local period_x = 3
+local period_y = 3
+local stars = {}
+while genned_stars < numstars 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
+ 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
+local node = am.use_program(am.program([[
+ precision highp float;
+ attribute vec3 stars;
+ uniform float time;
+ uniform float world_x;
+ uniform float world_y;
+ uniform float world_x_period;
+ uniform float world_y_period;
+ uniform mat4 MV;
+ uniform mat4 P;
+ void main() {
+ float world_x_off = mod(world_x, world_x_period);
+ float world_y_off = mod(world_y, world_y_period);
+ gl_Position = P * MV * vec4(stars.x - world_x_off, stars.y - world_y_off, 0.0, 1.0);
+ float intensity = sin(stars.z + time) * cos(time) + 1.;
+ gl_PointSize = pow(intensity, 2.) * stars.z * 0.3;
+ }
+ ]],[[
+ precision mediump float;
+ uniform vec4 color;
+ void main() {
+ gl_FragColor = color;
+ }
+]]))
+^ 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(),
+})
+^ 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
+end)
+return node