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

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

기본 요건

계속 진행하기 전에 기본 AR 개념ARCore 세션 구성 방법을 이해해야 합니다.

적절한 모드로 세션당 한 번씩 API를 구성합니다.

사용하려는 모드에 대해 세션당 한 번씩 광원 추정을 구성합니다.

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 모드를 구성하려면 각 프레임의 예상 광원을 가져온 다음 사용할 환경 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)
}

Environmental HDR API로 에너지 절약

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

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

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

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

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