किसी सीन में वर्चुअल ऑब्जेक्ट को असल में दिखाना

अपने ऐप्लिकेशन में लाइटिंग एस्टिमेशन का इस्तेमाल करने का तरीका जानें.

ज़रूरी शर्तें

आगे बढ़ने से पहले, पक्का करें कि आपको एआर से जुड़े बुनियादी कॉन्सेप्ट और एआरकोर सेशन को कॉन्फ़िगर करने का तरीका पता हो.

हर सेशन के लिए, सही मोड के साथ एपीआई को एक बार कॉन्फ़िगर करना

हर सेशन के लिए, लाइटिंग एस्टिमेशन को एक बार कॉन्फ़िगर करें. इसके लिए, वह मोड चुनें जिसका आपको इस्तेमाल करना है.

एनवायरमेंटल एचडीआर

// Configure the session's lighting estimation mode for
// AR_LIGHT_ESTIMATION_MODE_ENVIRONMENTAL_HDR.
ArConfig* config = NULL;
ArConfig_create(session, &config);
ArSession_getConfig(session, config);
ArConfig_setLightEstimationMode(session, config,
                                AR_LIGHT_ESTIMATION_MODE_ENVIRONMENTAL_HDR);
ArSession_configure(session, config);
ArConfig_destroy(config);

ऐंबियंट इंटेंसिटी

// Configure the session's lighting estimation mode for
// AR_LIGHT_ESTIMATION_MODE_AMBIENT_INTENSITY.
ArConfig* config = NULL;
ArConfig_create(session, &config);
ArSession_getConfig(session, config);
ArConfig_setLightEstimationMode(session, config,
                                AR_LIGHT_ESTIMATION_MODE_AMBIENT_INTENSITY);
ArSession_configure(session, config);
ArConfig_destroy(config);

बंद है

// Disable the session's lighting estimation mode.
ArConfig* config = NULL;
ArConfig_create(session, &config);
ArSession_getConfig(session, config);
ArConfig_setLightEstimationMode(session, config,
                                AR_LIGHT_ESTIMATION_MODE_DISABLED);
ArSession_configure(session, config);
ArConfig_destroy(config);

लाइटिंग एस्टिमेशन से मिली वैल्यू का इस्तेमाल करना

लाइटिंग एस्टिमेशन से मिली वैल्यू का इस्तेमाल करने के लिए, हर फ़्रेम के लिए रोशनी का अनुमान पाएं.

// Get the current frame.
ArFrame* ar_frame = NULL;
if (ArSession_update(session, ar_frame) != AR_SUCCESS) {
  LOGE("ArSession_update error");
  return;
}

// Get the light estimate for the current frame.
ArLightEstimate* ar_light_estimate = NULL;
ArLightEstimate_create(session, &ar_light_estimate);
ArFrame_getLightEstimate(session, ar_frame, ar_light_estimate);

ArLightEstimateState ar_light_estimate_state;
ArLightEstimate_getState(session, ar_light_estimate,
                         &ar_light_estimate_state);

// Check that the light estimate is valid before proceeding.
if (ar_light_estimate_state != AR_LIGHT_ESTIMATE_STATE_VALID) {
  LOGE("ArLightEstimateState is not valid.");
  ArLightEstimate_destroy(ar_light_estimate);
  return;
}

इसके बाद, मौजूदा कॉन्फ़िगरेशन के लिए, एनवायरमेंटल एचडीआर लाइटिंग कॉम्पोनेंट पाएं:

एनवायरमेंटल एचडीआर

// Get intensity and direction of the main directional light from the current
// light estimate.
float direction[3];
ArLightEstimate_getEnvironmentalHdrMainLightDirection(
    session, ar_light_estimate, direction);

float intensity[3];
ArLightEstimate_getEnvironmentalHdrMainLightIntensity(
    session, ar_light_estimate, intensity);

// Get ambient lighting as spherical harmonics coefficients.
float ambient_spherical_harmonics[27];
ArLightEstimate_getEnvironmentalHdrAmbientSphericalHarmonics(
    session, ar_light_estimate, ambient_spherical_harmonics);

// Get HDR environmental lighting as a cubemap in linear color space.
ArImageCubemap cubemap_textures;
ArLightEstimate_acquireEnvironmentalHdrCubemap(session, ar_light_estimate,
                                               cubemap_textures);
int width = -1;
int height = -1;
int32_t format = -1;
for (int i = 0; i < 6; ++i) {
  ArImage* image_ptr = cubemap_textures[i];
  // We can access the cubemap texture data through ArImage APIs.
  ArImage_getWidth(session, image_ptr, &width);
  ArImage_getHeight(session, image_ptr, &height);
  ArImage_getFormat(session, image_ptr, &format);
  // Acquired image must be released with ArImage_release once it is no
  // longer needed.
  ArImage_release(image_ptr);
}
ArLightEstimate_destroy(ar_light_estimate);

ऐंबियंट इंटेंसिटी

// Get the pixel intensity of AR_LIGHT_ESTIMATION_MODE_AMBIENT_INTENSITY mode.
float pixel_intensity;
ArLightEstimate_getPixelIntensity(session, ar_light_estimate,
                                  &pixel_intensity);

// Get the pixel color correction of
// AR_LIGHT_ESTIMATION_MODE_AMBIENT_INTENSITY mode.
float color_correction[4];
ArLightEstimate_getColorCorrection(session, ar_light_estimate,
                                   color_correction);
ArLightEstimate_destroy(ar_light_estimate);

एनवायरमेंटल एचडीआर एपीआई की मदद से ऊर्जा बचाना पक्का करना

ऊर्जा बचाने का मतलब है कि किसी सरफ़ेस से रिफ़्लेक्ट होने वाली रोशनी, उस रोशनी से ज़्यादा इंटेंस नहीं होगी जो सरफ़ेस पर पड़ने से पहले थी. फ़िज़िकली-बेस्ड रेंडरिंग में इस नियम का पालन किया जाता है. हालांकि, वीडियो गेम और मोबाइल ऐप्लिकेशन में इस्तेमाल होने वाले लेगसी रेंडरिंग पाइपलाइन में आम तौर पर इस नियम का पालन नहीं किया जाता है.

अगर एनवायरमेंटल एचडीआर लाइटिंग एस्टिमेशन के साथ फ़िज़िकली-बेस्ड रेंडरिंग पाइपलाइन का इस्तेमाल किया जा रहा है, तो पक्का करें कि आपके वर्चुअल ऑब्जेक्ट में फ़िज़िकली-बेस्ड मटीरियल का इस्तेमाल किया गया हो.

हालांकि, अगर फ़िज़िकली-बेस्ड पाइपलाइन का इस्तेमाल नहीं किया जा रहा है, तो आपके पास ये विकल्प हैं:

  • इसके लिए, सबसे सही तरीका है कि फ़िज़िकली-बेस्ड पाइपलाइन पर माइग्रेट किया जाए.

  • हालांकि, अगर ऐसा नहीं किया जा सकता, तो एक अच्छा तरीका यह है कि नॉन-फ़िज़िकली-बेस्ड मटीरियल से ऐल्बिडो वैल्यू को, एनर्जी कंज़र्वेशन फ़ैक्टर से गुणा किया जाए. इससे पक्का किया जा सकता है कि कम से कम बीआरडीएफ़ शेडिंग मॉडल को फ़िज़िकली-बेस्ड में बदला जा सके. हर बीआरडीएफ़ का फ़ैक्टर अलग होता है. उदाहरण के लिए, डिफ़्यूज़ रिफ़्लेक्शन के लिए यह 1/Pi होता है.