playcanvas / engine

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

Implement HDR rendering + postprocessing pipeline #4323

Open mvaligursky opened 2 years ago

mvaligursky commented 2 years ago

PlayCanvas by default renders everything in LDR to 8888 targets. Lighting in the shader takes place in linear HDR space, and at the end of the standard shader we apply tone-mapping to bring it to LDR range, and then apply gamma. Post-processing then takes place on top of that, usually directly in the gamma space.

I tried to enable HDR rendering and a bloom filter. The scene rendering takes place in linear HDR as before, and this is directly stored in 16F target in linear space. Great so far. Then the bloom runs, again in linear space, but internally it uses 8888 targets for blurs, so the HDR is lost. And also, we’re missing a way to apply tone mapping at the end / or somewhere in the post-processing, and also at the end a linear space image is generated, which is very contrasty - we need to bring it to gamma space.

Additionally the bloom does not look very good .. possibly related to the fact it uses LDR targets, but could be something else as well.

exploration PR: https://github.com/playcanvas/engine/pull/4322

slimbuck commented 2 years ago

I wonder how well rgbm 8888 targets would work... Rgbm should be blurrable etc without having to decode/encode, but not sure what artifacts might result.

mvaligursky commented 2 years ago

Yep, many implementations use RGBM and it's a viable / faster option, with some range limitations.

mvaligursky commented 2 years ago

https://learnopengl.com/Guest-Articles/2022/Phys.-Based-Bloom

mvaligursky commented 1 year ago

related https://github.com/playcanvas/engine/issues/5287

mvaligursky commented 1 year ago

related https://github.com/playcanvas/engine/issues/4284

mvaligursky commented 1 year ago

Ideally we'd implement in using this system when ready: https://github.com/playcanvas/engine/issues/5687

mvaligursky commented 10 months ago

related: https://github.com/playcanvas/engine/pull/5833