Bir sahnedeki sanal nesneleri gerçekçi bir şekilde ışıklandırın

Işıklandırma Tahmini'ni kendi uygulamalarınızda nasıl kullanacağınızı öğrenin.

Ön koşullar

Devam etmeden önce temel AR kavramlarını ve ARCore oturumunu nasıl yapılandıracağınızı anladığınızdan emin olun.

API'yi uygun modla oturum başına bir kez yapılandırın.

Kullanmak istediğiniz mod için Işık Tahmini'ni oturum başına bir kez yapılandırın.

Çevresel 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);

Ortam Yoğunluğu

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

Devre dışı

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

Işık Tahmini'nden elde edilen değerleri kullanın

Işık Tahmini'nden elde edilen değerleri kullanmak için her kareye ait ışık tahminini alın.

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

Ardından mevcut yapılandırmanın çevresel HDR ışıklandırma bileşenlerini edinin:

Çevresel 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);

Ortam Yoğunluğu

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

Environmental HDR API'leriyle enerji tasarrufunu sağlama

Enerji tasarrufu, bir yüzeyden yansıyan ışığın, yüzeye çarpmadan önce olduğundan daha yoğun olmaması ilkesine dayanır. Bu kural, fiziksel olarak oluşturma işleminde uygulanır ancak genellikle video oyunları ve mobil uygulamalarda kullanılan eski oluşturma ardışık düzenlerinden çıkarılır.

Çevresel HDR ışık tahmini içeren fiziksel tabanlı bir oluşturma ardışık düzeni kullanıyorsanız sanal nesnelerinizde fiziksel tabanlı malzemelerin kullanıldığından emin olmanız yeterlidir.

Ancak fiziksel tabanlı bir ardışık düzen kullanmıyorsanız birkaç seçeneğiniz vardır:

  • Bunun için en ideal çözüm, fiziksel tabanlı bir ardışık düzene geçmektir.

  • Ancak bu mümkün değilse iyi bir çözüm, fiziksel olmayan bir malzemeden elde edilen albedo değerini bir enerji tasarrufu faktörüyle çarpmaktır. Bu, en azından BRDF gölgelendirme modelinin fiziksel tabanlı biçime dönüştürülebilmesini sağlar. Her BRDF'nin farklı bir faktörü vardır. Örneğin, dağınık yansıma için 1/Pi'dır.