Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fgnm opened this issue Nov 22, 2022 · 2 comments
Open

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

fgnm opened this issue Nov 22, 2022 · 2 comments

Comments

@fgnm
Copy link

fgnm commented Nov 22, 2022

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
Copy link
Author

fgnm commented Nov 26, 2022

@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)

@MikOfClassX
Copy link

it looks realy nice IMHO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants