summaryrefslogtreecommitdiff
path: root/src/shaders/stars.lua
diff options
context:
space:
mode:
authorAlexander M Pickering <alex@cogarr.net>2025-01-25 20:40:09 -0600
committerAlexander M Pickering <alex@cogarr.net>2025-01-25 20:40:09 -0600
commitb174b8c00026253fd40ec262e430b0bb764e31ea (patch)
tree173d294b98fe14727aef9cd42542f41a940f5ffa /src/shaders/stars.lua
parent89a8f94ac0206412c1a2d7b8766d97dbdbd36253 (diff)
downloadggj25-b174b8c00026253fd40ec262e430b0bb764e31ea.tar.gz
ggj25-b174b8c00026253fd40ec262e430b0bb764e31ea.tar.bz2
ggj25-b174b8c00026253fd40ec262e430b0bb764e31ea.zip
work
Diffstat (limited to 'src/shaders/stars.lua')
-rw-r--r--src/shaders/stars.lua77
1 files changed, 38 insertions, 39 deletions
diff --git a/src/shaders/stars.lua b/src/shaders/stars.lua
index 8d54b16..3e4138e 100644
--- a/src/shaders/stars.lua
+++ b/src/shaders/stars.lua
@@ -1,57 +1,43 @@
local win = require("window")
local color = require("color")
local world = require("world")
-local numstars = 400 -- we might have as many as 4 over
+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 = {}
-while genned_stars < numstars do
+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
- 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)
+ --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
-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., 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;
- }
-]]))
+assert(genned_stars == numstars, "Failed to generate stars")
+local node = am.blend("premult") ^ shim.stars
^ am.bind({
MV = mat4(
1, 0, 0, 0,
@@ -66,11 +52,24 @@ local node = am.use_program(am.program([[
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