better lighting

This commit is contained in:
asrael 2026-01-31 09:31:17 -06:00
parent 805a2713a3
commit 6ed4e17065
75 changed files with 6417 additions and 3667 deletions

View file

@ -59,6 +59,10 @@
(let [s (const ctx scale)]
(ctx.graph:add_node procgen.OP_NOISE_VALUE ctx.x ctx.y s 0 0)))
(fn noise-value-at [ctx x y scale]
(let [s (const ctx scale)]
(ctx.graph:add_node procgen.OP_NOISE_VALUE x y s 0 0)))
(fn noise-perlin [ctx scale]
(let [s (const ctx scale)]
(ctx.graph:add_node procgen.OP_NOISE_PERLIN ctx.x ctx.y s 0 0)))
@ -68,6 +72,11 @@
p (const ctx persistence)]
(ctx.graph:add_node procgen.OP_NOISE_FBM ctx.x ctx.y s p octaves)))
(fn noise-fbm-at [ctx x y octaves scale persistence]
(let [s (const ctx scale)
p (const ctx persistence)]
(ctx.graph:add_node procgen.OP_NOISE_FBM x y s p octaves)))
(fn noise-ridged [ctx octaves scale persistence]
(let [s (const ctx scale)
p (const ctx persistence)]
@ -165,4 +174,157 @@
(g:destroy)
tex-id)))
(fn textures.wood-planks [seed base-color]
(let [g (build-graph seed
(fn [ctx]
(let [tex-size 64
plank-count 2
pixel-x (floor ctx (mul ctx ctx.x (const ctx tex-size)))
plank-x (div ctx pixel-x (const ctx (/ tex-size plank-count)))
plank-fract (fract ctx plank-x)
edge-dist (min-op ctx plank-fract (sub ctx (const ctx 1.0) plank-fract))
gap-threshold (const ctx 0.04)
is-gap (sub ctx gap-threshold edge-dist)
plank-tint (mul ctx (noise-value ctx 6) (const ctx 0.25))
grain-x (mul ctx ctx.x (const ctx 12))
grain-y (mul ctx ctx.y (const ctx 2))
grain-base (noise-fbm-at ctx grain-x grain-y 3 4 0.6)
grain-fine-x (mul ctx ctx.x (const ctx 48))
grain-fine-y (mul ctx ctx.y (const ctx 6))
grain-fine (noise-value-at ctx grain-fine-x grain-fine-y 1)
grain (add ctx (mul ctx grain-base (const ctx 0.6))
(mul ctx grain-fine (const ctx 0.4)))
wood-val (add ctx grain plank-tint)
wood-quant (quantize ctx wood-val base-color 6)
gap-shade (sub ctx wood-val (const ctx 0.15))
gap-quant (quantize ctx gap-shade base-color 6)]
(select ctx is-gap gap-quant wood-quant))))]
(let [tex-id (g:eval_texture 64 64)]
(g:destroy)
tex-id)))
(fn textures.diagonal-planks [seed base-color]
(let [g (build-graph seed
(fn [ctx]
(let [tex-size 64
plank-count 4
diag (add ctx ctx.x ctx.y)
pixel-diag (floor ctx (mul ctx diag (const ctx tex-size)))
plank-diag (div ctx pixel-diag (const ctx (/ tex-size plank-count)))
plank-fract (fract ctx plank-diag)
edge-dist (min-op ctx plank-fract (sub ctx (const ctx 1.0) plank-fract))
gap-threshold (const ctx 0.06)
is-gap (sub ctx gap-threshold edge-dist)
plank-id (floor ctx plank-diag)
plank-tint (mul ctx (noise-value-at ctx plank-id (const ctx 0) 8) (const ctx 0.2))
grain-diag (mul ctx diag (const ctx 8))
grain-perp (sub ctx ctx.x ctx.y)
grain-base (noise-fbm-at ctx grain-diag grain-perp 3 6 0.5)
grain-fine (noise-value-at ctx (mul ctx grain-diag (const ctx 4)) grain-perp 1)
grain (add ctx (mul ctx grain-base (const ctx 0.5))
(mul ctx grain-fine (const ctx 0.3)))
wood-val (add ctx grain plank-tint)
wood-quant (quantize ctx wood-val base-color 5)
gap-shade (sub ctx wood-val (const ctx 0.2))
gap-quant (quantize ctx gap-shade base-color 5)]
(select ctx is-gap gap-quant wood-quant))))]
(let [tex-id (g:eval_texture 64 64)]
(g:destroy)
tex-id)))
(fn textures.cobble-timber [seed stone-color moss-color wood-color]
(let [g (build-graph seed
(fn [ctx]
(let [warp-x (noise-fbm ctx 2 3 0.5)
warp-y (noise-value ctx 4)
warped-x (add ctx ctx.x (mul ctx warp-x (const ctx 0.15)))
warped-y (add ctx ctx.y (mul ctx warp-y (const ctx 0.15)))
cell (ctx.graph:add_node procgen.OP_VORONOI_CELL warped-x warped-y (const ctx 5) 0 0)
edge (ctx.graph:add_node procgen.OP_VORONOI_EDGE warped-x warped-y (const ctx 5) 0 0)
mortar-threshold (const ctx 0.08)
is-mortar (sub ctx mortar-threshold edge)
mortar-color (const ctx 79)
stone-detail (noise-value ctx 48)
stone-base (mul ctx cell (const ctx 0.6))
stone-combined (add ctx stone-base (mul ctx stone-detail (const ctx 0.4)))
stone-quant (quantize ctx stone-combined stone-color 8)
moss-pattern (noise-fbm ctx 4 10 0.5)
moss-detail (noise-value ctx 64)
moss-var (add ctx (mul ctx moss-pattern (const ctx 0.7))
(mul ctx moss-detail (const ctx 0.3)))
moss-threshold (const ctx 0.55)
has-moss (sub ctx moss-pattern moss-threshold)
moss-quant (quantize ctx moss-var moss-color 6)
stone-or-moss (select ctx has-moss moss-quant stone-quant)]
(select ctx is-mortar mortar-color stone-or-moss))))]
(let [tex-id (g:eval_texture 64 64)]
(g:destroy)
tex-id)))
(fn textures.plaster-wall [seed base-color]
(let [g (build-graph seed
(fn [ctx]
(let [plaster-base (noise-fbm ctx 3 24 0.4)
plaster-detail (noise-value ctx 64)
plaster-rough (noise-turbulence ctx 2 32 0.5)
combined (add ctx (mul ctx plaster-base (const ctx 0.5))
(add ctx (mul ctx plaster-detail (const ctx 0.3))
(mul ctx plaster-rough (const ctx 0.2))))
crack-noise (noise-ridged ctx 2 8 0.6)
crack-threshold (const ctx 0.75)
has-crack (sub ctx crack-noise crack-threshold)
crack-color (const ctx (- base-color 2))
plaster-quant (quantize ctx combined base-color 4)]
(select ctx has-crack crack-color plaster-quant))))]
(let [tex-id (g:eval_texture 64 64)]
(g:destroy)
tex-id)))
(fn textures.timber-frame [seed wood-color plaster-color]
(let [g (build-graph seed
(fn [ctx]
(let [h-beam-count 2
v-beam-count 1.5
beam-half-width 0.08
scaled-x (mul ctx ctx.x (const ctx h-beam-count))
scaled-y (mul ctx ctx.y (const ctx v-beam-count))
dist-to-h-beam (abs ctx (sub ctx (fract ctx scaled-y) (const ctx 0.5)))
dist-to-v-beam (abs ctx (sub ctx (fract ctx scaled-x) (const ctx 0.5)))
is-h-timber (sub ctx beam-half-width dist-to-h-beam)
is-v-timber (sub ctx beam-half-width dist-to-v-beam)
wood-grain (noise-fbm ctx 2 48 0.5)
wood-quant (quantize ctx wood-grain wood-color 4)
plaster-noise (noise-fbm ctx 3 16 0.4)
plaster-quant (quantize ctx plaster-noise plaster-color 3)
timber-or-plaster (select ctx is-h-timber wood-quant
(select ctx is-v-timber wood-quant plaster-quant))]
timber-or-plaster)))]
(let [tex-id (g:eval_texture 64 64)]
(g:destroy)
tex-id)))
(fn textures.door []
(let [(tex err) (pxl8.load_sprite "res/textures/door.ase")]
(if tex
tex
(do (pxl8.error (.. "Failed to load res/textures/door.ase, error: " (tostring err))) nil))))
(fn textures.wood-trim [seed base-color]
(let [g (build-graph seed
(fn [ctx]
(let [plank-tint (mul ctx (noise-value ctx 6) (const ctx 0.25))
grain-x (mul ctx ctx.x (const ctx 12))
grain-y (mul ctx ctx.y (const ctx 2))
grain-base (noise-fbm-at ctx grain-x grain-y 3 4 0.6)
grain-fine-x (mul ctx ctx.x (const ctx 48))
grain-fine-y (mul ctx ctx.y (const ctx 6))
grain-fine (noise-value-at ctx grain-fine-x grain-fine-y 1)
grain (add ctx (mul ctx grain-base (const ctx 0.6))
(mul ctx grain-fine (const ctx 0.4)))
wood-val (add ctx grain plank-tint)]
(quantize ctx wood-val base-color 6))))]
(let [tex-id (g:eval_texture 64 16)]
(g:destroy)
tex-id)))
textures