বাস্তবসম্মতভাবে একটি দৃশ্যে ভার্চুয়াল বস্তুকে আলোকিত করুন

আপনার নিজের অ্যাপে লাইটিং এস্টিমেশন কীভাবে ব্যবহার করবেন তা শিখুন।

পূর্বশর্ত

এগিয়ে যাওয়ার আগে নিশ্চিত হয়ে নিন যে আপনি AR-এর মৌলিক ধারণাগুলো এবং কীভাবে একটি ARCore সেশন কনফিগার করতে হয় তা বোঝেন।

প্রতি সেশনে একবার উপযুক্ত মোড ব্যবহার করে API কনফিগার করুন।

আপনি যে মোডটি ব্যবহার করতে চান, তার জন্য প্রতি সেশনে একবার লাইটিং এস্টিমেশন কনফিগার করুন।

পরিবেশগত HDR

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

তারপর বর্তমান কনফিগারেশনের জন্য পরিবেশগত HDR লাইটিং উপাদানগুলো সংগ্রহ করুন:

পরিবেশগত HDR

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

পরিবেশগত HDR API-এর মাধ্যমে শক্তি সংরক্ষণ নিশ্চিত করা

শক্তি সংরক্ষণ নীতি অনুযায়ী, কোনো পৃষ্ঠতল থেকে প্রতিফলিত আলোর তীব্রতা সেই পৃষ্ঠতলে আঘাত করার আগের তীব্রতার চেয়ে কখনোই বেশি হবে না। এই নিয়মটি ভৌত-ভিত্তিক রেন্ডারিং-এ প্রয়োগ করা হয়, কিন্তু ভিডিও গেম এবং মোবাইল অ্যাপে ব্যবহৃত পুরোনো রেন্ডারিং পাইপলাইনগুলো থেকে এটি সাধারণত বাদ দেওয়া হয়।

আপনি যদি এনভায়রনমেন্টাল এইচডিআর লাইট এস্টিমেশন সহ একটি ফিজিক্যালি-বেসড রেন্ডারিং পাইপলাইন ব্যবহার করেন, তাহলে শুধু নিশ্চিত করুন যে আপনার ভার্চুয়াল অবজেক্টগুলোতে ফিজিক্যালি-বেসড ম্যাটেরিয়াল ব্যবহার করা হয়েছে।

তবে, আপনি যদি ফিজিক্যালি-বেসড পাইপলাইন ব্যবহার না করেন, তাহলে আপনার কাছে কয়েকটি বিকল্প রয়েছে:

  • এর সবচেয়ে আদর্শ সমাধান হলো ভৌত-ভিত্তিক পাইপলাইনে স্থানান্তরিত হওয়া।

  • তবে, যদি তা সম্ভব না হয়, তাহলে একটি ভালো বিকল্প উপায় হলো কোনো অবাস্তব-ভিত্তিক উপাদানের অ্যালবেডো মানকে একটি শক্তি সংরক্ষণ গুণক দিয়ে গুণ করা। এর মাধ্যমে অন্তত এটা নিশ্চিত করা যায় যে BRDF শেডিং মডেলটিকে বাস্তব-ভিত্তিক মডেলে রূপান্তর করা যাবে। প্রতিটি BRDF-এর জন্য গুণকটি ভিন্ন হয় — উদাহরণস্বরূপ, একটি ডিফিউজ প্রতিফলনের জন্য এটি হলো 1/Pi।