filament icon indicating copy to clipboard operation
filament copied to clipboard

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

Open yuxinabc opened this issue 1 year ago • 3 comments

⚠️ 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):

  • Device: OnePlus 9 5G
  • OS: Android13
  • filament version 1.49.2

yuxinabc avatar May 07 '24 16:05 yuxinabc

Looks like a problem with refraction

romainguy avatar May 07 '24 18:05 romainguy

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?

yuxinabc avatar May 07 '24 18:05 yuxinabc

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

pixelflinger avatar May 08 '24 23:05 pixelflinger