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

Gltf object behind model with occluder material still visible #3331

Closed Miao-10k closed 3 years ago

Miao-10k commented 3 years ago

I first loaded a gltf object which is a room and another gltf object which is a container of the room that is a little bit larger than the room such that I can put the room totally inside the container. This is the room: image

This is the container: image

Then I change the material of the container to an occluder material and set the render priority to camera > container > room. I suppose that the container would occlude the room so that I can achieve something like a portal. But the fact is while the container itself looks like invisible, the outside of the room is not occluded。 This is my Occluder Material:

material {
    "name" : "Face Mesh Occluder",
    "parameters" : [
        {
            "type" : "float",
            "name" : "unused"
        }
    ],
    "shadingModel" : "unlit",
    "colorWrite" : false,
    "depthWrite" : true,
}

This is what I expect: WechatIMG26

This is what I get: WechatIMG25

I am using filament with the open-source sceneform 1.6.0 on android devices. The gltf object is loaded by gltfio and I only use the filament way to change the material. I'm not sure if this is a bug. I suspect this problem may be related to the material generated by gltfio. I've gone through other issues about occlusion material but didn't get a solution. Hope can get some help here.

romainguy commented 3 years ago

The only thing I can think of is that your render priority is inverted, lower priorities (lower numbers) are rendered first.

Miao-10k commented 3 years ago

Hi @romainguy, I set the render priority as following camera = 0, container = 4, room = 7. So I think this may not the reason. I forgot to mention that I tried to change the material of all the entities of the room to sceneform_opaque_textured_material.filamat. The screenshot is attached below. It looks black because I didn't give the texture to the room when changing the material. But I noticed that some part of the room is occluded in this case. That's why I suspect its about the material generated by gltfio. If it is because the material, is there any chance I can change the material without giving the texture again to achieve the expected result? In addition, I found that some parts inside the room are still not occluded. Those parts change between visible and invisible during I change the pose of my phone. Is this another problem? This is sceneform_opaque_textured_material:

material {
    "name" : "Opaque Textured",

    "parameters" : [ 
        {
           "type" : "sampler2d",
           "name" : "texture"
        },
        {
           "type" : "float",
           "name" : "metallic"
        },
        {
            "type" : "float",
            "name" : "roughness"
        },
        {
            "type" : "float",
            "name" : "reflectance"
        }
    ],
    "requires" : [
        "position",
        "uv0"
    ],
    "shadingModel" : "lit",
    "blending" : "opaque"
}
fragment {
    void material(inout MaterialInputs material) {
        prepareMaterial(material);
        material.baseColor = texture(materialParams_texture, getUV0());
        material.metallic = materialParams.metallic;
        material.roughness = materialParams.roughness;
        material.reflectance = materialParams.reflectance;
    }
}

This is what I get with occluder material for the container, sceneform_opaque_textured_material for the room and the same render priority as before: WechatIMG28

Miao-10k commented 3 years ago

Hi @romainguy, I found that actually priority is the cause. I was using sceneform api to set the priority. Although I set the priority number right but I think there may be problems inside the sceneform implementation of setting priority. After changing to filament way to set the priority, everything just works fine. I apologize that this is not a filament error and thank you for your support.