Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "engine: move setFrontFaceWindingInverted from View to Materia… #7360

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Instead, if you are authoring a PR for the main branch, add your release note to
- engine: Add `Material::getFeatureLevel()`
- engine: Add missing `Material::getReflectionMode()` method in Java
- engine: Support basic usage of post-processing materials on feature level 0
- engine: move `setFrontFaceWindingInverted` from `View` to `MaterialInstance` [**API CHANGE**]

## v1.45.1

Expand Down
34 changes: 10 additions & 24 deletions android/filament-android/src/main/cpp/MaterialInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,13 +433,6 @@ Java_com_google_android_filament_MaterialInstance_nSetStencilWriteMask(JNIEnv*,
instance->setStencilWriteMask(writeMask, static_cast<MaterialInstance::StencilFace>(face));
}

extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_MaterialInstance_nSetFrontFaceWindingInverted(JNIEnv*,
jclass, jlong nativeMaterialInstance, jboolean inverted) {
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
instance->setFrontFaceWindingInverted(inverted);
}

extern "C"
JNIEXPORT jstring JNICALL
Java_com_google_android_filament_MaterialInstance_nGetName(JNIEnv* env, jclass,
Expand Down Expand Up @@ -476,85 +469,78 @@ extern "C"
JNIEXPORT jfloat JNICALL
Java_com_google_android_filament_MaterialInstance_nGetMaskThreshold(JNIEnv* env, jclass clazz,
jlong nativeMaterialInstance) {
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
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) {
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
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) {
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
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) {
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
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) {
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
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) {
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
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) {
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
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) {
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
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) {
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
MaterialInstance* instance = (MaterialInstance*)nativeMaterialInstance;
return instance->isDepthCullingEnabled();
}

extern "C"
JNIEXPORT jint JNICALL
Java_com_google_android_filament_MaterialInstance_nGetDepthFunc(JNIEnv* env, jclass clazz,
jlong nativeMaterialInstance) {
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
MaterialInstance* instance = (MaterialInstance*)nativeMaterialInstance;
return (jint)instance->getDepthFunc();
}

extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_MaterialInstance_nIsFrontFaceWindingInverted(JNIEnv*,
jclass, jlong nativeMaterialInstance) {
MaterialInstance* instance = (MaterialInstance*) nativeMaterialInstance;
return static_cast<jboolean>(instance->isFrontFaceWindingInverted());
}
14 changes: 14 additions & 0 deletions android/filament-android/src/main/cpp/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,20 @@ Java_com_google_android_filament_View_nIsPostProcessingEnabled(JNIEnv*,
return static_cast<jboolean>(view->isPostProcessingEnabled());
}

extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetFrontFaceWindingInverted(JNIEnv*,
jclass, jlong nativeView, jboolean inverted) {
View* view = (View*) nativeView;
view->setFrontFaceWindingInverted(inverted);
}

extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_View_nIsFrontFaceWindingInverted(JNIEnv*,
jclass, jlong nativeView) {
View* view = (View*) nativeView;
return static_cast<jboolean>(view->isFrontFaceWindingInverted());
}

extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetAmbientOcclusion(JNIEnv*, jclass, jlong nativeView, jint ordinal) {
View* view = (View*) nativeView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -850,32 +850,6 @@ public void setStencilWriteMask(int writeMask) {
setStencilWriteMask(writeMask, StencilFace.FRONT_AND_BACK);
}

/**
* Returns true if front face winding order is inverted.
*
* @see #setFrontFaceWindingInverted
*/
public boolean isFrontFaceWindingInverted() {
return nIsFrontFaceWindingInverted(getNativeObject());
}

/**
* Inverts the winding order of front faces. By default front faces use a counter-clockwise
* winding order. When the winding order is inverted, front faces are faces with a clockwise
* winding order.
*
* Changing the winding order will directly affect the culling mode in materials
* (see Material#getCullingMode).
*
* Inverting the winding order of front faces is useful when rendering mirrored reflections
* (water, mirror surfaces, front camera in AR, etc.).
*
* @param inverted True to invert front faces, false otherwise.
*/
public void setFrontFaceWindingInverted(boolean inverted) {
nSetFrontFaceWindingInverted(getNativeObject(), inverted);
}

public long getNativeObject() {
if (mNativeObject == 0) {
throw new IllegalStateException("Calling method on destroyed MaterialInstance");
Expand Down Expand Up @@ -967,9 +941,6 @@ private static native void nSetStencilReadMask(long nativeMaterialInstance, int
private static native void nSetStencilWriteMask(long nativeMaterialInstance, int writeMask,
long face);

private static native void nSetFrontFaceWindingInverted(long nativeView, boolean inverted);
private static native boolean nIsFrontFaceWindingInverted(long nativeView);

private static native String nGetName(long nativeMaterialInstance);
private static native long nGetMaterial(long nativeMaterialInstance);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,32 @@ public void setPostProcessingEnabled(boolean enabled) {
nSetPostProcessingEnabled(getNativeObject(), enabled);
}

/**
* Returns true if post-processing is enabled.
*
* @see #setPostProcessingEnabled
*/
public boolean isFrontFaceWindingInverted() {
return nIsFrontFaceWindingInverted(getNativeObject());
}

/**
* Inverts the winding order of front faces. By default front faces use a counter-clockwise
* winding order. When the winding order is inverted, front faces are faces with a clockwise
* winding order.
*
* Changing the winding order will directly affect the culling mode in materials
* (see Material#getCullingMode).
*
* Inverting the winding order of front faces is useful when rendering mirrored reflections
* (water, mirror surfaces, front camera in AR, etc.).
*
* @param inverted True to invert front faces, false otherwise.
*/
public void setFrontFaceWindingInverted(boolean inverted) {
nSetFrontFaceWindingInverted(getNativeObject(), inverted);
}

/**
* Sets options relative to dynamic lighting for this view.
*
Expand Down Expand Up @@ -1185,6 +1211,8 @@ void clearNativeObject() {
private static native void nSetColorGrading(long nativeView, long nativeColorGrading);
private static native void nSetPostProcessingEnabled(long nativeView, boolean enabled);
private static native boolean nIsPostProcessingEnabled(long nativeView);
private static native void nSetFrontFaceWindingInverted(long nativeView, boolean inverted);
private static native boolean nIsFrontFaceWindingInverted(long nativeView);
private static native void nSetAmbientOcclusion(long nativeView, int ordinal);
private static native int nGetAmbientOcclusion(long nativeView);
private static native void nSetAmbientOcclusionOptions(long nativeView, float radius, float bias, float power, float resolution, float intensity, float bilateralThreshold, int quality, int lowPassFilter, int upsampling, boolean enabled, boolean bentNormals, float minHorizonAngleRad);
Expand Down
21 changes: 0 additions & 21 deletions filament/include/filament/MaterialInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,27 +480,6 @@ class UTILS_PUBLIC MaterialInstance : public FilamentAPI {
void setStencilWriteMask(uint8_t writeMask,
StencilFace face = StencilFace::FRONT_AND_BACK) noexcept;

/**
* Inverts the winding order of front faces. By default front faces use a counter-clockwise
* winding order. When the winding order is inverted, front faces are faces with a clockwise
* winding order.
*
* Changing the winding order will directly affect the culling mode in materials
* (see Material::getCullingMode()).
*
* Inverting the winding order of front faces is useful when rendering mirrored reflections
* (water, mirror surfaces, front camera in AR, etc.).
*
* @param inverted True to invert front faces, false otherwise.
*/
void setFrontFaceWindingInverted(bool inverted) noexcept;

/**
* Returns true if the winding order of front faces is inverted.
* See setFrontFaceWindingInverted() for more information.
*/
bool isFrontFaceWindingInverted() const noexcept;

protected:
// prevent heap allocation
~MaterialInstance() = default;
Expand Down
21 changes: 21 additions & 0 deletions filament/include/filament/View.h
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,27 @@ class UTILS_PUBLIC View : public FilamentAPI {
//! Returns true if post-processing is enabled. See setPostProcessingEnabled() for more info.
bool isPostProcessingEnabled() const noexcept;

/**
* Inverts the winding order of front faces. By default front faces use a counter-clockwise
* winding order. When the winding order is inverted, front faces are faces with a clockwise
* winding order.
*
* Changing the winding order will directly affect the culling mode in materials
* (see Material::getCullingMode()).
*
* Inverting the winding order of front faces is useful when rendering mirrored reflections
* (water, mirror surfaces, front camera in AR, etc.).
*
* @param inverted True to invert front faces, false otherwise.
*/
void setFrontFaceWindingInverted(bool inverted) noexcept;

/**
* Returns true if the winding order of front faces is inverted.
* See setFrontFaceWindingInverted() for more information.
*/
bool isFrontFaceWindingInverted() const noexcept;

/**
* Enables use of the stencil buffer.
*
Expand Down
8 changes: 0 additions & 8 deletions filament/src/MaterialInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,4 @@ bool MaterialInstance::isDepthCullingEnabled() const noexcept {
return downcast(this)->isDepthCullingEnabled();
}

void MaterialInstance::setFrontFaceWindingInverted(bool inverted) noexcept {
downcast(this)->setFrontFaceWindingInverted(inverted);
}

bool MaterialInstance::isFrontFaceWindingInverted() const noexcept {
return downcast(this)->isFrontFaceWindingInverted();
}

} // namespace filament
17 changes: 9 additions & 8 deletions filament/src/RenderPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ void RenderPass::instanceify(FEngine& engine) noexcept {
UTILS_ALWAYS_INLINE // this function exists only to make the code more readable. we want it inlined.
inline // and we don't need it in the compilation unit
void RenderPass::setupColorCommand(Command& cmdDraw, Variant variant,
FMaterialInstance const* const UTILS_RESTRICT mi, bool invertedFrontFaces) noexcept {
FMaterialInstance const* const UTILS_RESTRICT mi, bool inverseFrontFaces) noexcept {

FMaterial const * const UTILS_RESTRICT ma = mi->getMaterial();
variant = Variant::filterVariant(variant, ma->isVariantLit());
Expand Down Expand Up @@ -362,7 +362,7 @@ void RenderPass::setupColorCommand(Command& cmdDraw, Variant variant,
cmdDraw.primitive.rasterState.blendFunctionDstAlpha = blendingMustBeOff ?
BlendFunction::ZERO : cmdDraw.primitive.rasterState.blendFunctionDstAlpha;

cmdDraw.primitive.rasterState.inverseFrontFaces = invertedFrontFaces;
cmdDraw.primitive.rasterState.inverseFrontFaces = inverseFrontFaces;
cmdDraw.primitive.rasterState.culling = mi->getCullingMode();
cmdDraw.primitive.rasterState.colorWrite = mi->isColorWriteEnabled();
cmdDraw.primitive.rasterState.depthWrite = mi->isDepthWriteEnabled();
Expand Down Expand Up @@ -463,6 +463,7 @@ RenderPass::Command* RenderPass::generateCommandsImpl(uint32_t extraFlags,
auto const* const UTILS_RESTRICT soaInstanceInfo = soa.data<FScene::INSTANCES>();

const bool hasShadowing = renderFlags & HAS_SHADOWING;
const bool viewInverseFrontFaces = renderFlags & HAS_INVERSE_FRONT_FACES;
const bool hasInstancedStereo = renderFlags & IS_STEREOSCOPIC;

Command cmdColor;
Expand Down Expand Up @@ -517,6 +518,7 @@ RenderPass::Command* RenderPass::generateCommandsImpl(uint32_t extraFlags,
const uint32_t distanceBits = reinterpret_cast<uint32_t&>(distance);

// calculate the per-primitive face winding order inversion
const bool inverseFrontFaces = viewInverseFrontFaces ^ soaVisibility[i].reversedWindingOrder;
const bool hasMorphing = soaVisibility[i].morphing;
const bool hasSkinningOrMorphing = soaVisibility[i].skinning || hasMorphing;

Expand Down Expand Up @@ -554,6 +556,7 @@ RenderPass::Command* RenderPass::generateCommandsImpl(uint32_t extraFlags,
soaInstanceInfo[i].count | PrimitiveInfo::USER_INSTANCE_MASK;
cmdDepth.primitive.instanceBufferHandle = soaInstanceInfo[i].handle;
cmdDepth.primitive.materialVariant.setSkinning(hasSkinningOrMorphing);
cmdDepth.primitive.rasterState.inverseFrontFaces = inverseFrontFaces;

if (UTILS_UNLIKELY(hasInstancedStereo)) {
cmdColor.primitive.instanceCount =
Expand All @@ -565,9 +568,8 @@ RenderPass::Command* RenderPass::generateCommandsImpl(uint32_t extraFlags,
renderableVariant.setFog(soaVisibility[i].fog && Variant::isFogVariant(variant));
}

bool const shadowCaster = soaVisibility[i].castShadows & hasShadowing;
bool const writeDepthForShadowCasters = depthContainsShadowCasters & shadowCaster;
bool const reverseWindingOrder = soaVisibility[i].reversedWindingOrder;
const bool shadowCaster = soaVisibility[i].castShadows & hasShadowing;
const bool writeDepthForShadowCasters = depthContainsShadowCasters & shadowCaster;

const Slice<FRenderPrimitive>& primitives = soaPrimitives[i];
const FRenderableManager::SkinningBindingInfo& skinning = soaSkinning[i];
Expand All @@ -582,11 +584,10 @@ RenderPass::Command* RenderPass::generateCommandsImpl(uint32_t extraFlags,
auto const& morphTargets = morphing.targets[pi];
FMaterialInstance const* const mi = primitive.getMaterialInstance();
FMaterial const* const ma = mi->getMaterial();
bool const invertedFrontFaces = mi->isFrontFaceWindingInverted() ^ reverseWindingOrder;

if constexpr (isColorPass) {
cmdColor.primitive.primitiveHandle = primitive.getHwHandle();
RenderPass::setupColorCommand(cmdColor, renderableVariant, mi, invertedFrontFaces);
RenderPass::setupColorCommand(cmdColor, renderableVariant, mi, inverseFrontFaces);

cmdColor.primitive.skinningHandle = skinning.handle;
cmdColor.primitive.skinningOffset = skinning.offset;
Expand Down Expand Up @@ -615,6 +616,7 @@ RenderPass::Command* RenderPass::generateCommandsImpl(uint32_t extraFlags,
cmdColor.key |= makeField(primitive.getBlendOrder(),
BLEND_ORDER_MASK, BLEND_ORDER_SHIFT);


const TransparencyMode mode = mi->getTransparencyMode();

// handle transparent objects, two techniques:
Expand Down Expand Up @@ -692,7 +694,6 @@ RenderPass::Command* RenderPass::generateCommandsImpl(uint32_t extraFlags,
cmdDepth.primitive.primitiveHandle = primitive.getHwHandle();
cmdDepth.primitive.mi = mi;
cmdDepth.primitive.rasterState.culling = mi->getCullingMode();
cmdDepth.primitive.rasterState.inverseFrontFaces = invertedFrontFaces;

cmdDepth.primitive.skinningHandle = skinning.handle;
cmdDepth.primitive.skinningOffset = skinning.offset;
Expand Down
Loading
Loading