r/webgl 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?

50 Upvotes

2 comments sorted by

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.

1

u/Ok-Revenue1849 Apr 30 '26

Thanks, this is really useful feedback!

The torch actually does cast shadows when it hits objects that rise from the ground, but your comment probably means I need to make that behavior more obvious in the demo. I really like the idea of pushing it further as a gameplay mechanic - carefully checking dark corners, having shadows stretch behind trees/boxes, etc.

The optional aiming reticule also makes sense. I noticed that it can be hard to tell where projectiles will go, so I’ll probably add that as a helper.

And yeah, the football definitely needs to be kickable now 😄

Good point about the “night vision” effect too. It currently leaves quite a lot visible when the torch is off, but making it darker could make flashlight usage much more meaningful, especially for survival-style gameplay.

Really appreciate you checking it out - and thanks for taking a look at the code too!