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.36k stars 1.84k forks source link

The same material and the same setting parameters result in different display effects between perspective projection and orthographic projection. #7832

Open yuxinabc opened 1 month ago

yuxinabc commented 1 month ago

⚠️ Issues not using this template will be systematically closed.

Describe the bug A clear and concise description of what the bug is. The same material and the same setting parameters result in different display effects between perspective projection and orthographic projection.

To Reproduce Set perspective projection:

val height = view.viewport.height
val aspect = width.toDouble() / height.toDouble()
    camera.setLensProjection(
           cameraFocalLength.toDouble(),
          aspect,
           cameraNear.toDouble(),
           cameraFar.toDouble())

Set up orthographic projection:

        val width = view.viewport.width
        val height = view.viewport.height
        val aspect = width.toDouble() / height.toDouble()
        val scale = 2.0 
        val left = -scale * aspect
        val right = scale * aspect
        val bottom = -scale
        val top = scale
        val near = cameraNear.toDouble()
        val far = cameraFar.toDouble()
        camera.setProjection(
            Camera.Projection.ORTHO,
            left,
            right,
            bottom,
            top,
            near,
            far
        )

Set material parameters:

 setParameter("ior", 1.517f)
  setParameter("roughness", 0.38f)
   setParameter("transmission", 1f)
  setParameter("reflectance", 0.0f)

material.mat:

material {
    name : TransparentMaterial,
    requires : [
        uv0
    ],
    shadingModel : lit,
    refractionMode : screenspace, // Choose a refraction mode: none, cubemap, or screenspace
    refractionType : thin, // Choose refraction type: solid or thin
    depthWrite : true, // Changed to true to properly handle depth for refractive materials
    parameters : [
        {
            type : "float3",
            name : "baseColor"
        },
        {
            type : "float",
            name : "roughness"
        },
        {
            type : "float",
            name : "ior"
        }
        ,
        {
            type : "float",
            name : "transmission"
        },
        {
            type : float,
            name : reflectance
        }
         ,
        {
            type : float,
            name : microThickness
        }
    ],
}
fragment {
    void material(inout MaterialInputs material) {
        prepareMaterial(material);
        material.metallic = 0.0;
        material.baseColor.rgb = materialParams.baseColor;
        material.roughness = materialParams.roughness;
        material.ior = materialParams.ior;
        material.transmission = materialParams.transmission;
        material.reflectance = materialParams.reflectance;
        material.microThickness = materialParams.microThickness;
    }
}

Expected behavior The display effect of orthogonal projection is the same as that of perspective projection.

Screenshots

https://github.com/google/filament/assets/6195253/ee60cd2c-2e22-453d-883c-565f77e20e93

https://github.com/google/filament/assets/6195253/0abadbe3-95c4-4726-9288-996f7caa26c0

Smartphone (please complete the following information):

romainguy commented 1 month ago

Looks like a problem with refraction

yuxinabc commented 1 month ago

Looks like a problem with refraction

The material becomes 100% transparent under orthogonal projection, as if it turned into air. How should I set the refraction?

pixelflinger commented 1 month ago

I'm not sure refraction works with an ortho projection.