Skip to content

Commit 15172ec

Browse files
Added HelloAR Android sample
1 parent c16517c commit 15172ec

38 files changed

Lines changed: 2994 additions & 10 deletions

Android/HelloAR/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.cxx

Android/HelloAR/CMakeLists.txt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright (C) 2017 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
##
15+
16+
# For more information about using CMake with Android Studio, read the
17+
# documentation: https://d.android.com/studio/projects/add-native-code.html
18+
19+
# Sets the minimum version of CMake required to build the native library.
20+
21+
cmake_minimum_required(VERSION 3.4.1)
22+
23+
# Import the ARCore library.
24+
add_library(arcore SHARED IMPORTED)
25+
# ARCORE_LIBPATH and ARCORE_INCLUDE are given by gradle to cmake build
26+
set_target_properties(arcore PROPERTIES
27+
IMPORTED_LOCATION ${ARCORE_LIBPATH}/${ANDROID_ABI}/libarcore_sdk_c.so
28+
INTERFACE_INCLUDE_DIRECTORIES ${ARCORE_INCLUDE}
29+
)
30+
31+
# This is the main app library.
32+
add_library(HelloAR SHARED
33+
src/main/cpp/BackgroundRenderer.cc
34+
src/main/cpp/hello_ar_application.cc
35+
src/main/cpp/jni_interface.cc
36+
src/main/cpp/ObjectRenderer.cc
37+
src/main/cpp/PlaneRenderer.cc
38+
src/main/cpp/PointCloudRenderer.cc
39+
src/main/cpp/util.cc
40+
../../Tutorials/Common/src/TexturedCube.cpp
41+
)
42+
43+
target_include_directories(HelloAR PRIVATE
44+
src/main/cpp
45+
)
46+
47+
target_link_libraries(HelloAR
48+
android
49+
log
50+
GLESv3
51+
arcore
52+
Diligent-BuildSettings
53+
Diligent-Common
54+
Diligent-GraphicsEngineOpenGL-shared
55+
Diligent-GraphicsTools
56+
Diligent-TextureLoader)

Android/HelloAR/build.gradle

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
apply plugin: 'com.android.application'
2+
3+
buildDir '../build/HelloAR'
4+
5+
def setVersionName = { ->
6+
if (project.hasProperty("androidVersionName")) {
7+
println("Replacing versionName with supplied build parameter: " +
8+
"$androidVersionName")
9+
return androidVersionName
10+
} else {
11+
return "1.0"
12+
}
13+
}
14+
15+
android {
16+
compileSdkVersion 28
17+
defaultConfig {
18+
applicationId "com.google.ar.core.examples.c.helloar"
19+
20+
// 24 is the minimum since ARCore only works with 24 and higher.
21+
minSdkVersion 24
22+
targetSdkVersion 28
23+
versionCode 1
24+
versionName setVersionName()
25+
}
26+
compileOptions {
27+
sourceCompatibility JavaVersion.VERSION_1_8
28+
targetCompatibility JavaVersion.VERSION_1_8
29+
}
30+
buildTypes {
31+
release {
32+
minifyEnabled false
33+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
34+
}
35+
}
36+
}
37+
38+
dependencies {
39+
implementation project(":Common")
40+
41+
implementation 'com.android.support:appcompat-v7:28.0.0'
42+
implementation 'com.android.support:design:28.0.0'
43+
}

Android/HelloAR/proguard-rules.pro

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /opt/android-sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2017 Google Inc.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
18+
package="com.google.ar.core.examples.c.helloar">
19+
20+
<uses-permission android:name="android.permission.CAMERA"/>
21+
<!-- This tag indicates that this application requires ARCore. This results in the application
22+
only being visible in the Google Play Store on devices that support ARCore. -->
23+
<uses-feature android:name="android.hardware.camera.ar" android:required="true"/>
24+
<uses-feature android:glEsVersion="0x00030000" android:required="true" />
25+
26+
<application
27+
android:allowBackup="true"
28+
android:icon="@drawable/ic_launcher"
29+
android:label="@string/app_name"
30+
android:theme="@style/AppTheme"
31+
android:usesCleartextTraffic="false">
32+
<!-- This tag indicates that this application requires ARCore. This results in the Google Play
33+
Store downloading and installing ARCore along with the application. -->
34+
<meta-data android:name="com.google.ar.core" android:value="required" />
35+
36+
<activity
37+
android:name=".HelloArActivity"
38+
android:label="@string/app_name"
39+
android:configChanges="orientation|screenSize"
40+
android:exported="true"
41+
android:theme="@style/Theme.AppCompat.NoActionBar"
42+
android:screenOrientation="locked">
43+
<intent-filter>
44+
<action android:name="android.intent.action.MAIN"/>
45+
<category android:name="android.intent.category.LAUNCHER"/>
46+
</intent-filter>
47+
</activity>
48+
</application>
49+
</manifest>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
Texture2D g_Texture;
2+
SamplerState g_Texture_sampler;
3+
4+
struct PSInput
5+
{
6+
float4 Pos : SV_POSITION;
7+
float2 UV : TEX_COORD;
8+
};
9+
10+
struct PSOutput
11+
{
12+
float4 Color : SV_TARGET;
13+
};
14+
15+
cbuffer Constants
16+
{
17+
float4x4 g_ModelView;
18+
float4x4 g_ModelViewProjection;
19+
20+
float4 g_LightingParameters;
21+
float4 g_ColorCorrectionParameters;
22+
float4 g_ObjectColor;
23+
}
24+
25+
void main(in PSInput PSIn,
26+
out PSOutput PSOut)
27+
{
28+
float3 Color = g_Texture.Sample(g_Texture_sampler, PSIn.UV).rgb * 0.5;
29+
30+
// Approximate sRGB gamma.
31+
const float kGamma = 0.4545454;
32+
const float kInverseGamma = 2.2;
33+
const float kMiddleGrayGamma = 0.466;
34+
35+
float3 ColorShift = g_ColorCorrectionParameters.rgb;
36+
float AveragePixelIntensity = g_ColorCorrectionParameters.a;
37+
38+
// Apply color to grayscale image only if the alpha of g_ObjectColor is
39+
// greater than or equal to 255.0.
40+
//if (g_ObjectColor.a >= 255.0)
41+
//{
42+
// float intensity = Color.r;
43+
// Color.rgb = g_ObjectColor.rgb * intensity / 255.0;
44+
//}
45+
46+
// Apply sRGB gamma before writing the fragment color.
47+
Color.rgb = pow(Color, float3(kGamma, kGamma, kGamma));
48+
// Apply average pixel intensity and color shift
49+
Color *= ColorShift * (AveragePixelIntensity / kMiddleGrayGamma);
50+
PSOut.Color = float4(Color, 1.0);
51+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
cbuffer Constants
2+
{
3+
float4x4 g_ModelView;
4+
float4x4 g_ModelViewProjection;
5+
6+
float4 g_LightingParameters;
7+
float4 g_ColorCorrectionParameters;
8+
float4 g_ObjectColor;
9+
}
10+
11+
struct VSInput
12+
{
13+
float3 Pos : ATTRIB0;
14+
float2 UV : ATTRIB1;
15+
};
16+
17+
struct PSInput
18+
{
19+
float4 Pos : SV_POSITION;
20+
float2 UV : TEX_COORD;
21+
};
22+
23+
24+
void main(in VSInput VSIn,
25+
out PSInput PSIn)
26+
{
27+
PSIn.Pos = mul(float4((VSIn.Pos + float3(0.0, 0.0, 1.0)) * 0.075, 1.0), g_ModelViewProjection);
28+
PSIn.UV = VSIn.UV;
29+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
Texture2D g_Texture;
3+
SamplerState g_Texture_sampler;
4+
5+
cbuffer Constants
6+
{
7+
float4x4 g_MVP;
8+
float4x4 g_ModelMat;
9+
float4 g_Normal;
10+
float4 g_Color;
11+
}
12+
13+
struct PSInput
14+
{
15+
float4 Pos : SV_POSITION;
16+
float2 UV : TEX_COORD;
17+
float Alpha : ALPHA;
18+
};
19+
20+
struct PSOutput
21+
{
22+
float4 Color : SV_TARGET;
23+
};
24+
25+
void main(in PSInput PSIn,
26+
out PSOutput PSOut)
27+
{
28+
float r = g_Texture.Sample(g_Texture_sampler, PSIn.UV).r;
29+
PSOut.Color = float4(g_Color.rgb, r * PSIn.Alpha);
30+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
cbuffer Constants
3+
{
4+
float4x4 g_MVP;
5+
float4x4 g_ModelMat;
6+
float4 g_Normal;
7+
float4 g_Color;
8+
}
9+
10+
struct VSInput
11+
{
12+
float3 Pos : ATTRIB0;
13+
};
14+
15+
struct PSInput
16+
{
17+
float4 Pos : SV_POSITION;
18+
float2 UV : TEX_COORD;
19+
float Alpha : ALPHA;
20+
};
21+
22+
void main(in VSInput VSIn,
23+
out PSInput PSIn)
24+
{
25+
// Vertex Z value is used as the alpha in this shader.
26+
PSIn.Alpha = VSIn.Pos.z;
27+
28+
float4 LocalPos = float4(VSIn.Pos.x, 0.0, VSIn.Pos.y, 1.0);
29+
PSIn.Pos = mul(LocalPos, g_MVP);
30+
31+
float4 WorldPos = mul(LocalPos, g_ModelMat);
32+
33+
// Construct two vectors that are orthogonal to the normal.
34+
// This arbitrary choice is not co-linear with either horizontal
35+
// or vertical plane normals.
36+
float3 arbitrary = float3(1.0, 1.0, 0.0);
37+
float3 float_u = normalize(cross(g_Normal.xyz, arbitrary));
38+
float3 float_v = normalize(cross(g_Normal.xyz, float_u));
39+
40+
// Project vertices in world frame onto float_u and float_v.
41+
PSIn.UV = float2(dot(WorldPos.xyz, float_u),
42+
dot(WorldPos.xyz, float_v));
43+
}
51.3 KB
Loading

0 commit comments

Comments
 (0)