-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Spherical Harmonics incorrect for some environment maps? #744
Comments
@pixelflinger is our SH specialist. A couple of things to note:
|
We also premultiply the SH by the basis (we basically output colors), not sure what Babylon, etc. expect. |
I actually multiply by π when exporting from Dimension to get things to look correct in Babylon but I wouldn't expect any colours near (and definitely not below) zero for this image so it seems like more than just a scale factor issue, no? |
Using the output of this call as .txt as @romainguy suggested to me, gives SH coeffs that work beautifully in Babylon. So, problem solved! |
I've changed my code from |
Looking at the code of the two methods it seems to be doing exactly the same thing. The difference could be in |
Hmmm, I must be doing something wrong. I'll take another look tomorrow. |
Could still be on our side if we mirror twice. |
Perhaps I'm missing something very basic but when using the SH visualizer the Y-axis appears to be flipped (with and without |
The mirroring option is only horizontal. I don't know how that visualizer works. Is lighting flipped in other engines too? What's the coordinates system of that visualizer? Filament uses right handed, Y up. |
Got it, the visualizer appears to use Three.js so it's right handed, Y-up. This is the case for me on the nightly build as well as the latest pre-release and stable release. I am using the 4K .hdr version as input. I've used the following command: |
Our SH reconstruction is pretty simple:
Where |
I wonder if the issue could come from here: https://github.com/google/filament/blob/master/tools/cmgen/src/Cubemap.h#L118 I don't know if the direction is supposed to be the direction of the light or the direction to a point on the cubemap. @pixelflinger would know. |
I just remembered that Cesium.js is using the wrong reconstruction because their current implementation looks like this: https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Shaders/Builtin/Functions/sphericalHarmonics.glsl and should be using the implementation you mentioned above (as they also generate SH through I swapped out the reconstruction in the SH visualizer with the implementation in Filament which now renders correctly (using |
I'm having trouble tracking which problems are still problems :-) |
I can't speak for
When I use We need a visualizer that takes raw SHs to test this. I don't think there is a problem with Here is the image I used for my tests: And the result I got with both And this is what the visualizer shows for The Y "inversion" comes from the fact |
So it seems that @MiiBond Is that what you're asking for? |
Describe the bug
The spherical harmonics coefficients produced by cmgen usually appear correctly when rendered in Babylon.js or other engines. However, the
ennis.exr
(http://gl.ict.usc.edu/data/highresprobes/) environment map produces SH coeffs that result in very dark lighting on the positive Z axis (perhaps even negative lighting). This occurs in both Babylon.js as well as this online SH visualizer:SH visualization of ennis.exr
I'm wondering if this is somehow related to there being such a large range in values in this particular image.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The dark side of the sphere should at least have some lighting, especially with high exposure but it always appears black. Perhaps I have a fundamental misunderstanding of SH's that's affecting my expectations.
Screenshots


The text was updated successfully, but these errors were encountered: