diff --git a/android/filament-android/src/main/cpp/Engine.cpp b/android/filament-android/src/main/cpp/Engine.cpp
index 4b3b33e530..f571422255 100644
--- a/android/filament-android/src/main/cpp/Engine.cpp
+++ b/android/filament-android/src/main/cpp/Engine.cpp
@@ -571,3 +571,9 @@ Java_com_google_android_filament_Engine_nBuilderBuild(JNIEnv*, jclass, jlong nat
Engine::Builder* builder = (Engine::Builder*) nativeBuilder;
return (jlong) builder->build();
}
+
+extern "C"
+JNIEXPORT jlong JNICALL
+Java_com_google_android_filament_Engine_getSteadyClockTimeNano(JNIEnv *env, jclass clazz) {
+ return (jlong)Engine::getSteadyClockTimeNano();
+}
diff --git a/android/filament-android/src/main/cpp/Material.cpp b/android/filament-android/src/main/cpp/Material.cpp
index 7ef3b0b5be..e923d210b0 100644
--- a/android/filament-android/src/main/cpp/Material.cpp
+++ b/android/filament-android/src/main/cpp/Material.cpp
@@ -25,12 +25,17 @@ using namespace filament;
extern "C" JNIEXPORT jlong JNICALL
Java_com_google_android_filament_Material_nBuilderBuild(JNIEnv *env, jclass,
- jlong nativeEngine, jobject buffer_, jint size) {
+ jlong nativeEngine, jobject buffer_, jint size, jint shBandCount) {
Engine* engine = (Engine*) nativeEngine;
AutoBuffer buffer(env, buffer_, size);
- Material* material = Material::Builder()
+ auto builder = Material::Builder();
+ if (shBandCount) {
+ builder.sphericalHarmonicsBandCount(shBandCount);
+ }
+ Material* material = builder
.package(buffer.getData(), buffer.getSize())
.build(*engine);
+
return (jlong) material;
}
diff --git a/android/filament-android/src/main/cpp/Renderer.cpp b/android/filament-android/src/main/cpp/Renderer.cpp
index c48b616f56..1dc252d356 100644
--- a/android/filament-android/src/main/cpp/Renderer.cpp
+++ b/android/filament-android/src/main/cpp/Renderer.cpp
@@ -187,3 +187,10 @@ Java_com_google_android_filament_Renderer_nSetPresentationTime(JNIEnv *, jclass
Renderer *renderer = (Renderer *) nativeRenderer;
renderer->setPresentationTime(monotonicClockNanos);
}
+
+extern "C" JNIEXPORT void JNICALL
+Java_com_google_android_filament_Renderer_nSetVsyncTime(JNIEnv *, jclass,
+ jlong nativeRenderer, jlong steadyClockTimeNano) {
+ Renderer *renderer = (Renderer *) nativeRenderer;
+ renderer->setVsyncTime(steadyClockTimeNano);
+}
diff --git a/android/filament-android/src/main/java/com/google/android/filament/Engine.java b/android/filament-android/src/main/java/com/google/android/filament/Engine.java
index 5a28d1eae8..6c4c5119e3 100644
--- a/android/filament-android/src/main/java/com/google/android/filament/Engine.java
+++ b/android/filament-android/src/main/java/com/google/android/filament/Engine.java
@@ -1292,7 +1292,6 @@ public class Engine {
/**
* Switch the command queue to unprotected mode. Protected mode can be activated via
* Renderer::beginFrame() using a protected SwapChain.
-
* @see Renderer
* @see SwapChain
*/
@@ -1300,6 +1299,13 @@ public class Engine {
nUnprotected(getNativeObject());
}
+ /**
+ * Get the current time. This is a convenience function that simply returns the
+ * time in nanosecond since epoch of std::chrono::steady_clock.
+ * @return current time in nanosecond since epoch of std::chrono::steady_clock.
+ * @see Renderer#beginFrame
+ */
+ public static native long getSteadyClockTimeNano();
@UsedByReflection("TextureHelper.java")
public long getNativeObject() {
diff --git a/android/filament-android/src/main/java/com/google/android/filament/Material.java b/android/filament-android/src/main/java/com/google/android/filament/Material.java
index 80b143ee80..cd71bbae73 100644
--- a/android/filament-android/src/main/java/com/google/android/filament/Material.java
+++ b/android/filament-android/src/main/java/com/google/android/filament/Material.java
@@ -346,6 +346,7 @@ public class Material {
public static class Builder {
private Buffer mBuffer;
private int mSize;
+ private int mShBandCount = 0;
/**
* Specifies the material data. The material data is a binary blob produced by
@@ -361,6 +362,22 @@ public class Material {
return this;
}
+ /**
+ * Sets the quality of the indirect lights computations. This is only taken into account
+ * if this material is lit and in the surface domain. This setting will affect the
+ * IndirectLight computation if one is specified on the Scene and Spherical Harmonics
+ * are used for the irradiance.
+ *
+ * @param shBandCount Number of spherical harmonic bands. Must be 1, 2 or 3 (default).
+ * @return Reference to this Builder for chaining calls.
+ * @see IndirectLight
+ */
+ @NonNull
+ public Builder sphericalHarmonicsBandCount(@IntRange(from = 0) int shBandCount) {
+ mShBandCount = shBandCount;
+ return this;
+ }
+
/**
* Creates and returns the Material object.
*
@@ -372,7 +389,8 @@ public class Material {
*/
@NonNull
public Material build(@NonNull Engine engine) {
- long nativeMaterial = nBuilderBuild(engine.getNativeObject(), mBuffer, mSize);
+ long nativeMaterial = nBuilderBuild(engine.getNativeObject(),
+ mBuffer, mSize, mShBandCount);
if (nativeMaterial == 0) throw new IllegalStateException("Couldn't create Material");
return new Material(nativeMaterial);
}
@@ -1023,7 +1041,7 @@ public class Material {
mNativeObject = 0;
}
- private static native long nBuilderBuild(long nativeEngine, @NonNull Buffer buffer, int size);
+ private static native long nBuilderBuild(long nativeEngine, @NonNull Buffer buffer, int size, int shBandCount);
private static native long nCreateInstance(long nativeMaterial);
private static native long nCreateInstanceWithName(long nativeMaterial, @NonNull String name);
private static native long nGetDefaultInstance(long nativeMaterial);
diff --git a/android/filament-android/src/main/java/com/google/android/filament/Renderer.java b/android/filament-android/src/main/java/com/google/android/filament/Renderer.java
index ab70e9ed38..4fb447db2c 100644
--- a/android/filament-android/src/main/java/com/google/android/filament/Renderer.java
+++ b/android/filament-android/src/main/java/com/google/android/filament/Renderer.java
@@ -284,6 +284,19 @@ public class Renderer {
nSetPresentationTime(getNativeObject(), monotonicClockNanos);
}
+ /**
+ * The use of this method is optional. It sets the VSYNC time expressed as the duration in
+ * nanosecond since epoch of std::chrono::steady_clock.
+ * If called, passing 0 to frameTimeNanos in Renderer.BeginFrame will use this
+ * time instead.
+ * @param steadyClockTimeNano duration in nanosecond since epoch of std::chrono::steady_clock
+ * @see Engine#getSteadyClockTimeNano
+ * @see Renderer#beginFrame
+ */
+ public void setVsyncTime(long steadyClockTimeNano) {
+ nSetVsyncTime(getNativeObject(), steadyClockTimeNano);
+ }
+
/**
* Sets up a frame for this Renderer.
*
beginFrame manages frame pacing, and returns whether or not a frame should be
@@ -702,6 +715,7 @@ public class Renderer {
}
private static native void nSetPresentationTime(long nativeObject, long monotonicClockNanos);
+ private static native void nSetVsyncTime(long nativeObject, long steadyClockTimeNano);
private static native boolean nBeginFrame(long nativeRenderer, long nativeSwapChain, long frameTimeNanos);
private static native void nEndFrame(long nativeRenderer);
private static native void nRender(long nativeRenderer, long nativeView);
diff --git a/filament/include/filament/Engine.h b/filament/include/filament/Engine.h
index 2aed82736f..1c44fe9ab9 100644
--- a/filament/include/filament/Engine.h
+++ b/filament/include/filament/Engine.h
@@ -1021,6 +1021,21 @@ public:
void resetBackendState() noexcept;
#endif
+ /**
+ * Get the current time. This is a convenience function that simply returns the
+ * time in nanosecond since epoch of std::chrono::steady_clock.
+ * A possible implementation is:
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ * return std::chrono::steady_clock::now().time_since_epoch().count();
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * @return current time in nanosecond since epoch of std::chrono::steady_clock.
+ * @see Renderer::beginFrame()
+ */
+ static uint64_t getSteadyClockTimeNano() noexcept;
+
+
DebugRegistry& getDebugRegistry() noexcept;
protected:
diff --git a/filament/include/filament/IndirectLight.h b/filament/include/filament/IndirectLight.h
index c230dac8fe..c4cc62ecd7 100644
--- a/filament/include/filament/IndirectLight.h
+++ b/filament/include/filament/IndirectLight.h
@@ -158,6 +158,8 @@ public:
*
* @return This Builder, for chaining calls.
*
+ * @see Material::Builder::sphericalHarmonicsBandCount()
+ *
* @note
* Because the coefficients are pre-scaled, `sh[0]` is the environment's
* average irradiance.
diff --git a/filament/include/filament/Material.h b/filament/include/filament/Material.h
index b4b9bbed3e..11cbaef30d 100644
--- a/filament/include/filament/Material.h
+++ b/filament/include/filament/Material.h
@@ -140,6 +140,18 @@ public:
return constant(name, strlen(name), value);
}
+ /**
+ * Sets the quality of the indirect lights computations. This is only taken into account
+ * if this material is lit and in the surface domain. This setting will affect the
+ * IndirectLight computation if one is specified on the Scene and Spherical Harmonics
+ * are used for the irradiance.
+ *
+ * @param shBandCount Number of spherical harmonic bands. Must be 1, 2 or 3 (default).
+ * @return Reference to this Builder for chaining calls.
+ * @see IndirectLight
+ */
+ Builder& sphericalHarmonicsBandCount(size_t shBandCount) noexcept;
+
/**
* Creates the Material object and returns a pointer to it.
*
diff --git a/filament/include/filament/Renderer.h b/filament/include/filament/Renderer.h
index fdc291b1fd..83b6281604 100644
--- a/filament/include/filament/Renderer.h
+++ b/filament/include/filament/Renderer.h
@@ -227,6 +227,17 @@ public:
static constexpr CopyFrameFlag CLEAR = 0x4;
+ /**
+ * The use of this method is optional. It sets the VSYNC time expressed as the duration in
+ * nanosecond since epoch of std::chrono::steady_clock.
+ * If called, passing 0 to vsyncSteadyClockTimeNano in Renderer::BeginFrame will use this
+ * time instead.
+ * @param steadyClockTimeNano duration in nanosecond since epoch of std::chrono::steady_clock
+ * @see Engine::getSteadyClockTimeNano()
+ * @see Renderer::BeginFrame()
+ */
+ void setVsyncTime(uint64_t steadyClockTimeNano) noexcept;
+
/**
* Set-up a frame for this Renderer.
*
diff --git a/filament/src/Engine.cpp b/filament/src/Engine.cpp
index ad110dbc92..477a0871c8 100644
--- a/filament/src/Engine.cpp
+++ b/filament/src/Engine.cpp
@@ -39,6 +39,8 @@
#include