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

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

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

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

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

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

Java

// Configure the session with the Lighting Estimation API in ENVIRONMENTAL_HDR mode.
Config config = session.getConfig();
config.setLightEstimationMode(LightEstimationMode.ENVIRONMENTAL_HDR);
session.configure(config);

// Configure the session with the Lighting Estimation API in AMBIENT_INTENSITY mode.
Config config = session.getConfig();
config.setLightEstimationMode(LightEstimationMode.AMBIENT_INTENSITY);
session.configure(config);

// Configure the session with the Lighting Estimation API turned off.
Config config = session.getConfig();
config.setLightEstimationMode(LightEstimationMode.DISABLED);
session.configure(config);

Kotlin

// Configure the session with the Lighting Estimation API in ENVIRONMENTAL_HDR mode.
Config config = session.config
config.lightEstimationMode = LightEstimationMode.ENVIRONMENTAL_HDR
session.configure(config)

// Configure the session with the Lighting Estimation API in AMBIENT_INTENSITY mode.
Config config = session.config
config.lightEstimationMode = LightEstimationMode.AMBIENT_INTENSITY
session.configure(config)

// Configure the session with the Lighting Estimation API turned off.
Config config = session.config
config.lightEstimationMode = LightEstimationMode.DISABLED
session.configure(config)

ENVIRONMENTAL_HDR मोड कॉन्फ़िगर करें

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

Java

void update() {
  // Get the current frame.
  Frame frame = session.update();

  // Get the light estimate for the current frame.
  LightEstimate lightEstimate = frame.getLightEstimate();

  // Get intensity and direction of the main directional light from the current light estimate.
  float[] intensity = lightEstimate.getEnvironmentalHdrMainLightIntensity(); // note - currently only out param.
  float[] direction = lightEstimate.getEnvironmentalHdrMainLightDirection();
  app.setDirectionalLightValues(intensity, direction); // app-specific code.

  // Get ambient lighting as spherical harmonics coefficients.
  float[] harmonics = lightEstimate.getEnvironmentalHdrAmbientSphericalHarmonics();
  app.setAmbientSphericalHarmonicsLightValues(harmonics); // app-specific code.

  // Get HDR environmental lighting as a cubemap in linear color space.
  Image[] lightmaps = lightEstimate.acquireEnvironmentalHdrCubeMap();
  for (int i = 0; i < lightmaps.length /*should be 6*/; ++i) {
    app.uploadToTexture(i, lightmaps[i]);  // app-specific code.
  }
}

Kotlin

fun update() {
  // Get the current frame.
  val frame = session.update()

  // Get the light estimate for the current frame.
  val lightEstimate = frame.lightEstimate

  // Get intensity and direction of the main directional light from the current light estimate.
  val intensity = lightEstimate.environmentalHdrMainLightIntensity
  val direction = lightEstimate.environmentalHdrMainLightDirection
  app.setDirectionalLightValues(intensity, direction) // app-specific code.

  // Get ambient lighting as spherical harmonics coefficients.
  val harmonics = lightEstimate.environmentalHdrAmbientSphericalHarmonics
  app.ambientSphericalHarmonicsLightValues = harmonics // app-specific code.

  // Get HDR environmental lighting as a cubemap in linear color space.
  val lightMaps = lightEstimate.acquireEnvironmentalHdrCubeMap();
  for ((index, lightMap) in lightMaps.withIndex()) { // 6 maps total.
    app.uploadToTexture(index, lightMap); // app-specific code.
  }
}

AMBIENT_INTENSITY मोड कॉन्फ़िगर करें

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

Java

 // Avoid allocation on every frame.
float[] colorCorrection = new float[4];

Kotlin

val colorCorrection = floatArrayOf(0.0f, 0.0f, 0.0f, 0.0f)

हर फ़्रेम के लिए रोशनी का अनुमान लगाएं और फिर, आस-पास के माहौल की तीव्रता के कॉम्पोनेंट पाएं.

Java

void update() {
  // Get the current frame.
  Frame frame = session.update();

  // Get the light estimate for the current frame.
  LightEstimate lightEstimate = frame.getLightEstimate();

  // Get the pixel intensity of AMBIENT_INTENSITY mode.
  float pixelIntensity = lightEstimate.getPixelIntensity();

  // Read the pixel color correction of AMBIENT_INTENSITY mode into colorCorrection.
  lightEstimate.getColorCorrection(colorCorrection, 0);
}

Kotlin

fun update() {
    // Get the current frame.
  val frame = session.update()

  // Get the light estimate for the current frame.
  val lightEstimate = frame.lightEstimate

  // Get the pixel intensity of AMBIENT_INTENSITY mode.
  val pixelIntensity = lightEstimate.pixelIntensity

  // Read the pixel color correction of AMBIENT_INTENSITY mode into colorCorrection.
  lightEstimate.getColorCorrection(colorCorrection, 0)
}

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

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

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

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

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

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