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

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

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

आगे बढ़ने से पहले, पक्का करें कि आपने बुनियादी एआर (ऑगमेंटेड रिएलिटी) सिद्धांत और ARCore सेशन को कॉन्फ़िगर करने का तरीका समझ लिया है.

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

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

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

// 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);

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

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

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

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

  • इस समस्या को ठीक करने का सबसे अच्छा तरीका, पाइपलाइन पर माइग्रेट करना है.

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