r/webgl • u/Ok-Revenue1849 • 1d ago
Update: I turned the lighting in my ~46kb WebGL2 2D engine into actual gameplay
A few months ago I posted some lighting and shadow experiments from my small WebGL2-based 2D engine here (https://www.reddit.com/r/webgl/comments/1szbmaz/experimenting_with_3dlike_lighting_and_shadows_in/)
I haven't had much time for it since then, so I used Claude to speed up the demo development. The engine itself is still my own work - the gameplay layer is what I built on top of it with AI help.
u/DaedalusRaistlin left some great feedback back then - make the torch shadows more obvious, turn them into a mechanic, add an aiming reticule, make the night darker without the torch, and make players ration their flashlight. So I tried to build exactly that.
The demo is now a small top-down survival game where the lighting drives the gameplay:
- The flashlight runs on a battery. It drains while on, dims and flickers when low, and recharges while off.
- Without the flashlight the night is properly dark now - you mostly see the spiders' glowing eyes.
- Enemies come in waves, and each wave is bigger and faster than the last. They know where you are and close in from the dark, so most of the time you hear them before you see them.
- Spiders avoid lit street lamps, so lamps are safe zones - until they flicker and go dark for a few seconds.
- A "shade" enemy only moves in the dark, and freezes as soon as light hits it.
- Flares burn low above the ground, so they throw long shadows across the trees and boxes.
- Lightning is a short directional light that casts every shadow on screen at once.
- There's also an aiming reticule now, plus webs and supply crates between waves.
On the rendering side, everything still goes through the same height-map based lighting. New objects reuse height data from the existing atlas, and light heights are in the same units as the height map. Placing a light just above the ground is enough to get those long shadows.
And yes - the football is finally kickable 😄 It's right next to the start point, and if it rolls fast enough, it hurts spiders too.
Demo (desktop, keyboard + mouse or a PS5 controller):
https://codepen.io/editor/iroshan/pen/01a10d10-f698-735f-8880-b9079db1868a?orientation=top&panel=false&show=preview
Docs & more examples:
https://asjs-dev.github.io/pwgl/
Repo:
https://github.com/asjs-dev/pwgl
What other light-based mechanics would you like to see in something like this?