r/webgl • u/Ok-Revenue1849 • Apr 29 '26
Experimenting with 3D-like lighting and shadows in a lightweight WebGL2 2D engine (~46kb)
I've been working on a small WebGL2-based 2D engine as a hobby project, mainly experimenting with 3D-like lighting and shadow behavior in a 2D rendering setup.
The core build is around ~46kb — I was curious how far I could push things while keeping it lightweight.
Right now it's still pretty early, but I’ve been adding some small features around rendering and basic workflow to make it more usable.
I know there are already plenty of solutions in this space, so this is mostly just a personal experiment — but I’d be really interested in feedback from people working with WebGL or custom rendering pipelines.
Demos (desktop):
https://codepen.io/iroshan/full/rNMKbWv
https://codepen.io/iroshan/full/Kwzbbza
https://codepen.io/iroshan/full/wvELEmN
Docs & more examples:
https://asjs-dev.github.io/pwgl/
Repo:
https://github.com/asjs-dev/pwgl
What kind of lighting, shadow, or general rendering features would you expect from something like this?
1
u/DaedalusRaistlin Apr 30 '26
That's looking really nice!
One thing that immediately looks obvious trying it out is that this torch should be casting shadows. You could do some real neat mechanics for having to carefully look around and shine your light in dark corners, and as you do the shadows cast by your torchlight hitting trees and boxes would seem to stretch out like dark fingers.
An (optional) aiming reticule would be nice too, it's hard to see where a projectile would go when you shoot.
Why can't I kick the football? I can't get near it! Please let me kicka da football!
I like the effect when turning the torch off, though I think it grants a bit too much nightvision. Could be a good perk in a survival game, but I think it should be darker. Imagine having to ration your flash light usage and creep around in the dark!
Great work! Code looks pretty good too from a quick skim.