From 5943382d23ef0003291f6d42a9629c7c95abc401 Mon Sep 17 00:00:00 2001 From: Ben Doherty Date: Thu, 21 Oct 2021 11:13:51 -0700 Subject: [PATCH 1/9] iOS: avoid precision issues with CACurrentMediaTime (#4753) --- ios/samples/gltf-viewer/gltf-viewer/FILViewController.mm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ios/samples/gltf-viewer/gltf-viewer/FILViewController.mm b/ios/samples/gltf-viewer/gltf-viewer/FILViewController.mm index a1a236fe4a..5ae108d847 100644 --- a/ios/samples/gltf-viewer/gltf-viewer/FILViewController.mm +++ b/ios/samples/gltf-viewer/gltf-viewer/FILViewController.mm @@ -45,6 +45,7 @@ using namespace utils; @implementation FILViewController { CADisplayLink* _displayLink; + CFTimeInterval _startTime; viewer::RemoteServer* _server; viewer::AutomationEngine* _automation; @@ -102,6 +103,7 @@ using namespace utils; [self stopDisplayLink]; // Call our render method 60 times a second. + _startTime = CACurrentMediaTime(); _displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(render)]; _displayLink.preferredFramesPerSecond = 60; [_displayLink addToRunLoop:NSRunLoop.currentRunLoop forMode:NSDefaultRunLoopMode]; @@ -230,7 +232,8 @@ using namespace utils; auto* animator = self.modelView.animator; if (animator) { if (animator->getAnimationCount() > 0) { - animator->applyAnimation(0, CACurrentMediaTime()); + CFTimeInterval elapsedTime = CACurrentMediaTime() - _startTime; + animator->applyAnimation(0, static_cast(elapsedTime)); } animator->updateBoneMatrices(); } From ef4dfcecd6aec7492825f6743848c7d6149eb86c Mon Sep 17 00:00:00 2001 From: Ben Doherty Date: Thu, 21 Oct 2021 11:27:05 -0700 Subject: [PATCH 2/9] Metal: support framebuffer fetch on M1 devices (#4735) --- filament/backend/src/metal/MetalDriver.mm | 20 +++++++++++--------- filament/backend/src/metal/MetalHandles.mm | 3 +-- libs/filamat/src/GLSLPostProcessor.cpp | 10 ++++++++-- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/filament/backend/src/metal/MetalDriver.mm b/filament/backend/src/metal/MetalDriver.mm index ac30da6bb6..f111dc613a 100644 --- a/filament/backend/src/metal/MetalDriver.mm +++ b/filament/backend/src/metal/MetalDriver.mm @@ -64,16 +64,19 @@ MetalDriver::MetalDriver(backend::MetalPlatform* platform) noexcept initializeSupportedGpuFamilies(mContext); - utils::slog.d << "Supported GPU families: " << utils::io::endl; + utils::slog.v << "Supported GPU families: " << utils::io::endl; if (mContext->highestSupportedGpuFamily.common > 0) { - utils::slog.d << " MTLGPUFamilyCommon" << (int) mContext->highestSupportedGpuFamily.common << utils::io::endl; + utils::slog.v << " MTLGPUFamilyCommon" << (int) mContext->highestSupportedGpuFamily.common << utils::io::endl; } if (mContext->highestSupportedGpuFamily.apple > 0) { - utils::slog.d << " MTLGPUFamilyApple" << (int) mContext->highestSupportedGpuFamily.apple << utils::io::endl; + utils::slog.v << " MTLGPUFamilyApple" << (int) mContext->highestSupportedGpuFamily.apple << utils::io::endl; } if (mContext->highestSupportedGpuFamily.mac > 0) { - utils::slog.d << " MTLGPUFamilyMac" << (int) mContext->highestSupportedGpuFamily.mac << utils::io::endl; + utils::slog.v << " MTLGPUFamilyMac" << (int) mContext->highestSupportedGpuFamily.mac << utils::io::endl; } + utils::slog.v << "Features:" << utils::io::endl; + utils::slog.v << " readWriteTextureSupport: " << + (bool) mContext->device.readWriteTextureSupport << utils::io::endl; // In order to support texture swizzling, the GPU needs to support it and the system be running // iOS 13+. @@ -650,11 +653,10 @@ bool MetalDriver::isRenderTargetFormatSupported(TextureFormat format) { } bool MetalDriver::isFrameBufferFetchSupported() { -#if defined(IOS) && !defined(FILAMENT_IOS_SIMULATOR) - return true; -#else - return false; -#endif + // FrameBuffer fetch is achievable via "programmable blending" in Metal, and only supported on + // Apple GPUs with readWriteTextureSupport. + return mContext->highestSupportedGpuFamily.apple >= 1 && + mContext->device.readWriteTextureSupport; } bool MetalDriver::isFrameBufferFetchMultiSampleSupported() { diff --git a/filament/backend/src/metal/MetalHandles.mm b/filament/backend/src/metal/MetalHandles.mm index 2e3dad5636..88133e15bb 100644 --- a/filament/backend/src/metal/MetalHandles.mm +++ b/filament/backend/src/metal/MetalHandles.mm @@ -352,8 +352,7 @@ MetalProgram::MetalProgram(id device, const Program& program) noexcep length:source.size() encoding:NSUTF8StringEncoding]; NSError* error = nil; - MTLCompileOptions* options = [MTLCompileOptions new]; - options.languageVersion = MTLLanguageVersion1_1; + // When options is nil, Metal uses the most recent language version available. id library = [device newLibraryWithSource:objcSource options:nil error:&error]; diff --git a/libs/filamat/src/GLSLPostProcessor.cpp b/libs/filamat/src/GLSLPostProcessor.cpp index 6c9de50f25..30d0f967f8 100644 --- a/libs/filamat/src/GLSLPostProcessor.cpp +++ b/libs/filamat/src/GLSLPostProcessor.cpp @@ -121,10 +121,16 @@ void GLSLPostProcessor::spirvToToMsl(const SpirvBlob *spirv, std::string *outMsl CompilerMSL::Options mslOptions = {}; mslOptions.platform = platform, - mslOptions.msl_version = CompilerMSL::Options::make_msl_version(1, 1); + mslOptions.msl_version = config.shaderModel == filament::backend::ShaderModel::GL_ES_30 ? + CompilerMSL::Options::make_msl_version(2, 0) : CompilerMSL::Options::make_msl_version(2, 2); - if (config.shaderModel == filament::backend::ShaderModel::GL_ES_30) { + if (config.hasFramebufferFetch) { mslOptions.use_framebuffer_fetch_subpasses = true; + // On macOS, framebuffer fetch is only available starting with MSL 2.3. Filament will only + // use framebuffer fetch materials on devices that support it. + if (config.shaderModel == filament::backend::ShaderModel::GL_CORE_41) { + mslOptions.msl_version = CompilerMSL::Options::make_msl_version(2, 3); + } } mslCompiler.set_msl_options(mslOptions); From 9a3c9ccbf3b0af5dc87c16e499f24c0c713e62e8 Mon Sep 17 00:00:00 2001 From: clayly <31773799+clayly@users.noreply.github.com> Date: Sun, 24 Oct 2021 21:12:15 +0300 Subject: [PATCH 3/9] android-samples-gradle-plugin-id (#4740) --- android/buildSrc/build.gradle | 14 ++++++++++++++ android/samples/sample-gltf-viewer/build.gradle | 8 +++++--- android/samples/sample-hello-camera/build.gradle | 8 +++++--- android/samples/sample-hello-triangle/build.gradle | 8 +++++--- .../sample-image-based-lighting/build.gradle | 8 +++++--- android/samples/sample-lit-cube/build.gradle | 8 +++++--- .../samples/sample-material-builder/build.gradle | 8 +++++--- android/samples/sample-multi-view/build.gradle | 8 +++++--- android/samples/sample-page-curl/build.gradle | 7 +++++-- android/samples/sample-stream-test/build.gradle | 8 +++++--- android/samples/sample-texture-view/build.gradle | 8 +++++--- .../samples/sample-textured-object/build.gradle | 8 +++++--- .../samples/sample-transparent-view/build.gradle | 8 +++++--- 13 files changed, 74 insertions(+), 35 deletions(-) diff --git a/android/buildSrc/build.gradle b/android/buildSrc/build.gradle index b965e9bb6e..d4315035f0 100644 --- a/android/buildSrc/build.gradle +++ b/android/buildSrc/build.gradle @@ -1,3 +1,17 @@ + +plugins { + id 'groovy-gradle-plugin' +} + +gradlePlugin { + plugins { + create("filament-tools-plugin") { + id = "filament-tools-plugin" + implementationClass = "FilamentToolsPlugin" + } + } +} + repositories { mavenCentral() } diff --git a/android/samples/sample-gltf-viewer/build.gradle b/android/samples/sample-gltf-viewer/build.gradle index 2e1230aac6..39e923f023 100644 --- a/android/samples/sample-gltf-viewer/build.gradle +++ b/android/samples/sample-gltf-viewer/build.gradle @@ -1,6 +1,8 @@ -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply plugin: FilamentToolsPlugin +plugins { + id 'com.android.application' + id 'kotlin-android' + id 'filament-tools-plugin' +} project.ext.isSample = true diff --git a/android/samples/sample-hello-camera/build.gradle b/android/samples/sample-hello-camera/build.gradle index eac4553fd4..3ff4b4b4e6 100644 --- a/android/samples/sample-hello-camera/build.gradle +++ b/android/samples/sample-hello-camera/build.gradle @@ -1,6 +1,8 @@ -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply plugin: FilamentToolsPlugin +plugins { + id 'com.android.application' + id 'kotlin-android' + id 'filament-tools-plugin' +} project.ext.isSample = true diff --git a/android/samples/sample-hello-triangle/build.gradle b/android/samples/sample-hello-triangle/build.gradle index 8c4e76849d..cb768787ce 100644 --- a/android/samples/sample-hello-triangle/build.gradle +++ b/android/samples/sample-hello-triangle/build.gradle @@ -1,6 +1,8 @@ -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply plugin: FilamentToolsPlugin +plugins { + id 'com.android.application' + id 'kotlin-android' + id 'filament-tools-plugin' +} project.ext.isSample = true diff --git a/android/samples/sample-image-based-lighting/build.gradle b/android/samples/sample-image-based-lighting/build.gradle index bf9a346a86..03328be1f4 100644 --- a/android/samples/sample-image-based-lighting/build.gradle +++ b/android/samples/sample-image-based-lighting/build.gradle @@ -1,6 +1,8 @@ -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply plugin: FilamentToolsPlugin +plugins { + id 'com.android.application' + id 'kotlin-android' + id 'filament-tools-plugin' +} project.ext.isSample = true diff --git a/android/samples/sample-lit-cube/build.gradle b/android/samples/sample-lit-cube/build.gradle index d649fa7be8..432ca05b91 100644 --- a/android/samples/sample-lit-cube/build.gradle +++ b/android/samples/sample-lit-cube/build.gradle @@ -1,6 +1,8 @@ -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply plugin: FilamentToolsPlugin +plugins { + id 'com.android.application' + id 'kotlin-android' + id 'filament-tools-plugin' +} project.ext.isSample = true diff --git a/android/samples/sample-material-builder/build.gradle b/android/samples/sample-material-builder/build.gradle index 4e9c186d6b..0d08d43b2c 100644 --- a/android/samples/sample-material-builder/build.gradle +++ b/android/samples/sample-material-builder/build.gradle @@ -1,6 +1,8 @@ -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply plugin: FilamentToolsPlugin +plugins { + id 'com.android.application' + id 'kotlin-android' + id 'filament-tools-plugin' +} project.ext.isSample = true diff --git a/android/samples/sample-multi-view/build.gradle b/android/samples/sample-multi-view/build.gradle index 15a858cbc5..b0562428d5 100644 --- a/android/samples/sample-multi-view/build.gradle +++ b/android/samples/sample-multi-view/build.gradle @@ -1,6 +1,8 @@ -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply plugin: FilamentToolsPlugin +plugins { + id 'com.android.application' + id 'kotlin-android' + id 'filament-tools-plugin' +} project.ext.isSample = true diff --git a/android/samples/sample-page-curl/build.gradle b/android/samples/sample-page-curl/build.gradle index 75efb4c90f..9a06422375 100644 --- a/android/samples/sample-page-curl/build.gradle +++ b/android/samples/sample-page-curl/build.gradle @@ -1,5 +1,8 @@ -apply plugin: 'com.android.application' -apply plugin: FilamentToolsPlugin +plugins { + id 'com.android.application' + id 'kotlin-android' + id 'filament-tools-plugin' +} project.ext.isSample = true diff --git a/android/samples/sample-stream-test/build.gradle b/android/samples/sample-stream-test/build.gradle index 865e031195..aea342fe4d 100644 --- a/android/samples/sample-stream-test/build.gradle +++ b/android/samples/sample-stream-test/build.gradle @@ -1,6 +1,8 @@ -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply plugin: FilamentToolsPlugin +plugins { + id 'com.android.application' + id 'kotlin-android' + id 'filament-tools-plugin' +} project.ext.isSample = true diff --git a/android/samples/sample-texture-view/build.gradle b/android/samples/sample-texture-view/build.gradle index 0c29f20273..e793516329 100644 --- a/android/samples/sample-texture-view/build.gradle +++ b/android/samples/sample-texture-view/build.gradle @@ -1,6 +1,8 @@ -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply plugin: FilamentToolsPlugin +plugins { + id 'com.android.application' + id 'kotlin-android' + id 'filament-tools-plugin' +} project.ext.isSample = true diff --git a/android/samples/sample-textured-object/build.gradle b/android/samples/sample-textured-object/build.gradle index 664398adc2..3228a5a2ed 100644 --- a/android/samples/sample-textured-object/build.gradle +++ b/android/samples/sample-textured-object/build.gradle @@ -1,6 +1,8 @@ -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply plugin: FilamentToolsPlugin +plugins { + id 'com.android.application' + id 'kotlin-android' + id 'filament-tools-plugin' +} project.ext.isSample = true diff --git a/android/samples/sample-transparent-view/build.gradle b/android/samples/sample-transparent-view/build.gradle index 0c29f20273..e793516329 100644 --- a/android/samples/sample-transparent-view/build.gradle +++ b/android/samples/sample-transparent-view/build.gradle @@ -1,6 +1,8 @@ -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply plugin: FilamentToolsPlugin +plugins { + id 'com.android.application' + id 'kotlin-android' + id 'filament-tools-plugin' +} project.ext.isSample = true From 5fea428243867572f285a6f2c734460c1f67130d Mon Sep 17 00:00:00 2001 From: Benjamin Doherty Date: Mon, 25 Oct 2021 11:01:01 -0700 Subject: [PATCH 4/9] Release Filament 1.12.10 --- README.md | 4 ++-- RELEASE_NOTES.md | 7 ++++++- android/gradle.properties | 2 +- ios/CocoaPods/Filament.podspec | 4 ++-- web/filament-js/package.json | 2 +- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index cb2a24bdb2..4c0d4d7505 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ repositories { } dependencies { - implementation 'com.google.android.filament:filament-android:1.12.9' + implementation 'com.google.android.filament:filament-android:1.12.10' } ``` @@ -52,7 +52,7 @@ Here are all the libraries available in the group `com.google.android.filament`: iOS projects can use CocoaPods to install the latest release: ``` -pod 'Filament', '~> 1.12.9' +pod 'Filament', '~> 1.12.10' ``` ### Snapshots diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index b233e98c02..d05d6bc22a 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -3,11 +3,16 @@ This file contains one line summaries of commits that are worthy of mentioning in release notes. A new header is inserted each time a *tag* is created. -## v1.12.11 (currently main branch) +## v1.12.12 (currently main branch) + +## v1.12.11 ## v1.12.10 - engine: rewrite dynamic resolution scaling controller for better accuracy and less jittering. +- Java: fix missing ASTC texture enum. +- tools: Fix normal map issues in mipgen. +- WebGL: expose some `SurfaceOrientation` functions. ## v1.12.9 diff --git a/android/gradle.properties b/android/gradle.properties index 2400272aa5..28712c5450 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,5 +1,5 @@ GROUP=com.google.android.filament -VERSION_NAME=1.12.9 +VERSION_NAME=1.12.10 POM_DESCRIPTION=Real-time physically based rendering engine for Android. diff --git a/ios/CocoaPods/Filament.podspec b/ios/CocoaPods/Filament.podspec index beef313ed8..8b9cc223f2 100644 --- a/ios/CocoaPods/Filament.podspec +++ b/ios/CocoaPods/Filament.podspec @@ -1,12 +1,12 @@ Pod::Spec.new do |spec| spec.name = "Filament" - spec.version = "1.12.9" + spec.version = "1.12.10" spec.license = { :type => "Apache 2.0", :file => "LICENSE" } spec.homepage = "https://google.github.io/filament" spec.authors = "Google LLC." spec.summary = "Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, and WASM/WebGL." spec.platform = :ios, "11.0" - spec.source = { :http => "https://github.com/google/filament/releases/download/v1.12.9/filament-v1.12.9-ios.tgz" } + spec.source = { :http => "https://github.com/google/filament/releases/download/v1.12.10/filament-v1.12.10-ios.tgz" } # Fix linking error with Xcode 12; we do not yet support the simulator on Apple silicon. spec.pod_target_xcconfig = { diff --git a/web/filament-js/package.json b/web/filament-js/package.json index b1ed090267..b1248ad603 100644 --- a/web/filament-js/package.json +++ b/web/filament-js/package.json @@ -1,6 +1,6 @@ { "name": "filament", - "version": "1.12.9", + "version": "1.12.10", "description": "Real-time physically based rendering engine", "main": "filament.js", "module": "filament.js", From 602a550d93ed126550c65db5616b9fb8b241dcf1 Mon Sep 17 00:00:00 2001 From: Benjamin Doherty Date: Mon, 25 Oct 2021 12:30:37 -0700 Subject: [PATCH 5/9] Bump version to 1.12.11 --- README.md | 4 ++-- android/gradle.properties | 2 +- ios/CocoaPods/Filament.podspec | 4 ++-- web/filament-js/package.json | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4c0d4d7505..b454300bfa 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ repositories { } dependencies { - implementation 'com.google.android.filament:filament-android:1.12.10' + implementation 'com.google.android.filament:filament-android:1.12.11' } ``` @@ -52,7 +52,7 @@ Here are all the libraries available in the group `com.google.android.filament`: iOS projects can use CocoaPods to install the latest release: ``` -pod 'Filament', '~> 1.12.10' +pod 'Filament', '~> 1.12.11' ``` ### Snapshots diff --git a/android/gradle.properties b/android/gradle.properties index 28712c5450..7612feb3b2 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,5 +1,5 @@ GROUP=com.google.android.filament -VERSION_NAME=1.12.10 +VERSION_NAME=1.12.11 POM_DESCRIPTION=Real-time physically based rendering engine for Android. diff --git a/ios/CocoaPods/Filament.podspec b/ios/CocoaPods/Filament.podspec index 8b9cc223f2..71c8b62198 100644 --- a/ios/CocoaPods/Filament.podspec +++ b/ios/CocoaPods/Filament.podspec @@ -1,12 +1,12 @@ Pod::Spec.new do |spec| spec.name = "Filament" - spec.version = "1.12.10" + spec.version = "1.12.11" spec.license = { :type => "Apache 2.0", :file => "LICENSE" } spec.homepage = "https://google.github.io/filament" spec.authors = "Google LLC." spec.summary = "Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, and WASM/WebGL." spec.platform = :ios, "11.0" - spec.source = { :http => "https://github.com/google/filament/releases/download/v1.12.10/filament-v1.12.10-ios.tgz" } + spec.source = { :http => "https://github.com/google/filament/releases/download/v1.12.11/filament-v1.12.11-ios.tgz" } # Fix linking error with Xcode 12; we do not yet support the simulator on Apple silicon. spec.pod_target_xcconfig = { diff --git a/web/filament-js/package.json b/web/filament-js/package.json index b1248ad603..34ae334466 100644 --- a/web/filament-js/package.json +++ b/web/filament-js/package.json @@ -1,6 +1,6 @@ { "name": "filament", - "version": "1.12.10", + "version": "1.12.11", "description": "Real-time physically based rendering engine", "main": "filament.js", "module": "filament.js", From 3e59925900ca5fd4d023c1c01ff3b7a1a6b77358 Mon Sep 17 00:00:00 2001 From: Benjamin Doherty Date: Tue, 26 Oct 2021 10:09:51 -0700 Subject: [PATCH 6/9] Remove problematic configuration-cache setting for release build --- android/gradle.properties | 2 -- 1 file changed, 2 deletions(-) diff --git a/android/gradle.properties b/android/gradle.properties index 7612feb3b2..1af8b47219 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -18,5 +18,3 @@ POM_DEVELOPER_NAME=Filament Team org.gradle.jvmargs=-Xmx1536m android.useAndroidX=true - -org.gradle.unsafe.configuration-cache=true From 88f382f0e3e5ee4eb584774c0ffba7291a3805c4 Mon Sep 17 00:00:00 2001 From: Benjamin Doherty Date: Tue, 19 Oct 2021 16:13:21 -0700 Subject: [PATCH 7/9] Revert "refactor colorgrading materials" This reverts commit fb86a77cf8dd9146f1ebcc7612739d0bb6fe3982. --- filament/CMakeLists.txt | 2 - .../materials/colorGrading/colorGrading.fs | 13 --- .../materials/colorGrading/colorGrading.mat | 79 ++++++++++------- .../colorGrading/colorGradingAsSubpass.mat | 87 +++++++++++-------- 4 files changed, 97 insertions(+), 84 deletions(-) delete mode 100644 filament/src/materials/colorGrading/colorGrading.fs diff --git a/filament/CMakeLists.txt b/filament/CMakeLists.txt index 7606b4f5b9..45a0520a12 100644 --- a/filament/CMakeLists.txt +++ b/filament/CMakeLists.txt @@ -275,7 +275,6 @@ add_custom_command( OUTPUT "${MATERIAL_DIR}/colorGrading.filamat" DEPENDS ../shaders/src/dithering.fs DEPENDS ../shaders/src/vignette.fs - DEPENDS src/materials/colorGrading/colorGrading.fs APPEND ) @@ -283,7 +282,6 @@ add_custom_command( OUTPUT "${MATERIAL_DIR}/colorGradingAsSubpass.filamat" DEPENDS ../shaders/src/dithering.fs DEPENDS ../shaders/src/vignette.fs - DEPENDS src/materials/colorGrading/colorGrading.fs APPEND ) diff --git a/filament/src/materials/colorGrading/colorGrading.fs b/filament/src/materials/colorGrading/colorGrading.fs deleted file mode 100644 index 2b2000142d..0000000000 --- a/filament/src/materials/colorGrading/colorGrading.fs +++ /dev/null @@ -1,13 +0,0 @@ -vec3 colorGrade(mediump sampler3D lut, const vec3 x) { - // Alexa LogC EI 1000 - const float a = 5.555556; - const float b = 0.047996; - const float c = 0.244161 / log2(10.0); - const float d = 0.386036; - vec3 logc = c * log2(a * x + b) + d; - - // Remap to sample pixel centers - logc = materialParams.lutSize.x + logc * materialParams.lutSize.y; - - return textureLod(lut, logc, 0.0).rgb; -} diff --git a/filament/src/materials/colorGrading/colorGrading.mat b/filament/src/materials/colorGrading/colorGrading.mat index 1c18adf80c..3501b631a3 100644 --- a/filament/src/materials/colorGrading/colorGrading.mat +++ b/filament/src/materials/colorGrading/colorGrading.mat @@ -79,9 +79,8 @@ fragment { #include "../../../../shaders/src/dithering.fs" #include "../../../../shaders/src/vignette.fs" -#include "colorGrading.fs" -void dummy(){} +void dummy(){ } float starburst(const vec2 uv) { // get an offset that continuously moves with the camera @@ -124,52 +123,68 @@ vec3 bloom(const vec3 color) { return result; } -vec4 resolveFragment(const ivec2 uv) { -#if POST_PROCESS_OPAQUE - return vec4(texelFetch(materialParams_colorBuffer, uv, 0).rgb, 1.0); -#else - vec4 color = texelFetch(materialParams_colorBuffer, uv, 0); - color.rgb *= 1.0 / (color.a + FLT_EPS); - return color; -#endif +vec3 colorGrade(mediump sampler3D lut, const vec3 x) { + // Alexa LogC EI 1000 + const float a = 5.555556; + const float b = 0.047996; + const float c = 0.244161 / log2(10.0); + const float d = 0.386036; + vec3 logc = c * log2(a * x + b) + d; + + // Remap to sample pixel centers + logc = materialParams.lutSize.x + logc * materialParams.lutSize.y; + + return textureLod(lut, logc, 0.0).rgb; } -void postProcess(inout PostProcessInputs postProcess) { - vec4 color = resolveFragment(ivec2(getUV())); +vec3 resolveFragment(const ivec2 uv) { + return texelFetch(materialParams_colorBuffer, uv, 0).rgb; +} - // Bloom +vec4 resolveAlphaFragment(const ivec2 uv) { + return texelFetch(materialParams_colorBuffer, uv, 0); +} + +vec4 resolve() { +#if POST_PROCESS_OPAQUE + vec4 color = vec4(resolveFragment(ivec2(getUV())), 1.0); if (materialParams.bloom.x > 0.0) { color.rgb = bloom(color.rgb); } - - // Vignette if (materialParams.vignette.x < MEDIUMP_FLT_MAX) { highp vec2 uv = getUV() * frameUniforms.resolution.zw; color.rgb = vignette(color.rgb, uv, materialParams.vignette, materialParams.vignetteColor); } - - // Color grading color.rgb = colorGrade(materialParams_lut, color.rgb); - - // output in premultiplied alpha -#if !POST_PROCESS_OPAQUE - color.rgb *= color.a + FLT_EPS; -#endif - - // dithering - if (materialParams.dithering > 0) { - color = dither(color, materialParams.temporalNoise); - } - - // kill alpha computations when opaque / fxaa luminance -#if POST_PROCESS_OPAQUE - color.a = 1.0; if (materialParams.fxaa > 0) { color.a = luminance(color.rgb); } +#else + vec4 color = resolveAlphaFragment(ivec2(getUV())); + color.rgb /= color.a + FLT_EPS; + if (materialParams.bloom.x > 0.0) { + color.rgb = bloom(color.rgb); + } + if (materialParams.vignette.x < MEDIUMP_FLT_MAX) { + highp vec2 uv = getUV() * frameUniforms.resolution.zw; + color.rgb = vignette(color.rgb, uv, materialParams.vignette, materialParams.vignetteColor); + } + color.rgb = colorGrade(materialParams_lut, color.rgb); + color.rgb *= color.a + FLT_EPS; #endif + return color; +} - postProcess.color = color; +void postProcess(inout PostProcessInputs postProcess) { + postProcess.color = resolve(); + if (materialParams.dithering > 0) { + vec4 dithered = dither(postProcess.color, materialParams.temporalNoise); +#if POST_PROCESS_OPAQUE + postProcess.color.rgb = dithered.rgb; +#else + postProcess.color = dithered; +#endif + } } } diff --git a/filament/src/materials/colorGrading/colorGradingAsSubpass.mat b/filament/src/materials/colorGrading/colorGradingAsSubpass.mat index 828ab6dc23..8b2eb982c4 100644 --- a/filament/src/materials/colorGrading/colorGradingAsSubpass.mat +++ b/filament/src/materials/colorGrading/colorGradingAsSubpass.mat @@ -71,51 +71,64 @@ fragment { #include "../../../../shaders/src/dithering.fs" #include "../../../../shaders/src/vignette.fs" -#include "colorGrading.fs" -void dummy(){} + vec3 colorGrade(mediump sampler3D lut, const vec3 x) { + // Alexa LogC EI 1000 + const float a = 5.555556; + const float b = 0.047996; + const float c = 0.244161 / log2(10.0); + const float d = 0.386036; + vec3 logc = c * log2(a * x + b) + d; -vec4 resolveFragment() { + // Remap to sample pixel centers + logc = materialParams.lutSize.x + logc * materialParams.lutSize.y; + + return textureLod(lut, logc, 0.0).rgb; + } + + vec3 resolveFragment(const ivec2 uv) { + return subpassLoad(materialParams_colorBuffer).rgb; + } + + vec4 resolveAlphaFragment(const ivec2 uv) { + return subpassLoad(materialParams_colorBuffer); + } + + vec4 resolve() { #if POST_PROCESS_OPAQUE - return vec4(subpassLoad(materialParams_colorBuffer).rgb, 1.0); + vec4 color = vec4(resolveFragment(ivec2(getUV())), 1.0); + if (materialParams.vignette.x < MEDIUMP_FLT_MAX) { + highp vec2 uv = getUV() * frameUniforms.resolution.zw; + color.rgb = vignette(color.rgb, uv, materialParams.vignette, materialParams.vignetteColor); + } + color.rgb = colorGrade(materialParams_lut, color.rgb); + if (materialParams.fxaa > 0) { + color.a = luminance(color.rgb); + } #else - vec4 color = subpassLoad(materialParams_colorBuffer); - color.rgb *= 1.0 / (color.a + FLT_EPS); - return color; + vec4 color = resolveAlphaFragment(ivec2(getUV())); + color.rgb /= color.a + FLT_EPS; + if (materialParams.vignette.x < MEDIUMP_FLT_MAX) { + highp vec2 uv = getUV() * frameUniforms.resolution.zw; + color.rgb = vignette(color.rgb, uv, materialParams.vignette, materialParams.vignetteColor); + } + color.rgb = colorGrade(materialParams_lut, color.rgb); + color.rgb *= color.a + FLT_EPS; #endif -} - -void postProcess(inout PostProcessInputs postProcess) { - vec4 color = resolveFragment(); - - // Vignette - if (materialParams.vignette.x < MEDIUMP_FLT_MAX) { - highp vec2 uv = getUV() * frameUniforms.resolution.zw; - color.rgb = vignette(color.rgb, uv, materialParams.vignette, materialParams.vignetteColor); + return color; } - // Color grading - color.rgb = colorGrade(materialParams_lut, color.rgb); - - // output in premultiplied alpha -#if !POST_PROCESS_OPAQUE - color.rgb *= color.a + FLT_EPS; -#endif - - // dithering - if (materialParams.dithering > 0) { - color = dither(color, materialParams.temporalNoise); - } - - // kill alpha computations when opaque / fxaa luminance + void postProcess(inout PostProcessInputs postProcess) { + vec4 color = resolve(); + if (materialParams.dithering > 0) { + vec4 dithered = dither(color, materialParams.temporalNoise); #if POST_PROCESS_OPAQUE - color.a = 1.0; - if (materialParams.fxaa > 0) { - color.a = luminance(color.rgb); - } + color.rgb = dithered.rgb; +#else + color = dithered; #endif - - postProcess.tonemappedOutput = color; -} + } + postProcess.tonemappedOutput = color; + } } From 1f05531d53f7ab9bc9850122b90e37e97f33c767 Mon Sep 17 00:00:00 2001 From: Ben Doherty Date: Thu, 28 Oct 2021 16:02:23 -0700 Subject: [PATCH 8/9] Call VirtualMachineEnv::JNI_OnLoad for non-Android Java builds (better fix) (#4779) --- android/filament-android/src/main/cpp/Filament.cpp | 10 ++++------ .../src/opengl/platforms/PlatformEGLAndroid.cpp | 5 ----- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/android/filament-android/src/main/cpp/Filament.cpp b/android/filament-android/src/main/cpp/Filament.cpp index 03ac36b840..0ae41e9270 100644 --- a/android/filament-android/src/main/cpp/Filament.cpp +++ b/android/filament-android/src/main/cpp/Filament.cpp @@ -16,9 +16,7 @@ #include -namespace filament { - extern jint JNI_OnLoad(JavaVM* vm, void* reserved); -}; +#include "private/backend/VirtualMachineEnv.h" JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { JNIEnv* env; @@ -26,9 +24,9 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { return -1; } -#if ANDROID - ::filament::JNI_OnLoad(vm, reserved); -#endif + // This must be called when the library is loaded. We need this to get a reference to the + // global VM + ::filament::VirtualMachineEnv::JNI_OnLoad(vm); return JNI_VERSION_1_6; } diff --git a/filament/backend/src/opengl/platforms/PlatformEGLAndroid.cpp b/filament/backend/src/opengl/platforms/PlatformEGLAndroid.cpp index 572ee44c80..fdbdbe0fe5 100644 --- a/filament/backend/src/opengl/platforms/PlatformEGLAndroid.cpp +++ b/filament/backend/src/opengl/platforms/PlatformEGLAndroid.cpp @@ -245,11 +245,6 @@ AcquiredImage PlatformEGLAndroid::transformAcquiredImage(AcquiredImage source) n return { eglImage, patchedCallback, closure, source.handler }; } -// This must be called when the library is loaded. We need this to get a reference to the global VM -void JNI_OnLoad(JavaVM* vm, void* reserved) { - ::filament::VirtualMachineEnv::JNI_OnLoad(vm); -} - } // namespace filament // --------------------------------------------------------------------------------------------- From b5c634045e6c7a79058360586766ec73636c94b3 Mon Sep 17 00:00:00 2001 From: Benjamin Doherty Date: Thu, 28 Oct 2021 16:13:34 -0700 Subject: [PATCH 9/9] Update RELEASE_NOTES for 1.12.11 --- RELEASE_NOTES.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index d05d6bc22a..f0b596f24b 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -7,6 +7,9 @@ A new header is inserted each time a *tag* is created. ## v1.12.11 +- Metal: Color grading performance improvement on M1 devices. +- samples: Fix glitchy animation seen in gltf-viewer iOS sample. + ## v1.12.10 - engine: rewrite dynamic resolution scaling controller for better accuracy and less jittering.