Skip to content

joshualibrarian/filament-java

Repository files navigation

filament-java

Desktop JVM bindings for Google Filament, a physically-based rendering (PBR) engine.

Filament is a high-performance C++ rendering engine with Vulkan, Metal, and OpenGL backends. It had official desktop Java bindings through v1.9.10, but Google removed them in v1.11.0 (July 2021). This project resurrects and maintains those bindings so any JVM application can use Filament for 3D rendering.

Platform Backend Status
Linux Vulkan, OpenGL Working
macOS Metal, Vulkan CI builds, untested
Windows Vulkan, OpenGL CI builds, untested

Quick Start

import dev.everydaythings.filament.*;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.glfw.GLFWNativeX11.*;

public class Minimal {
    public static void main(String[] args) {
        // Create a GLFW window
        glfwInit();
        glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
        long window = glfwCreateWindow(800, 600, "Filament", 0, 0);

        // Initialize Filament
        Filament.init();
        Engine engine = new Engine.Builder()
                .backend(Engine.Backend.VULKAN)
                .build();

        // Create rendering objects
        SwapChain swapChain = engine.createSwapChainFromRawPointer(
                glfwGetX11Window(window), 0);
        Renderer renderer = engine.createRenderer();
        View view = engine.createView();
        Scene scene = engine.createScene();
        Camera camera = engine.createCamera(
                engine.getEntityManager().create());

        view.setScene(scene);
        view.setCamera(camera);
        view.setViewport(new Viewport(0, 0, 800, 600));

        // Render loop
        while (!glfwWindowShouldClose(window)) {
            glfwPollEvents();
            if (renderer.beginFrame(swapChain, System.nanoTime())) {
                renderer.render(view);
                renderer.endFrame();
            }
        }

        // Cleanup
        engine.destroyRenderer(renderer);
        engine.destroyView(view);
        engine.destroyScene(scene);
        engine.destroyCameraComponent(camera.getEntity());
        engine.destroySwapChain(swapChain);
        engine.destroy();
        glfwDestroyWindow(window);
        glfwTerminate();
    }
}

Modules

Module Description
filament-java-core Java API — 40 wrapper classes (Engine, Renderer, Scene, View, Camera, Material, etc.)
filament-java-native JNI C++ bridge + native library (libfilament-jni.so / .dylib / .dll)
filament-java-gltfio glTF 2.0 model loading (AssetLoader, ResourceLoader, Animator)
filament-java-text MSDF text rendering (MsdfAtlas, MsdfFontManager, MsdfTextRenderer)
filament-java-lwjgl GLFW windowing integration via LWJGL

Text module details: filament-java-text/README.md

Examples

hello-triangle — Colored triangle with a custom material:

./gradlew :examples:hello-triangle:run

hello-gltf — Load and render a glTF model with lighting and animation:

./gradlew :examples:hello-gltf:run

hello-camera — Interactive orbit camera around a glTF model (left-drag orbit, right-drag pan, scroll zoom):

./gradlew :examples:hello-camera:run

hello-picking — Object selection via View.pick() — click on colored cubes to highlight them:

./gradlew :examples:hello-picking:run

Building from Source

Prerequisites

  • Java 21+
  • CMake 3.22+
  • Filament SDK (downloaded below)
  • Linux only: sudo apt install libc++-dev libc++abi-dev

Steps

  1. Download the Filament SDK (v1.69.2):
# Linux
curl -LO https://github.com/google/filament/releases/download/v1.69.2/filament-v1.69.2-linux.tgz
mkdir -p filament-sdk && tar xzf filament-v1.69.2-linux.tgz -C filament-sdk --strip-components=1

# macOS
curl -LO https://github.com/google/filament/releases/download/v1.69.2/filament-v1.69.2-mac.tgz
mkdir -p filament-sdk && tar xzf filament-v1.69.2-mac.tgz -C filament-sdk --strip-components=1

# Windows (PowerShell)
Invoke-WebRequest -Uri https://github.com/google/filament/releases/download/v1.69.2/filament-v1.69.2-windows.tgz -OutFile filament-sdk.tgz
mkdir filament-sdk; tar xzf filament-sdk.tgz -C filament-sdk --strip-components=1
  1. Build:
./gradlew build

This compiles the Java modules and builds the native library via CMake. The native .so/.dylib/.dll is automatically bundled into the filament-java-native JAR.

  1. Run an example:
./gradlew :examples:hello-triangle:run

Material Compilation

Material source files (.mat) are compiled to binary (.filamat) using matc from the Filament SDK:

./filament-sdk/bin/matc -p desktop -a vulkan -a opengl -o output.filamat input.mat

Architecture

The Java classes are thin JNI wrappers — each holds a long nativeObject pointer to a C++ Filament object. The JNI C++ layer forwards calls directly to Filament's C++ API. Windowing is handled by GLFW via LWJGL, keeping the core free of AWT/Swing/JavaFX dependencies.

Your Application
    |
    +-- filament-java-core      (Java API)
    +-- filament-java-gltfio    (glTF loading, optional)
    +-- filament-java-text      (MSDF text rendering, optional)
    +-- filament-java-lwjgl     (GLFW windowing)
    +-- filament-java-native    (JNI bridge -> libfilament-jni -> Filament C++)
            |
            +-- Filament Engine (Vulkan / Metal / OpenGL)

The JNI sources originate from Filament's Android bindings (android/filament-android/src/main/cpp/), which are platform-agnostic — they use only <jni.h> and Filament headers with zero Android NDK calls.

Text System (MSDF + Emoji)

The filament-java-text module now supports:

  • Runtime MSDF/MTSDF atlas generation from TTF/OTF
  • Multi-font fallback chains
  • HarfBuzz shaping on the primary font
  • COLRv0 color emoji layers (e.g. bundled Twemoji Mozilla)
  • Glyph-by-index generation for COLR layer glyphs

Runtime toggles:

  • -Dfilament.msdf.useExtOnMacArm=true Force LWJGL MSDFGenExt path on macOS arm64 (default is safer core-shape path).
  • -Dfilament.msdf.safeSdf=true Emergency single-channel SDF mode (stability-first).
  • -Dfilament.msdf.forceMtsdf=true Force MTSDF generation even when safeSdf is enabled.

Notes:

  • Materials are compiled for desktop backends and include Metal support in this repo.
  • For full icon consistency in app UIs, pair text shaping with explicit icon assets (for example OpenMoji SVGs) at the application layer.

Status

Core API, glTF loading, and MSDF text are working in active desktop use (Linux and macOS). Windows support is built in CI; runtime coverage is more limited.

Contributions and bug reports are welcome.

License

Apache License 2.0 — see LICENSE.

Filament is developed by Google and licensed under Apache 2.0. This project is an independent, community-maintained fork of the desktop Java bindings.

About

Desktop JVM bindings for Google Filament (PBR rendering engine)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors