diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index 7dd8179a57..c94eb4cf8f 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -4,6 +4,7 @@ This file contains one line summaries of commits that are worthy of mentioning i
A new header is inserted each time a *tag* is created.
## Next release
+- Added support for solid and thin layer cubemap and screen-space refraction.
- Improve high roughness material rendering by default when regenerating environments maps
diff --git a/android/filament-android/src/main/cpp/Material.cpp b/android/filament-android/src/main/cpp/Material.cpp
index 115b727c62..be16c7f420 100644
--- a/android/filament-android/src/main/cpp/Material.cpp
+++ b/android/filament-android/src/main/cpp/Material.cpp
@@ -84,6 +84,23 @@ Java_com_google_android_filament_Material_nGetBlendingMode(JNIEnv*, jclass,
return (jint) material->getBlendingMode();
}
+
+extern "C"
+JNIEXPORT jint JNICALL
+Java_com_google_android_filament_Material_nGetRefraction(JNIEnv*, jclass,
+ jlong nativeMaterial) {
+ Material* material = (Material*) nativeMaterial;
+ return (jint) material->getRefraction();
+}
+
+extern "C"
+JNIEXPORT jint JNICALL
+Java_com_google_android_filament_Material_nGetRefractionType(JNIEnv*, jclass,
+ jlong nativeMaterial) {
+ Material* material = (Material*) nativeMaterial;
+ return (jint) material->getRefractionType();
+}
+
extern "C"
JNIEXPORT jint JNICALL
Java_com_google_android_filament_Material_nGetVertexDomain(JNIEnv*, jclass,
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 9e1898f925..1571446ff9 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
@@ -141,6 +141,31 @@ public class Material {
SCREEN,
}
+ /**
+ * Supported refraction modes
+ *
+ * @see
+ *
+ * Blending and transparency: refraction
+ */
+ public enum Refraction {
+ NONE,
+ CUBEMAP,
+ SCREEN_SPACE
+ }
+
+ /**
+ * Supported refraction types
+ *
+ * @see
+ *
+ * Blending and transparency: refractionType
+ */
+ public enum RefractionType {
+ SOLID,
+ THIN
+ }
+
/**
* Supported types of vertex domains
*
@@ -351,6 +376,29 @@ public class Material {
return BlendingMode.values()[nGetBlendingMode(getNativeObject())];
}
+ /**
+ * Returns the refraction mode of this material.
+ *
+ * @see
+ *
+ * Blending and transparency: refraction
+ */
+ public Refraction getRefraction() {
+ return Refraction.values()[nGetRefraction(getNativeObject())];
+ }
+
+ /**
+ * Returns the refraction type of this material.
+ *
+ * @see
+ *
+ * Blending and transparency: refractionType
+ */
+ public RefractionType getRefractionType() {
+ return RefractionType.values()[nGetRefractionType(getNativeObject())];
+ }
+
+
/**
* Returns the vertex domain of this material.
*
@@ -847,6 +895,9 @@ public class Material {
private static native float nGetMaskThreshold(long nativeMaterial);
private static native float nGetSpecularAntiAliasingVariance(long nativeMaterial);
private static native float nGetSpecularAntiAliasingThreshold(long nativeMaterial);
+ private static native int nGetRefraction(long nativeMaterial);
+ private static native int nGetRefractionType(long nativeMaterial);
+
private static native int nGetParameterCount(long nativeMaterial);
private static native void nGetParameters(long nativeMaterial,
diff --git a/filament/include/filament/Material.h b/filament/include/filament/Material.h
index 4a2da8150d..0c4af59e02 100644
--- a/filament/include/filament/Material.h
+++ b/filament/include/filament/Material.h
@@ -179,6 +179,12 @@ public:
//! Returns the list of vertex attributes required by this material.
AttributeBitset getRequiredAttributes() const noexcept;
+ //! Returns the refraction mode used by this material.
+ Refraction getRefraction() const noexcept;
+
+ // Return the refraction type used by this material.
+ RefractionType getRefractionType() const noexcept;
+
/**
* Returns the number of parameters declared by this material.
* The returned value can be 0.
diff --git a/filament/src/Material.cpp b/filament/src/Material.cpp
index 1912de8cae..555b8a9e90 100644
--- a/filament/src/Material.cpp
+++ b/filament/src/Material.cpp
@@ -160,6 +160,8 @@ FMaterial::FMaterial(FEngine& engine, const Material::Builder& builder)
parser->getVertexDomain(&mVertexDomain);
parser->getMaterialDomain(&mMaterialDomain);
parser->getRequiredAttributes(&mRequiredAttributes);
+ parser->getRefraction(&mRefraction);
+ parser->getRefractionType(&mRefractionType);
if (mBlendingMode == BlendingMode::MASKED) {
parser->getMaskThreshold(&mMaskThreshold);
@@ -601,6 +603,14 @@ AttributeBitset Material::getRequiredAttributes() const noexcept {
return upcast(this)->getRequiredAttributes();
}
+Refraction Material::getRefraction() const noexcept {
+ return upcast(this)->getRefraction();
+}
+
+RefractionType Material::getRefractionType() const noexcept {
+ return upcast(this)->getRefractionType();
+}
+
bool Material::hasParameter(const char* name) const noexcept {
return upcast(this)->hasParameter(name);
}
diff --git a/filament/src/MaterialParser.cpp b/filament/src/MaterialParser.cpp
index 1199f12550..8ecbcc773c 100644
--- a/filament/src/MaterialParser.cpp
+++ b/filament/src/MaterialParser.cpp
@@ -246,6 +246,18 @@ bool MaterialParser::getRequiredAttributes(AttributeBitset* value) const noexcep
return true;
}
+bool MaterialParser::getRefraction(Refraction* value) const noexcept {
+ static_assert(sizeof(Refraction) == sizeof(uint8_t),
+ "Refraction expected size is wrong");
+ return mImpl.getFromSimpleChunk(ChunkType::MaterialRefraction, (uint8_t*)value);
+}
+
+bool MaterialParser::getRefractionType(RefractionType* value) const noexcept {
+ static_assert(sizeof(RefractionType) == sizeof(uint8_t),
+ "RefractionType expected size is wrong");
+ return mImpl.getFromSimpleChunk(ChunkType::MaterialRefractionType, (uint8_t*)value);
+}
+
bool MaterialParser::getShader(ShaderBuilder& shader,
ShaderModel shaderModel, uint8_t variant, ShaderType stage) noexcept {
return mImpl.mMaterialChunk.getShader(shader,
diff --git a/filament/src/MaterialParser.h b/filament/src/MaterialParser.h
index cdca4ab2f4..8ba077897c 100644
--- a/filament/src/MaterialParser.h
+++ b/filament/src/MaterialParser.h
@@ -75,6 +75,8 @@ public:
bool getMaskThreshold(float*) const noexcept;
bool hasShadowMultiplier(bool*) const noexcept;
bool getRequiredAttributes(AttributeBitset*) const noexcept;
+ bool getRefraction(Refraction* value) const noexcept;
+ bool getRefractionType(RefractionType* value) const noexcept;
bool hasCustomDepthShader(bool* value) const noexcept;
bool hasSpecularAntiAliasing(bool* value) const noexcept;
bool getSpecularAntiAliasingVariance(float* value) const noexcept;
diff --git a/filament/src/details/Material.h b/filament/src/details/Material.h
index bd31a3df2f..30afe2996d 100644
--- a/filament/src/details/Material.h
+++ b/filament/src/details/Material.h
@@ -115,6 +115,8 @@ public:
float getMaskThreshold() const noexcept { return mMaskThreshold; }
bool hasShadowMultiplier() const noexcept { return mHasShadowMultiplier; }
AttributeBitset getRequiredAttributes() const noexcept { return mRequiredAttributes; }
+ Refraction getRefraction() const noexcept { return mRefraction; }
+ RefractionType getRefractionType() const noexcept { return mRefractionType; }
bool hasSpecularAntiAliasing() const noexcept { return mSpecularAntiAliasing; }
float getSpecularAntiAliasingVariance() const noexcept { return mSpecularAntiAliasingVariance; }
@@ -170,6 +172,8 @@ private:
MaterialDomain mMaterialDomain = MaterialDomain::SURFACE;
CullingMode mCullingMode = CullingMode::NONE;
AttributeBitset mRequiredAttributes;
+ Refraction mRefraction = Refraction::NONE;
+ RefractionType mRefractionType = RefractionType::SOLID;
uint64_t mMaterialProperties = 0;
float mMaskThreshold = 0.4f;