Skip to content

Commit e28822d

Browse files
jeremyvcdevbridie
authored andcommitted
ARCore Android SDK v1.31.0
1 parent e271aa3 commit e28822d

File tree

151 files changed

+168294
-378
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

151 files changed

+168294
-378
lines changed

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ releases](https://github.com/google-ar/arcore-android-sdk/releases)
1111

1212
are licensed as follows:
1313

14-
Covered by the **Google APIs Terms of Service** at
15-
[https://developers.google.com/terms/](https://developers.google.com/terms/)
14+
Governed by the **ARCore Additional Terms of Service** at
15+
[https://developers.google.com/ar/develop/terms](https://developers.google.com/ar/develop/terms)
1616

1717
===============================================================================
1818
Section 2: ARCore SDK source files

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ The SDK release notes are available on the
4646
## Terms & Conditions
4747

4848
By downloading the ARCore SDK for Android, you agree that the
49-
[Google APIs Terms of Service](//developers.google.com/terms/) governs your use
50-
thereof.
49+
[**ARCore Additional Terms of Service**](https://developers.google.com/ar/develop/terms)
50+
governs your use thereof.
5151

5252

5353
## User privacy requirements

libraries/include/arcore_c_api.h

Lines changed: 722 additions & 13 deletions
Large diffs are not rendered by default.

samples/augmented_faces_java/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ android {
2626

2727
dependencies {
2828
// ARCore (Google Play Services for AR) library.
29-
implementation 'com.google.ar:core:1.30.0'
29+
implementation 'com.google.ar:core:1.31.0'
3030

3131
// Obj - a simple Wavefront OBJ file loader
3232
// https://github.com/javagl/Obj
5.05 KB
Loading

samples/augmented_faces_java/app/src/main/assets/shaders/background_show_depth_color_visualization.frag

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
precision mediump float;
1818

1919
uniform sampler2D u_DepthTexture;
20+
uniform sampler2D u_ColorMap;
2021

2122
varying vec2 v_TexCoord;
2223

23-
const highp float kMaxDepth = 8000.0; // In millimeters.
24+
const float kMidDepthMeters = 8.0;
25+
const float kMaxDepthMeters = 30.0;
2426

2527
float DepthGetMillimeters(in sampler2D depth_texture, in vec2 depth_uv) {
2628
// Depth is packed into the red and green components of its texture.
@@ -29,37 +31,39 @@ float DepthGetMillimeters(in sampler2D depth_texture, in vec2 depth_uv) {
2931
return dot(packedDepthAndVisibility.xy, vec2(255.0, 256.0 * 255.0));
3032
}
3133

32-
// Returns a color corresponding to the depth passed in. Colors range from red
33-
// to green to blue, where red is closest and blue is farthest.
34-
//
35-
// Uses Turbo color mapping:
36-
// https://ai.googleblog.com/2019/08/turbo-improved-rainbow-colormap-for.html
37-
vec3 DepthGetColorVisualization(in float x) {
38-
const vec4 kRedVec4 = vec4(0.55305649, 3.00913185, -5.46192616, -11.11819092);
39-
const vec4 kGreenVec4 = vec4(0.16207513, 0.17712472, 15.24091500, -36.50657960);
40-
const vec4 kBlueVec4 = vec4(-0.05195877, 5.18000081, -30.94853351, 81.96403246);
41-
const vec2 kRedVec2 = vec2(27.81927491, -14.87899417);
42-
const vec2 kGreenVec2 = vec2(25.95549545, -5.02738237);
43-
const vec2 kBlueVec2 = vec2(-86.53476570, 30.23299484);
44-
const float kInvalidDepthThreshold = 0.01;
45-
46-
// Adjusts color space via 6 degree poly interpolation to avoid pure red.
47-
x = clamp(x * 0.9 + 0.03, 0.0, 1.0);
48-
vec4 v4 = vec4(1.0, x, x * x, x * x * x);
49-
vec2 v2 = v4.zw * v4.z;
50-
vec3 polynomial_color = vec3(
51-
dot(v4, kRedVec4) + dot(v2, kRedVec2),
52-
dot(v4, kGreenVec4) + dot(v2, kGreenVec2),
53-
dot(v4, kBlueVec4) + dot(v2, kBlueVec2)
54-
);
34+
// Returns linear interpolation position of value between min and max bounds.
35+
// E.g. InverseLerp(1100, 1000, 2000) returns 0.1.
36+
float InverseLerp(float value, float min_bound, float max_bound) {
37+
return clamp((value - min_bound) / (max_bound - min_bound), 0.0, 1.0);
38+
}
5539

56-
return step(kInvalidDepthThreshold, x) * polynomial_color;
40+
// Returns a color corresponding to the depth passed in.
41+
// The input x is normalized in range 0 to 1.
42+
vec3 DepthGetColorVisualization(in float x) {
43+
return texture2D(u_ColorMap, vec2(x, 0.5)).rgb;
5744
}
5845

5946
void main() {
60-
highp float normalized_depth =
61-
clamp(DepthGetMillimeters(u_DepthTexture, v_TexCoord.xy) / kMaxDepth,
62-
0.0, 1.0);
47+
// Interpolating in units of meters is more stable, due to limited floating
48+
// point precision on GPU.
49+
float depth_mm = DepthGetMillimeters(u_DepthTexture, v_TexCoord.xy);
50+
float depth_meters = depth_mm * 0.001;
51+
52+
// Selects the portion of the color palette to use.
53+
float normalized_depth = 0.0;
54+
if (depth_meters < kMidDepthMeters) {
55+
// Short-range depth (0m to 8m) maps to first half of the color palette.
56+
normalized_depth = InverseLerp(depth_meters, 0.0, kMidDepthMeters) * 0.5;
57+
} else {
58+
// Long-range depth (8m to 30m) maps to second half of the color palette.
59+
normalized_depth =
60+
InverseLerp(depth_meters, kMidDepthMeters, kMaxDepthMeters) * 0.5 + 0.5;
61+
}
62+
63+
// Converts depth to color by with the selected value in the color map.
6364
vec4 depth_color = vec4(DepthGetColorVisualization(normalized_depth), 1.0);
65+
66+
// Invalid depth (pixels with value 0) mapped to black.
67+
depth_color.rgb *= sign(depth_meters);
6468
gl_FragColor = depth_color;
6569
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.ar.core.examples.java.common.helpers;
17+
18+
import android.Manifest;
19+
import android.app.Activity;
20+
import android.content.Intent;
21+
import android.content.pm.PackageManager;
22+
import android.net.Uri;
23+
import android.provider.Settings;
24+
import androidx.core.app.ActivityCompat;
25+
import androidx.core.content.ContextCompat;
26+
27+
/** Helper to ask location permission. */
28+
public final class LocationPermissionHelper {
29+
private static final int LOCATION_PERMISSION_CODE = 1;
30+
private static final String LOCATION_PERMISSION = Manifest.permission.ACCESS_FINE_LOCATION;
31+
32+
/** Check to see we have the necessary permissions for this app. */
33+
public static boolean hasFineLocationPermission(Activity activity) {
34+
return ContextCompat.checkSelfPermission(activity, LOCATION_PERMISSION)
35+
== PackageManager.PERMISSION_GRANTED;
36+
}
37+
38+
/** Check to see we have the necessary permissions for this app, and ask for them if we don't. */
39+
public static void requestFineLocationPermission(Activity activity) {
40+
ActivityCompat.requestPermissions(
41+
activity, new String[] {LOCATION_PERMISSION}, LOCATION_PERMISSION_CODE);
42+
}
43+
44+
/** Check to see if the array of given permissions contain the location permission. */
45+
public static boolean hasFineLocationPermissionsResponseInResult(String[] permissions) {
46+
for (String permission : permissions) {
47+
if (LOCATION_PERMISSION.equals(permission)) {
48+
return true;
49+
}
50+
}
51+
52+
return false;
53+
}
54+
55+
/** Check to see if we need to show the rationale for this permission. */
56+
public static boolean shouldShowRequestPermissionRationale(Activity activity) {
57+
return ActivityCompat.shouldShowRequestPermissionRationale(activity, LOCATION_PERMISSION);
58+
}
59+
60+
/** Launch Application Setting to grant permission. */
61+
public static void launchPermissionSettings(Activity activity) {
62+
Intent intent = new Intent();
63+
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
64+
intent.setData(Uri.fromParts("package", activity.getPackageName(), null));
65+
activity.startActivity(intent);
66+
}
67+
}

samples/augmented_image_c/app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ android {
5353

5454
dependencies {
5555
// ARCore (Google Play Services for AR) library.
56-
implementation 'com.google.ar:core:1.30.0'
57-
natives 'com.google.ar:core:1.30.0'
56+
implementation 'com.google.ar:core:1.31.0'
57+
natives 'com.google.ar:core:1.31.0'
5858

5959
implementation 'androidx.appcompat:appcompat:1.1.0'
6060
implementation 'com.google.android.material:material:1.1.0'
5.05 KB
Loading

samples/augmented_image_c/app/src/main/assets/shaders/background_show_depth_color_visualization.frag

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
precision mediump float;
1818

1919
uniform sampler2D u_DepthTexture;
20+
uniform sampler2D u_ColorMap;
2021

2122
varying vec2 v_TexCoord;
2223

23-
const highp float kMaxDepth = 8000.0; // In millimeters.
24+
const float kMidDepthMeters = 8.0;
25+
const float kMaxDepthMeters = 30.0;
2426

2527
float DepthGetMillimeters(in sampler2D depth_texture, in vec2 depth_uv) {
2628
// Depth is packed into the red and green components of its texture.
@@ -29,37 +31,39 @@ float DepthGetMillimeters(in sampler2D depth_texture, in vec2 depth_uv) {
2931
return dot(packedDepthAndVisibility.xy, vec2(255.0, 256.0 * 255.0));
3032
}
3133

32-
// Returns a color corresponding to the depth passed in. Colors range from red
33-
// to green to blue, where red is closest and blue is farthest.
34-
//
35-
// Uses Turbo color mapping:
36-
// https://ai.googleblog.com/2019/08/turbo-improved-rainbow-colormap-for.html
37-
vec3 DepthGetColorVisualization(in float x) {
38-
const vec4 kRedVec4 = vec4(0.55305649, 3.00913185, -5.46192616, -11.11819092);
39-
const vec4 kGreenVec4 = vec4(0.16207513, 0.17712472, 15.24091500, -36.50657960);
40-
const vec4 kBlueVec4 = vec4(-0.05195877, 5.18000081, -30.94853351, 81.96403246);
41-
const vec2 kRedVec2 = vec2(27.81927491, -14.87899417);
42-
const vec2 kGreenVec2 = vec2(25.95549545, -5.02738237);
43-
const vec2 kBlueVec2 = vec2(-86.53476570, 30.23299484);
44-
const float kInvalidDepthThreshold = 0.01;
45-
46-
// Adjusts color space via 6 degree poly interpolation to avoid pure red.
47-
x = clamp(x * 0.9 + 0.03, 0.0, 1.0);
48-
vec4 v4 = vec4(1.0, x, x * x, x * x * x);
49-
vec2 v2 = v4.zw * v4.z;
50-
vec3 polynomial_color = vec3(
51-
dot(v4, kRedVec4) + dot(v2, kRedVec2),
52-
dot(v4, kGreenVec4) + dot(v2, kGreenVec2),
53-
dot(v4, kBlueVec4) + dot(v2, kBlueVec2)
54-
);
34+
// Returns linear interpolation position of value between min and max bounds.
35+
// E.g. InverseLerp(1100, 1000, 2000) returns 0.1.
36+
float InverseLerp(float value, float min_bound, float max_bound) {
37+
return clamp((value - min_bound) / (max_bound - min_bound), 0.0, 1.0);
38+
}
5539

56-
return step(kInvalidDepthThreshold, x) * polynomial_color;
40+
// Returns a color corresponding to the depth passed in.
41+
// The input x is normalized in range 0 to 1.
42+
vec3 DepthGetColorVisualization(in float x) {
43+
return texture2D(u_ColorMap, vec2(x, 0.5)).rgb;
5744
}
5845

5946
void main() {
60-
highp float normalized_depth =
61-
clamp(DepthGetMillimeters(u_DepthTexture, v_TexCoord.xy) / kMaxDepth,
62-
0.0, 1.0);
47+
// Interpolating in units of meters is more stable, due to limited floating
48+
// point precision on GPU.
49+
float depth_mm = DepthGetMillimeters(u_DepthTexture, v_TexCoord.xy);
50+
float depth_meters = depth_mm * 0.001;
51+
52+
// Selects the portion of the color palette to use.
53+
float normalized_depth = 0.0;
54+
if (depth_meters < kMidDepthMeters) {
55+
// Short-range depth (0m to 8m) maps to first half of the color palette.
56+
normalized_depth = InverseLerp(depth_meters, 0.0, kMidDepthMeters) * 0.5;
57+
} else {
58+
// Long-range depth (8m to 30m) maps to second half of the color palette.
59+
normalized_depth =
60+
InverseLerp(depth_meters, kMidDepthMeters, kMaxDepthMeters) * 0.5 + 0.5;
61+
}
62+
63+
// Converts depth to color by with the selected value in the color map.
6364
vec4 depth_color = vec4(DepthGetColorVisualization(normalized_depth), 1.0);
65+
66+
// Invalid depth (pixels with value 0) mapped to black.
67+
depth_color.rgb *= sign(depth_meters);
6468
gl_FragColor = depth_color;
6569
}

0 commit comments

Comments
 (0)