xrFrame_getLightEstimate_valid.https.html (3745B)
1 <!DOCTYPE html> 2 <body> 3 <script src=/resources/testharness.js></script> 4 <script src=/resources/testharnessreport.js></script> 5 <script src="../resources/webxr_util.js"></script> 6 <script src="../resources/webxr_test_asserts.js"></script> 7 <script src="../resources/webxr_test_constants.js"></script> 8 9 <script> 10 let testName = "Can get XRLightEstimates during frame"; 11 let fakeDeviceInitParams = IMMERSIVE_AR_DEVICE; 12 13 let fakeEstimateCoefficients = [ 14 0.01, 0.02, 0.03, 15 0.04, 0.05, 0.06, 16 0.07, 0.08, 0.09, 17 0.10, 0.11, 0.12, 18 0.13, 0.14, 0.15, 19 0.16, 0.17, 0.18, 20 0.19, 0.20, 0.21, 21 0.22, 0.23, 0.24, 22 0.25, 0.26, 0.27 23 ]; 24 25 let fakeDirectionInit = { x: 1.0, y: 0.0, z: 0.0, w: 0.0 }; 26 let fakeIntensityInit = { x: 0.0, y: 0.0, z: 1.0, w: 1.0 }; 27 28 let testFunction = (session, controller, t) => new Promise((resolve) => { 29 let lightProbe = null; 30 function onFrameWithNoLightEstimation(time, frame) { 31 let estimate = frame.getLightEstimate(lightProbe); 32 t.step(() => { 33 assert_equals(estimate, null); 34 }); 35 36 controller.setLightEstimate({ 37 sphericalHarmonicsCoefficients: fakeEstimateCoefficients 38 }); 39 40 requestSkipAnimationFrame(session, onFrameWithCoefficients); 41 } 42 43 function onFrameWithCoefficients(time, frame) { 44 let estimate = frame.getLightEstimate(lightProbe); 45 t.step(() => { 46 assert_not_equals(estimate, null); 47 assert_equals(estimate.sphericalHarmonicsCoefficients.length, 27); 48 assert_point_approx_equals(estimate.primaryLightDirection, { x: 0.0, y: 1.0, z: 0.0, w: 0.0 }); 49 assert_point_approx_equals(estimate.primaryLightIntensity, { x: 0.0, y: 0.0, z: 0.0, w: 1.0 }); 50 }); 51 52 controller.setLightEstimate({ 53 sphericalHarmonicsCoefficients: fakeEstimateCoefficients, 54 primaryLightDirection: fakeDirectionInit, 55 }); 56 57 requestSkipAnimationFrame(session, onFrameWithDirection); 58 } 59 60 function onFrameWithDirection(time, frame) { 61 let estimate = frame.getLightEstimate(lightProbe); 62 t.step(() => { 63 assert_not_equals(estimate, null); 64 assert_equals(estimate.sphericalHarmonicsCoefficients.length, 27); 65 assert_point_approx_equals(estimate.primaryLightDirection, fakeDirectionInit); 66 assert_point_approx_equals(estimate.primaryLightIntensity, { x: 0.0, y: 0.0, z: 0.0, w: 1.0 }); 67 }); 68 69 controller.setLightEstimate({ 70 sphericalHarmonicsCoefficients: fakeEstimateCoefficients, 71 primaryLightDirection: fakeDirectionInit, 72 primaryLightIntensity: fakeIntensityInit 73 }); 74 75 requestSkipAnimationFrame(session, onFrameWithDirectionAndIntensity); 76 } 77 78 function onFrameWithDirectionAndIntensity(time, frame) { 79 let estimate = frame.getLightEstimate(lightProbe); 80 t.step(() => { 81 assert_not_equals(estimate, null); 82 assert_equals(estimate.sphericalHarmonicsCoefficients.length, 27); 83 assert_point_approx_equals(estimate.primaryLightDirection, fakeDirectionInit); 84 assert_point_approx_equals(estimate.primaryLightIntensity, fakeIntensityInit); 85 }); 86 87 resolve(); 88 } 89 90 // Request a default lightProbe 91 session.requestLightProbe({reflectionFormat: session.preferredReflectionFormat }).then((probe) => { 92 lightProbe = probe; 93 session.requestAnimationFrame(onFrameWithNoLightEstimation); 94 }); 95 }); 96 97 xr_session_promise_test( 98 testName, 99 testFunction, 100 IMMERSIVE_AR_DEVICE, 101 'immersive-ar', {'requiredFeatures': ['light-estimation']}); 102 103 </script> 104 </body>