Skip to content

Commit b43df23

Browse files
authored
Merge branch 'main' into pf/matdbg-fix-collision
2 parents d92a229 + 1f1389e commit b43df23

File tree

29 files changed

+163
-96
lines changed

29 files changed

+163
-96
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ repositories {
3131
}
3232
3333
dependencies {
34-
implementation 'com.google.android.filament:filament-android:1.56.3'
34+
implementation 'com.google.android.filament:filament-android:1.56.4'
3535
}
3636
```
3737

@@ -51,7 +51,7 @@ Here are all the libraries available in the group `com.google.android.filament`:
5151
iOS projects can use CocoaPods to install the latest release:
5252

5353
```shell
54-
pod 'Filament', '~> 1.56.3'
54+
pod 'Filament', '~> 1.56.4'
5555
```
5656

5757
## Documentation

RELEASE_NOTES.md

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ A new header is inserted each time a *tag* is created.
77
Instead, if you are authoring a PR for the main branch, add your release note to
88
[NEW_RELEASE_NOTES.md](./NEW_RELEASE_NOTES.md).
99

10+
## v1.56.5
11+
12+
1013
## v1.56.4
1114

1215

android/filament-android/src/main/cpp/Material.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ using namespace filament;
2525

2626
extern "C" JNIEXPORT jlong JNICALL
2727
Java_com_google_android_filament_Material_nBuilderBuild(JNIEnv *env, jclass,
28-
jlong nativeEngine, jobject buffer_, jint size, jint shBandCount) {
28+
jlong nativeEngine, jobject buffer_, jint size, jint shBandCount, jint shadowQuality) {
2929
Engine* engine = (Engine*) nativeEngine;
3030
AutoBuffer buffer(env, buffer_, size);
3131
auto builder = Material::Builder();
3232
if (shBandCount) {
3333
builder.sphericalHarmonicsBandCount(shBandCount);
3434
}
35+
builder.shadowSamplingQuality((Material::Builder::ShadowSamplingQuality)shadowQuality);
3536
Material* material = builder
3637
.package(buffer.getData(), buffer.getSize())
3738
.build(*engine);

android/filament-android/src/main/java/com/google/android/filament/Material.java

+23-2
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,18 @@ public Material(long nativeMaterial) {
344344
}
345345

346346
public static class Builder {
347+
public enum ShadowSamplingQuality {
348+
/** 2x2 PCF */
349+
HARD,
350+
/** 3x3 gaussian filter */
351+
LOW,
352+
}
353+
347354
private Buffer mBuffer;
348355
private int mSize;
349356
private int mShBandCount = 0;
357+
private ShadowSamplingQuality mShadowSamplingQuality = ShadowSamplingQuality.LOW;
358+
350359

351360
/**
352361
* Specifies the material data. The material data is a binary blob produced by
@@ -378,6 +387,18 @@ public Builder sphericalHarmonicsBandCount(@IntRange(from = 0) int shBandCount)
378387
return this;
379388
}
380389

390+
/**
391+
* Set the quality of shadow sampling. This is only taken into account
392+
* if this material is lit and in the surface domain.
393+
* @param quality
394+
* @return Reference to this Builder for chaining calls.
395+
*/
396+
@NonNull
397+
public Builder shadowSamplingQuality(ShadowSamplingQuality quality) {
398+
mShadowSamplingQuality = quality;
399+
return this;
400+
}
401+
381402
/**
382403
* Creates and returns the Material object.
383404
*
@@ -390,7 +411,7 @@ public Builder sphericalHarmonicsBandCount(@IntRange(from = 0) int shBandCount)
390411
@NonNull
391412
public Material build(@NonNull Engine engine) {
392413
long nativeMaterial = nBuilderBuild(engine.getNativeObject(),
393-
mBuffer, mSize, mShBandCount);
414+
mBuffer, mSize, mShBandCount, mShadowSamplingQuality.ordinal());
394415
if (nativeMaterial == 0) throw new IllegalStateException("Couldn't create Material");
395416
return new Material(nativeMaterial);
396417
}
@@ -1041,7 +1062,7 @@ void clearNativeObject() {
10411062
mNativeObject = 0;
10421063
}
10431064

1044-
private static native long nBuilderBuild(long nativeEngine, @NonNull Buffer buffer, int size, int shBandCount);
1065+
private static native long nBuilderBuild(long nativeEngine, @NonNull Buffer buffer, int size, int shBandCount, int shadowQuality);
10451066
private static native long nCreateInstance(long nativeMaterial);
10461067
private static native long nCreateInstanceWithName(long nativeMaterial, @NonNull String name);
10471068
private static native long nGetDefaultInstance(long nativeMaterial);

android/gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
GROUP=com.google.android.filament
2-
VERSION_NAME=1.56.3
2+
VERSION_NAME=1.56.4
33

44
POM_DESCRIPTION=Real-time physically based rendering engine for Android.
55

docs/Filament.html

+1-1
Large diffs are not rendered by default.

docs/remote/filament.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/remote/filament.wasm

985 Bytes
Binary file not shown.

docs/webgl/filament.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/webgl/filament.wasm

977 Bytes
Binary file not shown.

docs/webgl/triangle.filamat

175 Bytes
Binary file not shown.

filament/backend/src/metal/MetalContext.h

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ struct MetalContext {
155155

156156
RenderPassFlags currentRenderPassFlags;
157157
MetalRenderTarget* currentRenderTarget = nullptr;
158+
bool validPipelineBound = false;
158159

159160
// State trackers.
160161
PipelineStateTracker pipelineState;

filament/backend/src/metal/MetalDriver.mm

+7
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,7 @@
16571657
// during the draw call when the program is invalid. The shader compile error has already been
16581658
// dumped to the console at this point, so it's fine to simply return early.
16591659
if (FILAMENT_ENABLE_MATDBG && UTILS_UNLIKELY(!functions)) {
1660+
mContext->validPipelineBound = false;
16601661
return;
16611662
}
16621663

@@ -1789,6 +1790,8 @@
17891790
clamp:0.0];
17901791
mContext->currentPolygonOffset = ps.polygonOffset;
17911792
}
1793+
1794+
mContext->validPipelineBound = true;
17921795
}
17931796

17941797
void MetalDriver::bindRenderPrimitive(Handle<HwRenderPrimitive> rph) {
@@ -1886,6 +1889,10 @@
18861889
<< "draw() without a valid command encoder.";
18871890
DEBUG_LOG("draw2(...)\n");
18881891

1892+
if (FILAMENT_ENABLE_MATDBG && UTILS_UNLIKELY(!mContext->validPipelineBound)) {
1893+
return;
1894+
}
1895+
18891896
// Bind the offset data.
18901897
if (mContext->dynamicOffsets.isDirty()) {
18911898
const auto [size, data] = mContext->dynamicOffsets.getOffsets();

filament/include/filament/Material.h

+13
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ class UTILS_PUBLIC Material : public FilamentAPI {
103103
Builder& operator=(Builder const& rhs) noexcept;
104104
Builder& operator=(Builder&& rhs) noexcept;
105105

106+
enum class ShadowSamplingQuality : uint8_t {
107+
HARD, // 2x2 PCF
108+
LOW // 3x3 gaussian filter
109+
};
110+
106111
/**
107112
* Specifies the material data. The material data is a binary blob produced by
108113
* libfilamat or by matc.
@@ -152,6 +157,14 @@ class UTILS_PUBLIC Material : public FilamentAPI {
152157
*/
153158
Builder& sphericalHarmonicsBandCount(size_t shBandCount) noexcept;
154159

160+
/**
161+
* Set the quality of shadow sampling. This is only taken into account
162+
* if this material is lit and in the surface domain.
163+
* @param quality
164+
* @return
165+
*/
166+
Builder& shadowSamplingQuality(ShadowSamplingQuality quality) noexcept;
167+
155168
/**
156169
* Creates the Material object and returns a pointer to it.
157170
*

filament/include/filament/Options.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ struct MultiSampleAntiAliasingOptions {
438438
* @see setTemporalAntiAliasingOptions()
439439
*/
440440
struct TemporalAntiAliasingOptions {
441-
float filterWidth = 1.0f; //!< reconstruction filter width typically between 0.2 (sharper, aliased) and 1.5 (smoother)
441+
float filterWidth = 1.0f; //!< reconstruction filter width typically between 1 (sharper) and 2 (smoother)
442442
float feedback = 0.12f; //!< history feedback, between 0 (maximum temporal AA) and 1 (no temporal AA).
443443
float lodBias = -1.0f; //!< texturing lod bias (typically -1 or -2)
444444
float sharpness = 0.0f; //!< post-TAA sharpen, especially useful when upscaling is true.

filament/src/PostProcessManager.cpp

+25-10
Original file line numberDiff line numberDiff line change
@@ -2622,7 +2622,7 @@ void PostProcessManager::TaaJitterCamera(
26222622
current.projection = inoutCameraInfo->projection * inoutCameraInfo->getUserViewMatrix();
26232623
current.frameId = previous.frameId + 1;
26242624

2625-
auto jitterPosition = [pattern = taaOptions.jitterPattern](size_t frameIndex){
2625+
auto jitterPosition = [pattern = taaOptions.jitterPattern](size_t frameIndex) -> float2 {
26262626
using JitterPattern = TemporalAntiAliasingOptions::JitterPattern;
26272627
switch (pattern) {
26282628
case JitterPattern::RGSS_X4:
@@ -2636,6 +2636,7 @@ void PostProcessManager::TaaJitterCamera(
26362636
case JitterPattern::HALTON_23_X32:
26372637
return sHaltonSamples(frameIndex);
26382638
}
2639+
return { 0.0f, 0.0f };
26392640
};
26402641

26412642
// sample position within a pixel [-0.5, 0.5]
@@ -2759,15 +2760,31 @@ FrameGraphId<FrameGraphTexture> PostProcessManager::taa(FrameGraph& fg,
27592760
}};
27602761

27612762
constexpr float2 sampleOffsets[9] = {
2762-
{ -1.0f, -1.0f }, { 0.0f, -1.0f }, { 1.0f, -1.0f },
2763-
{ -1.0f, 0.0f }, { 0.0f, 0.0f }, { 1.0f, 0.0f },
2764-
{ -1.0f, 1.0f }, { 0.0f, 1.0f }, { 1.0f, 1.0f },
2763+
{ -1.0f, -1.0f }, { 0.0f, -1.0f }, { 1.0f, -1.0f }, { -1.0f, 0.0f },
2764+
{ 0.0f, 0.0f },
2765+
{ 1.0f, 0.0f }, { -1.0f, 1.0f }, { 0.0f, 1.0f }, { 1.0f, 1.0f },
27652766
};
27662767

27672768
constexpr float2 subSampleOffsets[4] = {
2768-
{ -0.25f, 0.25f }, { 0.25f, 0.25f }, { 0.25f, -0.25f }, { -0.25f, -0.25f }
2769+
{ -0.25f, 0.25f },
2770+
{ 0.25f, 0.25f },
2771+
{ 0.25f, -0.25f },
2772+
{ -0.25f, -0.25f }
27692773
};
27702774

2775+
UTILS_UNUSED
2776+
auto const lanczos = [](float x, float a) -> float {
2777+
if (x <= std::numeric_limits<float>::epsilon()) {
2778+
return 1.0f;
2779+
}
2780+
if (std::abs(x) <= a) {
2781+
return (a * std::sin(f::PI * x) * std::sin(f::PI * x / a))
2782+
/ ((f::PI * f::PI) * (x * x));
2783+
}
2784+
return 0.0f;
2785+
};
2786+
2787+
float const filterWidth = std::clamp(taaOptions.filterWidth, 1.0f, 2.0f);
27712788
float4 sum = 0.0;
27722789
float4 weights[9];
27732790

@@ -2777,11 +2794,9 @@ FrameGraphId<FrameGraphTexture> PostProcessManager::taa(FrameGraph& fg,
27772794
for (size_t i = 0; i < 9; i++) {
27782795
float2 const o = sampleOffsets[i];
27792796
for (size_t j = 0; j < 4; j++) {
2780-
float2 const s = taaOptions.upscaling ? subSampleOffsets[j] : float2{ 0 };
2781-
float2 const d = (o - current.jitter - s) / taaOptions.filterWidth;
2782-
// This is a gaussian fit of a 3.3-wide Blackman-Harris window
2783-
// see: "High Quality Temporal Supersampling" by Brian Karis
2784-
weights[i][j] = std::exp(-2.29f * (d.x * d.x + d.y * d.y));
2797+
float2 const subPixelOffset = taaOptions.upscaling ? subSampleOffsets[j] : float2{ 0 };
2798+
float2 const d = (o - (current.jitter - subPixelOffset)) / filterWidth;
2799+
weights[i][j] = lanczos(length(d), filterWidth);
27852800
}
27862801
sum += weights[i];
27872802
}

filament/src/PostProcessManager.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ class PostProcessManager {
428428

429429
template<size_t SIZE>
430430
struct JitterSequence {
431-
auto operator()(size_t i) const noexcept { return positions[i % SIZE] - 0.5f; }
431+
math::float2 operator()(size_t i) const noexcept { return positions[i % SIZE] - 0.5f; }
432432
const std::array<math::float2, SIZE> positions;
433433
};
434434

filament/src/RenderPass.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -680,8 +680,6 @@ RenderPass::Command* RenderPass::generateCommandsImpl(RenderPass::CommandTypeFla
680680
cmd.info.hasMorphing = (bool)morphing.handle;
681681
cmd.info.hasSkinning = (bool)skinning.handle;
682682

683-
assert_invariant(cmd.info.hasHybridInstancing || cmd.info.instanceCount <= 1);
684-
685683
// soaInstanceInfo[i].count is the number of instances the user has requested, either for
686684
// manual or hybrid instancing. Instanced stereo multiplies the number of instances by the
687685
// eye count.

filament/src/details/Material.cpp

+13-3
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ struct Material::BuilderDetails {
123123
size_t mSize = 0;
124124
bool mDefaultMaterial = false;
125125
int32_t mShBandsCount = 3;
126+
Builder::ShadowSamplingQuality mShadowSamplingQuality = Builder::ShadowSamplingQuality::LOW;
126127
std::unordered_map<
127128
utils::CString,
128129
std::variant<int32_t, float, bool>,
@@ -152,6 +153,11 @@ Material::Builder& Material::Builder::sphericalHarmonicsBandCount(size_t shBandC
152153
return *this;
153154
}
154155

156+
Material::Builder& Material::Builder::shadowSamplingQuality(ShadowSamplingQuality quality) noexcept {
157+
mImpl->mShadowSamplingQuality = quality;
158+
return *this;
159+
}
160+
155161
template<typename T, typename>
156162
Material::Builder& Material::Builder::constant(const char* name, size_t nameLength, T value) {
157163
FILAMENT_CHECK_PRECONDITION(name != nullptr) << "name cannot be null";
@@ -550,7 +556,7 @@ Program FMaterial::getProgramWithVariants(
550556
<< "The material '" << mName.c_str()
551557
<< "' has not been compiled to include the required GLSL or SPIR-V chunks for the "
552558
"vertex shader (variant="
553-
<< variant.key << ", filtered=" << vertexVariant.key << ").";
559+
<< +variant.key << ", filtered=" << +vertexVariant.key << ").";
554560

555561
/*
556562
* Fragment shader
@@ -565,7 +571,7 @@ Program FMaterial::getProgramWithVariants(
565571
<< "The material '" << mName.c_str()
566572
<< "' has not been compiled to include the required GLSL or SPIR-V chunks for the "
567573
"fragment shader (variant="
568-
<< variant.key << ", filtered=" << ").";
574+
<< +variant.key << ", filtered=" << +fragmentVariant.key << ").";
569575

570576
Program program;
571577
program.shader(ShaderStage::VERTEX, vsBuilder.data(), vsBuilder.size())
@@ -996,7 +1002,11 @@ void FMaterial::processSpecializationConstants(FEngine& engine, Material::Builde
9961002
+ReservedSpecializationConstants::CONFIG_STEREO_EYE_COUNT,
9971003
(int)engine.getConfig().stereoscopicEyeCount });
9981004
mSpecializationConstants.push_back({
999-
+ReservedSpecializationConstants::CONFIG_SH_BANDS_COUNT, builder->mShBandsCount });
1005+
+ReservedSpecializationConstants::CONFIG_SH_BANDS_COUNT,
1006+
builder->mShBandsCount });
1007+
mSpecializationConstants.push_back({
1008+
+ReservedSpecializationConstants::CONFIG_SHADOW_SAMPLING_METHOD,
1009+
(int32_t)builder->mShadowSamplingQuality });
10001010
if (UTILS_UNLIKELY(parser->getShaderLanguage() == ShaderLanguage::ESSL1)) {
10011011
// The actual value of this spec-constant is set in the OpenGLDriver backend.
10021012
mSpecializationConstants.push_back({

filament/src/ds/DescriptorSet.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ void DescriptorSet::setSampler(
149149

150150
DescriptorSet DescriptorSet::duplicate(DescriptorSetLayout const& layout) const noexcept {
151151
DescriptorSet set{layout};
152-
memcpy(set.mDescriptors.data(), mDescriptors.data(), mDescriptors.size() * sizeof(Desc));
152+
set.mDescriptors = mDescriptors; // Use the vector's assignment operator
153153
set.mDirty = mDirty;
154154
set.mValid = mValid;
155155
return set;

0 commit comments

Comments
 (0)