Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, and WebGL2
Filament is a real-time physically based rendering engine for Android, iOS, Linux, macOS, Windows,
and WebGL. It is designed to be as small as possible and as efficient as possible on Android.
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 projects can simply declare Filament libraries as Maven dependencies:
repositories {
// ...
mavenCentral()
}
dependencies {
implementation 'com.google.android.filament:filament-android:1.56.1'
}
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.56.1'
matc
and how to write custom materials.
Encodings
Primitive Types
Animation
Extensions
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.
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.
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.
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.
Please read and follow the steps in CONTRIBUTING.md. Make sure you are
familiar with the code style.
This repository not only contains the core Filament engine, but also its supporting libraries
and tools.
android
: Android libraries and projects
filamat-android
: Filament material generation library (AAR) for Androidfilament-android
: Filament library (AAR) for Androidfilament-utils-android
: Extra utilities (KTX loader, math types, etc.)gltfio-android
: Filament glTF loading library (AAR) for Androidsamples
: Android-specific Filament samplesart
: Source for various artworks (logos, PDF manuals, etc.)assets
: 3D assets to use with sample applicationsbuild
: CMake build scriptsdocs
: Documentation
math
: Mathematica notebooks used to explore BRDFs, equations, etc.filament
: Filament rendering engine (minimal dependencies)
backend
: Rendering backends/drivers (Vulkan, Metal, OpenGL/ES)ide
: Configuration files for IDEs (CLion, etc.)ios
: Sample projects for iOSlibs
: Libraries
bluegl
: OpenGL bindings for macOS, Linux and Windowsbluevk
: Vulkan bindings for macOS, Linux, Windows and Androidcamutils
: Camera manipulation utilitiesfilabridge
: Library shared by the Filament engine and host toolsfilaflat
: Serialization/deserialization library used for materialsfilagui
: Helper library for Dear ImGuifilamat
: Material generation libraryfilamentapp
: SDL2 skeleton to build sample appsfilameshio
: Tiny filamesh parsing library (see also tools/filamesh
)geometry
: Mesh-related utilitiesgltfio
: Loader for glTF 2.0ibl
: IBL generation toolsimage
: Image filtering and simple transformsimageio
: Image file reading / writing, only intended for internal usematdbg
: DebugServer for inspecting shaders at run-time (debug builds only)math
: Math librarymathio
: Math types support for output streamsutils
: Utility library (threads, memory, data structures, etc.)viewer
: glTF viewer library (requires gltfio)samples
: Sample desktop applicationsshaders
: Shaders used by filamat
and matc
third_party
: External libraries and assets
environments
: Environment maps under CC0 license that can be used with cmgen
models
: Models under permissive licensestextures
: Textures under CC0 licensetools
: Host tools
cmgen
: Image-based lighting asset generatorfilamesh
: Mesh converterglslminifier
: Minifies GLSL source codematc
: Material compilermatinfo
Displays information about materials compiled with matc
mipgen
Generates a series of miplevels from a source imagenormal-blending
: Tool to blend normal mapsresgen
Aggregates binary blobs into embeddable resourcesroughness-prefilter
: Pre-filters a roughness map from a normal map to reduce aliasingspecular-color
: Computes the specular color of conductors based on spectral dataweb
: JavaScript bindings, documentation, and samplesPlease see LICENSE.
This is not an officially supported Google product.