Add MaterialInstance getters for overridable properties (#6243)
In addition to the new getters, this change fixes the duplication of a MaterialInstance, which didn't carry along the following states: - alpha mask threshold - specular AA threshold - specular AA variance - double sidedness TODO: stencil state, polygon offset and scissor are stil not queryable
This commit is contained in:
@@ -10,6 +10,7 @@ A new header is inserted each time a *tag* is created.
|
||||
- gltfio: fix glTF breaking issue
|
||||
- gltfio: recompute bounding boxes with morph targets
|
||||
- engine: primitives with `CullingMode::FRONT_AND_BACK` are now skipped.
|
||||
- engine: add missing getters on `MaterialInstance`
|
||||
|
||||
## v1.28.2
|
||||
|
||||
|
||||
@@ -452,3 +452,84 @@ Java_com_google_android_filament_MaterialInstance_nDuplicate(JNIEnv* env, jclass
|
||||
}
|
||||
return (jlong)mi;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jfloat JNICALL
|
||||
Java_com_google_android_filament_MaterialInstance_nGetMaskThreshold(JNIEnv* env, jclass clazz,
|
||||
jlong nativeMaterialInstance) {
|
||||
// TODO: implement nGetMaskThreshold()
|
||||
MaterialInstance* instance = (MaterialInstance*)nativeMaterialInstance;
|
||||
return instance->getMaskThreshold();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jfloat JNICALL
|
||||
Java_com_google_android_filament_MaterialInstance_nGetSpecularAntiAliasingVariance(JNIEnv* env,
|
||||
jclass clazz, jlong nativeMaterialInstance) {
|
||||
// TODO: implement nGetSpecularAntiAliasingVariance()
|
||||
MaterialInstance* instance = (MaterialInstance*)nativeMaterialInstance;
|
||||
return instance->getSpecularAntiAliasingVariance();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jfloat JNICALL
|
||||
Java_com_google_android_filament_MaterialInstance_nGetSpecularAntiAliasingThreshold(JNIEnv* env,
|
||||
jclass clazz, jlong nativeMaterialInstance) {
|
||||
// TODO: implement nGetSpecularAntiAliasingThreshold()
|
||||
MaterialInstance* instance = (MaterialInstance*)nativeMaterialInstance;
|
||||
return instance->getSpecularAntiAliasingThreshold();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_MaterialInstance_nIsDoubleSided(JNIEnv* env, jclass clazz,
|
||||
jlong nativeMaterialInstance) {
|
||||
// TODO: implement nIsDoubleSided()
|
||||
MaterialInstance* instance = (MaterialInstance*)nativeMaterialInstance;
|
||||
return instance->isDoubleSided();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_google_android_filament_MaterialInstance_nGetCullingMode(JNIEnv* env, jclass clazz,
|
||||
jlong nativeMaterialInstance) {
|
||||
// TODO: implement nGetCullingMode()
|
||||
MaterialInstance* instance = (MaterialInstance*)nativeMaterialInstance;
|
||||
return (jint)instance->getCullingMode();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_MaterialInstance_nIsColorWriteEnabled(JNIEnv* env, jclass clazz,
|
||||
jlong nativeMaterialInstance) {
|
||||
// TODO: implement nIsColorWriteEnabled()
|
||||
MaterialInstance* instance = (MaterialInstance*)nativeMaterialInstance;
|
||||
return instance->isColorWriteEnabled();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_MaterialInstance_nIsDepthWriteEnabled(JNIEnv* env, jclass clazz,
|
||||
jlong nativeMaterialInstance) {
|
||||
// TODO: implement nIsDepthWriteEnabled()
|
||||
MaterialInstance* instance = (MaterialInstance*)nativeMaterialInstance;
|
||||
return instance->isDepthWriteEnabled();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_MaterialInstance_nIsStencilWriteEnabled(JNIEnv* env, jclass clazz,
|
||||
jlong nativeMaterialInstance) {
|
||||
// TODO: implement nIsStencilWriteEnabled()
|
||||
MaterialInstance* instance = (MaterialInstance*)nativeMaterialInstance;
|
||||
return instance->isStencilWriteEnabled();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_google_android_filament_MaterialInstance_nIsDepthCullingEnabled(JNIEnv* env, jclass clazz,
|
||||
jlong nativeMaterialInstance) {
|
||||
// TODO: implement nIsDepthCullingEnabled()
|
||||
MaterialInstance* instance = (MaterialInstance*)nativeMaterialInstance;
|
||||
return instance->isDepthCullingEnabled();
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.google.android.filament.proguard.UsedByNative;
|
||||
|
||||
@UsedByNative("AssetLoader.cpp")
|
||||
public class MaterialInstance {
|
||||
private static final Material.CullingMode[] sCullingModeValues = Material.CullingMode.values();
|
||||
private Material mMaterial;
|
||||
private String mName;
|
||||
private long mNativeObject;
|
||||
@@ -473,6 +474,14 @@ public class MaterialInstance {
|
||||
nSetMaskThreshold(getNativeObject(), threshold);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the minimum alpha value a fragment must have to not be discarded when the blend
|
||||
* mode is MASKED
|
||||
*/
|
||||
public float getMaskThreshold() {
|
||||
return nGetMaskThreshold(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the screen space variance of the filter kernel used when applying specular
|
||||
* anti-aliasing. The default value is set to 0.15. The specified value should be between
|
||||
@@ -486,6 +495,14 @@ public class MaterialInstance {
|
||||
nSetSpecularAntiAliasingVariance(getNativeObject(), variance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the screen space variance of the filter kernel used when applying specular
|
||||
* anti-aliasing.
|
||||
*/
|
||||
public float getSpecularAntiAliasingVariance() {
|
||||
return nGetSpecularAntiAliasingVariance(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the clamping threshold used to suppress estimation errors when applying specular
|
||||
* anti-aliasing. The default value is set to 0.2. The specified value should be between 0
|
||||
@@ -499,6 +516,14 @@ public class MaterialInstance {
|
||||
nSetSpecularAntiAliasingThreshold(getNativeObject(), threshold);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the clamping threshold used to suppress estimation errors when applying specular
|
||||
* anti-aliasing.
|
||||
*/
|
||||
public float getSpecularAntiAliasingThreshold() {
|
||||
return nGetSpecularAntiAliasingThreshold(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables double-sided lighting if the parent Material has double-sided capability,
|
||||
* otherwise prints a warning. If double-sided lighting is enabled, backface culling is
|
||||
@@ -512,6 +537,14 @@ public class MaterialInstance {
|
||||
nSetDoubleSided(getNativeObject(), doubleSided);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether double-sided lighting is enabled when the parent Material has double-sided
|
||||
* capability.
|
||||
*/
|
||||
public boolean isDoubleSided() {
|
||||
return nIsDoubleSided(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the default triangle culling state that was set on the material.
|
||||
*
|
||||
@@ -519,10 +552,18 @@ public class MaterialInstance {
|
||||
* <a href="https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/rasterization:culling">
|
||||
* Rasterization: culling</a>
|
||||
*/
|
||||
public void setCullingMode(Material.CullingMode mode) {
|
||||
public void setCullingMode(@NonNull Material.CullingMode mode) {
|
||||
nSetCullingMode(getNativeObject(), mode.ordinal());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the face culling mode.
|
||||
*/
|
||||
@NonNull
|
||||
public Material.CullingMode getCullingMode() {
|
||||
return sCullingModeValues[nGetCullingMode(getNativeObject())];
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the default color-buffer write state that was set on the material.
|
||||
*
|
||||
@@ -534,6 +575,13 @@ public class MaterialInstance {
|
||||
nSetColorWrite(getNativeObject(), enable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether color write is enabled.
|
||||
*/
|
||||
public boolean isColorWriteEnabled() {
|
||||
return nIsColorWriteEnabled(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the default depth-buffer write state that was set on the material.
|
||||
*
|
||||
@@ -545,10 +593,27 @@ public class MaterialInstance {
|
||||
nSetDepthWrite(getNativeObject(), enable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether depth write is enabled.
|
||||
*/
|
||||
public boolean isDepthWriteEnabled() {
|
||||
return nIsDepthWriteEnabled(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or Disable stencil writes
|
||||
*/
|
||||
public void setStencilWrite(boolean enable) {
|
||||
nSetStencilWrite(getNativeObject(), enable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether stencil write is enabled.
|
||||
*/
|
||||
public boolean isStencilWriteEnabled() {
|
||||
return nIsStencilWriteEnabled(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the default depth testing state that was set on the material.
|
||||
*
|
||||
@@ -560,6 +625,13 @@ public class MaterialInstance {
|
||||
nSetDepthCulling(getNativeObject(), enable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether depth culling is enabled.
|
||||
*/
|
||||
public boolean isDepthCullingEnabled() {
|
||||
return nIsDepthCullingEnabled(getNativeObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the stencil comparison function (default is {@link TextureSampler.CompareFunction#ALWAYS}).
|
||||
*
|
||||
@@ -856,4 +928,15 @@ public class MaterialInstance {
|
||||
private static native long nGetMaterial(long nativeMaterialInstance);
|
||||
|
||||
private static native long nDuplicate(long otherNativeMaterialInstance, String name);
|
||||
|
||||
|
||||
private static native float nGetMaskThreshold(long nativeMaterialInstance);
|
||||
private static native float nGetSpecularAntiAliasingVariance(long nativeMaterialInstance);
|
||||
private static native float nGetSpecularAntiAliasingThreshold(long nativeMaterialInstance);
|
||||
private static native boolean nIsDoubleSided(long nativeMaterialInstance);
|
||||
private static native int nGetCullingMode(long nativeMaterialInstance);
|
||||
private static native boolean nIsColorWriteEnabled(long nativeMaterialInstance);
|
||||
private static native boolean nIsDepthWriteEnabled(long nativeMaterialInstance);
|
||||
private static native boolean nIsStencilWriteEnabled(long nativeMaterialInstance);
|
||||
private static native boolean nIsDepthCullingEnabled(long nativeMaterialInstance);
|
||||
}
|
||||
|
||||
@@ -277,6 +277,12 @@ public:
|
||||
*/
|
||||
void setMaskThreshold(float threshold) noexcept;
|
||||
|
||||
/**
|
||||
* Gets the minimum alpha value a fragment must have to not be discarded when the blend
|
||||
* mode is MASKED
|
||||
*/
|
||||
float getMaskThreshold() const noexcept;
|
||||
|
||||
/**
|
||||
* Sets the screen space variance of the filter kernel used when applying specular
|
||||
* anti-aliasing. The default value is set to 0.15. The specified value should be between
|
||||
@@ -284,6 +290,12 @@ public:
|
||||
*/
|
||||
void setSpecularAntiAliasingVariance(float variance) noexcept;
|
||||
|
||||
/**
|
||||
* Gets the screen space variance of the filter kernel used when applying specular
|
||||
* anti-aliasing.
|
||||
*/
|
||||
float getSpecularAntiAliasingVariance() const noexcept;
|
||||
|
||||
/**
|
||||
* Sets the clamping threshold used to suppress estimation errors when applying specular
|
||||
* anti-aliasing. The default value is set to 0.2. The specified value should be between 0
|
||||
@@ -291,6 +303,12 @@ public:
|
||||
*/
|
||||
void setSpecularAntiAliasingThreshold(float threshold) noexcept;
|
||||
|
||||
/**
|
||||
* Gets the clamping threshold used to suppress estimation errors when applying specular
|
||||
* anti-aliasing.
|
||||
*/
|
||||
float getSpecularAntiAliasingThreshold() const noexcept;
|
||||
|
||||
/**
|
||||
* Enables or disables double-sided lighting if the parent Material has double-sided capability,
|
||||
* otherwise prints a warning. If double-sided lighting is enabled, backface culling is
|
||||
@@ -298,36 +316,72 @@ public:
|
||||
*/
|
||||
void setDoubleSided(bool doubleSided) noexcept;
|
||||
|
||||
/**
|
||||
* Returns whether double-sided lighting is enabled when the parent Material has double-sided
|
||||
* capability.
|
||||
*/
|
||||
bool isDoubleSided() const noexcept;
|
||||
|
||||
/**
|
||||
* Specifies how transparent objects should be rendered (default is DEFAULT).
|
||||
*/
|
||||
void setTransparencyMode(TransparencyMode mode) noexcept;
|
||||
|
||||
/**
|
||||
* Returns the transparency mode.
|
||||
*/
|
||||
TransparencyMode getTransparencyMode() const noexcept;
|
||||
|
||||
/**
|
||||
* Overrides the default triangle culling state that was set on the material.
|
||||
*/
|
||||
void setCullingMode(CullingMode culling) noexcept;
|
||||
|
||||
/**
|
||||
* Returns the face culling mode.
|
||||
*/
|
||||
CullingMode getCullingMode() const noexcept;
|
||||
|
||||
/**
|
||||
* Overrides the default color-buffer write state that was set on the material.
|
||||
*/
|
||||
void setColorWrite(bool enable) noexcept;
|
||||
|
||||
/**
|
||||
* Returns whether color write is enabled.
|
||||
*/
|
||||
bool isColorWriteEnabled() const noexcept;
|
||||
|
||||
/**
|
||||
* Overrides the default depth-buffer write state that was set on the material.
|
||||
*/
|
||||
void setDepthWrite(bool enable) noexcept;
|
||||
|
||||
/**
|
||||
* Returns whether depth write is enabled.
|
||||
*/
|
||||
bool isDepthWriteEnabled() const noexcept;
|
||||
|
||||
/**
|
||||
* Overrides the default depth testing state that was set on the material.
|
||||
*/
|
||||
void setDepthCulling(bool enable) noexcept;
|
||||
|
||||
/**
|
||||
* Returns whether depth culling is enabled.
|
||||
*/
|
||||
bool isDepthCullingEnabled() const noexcept;
|
||||
|
||||
/**
|
||||
* Overrides the default stencil-buffer write state that was set on the material.
|
||||
*/
|
||||
void setStencilWrite(bool enable) noexcept;
|
||||
|
||||
/**
|
||||
* Returns whether stencil write is enabled.
|
||||
*/
|
||||
bool isStencilWriteEnabled() const noexcept;
|
||||
|
||||
/**
|
||||
* Sets the stencil comparison function (default is StencilCompareFunc::A).
|
||||
*
|
||||
|
||||
@@ -292,4 +292,44 @@ MaterialInstance* MaterialInstance::duplicate(MaterialInstance const* other, con
|
||||
}
|
||||
|
||||
|
||||
float MaterialInstance::getMaskThreshold() const noexcept {
|
||||
return downcast(this)->getMaskThreshold();
|
||||
}
|
||||
|
||||
float MaterialInstance::getSpecularAntiAliasingVariance() const noexcept {
|
||||
return downcast(this)->getSpecularAntiAliasingVariance();
|
||||
}
|
||||
|
||||
float MaterialInstance::getSpecularAntiAliasingThreshold() const noexcept {
|
||||
return downcast(this)->getSpecularAntiAliasingThreshold();
|
||||
}
|
||||
|
||||
bool MaterialInstance::isDoubleSided() const noexcept {
|
||||
return downcast(this)->isDoubleSided();
|
||||
}
|
||||
|
||||
TransparencyMode MaterialInstance::getTransparencyMode() const noexcept {
|
||||
return downcast(this)->getTransparencyMode();
|
||||
}
|
||||
|
||||
CullingMode MaterialInstance::getCullingMode() const noexcept {
|
||||
return downcast(this)->getCullingMode();
|
||||
}
|
||||
|
||||
bool MaterialInstance::isColorWriteEnabled() const noexcept {
|
||||
return downcast(this)->isColorWriteEnabled();
|
||||
}
|
||||
|
||||
bool MaterialInstance::isDepthWriteEnabled() const noexcept {
|
||||
return downcast(this)->isDepthWriteEnabled();
|
||||
}
|
||||
|
||||
bool MaterialInstance::isStencilWriteEnabled() const noexcept {
|
||||
return downcast(this)->isStencilWriteEnabled();
|
||||
}
|
||||
|
||||
bool MaterialInstance::isDepthCullingEnabled() const noexcept {
|
||||
return downcast(this)->isDepthCullingEnabled();
|
||||
}
|
||||
|
||||
} // namespace filament
|
||||
|
||||
@@ -358,8 +358,8 @@ void RenderPass::setupColorCommand(Command& cmdDraw, Variant variant,
|
||||
|
||||
cmdDraw.primitive.rasterState.inverseFrontFaces = inverseFrontFaces;
|
||||
cmdDraw.primitive.rasterState.culling = mi->getCullingMode();
|
||||
cmdDraw.primitive.rasterState.colorWrite = mi->getColorWrite();
|
||||
cmdDraw.primitive.rasterState.depthWrite = mi->getDepthWrite();
|
||||
cmdDraw.primitive.rasterState.colorWrite = mi->isColorWriteEnabled();
|
||||
cmdDraw.primitive.rasterState.depthWrite = mi->isDepthWriteEnabled();
|
||||
cmdDraw.primitive.rasterState.depthFunc = mi->getDepthFunc();
|
||||
cmdDraw.primitive.mi = mi;
|
||||
cmdDraw.primitive.materialVariant = variant;
|
||||
@@ -663,7 +663,7 @@ RenderPass::Command* RenderPass::generateCommandsImpl(uint32_t extraFlags,
|
||||
|
||||
// FIXME: should writeDepthForShadowCasters take precedence over mi->getDepthWrite()?
|
||||
cmdDepth.primitive.rasterState.depthWrite = (1 // only keep bit 0
|
||||
& (mi->getDepthWrite() | (mode == TransparencyMode::TWO_PASSES_ONE_SIDE))
|
||||
& (mi->isDepthWriteEnabled() | (mode == TransparencyMode::TWO_PASSES_ONE_SIDE))
|
||||
& !(filterTranslucentObjects & translucent)
|
||||
& !(depthFilterAlphaMaskedObjects & rs.alphaToCoverage))
|
||||
| writeDepthForShadowCasters;
|
||||
|
||||
@@ -35,17 +35,30 @@ namespace filament {
|
||||
|
||||
using namespace backend;
|
||||
|
||||
FMaterialInstance::FMaterialInstance() noexcept = default;
|
||||
FMaterialInstance::FMaterialInstance() noexcept
|
||||
: mCulling(CullingMode::BACK),
|
||||
mDepthFunc(RasterState::DepthFunc::LE),
|
||||
mColorWrite(false),
|
||||
mDepthWrite(false),
|
||||
mHasScissor(false),
|
||||
mIsDoubleSided(false),
|
||||
mTransparencyMode(TransparencyMode::DEFAULT) {
|
||||
}
|
||||
|
||||
FMaterialInstance::FMaterialInstance(FEngine& engine,
|
||||
FMaterialInstance const* other, const char* name)
|
||||
: mMaterial(other->mMaterial),
|
||||
mPolygonOffset(other->mPolygonOffset),
|
||||
mStencilState(other->mStencilState),
|
||||
mMaskThreshold(other->mMaskThreshold),
|
||||
mSpecularAntiAliasingVariance(other->mSpecularAntiAliasingVariance),
|
||||
mSpecularAntiAliasingThreshold(other->mSpecularAntiAliasingThreshold),
|
||||
mCulling(other->mCulling),
|
||||
mDepthFunc(other->mDepthFunc),
|
||||
mColorWrite(other->mColorWrite),
|
||||
mDepthWrite(other->mDepthWrite),
|
||||
mStencilState(other->mStencilState),
|
||||
mDepthFunc(other->mDepthFunc),
|
||||
mHasScissor(false),
|
||||
mIsDoubleSided(other->mIsDoubleSided),
|
||||
mScissorRect(other->mScissorRect),
|
||||
mName(name ? CString(name) : other->mName) {
|
||||
|
||||
@@ -63,10 +76,20 @@ FMaterialInstance::FMaterialInstance(FEngine& engine,
|
||||
mSbHandle = driver.createSamplerGroup(mSamplers.getSize());
|
||||
}
|
||||
|
||||
mMaterialSortingKey = RenderPass::makeMaterialSortingKey(
|
||||
material->getId(), material->generateMaterialInstanceId());
|
||||
if (material->hasDoubleSidedCapability()) {
|
||||
setDoubleSided(mIsDoubleSided);
|
||||
}
|
||||
|
||||
setMaskThreshold(mMaskThreshold);
|
||||
|
||||
setSpecularAntiAliasingThreshold(mSpecularAntiAliasingThreshold);
|
||||
|
||||
setSpecularAntiAliasingVariance(mSpecularAntiAliasingVariance);
|
||||
|
||||
setTransparencyMode(material->getTransparencyMode());
|
||||
|
||||
mMaterialSortingKey = RenderPass::makeMaterialSortingKey(
|
||||
material->getId(), material->generateMaterialInstanceId());
|
||||
}
|
||||
|
||||
FMaterialInstance* FMaterialInstance::duplicate(
|
||||
@@ -183,14 +206,29 @@ void FMaterialInstance::setParameterImpl(std::string_view name,
|
||||
|
||||
void FMaterialInstance::setMaskThreshold(float threshold) noexcept {
|
||||
setParameter("_maskThreshold", math::saturate(threshold));
|
||||
mMaskThreshold = math::saturate(threshold);
|
||||
}
|
||||
|
||||
float FMaterialInstance::getMaskThreshold() const noexcept {
|
||||
return mMaskThreshold;
|
||||
}
|
||||
|
||||
void FMaterialInstance::setSpecularAntiAliasingVariance(float variance) noexcept {
|
||||
setParameter("_specularAntiAliasingVariance", math::saturate(variance));
|
||||
mSpecularAntiAliasingVariance = math::saturate(variance);
|
||||
}
|
||||
|
||||
float FMaterialInstance::getSpecularAntiAliasingVariance() const noexcept {
|
||||
return mSpecularAntiAliasingVariance;
|
||||
}
|
||||
|
||||
void FMaterialInstance::setSpecularAntiAliasingThreshold(float threshold) noexcept {
|
||||
setParameter("_specularAntiAliasingThreshold", math::saturate(threshold * threshold));
|
||||
mSpecularAntiAliasingThreshold = std::sqrt(math::saturate(threshold * threshold));
|
||||
}
|
||||
|
||||
float FMaterialInstance::getSpecularAntiAliasingThreshold() const noexcept {
|
||||
return mSpecularAntiAliasingThreshold;
|
||||
}
|
||||
|
||||
void FMaterialInstance::setDoubleSided(bool doubleSided) noexcept {
|
||||
@@ -202,6 +240,11 @@ void FMaterialInstance::setDoubleSided(bool doubleSided) noexcept {
|
||||
if (doubleSided) {
|
||||
setCullingMode(CullingMode::NONE);
|
||||
}
|
||||
mIsDoubleSided = doubleSided;
|
||||
}
|
||||
|
||||
bool FMaterialInstance::isDoubleSided() const noexcept {
|
||||
return mIsDoubleSided;
|
||||
}
|
||||
|
||||
void FMaterialInstance::setTransparencyMode(TransparencyMode mode) noexcept {
|
||||
@@ -212,6 +255,10 @@ void FMaterialInstance::setDepthCulling(bool enable) noexcept {
|
||||
mDepthFunc = enable ? RasterState::DepthFunc::GE : RasterState::DepthFunc::A;
|
||||
}
|
||||
|
||||
bool FMaterialInstance::isDepthCullingEnabled() const noexcept {
|
||||
return mDepthFunc != RasterState::DepthFunc::A;
|
||||
}
|
||||
|
||||
const char* FMaterialInstance::getName() const noexcept {
|
||||
// To decide whether to use the parent material name as a fallback, we check for the nullness of
|
||||
// the instance's CString rather than calling empty(). This allows instances to override the
|
||||
|
||||
@@ -89,9 +89,11 @@ public:
|
||||
|
||||
backend::CullingMode getCullingMode() const noexcept { return mCulling; }
|
||||
|
||||
bool getColorWrite() const noexcept { return mColorWrite; }
|
||||
bool isColorWriteEnabled() const noexcept { return mColorWrite; }
|
||||
|
||||
bool getDepthWrite() const noexcept { return mDepthWrite; }
|
||||
bool isDepthWriteEnabled() const noexcept { return mDepthWrite; }
|
||||
|
||||
bool isStencilWriteEnabled() const noexcept { return mStencilState.stencilWrite; }
|
||||
|
||||
backend::StencilState getStencilState() const noexcept { return mStencilState; }
|
||||
|
||||
@@ -108,12 +110,20 @@ public:
|
||||
|
||||
void setMaskThreshold(float threshold) noexcept;
|
||||
|
||||
float getMaskThreshold() const noexcept;
|
||||
|
||||
void setSpecularAntiAliasingVariance(float variance) noexcept;
|
||||
|
||||
float getSpecularAntiAliasingVariance() const noexcept;
|
||||
|
||||
void setSpecularAntiAliasingThreshold(float threshold) noexcept;
|
||||
|
||||
float getSpecularAntiAliasingThreshold() const noexcept;
|
||||
|
||||
void setDoubleSided(bool doubleSided) noexcept;
|
||||
|
||||
bool isDoubleSided() const noexcept;
|
||||
|
||||
void setTransparencyMode(TransparencyMode mode) noexcept;
|
||||
|
||||
void setCullingMode(CullingMode culling) noexcept { mCulling = culling; }
|
||||
@@ -126,6 +136,8 @@ public:
|
||||
|
||||
void setDepthCulling(bool enable) noexcept;
|
||||
|
||||
bool isDepthCullingEnabled() const noexcept;
|
||||
|
||||
void setStencilCompareFunction(StencilCompareFunc func, StencilFace face) noexcept {
|
||||
if (any(face & StencilFace::FRONT)) {
|
||||
mStencilState.front.stencilFunc = func;
|
||||
@@ -222,19 +234,26 @@ private:
|
||||
|
||||
// keep these grouped, they're accessed together in the render-loop
|
||||
FMaterial const* mMaterial = nullptr;
|
||||
|
||||
backend::Handle<backend::HwBufferObject> mUbHandle;
|
||||
backend::Handle<backend::HwSamplerGroup> mSbHandle;
|
||||
|
||||
UniformBuffer mUniforms;
|
||||
backend::SamplerGroup mSamplers;
|
||||
backend::PolygonOffset mPolygonOffset;
|
||||
backend::CullingMode mCulling;
|
||||
bool mColorWrite;
|
||||
bool mDepthWrite;
|
||||
bool mHasScissor = false;
|
||||
backend::StencilState mStencilState = {};
|
||||
backend::RasterState::DepthFunc mDepthFunc;
|
||||
TransparencyMode mTransparencyMode;
|
||||
|
||||
backend::PolygonOffset mPolygonOffset{};
|
||||
backend::StencilState mStencilState{};
|
||||
|
||||
float mMaskThreshold = 0.0f;
|
||||
float mSpecularAntiAliasingVariance = 0.0f;
|
||||
float mSpecularAntiAliasingThreshold = 0.0f;
|
||||
|
||||
backend::CullingMode mCulling : 2;
|
||||
backend::RasterState::DepthFunc mDepthFunc : 3;
|
||||
bool mColorWrite : 1;
|
||||
bool mDepthWrite : 1;
|
||||
bool mHasScissor : 1;
|
||||
bool mIsDoubleSided : 1;
|
||||
TransparencyMode mTransparencyMode : 2;
|
||||
|
||||
uint64_t mMaterialSortingKey = 0;
|
||||
|
||||
|
||||
@@ -1250,12 +1250,24 @@ class_<MaterialInstance>("MaterialInstance")
|
||||
self->setParameter(name.c_str(), type, value); }), allow_raw_pointers())
|
||||
.function("setPolygonOffset", &MaterialInstance::setPolygonOffset)
|
||||
.function("setMaskThreshold", &MaterialInstance::setMaskThreshold)
|
||||
.function("getMaskThreshold", &MaterialInstance::getMaskThreshold)
|
||||
.function("setSpecularAntiAliasingVariance", &MaterialInstance::setSpecularAntiAliasingVariance)
|
||||
.function("getSpecularAntiAliasingVariance", &MaterialInstance::getSpecularAntiAliasingVariance)
|
||||
.function("setSpecularAntiAliasingThreshold", &MaterialInstance::setSpecularAntiAliasingThreshold)
|
||||
.function("getSpecularAntiAliasingThreshold", &MaterialInstance::getSpecularAntiAliasingThreshold)
|
||||
.function("setDoubleSided", &MaterialInstance::setDoubleSided)
|
||||
.function("isDoubleSided", &MaterialInstance::isDoubleSided)
|
||||
.function("setTransparencyMode", &MaterialInstance::setTransparencyMode)
|
||||
.function("getTransparencyMode", &MaterialInstance::getTransparencyMode)
|
||||
.function("setCullingMode", &MaterialInstance::setCullingMode)
|
||||
.function("getCullingMode", &MaterialInstance::getCullingMode)
|
||||
.function("setColorWrite", &MaterialInstance::setColorWrite)
|
||||
.function("isColorWriteEnabled", &MaterialInstance::isColorWriteEnabled)
|
||||
.function("setDepthWrite", &MaterialInstance::setDepthWrite)
|
||||
.function("isDepthWriteEnabled", &MaterialInstance::isDepthWriteEnabled)
|
||||
.function("setStencilWrite", &MaterialInstance::setStencilWrite)
|
||||
.function("setDepthCulling", &MaterialInstance::setDepthCulling)
|
||||
.function("isDepthCullingEnabled", &MaterialInstance::isDepthCullingEnabled)
|
||||
.function("setStencilCompareFunction", &MaterialInstance::setStencilCompareFunction)
|
||||
.function("setStencilCompareFunction", EMBIND_LAMBDA(void,
|
||||
(MaterialInstance* self, MaterialInstance::StencilCompareFunc func), {
|
||||
|
||||
@@ -398,6 +398,11 @@ enum_<backend::CullingMode>("CullingMode")
|
||||
.value("BACK", backend::CullingMode::BACK)
|
||||
.value("FRONT_AND_BACK", backend::CullingMode::FRONT_AND_BACK);
|
||||
|
||||
enum_<filament::TransparencyMode>("TransparencyMode")
|
||||
.value("DEFAULT", filament::TransparencyMode::DEFAULT)
|
||||
.value("TWO_PASSES_ONE_SIDE", filament::TransparencyMode::TWO_PASSES_ONE_SIDE)
|
||||
.value("TWO_PASSES_TWO_SIDES", filament::TransparencyMode::TWO_PASSES_TWO_SIDES);
|
||||
|
||||
enum_<backend::FeatureLevel>("FeatureLevel")
|
||||
.value("FEATURE_LEVEL_1", backend::FeatureLevel::FEATURE_LEVEL_1)
|
||||
.value("FEATURE_LEVEL_2", backend::FeatureLevel::FEATURE_LEVEL_2);
|
||||
|
||||
Reference in New Issue
Block a user