playcanvas / engine

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

Implement non-anisotropic GGX shader chunks #2869

Open raytranuk opened 3 years ago

raytranuk commented 3 years ago

Currently the GGX implementation only includes anisotropic shader chunks - however, it would be preferable to include a lower cost non-anisotropic implementation

cognitiveplus commented 3 years ago

Hi @raytranuk! I'm planning to start experimenting with GGX implementation based on Filament docs. Is there any progress on your side that you could share? Would be happy to join forces!

My current plan is:

Anybody interested is also welcome to the discussion!

raytranuk commented 3 years ago

Hi @cognitiveplus - thanks for the message - we are certainly interested in new contributors who can work with us to submit engine PRs.

Regarding GGX: Last year I submitted a PR with an anisotropic GGX specular implementation (https://github.com/playcanvas/engine/pull/1909) however, before exposing this publicly in the PlayCanvas editor, it would be better if we also had a lower cost isotropic GGX specular that can be used for the majority of materials which won't use anisotropy.

My current plan is: To create a custom script that would patch desired materials with GGX implementation chunks

Instead of a custom script, it may be better to add the new chunks to the engine and have them switched to using material properties. Ideally the new shader chunks and the new material properties could be submitted as an engine PR.

To create test HDRI scenes enabling side by side comparison of same objects with old / new materials (+ white furnace test)

This is a good idea - if added as new shader chunks controlled by material properties, you should be able to create a scene with some objects that use materials that have the new material properties set to enable the new shader chunks.

To implement additional material features currently unsupported by PC (fabric sheen, SSS approximation, etc)

Feel free to open new issue to track fabric sheen (I thought I did open an issue but can't find it) - ideally, we would meet the specs for the glTF sheen extension - and add support for it in our glb parser so that models that use sheen will work with the new shader chunks.

Regarding SSS: PlayCanvas is a forward renderer - and this makes good subsurface scattering quite difficult - however, I did find this technique: https://www.youtube.com/watch?v=k89NG-sz1AM - which may be possible to implement as new lighting shader chunks controlled with material properties.

Keep us up to date with your progress - and when ready please do open up a pull request - and we can help get it into shape to be added to the engine.

cognitiveplus commented 3 years ago

Hey @raytranuk, thank you for extended answer!

Sure, eventually all GGX-related code should go into Program Lib as custom chunks and get supported in the Editor over time (may be as GGXMaterial derived from StandardMaterial?), but for now I would just want to focus on quick prototype covering all the basics described in Filament docs / UE4 Siggraph 13 paper and compare them side by side. Then, once all shader parts work as intended they could be split into proper chunks and ported into the Engine.

Btw, I've seen your aniso GGX code - it's awesome 👍