playcanvas / engine

JavaScript game engine built on WebGL, WebGPU, WebXR and glTF
https://playcanvas.com
MIT License
9.69k stars 1.36k forks source link

Implement Textured Area Lights #4320

Open marklundin opened 2 years ago

marklundin commented 2 years ago

This ticket is a request for comments/progress tracker for adding textured area lights as an extension to the current LTC implementation.

image

DEMO

The above example includes an custom version of the engine (v1.54) that implements textured area lights using the current LTC shader chunks. It's using the cookie texture slot on the lighting system as the light source. Works with diffuse/specular/CC.

The blurriness/roughness is an approximation of a gaussian kernel that uses weighted samples of the mip-chain. This appears to be a better quality blur than many other approaches (especially at higher blurriness levels) but is cheaper to compute than most solutions of a similar quality. The cost is bound to the texture resolution (1k is 10 taps) and independent of the blur strength.

Tasks:

Optional:

Open Questions:

  1. Should the textured area lights use the cookie texture slot or a dedicated one. The semantics are different but there may also be some practical issues if one light has a cookie and another is a textured area light. This will also have implications for the cookie atlas in clustered lighting.
  2. Is it preferable to pre-compute a mipmap-less texture in a similar way to https://github.com/playcanvas/engine/pull/3783. This may not always be required if using dynamic/video textures for example but for static ones it may be better (same code path for all devices)

Related PRs Clustered Area Lights Clustered Lights mipmap-less environment lighting

Any feedback welcome @mvaligursky @slimbuck @willeastcott

mvaligursky commented 2 years ago

Fantastic work so far!

Perhaps it could work like this:

I think it would be ok if this was done only for the clustered lights, saving having to do this for normal lighting as well - as this will get deprecated in not too distant future most likely.

slimbuck commented 2 years ago

This is fricken amazing! 🥹

Do you have any idea what might be causing the spikes on the ministats GPU plot?

Screenshot 2022-06-10 at 17 50 11
marklundin commented 2 years ago

Will take a look @slimbuck, but it could well be the video texture upload which is happening independently of the update loop. I'll remove it and see if it makes a difference

marklundin commented 2 years ago

I'm not seeing the same spikes on my machine @slimbuck but I've disabled the video texture upload regardless

mvaligursky commented 2 years ago

I think those spikes are caused by something (likely the GPU) taking longer than one frame, so on occasions a frame is skipped. Probably nothing to worry about at this stage.

mvaligursky commented 2 years ago

Just an update - in the engine 1.55 https://github.com/playcanvas/engine/releases/tag/v1.55.0 we've enabled the clustered lighting as the default lighting solution.

marklundin commented 2 years ago

That's great to hear @mvaligursky. I've not managed to integrate with the clustered lighting as yet as I've not had the time. It requires a bit of thought on the atlas texture fetches and sampling the mips without any bleeding

mvaligursky commented 2 years ago

Yep, that should be doable, and I can help. We have some similar parts we can use:

either of these we could probably use for initial non-optimal solution.