diff options
| author | Alex Pickering <alex@cogarr.net> | 2026-02-01 13:14:32 -0600 |
|---|---|---|
| committer | Alexander M Pickering <alex@cogarr.net> | 2026-02-01 13:14:32 -0600 |
| commit | 3a975db66a3711f34e8b64bb27a8eaca79fdeca9 (patch) | |
| tree | fcc12f8f9d638ff575c1963796de76b7628854b4 /src/shaders/stars.lua | |
| download | ggj26-3a975db66a3711f34e8b64bb27a8eaca79fdeca9.tar.gz ggj26-3a975db66a3711f34e8b64bb27a8eaca79fdeca9.tar.bz2 ggj26-3a975db66a3711f34e8b64bb27a8eaca79fdeca9.zip | |
Diffstat (limited to 'src/shaders/stars.lua')
| -rw-r--r-- | src/shaders/stars.lua | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/shaders/stars.lua b/src/shaders/stars.lua new file mode 100644 index 0000000..3e4138e --- /dev/null +++ b/src/shaders/stars.lua @@ -0,0 +1,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 |
