diff --git a/android/filament-android/src/main/cpp/MaterialInstance.cpp b/android/filament-android/src/main/cpp/MaterialInstance.cpp
index c5c4ba78fb..5f91d88162 100644
--- a/android/filament-android/src/main/cpp/MaterialInstance.cpp
+++ b/android/filament-android/src/main/cpp/MaterialInstance.cpp
@@ -329,6 +329,18 @@ Java_com_google_android_filament_MaterialInstance_nSetCullingMode(JNIEnv*,
instance->setCullingMode((MaterialInstance::CullingMode) cullingMode);
}
+
+extern "C"
+JNIEXPORT void JNICALL
+Java_com_google_android_filament_MaterialInstance_nSetCullingModeSeparate(JNIEnv*, jclass,
+ jlong nativeMaterialInstance,
+ jlong colorPassCullingMode, jlong shadowPassCullingMode) {
+ MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
+ instance->setCullingMode(
+ (MaterialInstance::CullingMode) colorPassCullingMode,
+ (MaterialInstance::CullingMode) shadowPassCullingMode);
+}
+
extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_MaterialInstance_nSetColorWrite(JNIEnv*,
@@ -505,6 +517,14 @@ Java_com_google_android_filament_MaterialInstance_nGetCullingMode(JNIEnv* env, j
return (jint)instance->getCullingMode();
}
+extern "C"
+JNIEXPORT jint JNICALL
+Java_com_google_android_filament_MaterialInstance_nGetShadowCullingMode(JNIEnv* env, jclass,
+ jlong nativeMaterialInstance) {
+ MaterialInstance* instance = (MaterialInstance*)nativeMaterialInstance;
+ return (jint)instance->getShadowCullingMode();
+}
+
extern "C"
JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_MaterialInstance_nIsColorWriteEnabled(JNIEnv* env, jclass clazz,
diff --git a/android/filament-android/src/main/java/com/google/android/filament/MaterialInstance.java b/android/filament-android/src/main/java/com/google/android/filament/MaterialInstance.java
index 389999b7d8..8efd7f841d 100644
--- a/android/filament-android/src/main/java/com/google/android/filament/MaterialInstance.java
+++ b/android/filament-android/src/main/java/com/google/android/filament/MaterialInstance.java
@@ -556,6 +556,20 @@ public class MaterialInstance {
nSetCullingMode(getNativeObject(), mode.ordinal());
}
+ /**
+ * Overrides the default triangle culling state that was set on the material separately for the
+ * color and shadow passes
+ *
+ * @see
+ *
+ * Rasterization: culling
+ */
+ public void setCullingMode(@NonNull Material.CullingMode colorPassCullingMode,
+ @NonNull Material.CullingMode shadowPassCullingMode) {
+ nSetCullingModeSeparate(getNativeObject(),
+ colorPassCullingMode.ordinal(), shadowPassCullingMode.ordinal());
+ }
+
/**
* Returns the face culling mode.
*/
@@ -564,6 +578,14 @@ public class MaterialInstance {
return sCullingModeValues[nGetCullingMode(getNativeObject())];
}
+ /**
+ * Returns the face culling mode for the shadow passes.
+ */
+ @NonNull
+ public Material.CullingMode getShadowCullingMode() {
+ return sCullingModeValues[nGetShadowCullingMode(getNativeObject())];
+ }
+
/**
* Overrides the default color-buffer write state that was set on the material.
*
@@ -920,6 +942,8 @@ public class MaterialInstance {
private static native void nSetDoubleSided(long nativeMaterialInstance, boolean doubleSided);
private static native void nSetCullingMode(long nativeMaterialInstance, long mode);
+ private static native void nSetCullingModeSeparate(long nativeMaterialInstance,
+ long colorPassCullingMode, long shadowPassCullingMode);
private static native void nSetColorWrite(long nativeMaterialInstance, boolean enable);
private static native void nSetDepthWrite(long nativeMaterialInstance, boolean enable);
private static native void nSetStencilWrite(long nativeMaterialInstance, boolean enable);
@@ -952,6 +976,7 @@ public class MaterialInstance {
private static native float nGetSpecularAntiAliasingThreshold(long nativeMaterialInstance);
private static native boolean nIsDoubleSided(long nativeMaterialInstance);
private static native int nGetCullingMode(long nativeMaterialInstance);
+ private static native int nGetShadowCullingMode(long nativeMaterialInstance);
private static native boolean nIsColorWriteEnabled(long nativeMaterialInstance);
private static native boolean nIsDepthWriteEnabled(long nativeMaterialInstance);
private static native boolean nIsStencilWriteEnabled(long nativeMaterialInstance);
diff --git a/filament/include/filament/MaterialInstance.h b/filament/include/filament/MaterialInstance.h
index 72989075f3..a81cf69836 100644
--- a/filament/include/filament/MaterialInstance.h
+++ b/filament/include/filament/MaterialInstance.h
@@ -121,7 +121,7 @@ public:
/** inline helper to provide the name as a null-terminated string literal */
template>
- void setParameter(StringLiteral name, T const& value) {
+ void setParameter(StringLiteral const name, T const& value) {
setParameter(name.data, name.size, value);
}
@@ -148,14 +148,14 @@ public:
/** inline helper to provide the name as a null-terminated string literal */
template>
- void setParameter(StringLiteral name, const T* UTILS_NONNULL values, size_t count) {
+ void setParameter(StringLiteral const name, const T* UTILS_NONNULL values, size_t const count) {
setParameter(name.data, name.size, values, count);
}
/** inline helper to provide the name as a null-terminated C string */
template>
void setParameter(const char* UTILS_NONNULL name,
- const T* UTILS_NONNULL values, size_t count) {
+ const T* UTILS_NONNULL values, size_t const count) {
setParameter(name, strlen(name), values, count);
}
@@ -176,7 +176,7 @@ public:
Texture const* UTILS_NULLABLE texture, TextureSampler const& sampler);
/** inline helper to provide the name as a null-terminated string literal */
- void setParameter(StringLiteral name,
+ void setParameter(StringLiteral const name,
Texture const* UTILS_NULLABLE texture, TextureSampler const& sampler) {
setParameter(name.data, name.size, texture, sampler);
}
@@ -202,12 +202,12 @@ public:
RgbType type, math::float3 color);
/** inline helper to provide the name as a null-terminated string literal */
- void setParameter(StringLiteral name, RgbType type, math::float3 color) {
+ void setParameter(StringLiteral const name, RgbType const type, math::float3 const color) {
setParameter(name.data, name.size, type, color);
}
/** inline helper to provide the name as a null-terminated C string */
- void setParameter(const char* UTILS_NONNULL name, RgbType type, math::float3 color) {
+ void setParameter(const char* UTILS_NONNULL name, RgbType const type, math::float3 const color) {
setParameter(name, strlen(name), type, color);
}
@@ -226,12 +226,12 @@ public:
RgbaType type, math::float4 color);
/** inline helper to provide the name as a null-terminated string literal */
- void setParameter(StringLiteral name, RgbaType type, math::float4 color) {
+ void setParameter(StringLiteral const name, RgbaType const type, math::float4 const color) {
setParameter(name.data, name.size, type, color);
}
/** inline helper to provide the name as a null-terminated C string */
- void setParameter(const char* UTILS_NONNULL name, RgbaType type, math::float4 color) {
+ void setParameter(const char* UTILS_NONNULL name, RgbaType const type, math::float4 const color) {
setParameter(name, strlen(name), type, color);
}
@@ -251,7 +251,7 @@ public:
/** inline helper to provide the name as a null-terminated C string */
template>
- T getParameter(StringLiteral name) const {
+ T getParameter(StringLiteral const name) const {
return getParameter(name.data, name.size);
}
@@ -376,11 +376,22 @@ public:
*/
void setCullingMode(CullingMode culling) noexcept;
+ /**
+ * Overrides the default triangle culling state that was set on the material separately for the
+ * color and shadow passes
+ */
+ void setCullingMode(CullingMode colorPassCullingMode, CullingMode shadowPassCullingMode) noexcept;
+
/**
* Returns the face culling mode.
*/
CullingMode getCullingMode() const noexcept;
+ /**
+ * Returns the face culling mode for the shadow passes.
+ */
+ CullingMode getShadowCullingMode() const noexcept;
+
/**
* Overrides the default color-buffer write state that was set on the material.
*/
diff --git a/filament/src/MaterialInstance.cpp b/filament/src/MaterialInstance.cpp
index e141a62aeb..d36831a217 100644
--- a/filament/src/MaterialInstance.cpp
+++ b/filament/src/MaterialInstance.cpp
@@ -17,6 +17,26 @@
#include
#include "details/Material.h"
+#include "details/MaterialInstance.h"
+
+#include
+#include
+
+#include
+
+#include
+#include
+
+#include