google / filament

Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, and WebGL2
https://google.github.io/filament/
Apache License 2.0
17.63k stars 1.86k forks source link

How to bloom a particular material in a glb model? #2672

Closed balarayen closed 4 years ago

balarayen commented 4 years ago

In Android sceneform sdk, I tried enabling bloom option by using the camerastream's ExternalTexture as the dirt texture. It makes everything that are whitish in the camera scene to glow.

But I want to make a specific face of a cube (say glb model) that has some emissive material in red color to glow. How to do that with a FilamentAsset? Please clarify.

Smartphone:

romainguy commented 4 years ago

All you have to do is enable bloom (and you shouldn't set the camera stream as the dirt texture) on the Filament View object. Then you need either a strong light or a strong emissive material to get bloom.

balarayen commented 4 years ago

@romainguy But setBloomOptions mandates to pass a dirt texture. Without a texture, it crashed due to null. What should be passed as the dirt texture? Please clarify.

In View.java

    /**
     * Sets bloom options.
     *
     * @param options Options for bloom.
     */
    public void setBloomOptions(@NonNull BloomOptions options) {
        mBloomOptions = options;
        nSetBloomOptions(getNativeObject(), options.dirt.getNativeObject(),
                options.dirtStrength, options.strength, options.resolution,
                options.anamorphism, options.levels, options.blendingMode.ordinal(),
                options.threshold, options.enabled);
    }
romainguy commented 4 years ago

The dirt texture is optional.

balarayen commented 4 years ago

@romainguy But setBloomOptions mandates to pass a dirt texture. Without a texture, it crashed due to null. What should be passed as the dirt texture? Please clarify.

In View.java

    /**
     * Sets bloom options.
     *
     * @param options Options for bloom.
     */
    public void setBloomOptions(@NonNull BloomOptions options) {
        mBloomOptions = options;
        nSetBloomOptions(getNativeObject(), options.dirt.getNativeObject(),
                options.dirtStrength, options.strength, options.resolution,
                options.anamorphism, options.levels, options.blendingMode.ordinal(),
                options.threshold, options.enabled);
    }

This code from my previous comment is from filament 1.4.5. With the latest updates from sceneformsdk, I could upgrade filament to v1.7.0, where I can pass the dirt as null. Thanks @romainguy for your time.

    public void setBloomOptions(@NonNull BloomOptions options) {
        mBloomOptions = options;
        nSetBloomOptions(getNativeObject(), options.dirt != null ? options.dirt.getNativeObject() : 0,
                options.dirtStrength, options.strength, options.resolution,
                options.anamorphism, options.levels, options.blendingMode.ordinal(),
                options.threshold, options.enabled);
    }
romainguy commented 4 years ago

It's a bug in an old version, Sceneform was recently updated to Filament 1.7.0 so you should update your copy of Sceneform.