mgsx-dev/gdx-gltf

[Feature Request] Add Spherical Harmonics to PBR light shader

fgnm opened this issue · 2 comments

fgnm commented

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..

#ifdef sphericalHarmonicsFlag
ambientLight += u_sphericalHarmonics[0];
ambientLight += u_sphericalHarmonics[1] * normal.x;
ambientLight += u_sphericalHarmonics[2] * normal.y;
ambientLight += u_sphericalHarmonics[3] * normal.z;
ambientLight += u_sphericalHarmonics[4] * (normal.x * normal.z);
ambientLight += u_sphericalHarmonics[5] * (normal.z * normal.y);
ambientLight += u_sphericalHarmonics[6] * (normal.y * normal.x);
ambientLight += u_sphericalHarmonics[7] * (3.0 * normal.z * normal.z - 1.0);
ambientLight += u_sphericalHarmonics[8] * (normal.x * normal.x - normal.y * normal.y);
#endif // sphericalHarmonicsFlag

Weird, btw this could be an improvement to this library, a lot of PBR rendering implements this feature.

Thanks!

fgnm commented

@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. fgnm/ARPlayground@e9c75b2 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)

it looks realy nice IMHO