mgsx-dev / gdx-gltf

GLTF 2.0 3D format support and PBR shader implementation for LibGDX
Apache License 2.0
214 stars 50 forks source link

[Feature Request] Add Spherical Harmonics to PBR light shader #91

Open fgnm opened 1 year ago

fgnm commented 1 year ago

Again, this could be another minor feature, however could be nice to have :) A brief explain of Spherical Harmonics can be found in the ARCore documentation, with also some examples: https://developers.google.com/ar/develop/lighting-estimation#ambient_spherical_harmonics

I also noticed that in the default libGDX shader spherical harmonics are implemented but there's nothing that sets the sphericalHarmonicsFlag in the Java side.. https://github.com/mgsx-dev/gdx-gltf/blob/c8047c23a269179c985664b5869a25e056d8c84a/gltf/src/net/mgsx/gltf/shaders/default.vs.glsl#L279-L289 Weird, btw this could be an improvement to this library, a lot of PBR rendering implements this feature.

Thanks!

fgnm commented 1 year ago

@mgsx-dev I did a POC implementation of SH in your library.. Doesn't looks like so bad, I'm not sure if the shader and calculations are right, basically I copied from official google ar example (https://github.com/google-ar/arcore-android-sdk/tree/master/samples/hello_ar_java) which include a PBR shader. I'd like to know what do you think, if and how could be improved, etc. https://github.com/fgnm/ARPlayground/commit/e9c75b2ecd899e1f38908ec06cd502bc6f045782 a part from extended Java classes the only glsl I've modified is the pbr.fs.glsl adding spherical harmonics.

Light on the model looks much more realistic :)

Without Spherical Harmonics With Spherical Harmonics
photo_2022-11-26_13-25-47 photo_2022-11-26_13-25-47 (2)
MikOfClassX commented 1 year ago

it looks realy nice IMHO