filament icon indicating copy to clipboard operation
filament copied to clipboard

The render effect(transparent aspect) is inconsistent on iOS and Android

Open Rankilau opened this issue 2 years ago • 4 comments

Describe the bug When iOS and Android are rendering the same 3D car model(the rendering parameters are also set the same as each other, through the filament framework), all the glass o on iOS is entirely opaque, but the glass on Android is transparent. The effect is as follows,could you please tell me how to make my glass on ios transparent? Thanks.

The effect is as follows,the first image is iOS,the second image is Android. Pasted Graphic 6 Pasted Graphic 5

Reproduction the problem, parameters as follows ` RenderQuality renderQual = _view->getRenderQuality(); renderQual.hdrColorBuffer = QualityLevel::MEDIUM; _view->setRenderQuality(renderQual);

// dynamic resolution often helps a lot
DynamicResolutionOptions dynamicResolutionOp = _view->getDynamicResolutionOptions();
dynamicResolutionOp.enabled = false;
dynamicResolutionOp.quality = QualityLevel::MEDIUM;
_view->setDynamicResolutionOptions(dynamicResolutionOp);

// MSAA is needed with dynamic resolution MEDIUM
MultiSampleAntiAliasingOptions multiSampleAntiAliasingOp = _view->getMultiSampleAntiAliasingOptions();
multiSampleAntiAliasingOp.enabled = true;
multiSampleAntiAliasingOp.sampleCount = 4;
_view->setMultiSampleAntiAliasingOptions(multiSampleAntiAliasingOp);

// FXAA is pretty cheap and helps a lot
_view->setAntiAliasing(AntiAliasing::FXAA);

 TemporalAntiAliasingOptions temporalAntiAliasingOp = _view->getTemporalAntiAliasingOptions();
 temporalAntiAliasingOp.enabled = false;
 _view->setTemporalAntiAliasingOptions(temporalAntiAliasingOp);

// ambient occlusion is the cheapest effect that adds a lot of quality
AmbientOcclusionOptions ambientOcclusionOp = _view->getAmbientOcclusionOptions();
ambientOcclusionOp.enabled = false;
_view->setAmbientOcclusionOptions(ambientOcclusionOp);

// bloom is pretty expensive but adds a fair amount of realism
BloomOptions bloomOp = _view->getBloomOptions();
bloomOp.enabled = true;
_view->setBloomOptions(bloomOp);

GuardBandOptions guardBandOp = _view->getGuardBandOptions();
guardBandOp.enabled = false;
_view->setGuardBandOptions(guardBandOp);

_view->setBlendMode(BlendMode::OPAQUE);`

Expected behavior On iOS, the glass is translucent also, the same as on Android, all the time

Device and OS iPhone12 iOS14, Xiaomi 11 Android 12

Rankilau avatar Feb 01 '23 13:02 Rankilau

Is your model a glTF? Are you able to upload it here?

bejado avatar Feb 07 '23 19:02 bejado

Thank you very much for your attention, My model is glTF, but sorry, because the model file is confidential, I cannot upload it. Lucky this problem has been solved in a slightly more complicated way,But I still don't know, what was the cause of the original bug, what do you speculate direction? Here's how to do it. 1、use glass.mat to generate a new glass.inc 2、loading glass.inc

static constexpr uint8_t BAKED_COLOR_PACKAGE[] = {
#include "glass.inc"
};

3、generate a new glassInstance through glass.inc, Replacement origin glass material

filament::Material* mMaterial = Material::Builder()
        .package((void*) BAKED_COLOR_PACKAGE, sizeof(BAKED_COLOR_PACKAGE))
        .build(*_engine);
MaterialInstance* glassInstance = mMaterial->createInstance();
glassInstance->setParameter("baseColor", RgbaType::sRGB, {0.25f,0.25f,0.25f,0.7f});
// Output all nodes, Replacement glass material
RenderableManager& rcm = _engine->getRenderableManager();
const utils::Entity* entity1 = _asset->getEntities();
    for (int i = 0;i < _asset->getEntityCount(); i++) {
        Entity entity = *(entity1 + i);
        MaterialInstance* matIns = rcm.getMaterialInstanceAt(rcm.getInstance(entity), 0);
        if (matIns != NULL) {
            const char* name = matIns->getName();
            if (strcmp(name,"Material.003") == 0) {
                // instance is the self-created material and entity is the found glass material
                rcm.setMaterialInstanceAt(rcm.getInstance(entity), 0, glassInstance);
            }
        }
    }

Rankilau avatar Feb 09 '23 11:02 Rankilau

Thank you very much for your attention, My model is glTF, but sorry, because the model file is confidential, I cannot upload it. Lucky this problem has been solved in a slightly more complicated way,But I still don't know, what was the cause of the original bug, what do you speculate direction? Here's how to do it. 1、use glass.mat to generate a new glass.inc 2、loading glass.inc

static constexpr uint8_t BAKED_COLOR_PACKAGE[] = {
#include "glass.inc"
};

3、generate a new glassInstance through glass.inc, Replacement origin glass material

filament::Material* mMaterial = Material::Builder()
        .package((void*) BAKED_COLOR_PACKAGE, sizeof(BAKED_COLOR_PACKAGE))
        .build(*_engine);
MaterialInstance* glassInstance = mMaterial->createInstance();
glassInstance->setParameter("baseColor", RgbaType::sRGB, {0.25f,0.25f,0.25f,0.7f});
// Output all nodes, Replacement glass material
RenderableManager& rcm = _engine->getRenderableManager();
const utils::Entity* entity1 = _asset->getEntities();
    for (int i = 0;i < _asset->getEntityCount(); i++) {
        Entity entity = *(entity1 + i);
        MaterialInstance* matIns = rcm.getMaterialInstanceAt(rcm.getInstance(entity), 0);
        if (matIns != NULL) {
            const char* name = matIns->getName();
            if (strcmp(name,"Material.003") == 0) {
                // instance is the self-created material and entity is the found glass material
                rcm.setMaterialInstanceAt(rcm.getInstance(entity), 0, glassInstance);
            }
        }
    }

Yes, i met same problem. Is there any progress about this inconsistent?

dandingol03 avatar May 27 '23 10:05 dandingol03

Have you try the opengl backend on ios device?

dandingol03 avatar May 27 '23 10:05 dandingol03