filament README

The project's README from github.com/google/filament. As one markdown file: README.md.

Filament

Android Build Status iOS Build Status Linux Build Status macOS Build Status Windows Build Status Web Build Status

Filament is a real-time physically based rendering engine for Android, iOS, Linux, macOS, Windows, and WASM. It is designed to be as small as possible and as efficient as possible on Android.

Download

Download Filament releases to access stable builds. Filament release archives contains host-side tools that are required to generate assets.

Make sure you always use tools from the same release as the runtime library. This is particularly important for matc (material compiler).

If you'd rather build Filament yourself, please refer to our build manual.

Android

Android projects can simply declare Filament libraries as Maven dependencies:

repositories {
    // ...
    mavenCentral()
}

dependencies {
    implementation 'com.google.android.filament:filament-android:1.76.1'
}

Here are all the libraries available in the group com.google.android.filament:

Artifact Description
filament-android The Filament rendering engine itself.
filament-android-debug Debug version of filament-android.
gltfio-android A glTF 2.0 loader for Filament, depends on filament-android.
filament-utils-android KTX loading, Kotlin math, and camera utilities, depends on gltfio-android.
filamat-android A runtime material builder/compiler. This library is large but contains a full shader compiler/validator/optimizer and supports both OpenGL and Vulkan.

iOS

iOS projects can use CocoaPods to install the latest release:

pod 'Filament', '~> 1.76.1'

Documentation

Examples

Night scene Night scene Materials Materials Helmet Screen-space refraction

Features

APIs

Backends

Rendering

Post processing

glTF 2.0

Rendering with Filament

Native Linux, macOS and Windows

You must create an Engine, a Renderer and a SwapChain. The SwapChain is created from a native window pointer (an NSView on macOS or a HWND on Windows for instance):

Engine* engine = Engine::create();
SwapChain* swapChain = engine->createSwapChain(nativeWindow);
Renderer* renderer = engine->createRenderer();

To render a frame you must then create a View, a Scene and a Camera:

Camera* camera = engine->createCamera(EntityManager::get().create());
View* view = engine->createView();
Scene* scene = engine->createScene();

view->setCamera(camera);
view->setScene(scene);

Renderables are added to the scene:

Entity renderable = EntityManager::get().create();
// build a quad
RenderableManager::Builder(1)
        .boundingBox({{ -1, -1, -1 }, { 1, 1, 1 }})
        .material(0, materialInstance)
        .geometry(0, RenderableManager::PrimitiveType::TRIANGLES, vertexBuffer, indexBuffer, 0, 6)
        .culling(false)
        .build(*engine, renderable);
scene->addEntity(renderable);

The material instance is obtained from a material, itself loaded from a binary blob generated by matc:

Material* material = Material::Builder()
        .package((void*) BAKED_MATERIAL_PACKAGE, sizeof(BAKED_MATERIAL_PACKAGE))
        .build(*engine);
MaterialInstance* materialInstance = material->createInstance();

To learn more about materials and matc, please refer to the materials documentation.

To render, simply pass the View to the Renderer:

// beginFrame() returns false if we need to skip a frame
if (renderer->beginFrame(swapChain)) {
    // for each View
    renderer->render(view);
    renderer->endFrame();
}

For complete examples of Linux, macOS and Windows Filament applications, look at the source files in the samples/ directory. These samples are all based on libs/filamentapp/ which contains the code that creates a native window with SDL2 and initializes the Filament engine, renderer and views.

For more information on how to prepare environment maps for image-based lighting please refer to BUILDING.md.

Android

See android/samples for examples of how to use Filament on Android.

You must always first initialize Filament by calling Filament.init().

Rendering with Filament on Android is similar to rendering from native code (the APIs are largely the same across languages). You can render into a Surface by passing a Surface to the createSwapChain method. This allows you to render to a SurfaceTexture, a TextureView or a SurfaceView. To make things easier we provide an Android specific API called UiHelper in the package com.google.android.filament.android. All you need to do is set a render callback on the helper and attach your SurfaceView or TextureView to it. You are still responsible for creating the swap chain in the onNativeWindowChanged() callback.

iOS

Filament is supported on iOS 11.0 and above. See ios/samples for examples of using Filament on iOS.

Filament on iOS is largely the same as native rendering with C++. A CAEAGLLayer or CAMetalLayer is passed to the createSwapChain method. Filament for iOS supports both Metal (preferred) and OpenGL ES.

Assets

To get started you can use the textures and environment maps found respectively in third_party/textures and third_party/environments. These assets are under CC0 license. Please refer to their respective URL.txt files to know more about the original authors.

Environments must be pre-processed using cmgen or using the libiblprefilter library.

How to make contributions

Please read and follow the steps in CONTRIBUTING.md. Make sure you are familiar with the code style.

Directory structure

This repository not only contains the core Filament engine, but also its supporting libraries and tools.

License

Please see LICENSE.

Disclaimer

This is not an officially supported Google product.

filament (google/filament)

Searching Database…

20.6K ·GitHub
这是什么东西?Filament 是谷歌开源的实时基于物理的渲染引擎(PBR),支持 Android、iOS、Linux、macOS、Windows 和 WASM/WebGL2,目标是做到尽可能小巧高效——在 Android 上尤其如此。
它是我写代码时调用的库,还是一个现成的应用?它是一个 C++ 渲染库,需要链接进你自己的应用,而不是现成的程序——在 Android 上提供 Java/JNI API,网页版则提供 JavaScript API。
怎么把它加到我的项目里?Android:声明 com.google.android.filament 的 Maven 构件(filament-android、用于 glTF 的 gltfio-android、提供 KTX 和数学辅助功能的 filament-utils-android)。iOS:通过 CocoaPods 安装。桌面端:从源码构建,然后从 samples/ 里基于 SDL2 的示例入手。
它底层用哪些图形 API——我需要 Vulkan 吗?它根据平台通过 OpenGL 4.1+、OpenGL ES 3.0+、Metal、Vulkan 1.0、WebGPU 或 WebGL 2.0 来渲染——iOS 上首选 Metal,WebGL 2.0 后端可以在任何支持的浏览器里运行。
材质方面有什么要注意的坑?材质需要提前编写,并用 matc 工具离线编译成引擎在运行时加载的二进制文件——而且宿主工具必须与运行时库来自同一个发布版本,否则资源可能出问题。
它能在 iOS 上用吗?支持哪些版本?支持 iOS 11.0 及以上版本。iOS 上首选 Metal 后端,也可以用 OpenGL ES,而且 iOS 上的渲染方式与桌面端原生 C++ 的用法基本一致。
它开箱自带哪些渲染特性?包含一个基于聚簇的正向渲染器,带有 Cook-Torrance BRDF、基于图像的光照、基于物理的相机和物理光照单位、级联阴影和接触阴影、SSAO、屏幕空间反射、雾效、景深散景、HDR 泛光、多种色调映射器、调色,以及 TAA/FXAA/MSAA 抗锯齿。
仓库里附带了哪些宿主工具?有 matc(材质编译器)、cmgen(基于图像的光照资源生成器)、mipgen(mip 层级生成器)、filamesh(网格转换器)、matinfo、matedit 和 glslminifier。环境贴图必须先用 cmgen 或 libiblprefilter 预处理才能使用。
有没有可以拿来练手的示例资源?有——仓库在 thirdparty/textures 和 thirdparty/environments 下提供了 CC0 许可的纹理和环境贴图,还有一些采用宽松许可的 3D 模型,以及在 samples/ 下基于 SDL2 构建的桌面示例应用。
Filament 是谷歌官方支持的产品吗?它由谷歌开发,但 README 中带有免责声明:'This is not an officially supported Google product.'(这不是谷歌官方支持的产品。)请把它当作没有支持保障的开源项目来使用。
Creator
google
Size
1.1 GB
Stars
20.6K
Age
8y
Commits · 90 Days