improve glow rendering

This commit is contained in:
asrael 2026-01-23 11:12:37 -06:00
parent 28c3e7ee04
commit 27c6fa628d
7 changed files with 145 additions and 48 deletions

View file

@ -1,5 +1,4 @@
(local pxl8 (require :pxl8))
(local effects (require :pxl8.effects))
(local SKY_GRADIENT_START 144)
(local SKY_GRADIENT_COUNT 16)
@ -25,6 +24,7 @@
(var sky-mesh nil)
(var star-count 0)
(var star-directions nil)
(var star-glows nil)
(var star-projected nil)
(var star-time 0)
(var tiny-stars [])
@ -167,6 +167,7 @@
(set star-count (+ (length tiny-stars) (length random-stars)))
(set star-directions (pxl8.create_vec3_array star-count))
(set star-glows (pxl8.create_glows 10000))
(set star-projected (pxl8.create_vec3_array star-count))
(var idx 0)
@ -185,9 +186,8 @@
(fn render-stars [cam-x cam-y cam-z intensity dt]
(set star-time (+ star-time (or dt 0)))
(when (and (> intensity 0) (> star-count 0))
(let [glows []
fade-in (* intensity intensity)
(when (and (> intensity 0) (> star-count 0) star-glows)
(let [fade-in (* intensity intensity)
time-factor (/ star-time 60)
star-rotation (/ (* star-time math.pi 2) STAR_CYCLE_PERIOD)
t (pxl8.mat4_translate cam-x cam-y cam-z)
@ -196,6 +196,7 @@
transform (pxl8.mat4_multiply t (pxl8.mat4_multiply r s))
tiny-count (length tiny-stars)]
(star-glows:clear)
(pxl8.project_points star-directions star-projected star-count transform)
(for [i 0 (- tiny-count 1)]
@ -204,11 +205,8 @@
(let [star (. tiny-stars (+ i 1))
int (math.floor (* star.brightness fade-in))]
(when (> int 8)
(table.insert glows {:x (math.floor screen.x) :y (math.floor screen.y)
:radius 1
:intensity int
:color star.color
:shape effects.GLOW_CIRCLE}))))))
(star-glows:add (math.floor screen.x) (math.floor screen.y)
1 int star.color pxl8.GLOW_CIRCLE))))))
(for [i 0 (- (length random-stars) 1)]
(let [screen (. star-projected (+ tiny-count i))]
@ -221,33 +219,20 @@
sy (math.floor screen.y)]
(if (> star.brightness 220)
(do
(table.insert glows {:x sx :y sy :radius 3
:intensity (math.floor (* int 1.5))
:color star.color :shape effects.GLOW_DIAMOND})
(table.insert glows {:x sx :y sy :radius 5
:intensity (math.floor (/ int 2))
:color star.color :shape effects.GLOW_CIRCLE}))
(star-glows:add sx sy 3 (math.floor (* int 1.5)) star.color pxl8.GLOW_DIAMOND)
(star-glows:add sx sy 5 (math.floor (/ int 2)) star.color pxl8.GLOW_CIRCLE))
(> star.brightness 180)
(do
(table.insert glows {:x sx :y sy :radius 2 :intensity int
:color star.color :shape effects.GLOW_DIAMOND})
(table.insert glows {:x sx :y sy :radius 4
:intensity (math.floor (/ int 3))
:color star.color :shape effects.GLOW_CIRCLE}))
(star-glows:add sx sy 2 int star.color pxl8.GLOW_DIAMOND)
(star-glows:add sx sy 4 (math.floor (/ int 3)) star.color pxl8.GLOW_CIRCLE))
(> star.brightness 120)
(do
(table.insert glows {:x sx :y sy :radius 2
:intensity (math.floor (* int 0.67))
:color star.color :shape effects.GLOW_DIAMOND})
(table.insert glows {:x sx :y sy :radius 3
:intensity (math.floor (/ int 4))
:color star.color :shape effects.GLOW_CIRCLE}))
(table.insert glows {:x sx :y sy :radius 2
:intensity (math.floor (* int 0.5))
:color star.color :shape effects.GLOW_CIRCLE}))))))
(star-glows:add sx sy 2 (math.floor (* int 0.67)) star.color pxl8.GLOW_DIAMOND)
(star-glows:add sx sy 3 (math.floor (/ int 4)) star.color pxl8.GLOW_CIRCLE))
(star-glows:add sx sy 2 (math.floor (* int 0.5)) star.color pxl8.GLOW_CIRCLE))))))
(when (> (length glows) 0)
(effects.glows glows)))))
(when (> (star-glows:count) 0)
(star-glows:render)))))
(fn render [cam-x cam-y cam-z wireframe]
(when (not sky-mesh) (create-sky-dome))