Skip to content

Environment map cleanup: No infinite mipmaps, wider epsilons for unit tests #12606

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

ggetz
Copy link
Contributor

@ggetz ggetz commented May 7, 2025

Description

This PR should fixes an error that arises with DynamicEnvironmentMap when ContextLimits.maximumCubeMapSize is zero, such as in a NodeJS environment where there is no working WebGL context. We set a bottom limit at 0, make sure we have valid array sizes, and don't try to update the maps unless we have at least 1 mipmap level.

While I was in the tests, I went ahead and cleaned up the failing unit tests described in the linked issue.

Issue number and link

Fixes #12302.

Testing plan

@angrycat9000 Would you mind verifying the issue you ran into, or alternatively, leaving reproduction instructions?

  1. To test the unit test fixes, run npm run test locally.
  2. Sanity check the "Image-Based Lighting" Sandcastle example by checking the "procedural environment lighting" toggle.

NPM

Create a test.js file in the root of the Cesium project and run node test.js. Make sure it does not error out.

import { readFileSync } from "node:fs";
import {Cesium3DTileset} from  "@cesium/engine";

const buffer = readFileSync("./Specs/Data/Cesium3DTiles/GeoJson/Point/tileset.json");
const tileset = await Cesium3DTileset.fromUrl(
  `data:application/json;base64,${encodeURIComponent(buffer.toString("base64url"))}`,
  { show: false },
);
tileset.destroy();

Author checklist

  • I have submitted a Contributor License Agreement
  • I have added my name to CONTRIBUTORS.md
  • I have updated CHANGES.md with a short summary of my change
  • I have added or updated unit tests to ensure consistent code coverage
  • I have updated the inline documentation, and included code examples where relevant
  • I have performed a self-review of my code

Copy link

github-actions bot commented May 7, 2025

Thank you for the pull request, @ggetz!

✅ We can confirm we have a CLA on file for you.

@angrycat9000
Copy link
Contributor

Verified this fixes the problem. Added instructions to the description on how to verify in nodejs

@ggetz
Copy link
Contributor Author

ggetz commented May 8, 2025

Thanks @angrycat9000! @jjhembd Can you verify the test fixes?

@jjhembd
Copy link
Contributor

jjhembd commented May 12, 2025

Thanks @ggetz, the code change makes sense. Some of the tests are fixed, but several others are still failing on my machine.

1) creates environment map and spherical harmonics at surface in Philadelphia with static lighting
     Scene/DynamicEnvironmentMapManager render tests
     Expected (0.09512791782617569, 0.09512791782617569, 0.05843571573495865) to equal epsilon (0.11017649620771408, 0.13869766891002655, 0.17165547609329224), 0.01.
    at <Jasmine>
    at UserContext.<anonymous> (packages/engine/Specs/Scene/DynamicEnvironmentMapManagerSpec.js:270:58 <- Build/Specs/SpecList.js:161668:58)
    at <Jasmine>
     Expected (0.06610184162855148, 0.06610184162855148, 0.04060539975762367) to equal epsilon (0.08705271780490875, 0.11016352474689484, 0.15077166259288788), 0.01.
    at <Jasmine>
    at UserContext.<anonymous> (packages/engine/Specs/Scene/DynamicEnvironmentMapManagerSpec.js:278:58 <- Build/Specs/SpecList.js:161676:58)
    at <Jasmine>

2) creates environment map and spherical harmonics at surface in Philadelphia with dynamic lighting
     Scene/DynamicEnvironmentMapManager render tests
     Expected (0.004076908342540264, 0.004076908342540264, 0.0027179396711289883) to equal epsilon (0.034476835280656815, 0.04265068098902702, 0.04163559526205063), 0.01.
    at <Jasmine>
    at UserContext.<anonymous> (packages/engine/Specs/Scene/DynamicEnvironmentMapManagerSpec.js:621:58 <- Build/Specs/SpecList.js:161965:58)
    at <Jasmine>
     Expected (0.0028329347260296345, 0.0028329347260296345, 0.0018886234611272812) to equal epsilon (0.01569328084588051, 0.023243442177772522, 0.025639381259679794), 0.01.
    at <Jasmine>
    at UserContext.<anonymous> (packages/engine/Specs/Scene/DynamicEnvironmentMapManagerSpec.js:629:58 <- Build/Specs/SpecList.js:161973:58)
    at <Jasmine>

3) lighting uses atmosphereScatteringIntensity value
     Scene/DynamicEnvironmentMapManager render tests
     Expected (0.023781979456543922, 0.023781979456543922, 0.014269187115132809) to equal epsilon (0.0322723351418972, 0.039464931935071945, 0.047749463468790054), 0.01.
    at <Jasmine>
    at UserContext.<anonymous> (packages/engine/Specs/Scene/DynamicEnvironmentMapManagerSpec.js:954:58 <- Build/Specs/SpecList.js:162244:58)
    at <Jasmine>
     Expected (0.01652546040713787, 0.01652546040713787, 0.00991527084261179) to equal epsilon (0.025989927351474762, 0.031872138381004333, 0.04223670810461044), 0.01.
    at <Jasmine>
    at UserContext.<anonymous> (packages/engine/Specs/Scene/DynamicEnvironmentMapManagerSpec.js:962:58 <- Build/Specs/SpecList.js:162252:58)
    at <Jasmine>

4) lighting uses gamma value
     Scene/DynamicEnvironmentMapManager render tests
     Expected (0.1821020245552063, 0.1821020245552063, 0.14133282005786896) to equal epsilon (0.18712928891181946, 0.21367456018924713, 0.23666927218437195), 0.01.
    at <Jasmine>
    at UserContext.<anonymous> (packages/engine/Specs/Scene/DynamicEnvironmentMapManagerSpec.js:1068:58 <- Build/Specs/SpecList.js:162341:58)
    at <Jasmine>
     Expected (0.1265377253293991, 0.1265377253293991, 0.09820842742919922) to equal epsilon (0.13568174839019775, 0.15787045657634735, 0.19085952639579773), 0.01.
    at <Jasmine>
    at UserContext.<anonymous> (packages/engine/Specs/Scene/DynamicEnvironmentMapManagerSpec.js:1076:58 <- Build/Specs/SpecList.js:162349:58)
    at <Jasmine>

5) lighting uses brightness value
     Scene/DynamicEnvironmentMapManager render tests
     Expected (0.047563958913087845, 0.047563958913087845, 0.028538374230265617) to equal epsilon (0.05981340631842613, 0.07419705390930176, 0.09077795594930649), 0.01.
    at <Jasmine>
    at UserContext.<anonymous> (packages/engine/Specs/Scene/DynamicEnvironmentMapManagerSpec.js:1182:58 <- Build/Specs/SpecList.js:162438:58)
    at <Jasmine>
     Expected (0.03305092081427574, 0.03305092081427574, 0.01983054168522358) to equal epsilon (0.051604993641376495, 0.06336799263954163, 0.08409948647022247), 0.01.
    at <Jasmine>
    at UserContext.<anonymous> (packages/engine/Specs/Scene/DynamicEnvironmentMapManagerSpec.js:1190:58 <- Build/Specs/SpecList.js:162446:58)
    at <Jasmine>

6) lighting uses saturation value
     Scene/DynamicEnvironmentMapManager render tests
     Expected (0.09240995347499847, 0.09240995347499847, 0.09240995347499847) to equal epsilon (0.13499368727207184, 0.13499368727207184, 0.13499368727207184), 0.01.
    at <Jasmine>
    at UserContext.<anonymous> (packages/engine/Specs/Scene/DynamicEnvironmentMapManagerSpec.js:1296:58 <- Build/Specs/SpecList.js:162535:58)
    at <Jasmine>
     Expected (0.06421317905187607, 0.06421317905187607, 0.06421317905187607) to equal epsilon (0.1081928238272667, 0.1081928238272667, 0.1081928238272667), 0.01.
    at <Jasmine>
    at UserContext.<anonymous> (packages/engine/Specs/Scene/DynamicEnvironmentMapManagerSpec.js:1304:58 <- Build/Specs/SpecList.js:162543:58)
    at <Jasmine>

7) lighting uses ground color value
     Scene/DynamicEnvironmentMapManager render tests
     Expected (0.21471722424030304, 0, 0) to equal epsilon (0.1342056840658188, 0.11958353966474533, 0.15991388261318207), 0.01.
    at <Jasmine>
    at UserContext.<anonymous> (packages/engine/Specs/Scene/DynamicEnvironmentMapManagerSpec.js:1410:58 <- Build/Specs/SpecList.js:162632:58)
    at <Jasmine>
     Expected (0.14920121431350708, 0, 0) to equal epsilon (0.07575193047523499, 0.11915278434753418, 0.15629366040229797), 0.01.
    at <Jasmine>
    at UserContext.<anonymous> (packages/engine/Specs/Scene/DynamicEnvironmentMapManagerSpec.js:1418:58 <- Build/Specs/SpecList.js:162640:58)
    at <Jasmine>

8) lighting uses ground albedo value
     Scene/DynamicEnvironmentMapManager render tests
     Expected (0.3071272671222687, 0.3071272671222687, 0.18753786385059357) to equal epsilon (0.15277373790740967, 0.1812949925661087, 0.19759616255760193), 0.01.
    at <Jasmine>
    at UserContext.<anonymous> (packages/engine/Specs/Scene/DynamicEnvironmentMapManagerSpec.js:1534:58 <- Build/Specs/SpecList.js:162738:58)
    at <Jasmine>
     Expected (0.21341443061828613, 0.21341443061828613, 0.13031496107578278) to equal epsilon (0.0670194923877716, 0.09013032913208008, 0.13857196271419525), 0.01.
    at <Jasmine>
    at UserContext.<anonymous> (packages/engine/Specs/Scene/DynamicEnvironmentMapManagerSpec.js:1542:58 <- Build/Specs/SpecList.js:162746:58)
    at <Jasmine>

@ggetz
Copy link
Contributor Author

ggetz commented May 13, 2025

Thanks for checking @jjhembd! Sorry for the back-and-forth. I've made all the rendering tests relative tests now, instead of any epsilon from an absolute value (which are probably clearer tests of the functionality anyway). Hopefully this works across both our machines 🤞

@jjhembd
Copy link
Contributor

jjhembd commented May 13, 2025

Hi @ggetz, this looks like another improvement. I still have 3 tests failing:

1) produces radiance values with mainly blue direct light
     Scene/DynamicEnvironmentMapManager render tests with static lighting at surface
     Expected 0.23497266155194546 to be greater than 0.3333333333333333.
    at <Jasmine>
    at UserContext.<anonymous> (packages/engine/Specs/Scene/DynamicEnvironmentMapManagerSpec.js:409:28 <- Build/Specs/SpecList.js:161785:28)
    at <Jasmine>

2) produces radiance values with mainly blue direct light
     Scene/DynamicEnvironmentMapManager render tests with dynamic lighting in philadelphia
     Expected 0.2500000535402551 to be greater than 0.3333333333333333.
    at <Jasmine>
    at UserContext.<anonymous> (packages/engine/Specs/Scene/DynamicEnvironmentMapManagerSpec.js:549:28 <- Build/Specs/SpecList.js:161888:28)
    at <Jasmine>

3) produces radiance values with more light reflected from the ground
     Scene/DynamicEnvironmentMapManager render tests with groundAlbedo property
     Expected (0.24079939723014832, 0.24079939723014832, 0.24079939723014832) to be less than (0, 0, 0).
    at <Jasmine>
    at UserContext.<anonymous> (packages/engine/Specs/Scene/DynamicEnvironmentMapManagerSpec.js:863:24 <- Build/Specs/SpecList.js:162117:24)
    at <Jasmine>
     Expected (-0.00046751584159210324, -0.00046751584159210324, -0.00046751584159210324) to be greater than (0, 0, 0).
    at <Jasmine>
    at UserContext.<anonymous> (packages/engine/Specs/Scene/DynamicEnvironmentMapManagerSpec.js:864:23 <- Build/Specs/SpecList.js:162118:23)
    at <Jasmine>
     Expected (0.000542024034075439, 0.000542024034075439, 0.000542024034075439) to be less than (0, 0, 0).
    at <Jasmine>
    at UserContext.<anonymous> (packages/engine/Specs/Scene/DynamicEnvironmentMapManagerSpec.js:865:23 <- Build/Specs/SpecList.js:162119:23)
    at <Jasmine>


TOTAL: 3 FAILED, 44 SUCCESS

I played with the second one,

2) produces radiance values with mainly blue direct light
     Scene/DynamicEnvironmentMapManager render tests with dynamic lighting in philadelphia

The spec includes 5 renders:

          scene.renderForSpecs(time);
          scene.renderForSpecs(time);
          scene.renderForSpecs(time);
          scene.renderForSpecs(time);
          scene.renderForSpecs(time);

I tried different numbers of renders, to see if something wasn't converged yet. But the result is unexpected: any number of renders between 1-4 gives the same value: 0.3333333333333333. (It still fails because it is not "greater than" the test value.) With 5 renders, the value changes to 0.2500000535402551 as above.

@angrycat9000
Copy link
Contributor

Ran into this same bug with the test in ion. Found that we had some tests that were creating a Cesium3DTileset before a Viewer was ever created (and therefore before ContextLimits was initialized). Ended up just creating a Viewer in the test setup to make sure that ContextLimits was initialized and then destroying it. That worked around the issues in our tests.

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

Successfully merging this pull request may close these issues.

Test failures in DynamicEnvironmentMapManager
3 participants