장면에서 현실적으로 밝은 가상 객체

자체 앱에서 밝기 추정을 사용하는 방법을 알아보세요.

기본 요건

계속 진행하기 전에 기본 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);

Environmental HDR API로 에너지 절약

에너지 절약은 표면에서 반사되는 빛이 표면에 닿기 전보다 더 강하지 않다는 원칙입니다. 이 규칙은 물리적 기반 렌더링에 적용되지만 일반적으로 비디오 게임 및 모바일 앱에 사용되는 기존 렌더링 파이프라인에서는 생략됩니다.

환경 HDR 광도 추정과 함께 물리적 기반 렌더링 파이프라인을 사용하는 경우 가상 객체에 물리적 기반 머티리얼이 사용되는지 확인하면 됩니다.

그러나 물리적 기반 파이프라인을 사용하지 않는 경우에는 몇 가지 옵션이 있습니다.

  • 가장 이상적인 솔루션은 물리적 기반 파이프라인으로 마이그레이션하는 것입니다.

  • 하지만 그럴 수 없다면 비물리적 기반 물질의 알베도 값에 에너지 보존 계수를 곱하는 것이 좋습니다. 이렇게 하면 최소한 BRDF 셰이딩 모델을 물리적 기반으로 변환할 수 있습니다. 각 BRDF에는 다른 계수가 있습니다. 예를 들어 확산 반사의 경우 1/Pi입니다.