Qt3D Problem with transparent object.



  • Hello. I'm adding a Sphere with a texture and a transparent Teapot to the scene. Everything is displayed as it should(pic 1). But when I swap the Sphere with the Teapot, the Sphere is always displayed in the foreground(pic 2) .

    pic 1. Sphere with texture and transparent Teapot
    0_1505835196973_5.9-back.png

    Scene.qml

    import QtQuick 2.0
    
    import Qt3D.Core 2.0
    import Qt3D.Render 2.0
    import Qt3D.Extras 2.0
    import Qt3D.Input 2.0
    
    Entity  {
        id: scene
        objectName: "scene"
        property real cameraDistance: 100
    
        function spherePos(pos, angle) {
            sphere.position = pos;
            sphere.angle = angle;
        }
    
        Camera {
            id: camera
            projectionType: CameraLens.PerspectiveProjection
            fieldOfView: 40
            aspectRatio:  _window.width / _window.height
            nearPlane : 0.1
            farPlane : 1000.0
            position: Qt.vector3d( 0.0, 100.0, 30 )
            upVector: Qt.vector3d( 0.0, 0.0, 1.0 )
            viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
        }
    
        components: [
            RenderSettings {
                activeFrameGraph: ForwardRenderer{
                    camera: camera
                    clearColor: "white"
                }
            }
        ]
    
        Sphere {
            id: sphere
        }
    
        Teapot {
    
        }
    }
    

    Sphere.qml

    import QtQuick 2.0
    import Qt3D.Core 2.0
    import Qt3D.Render 2.0
    import Qt3D.Extras 2.0
    
    Entity {
        property alias position: transform.translation
        property real angle: 0
    
        onPositionChanged: {
            var x = cameraDistance * Math.cos(-(angle-180)*Math.PI/180)
            var y = cameraDistance * Math.sin(-(angle-180)*Math.PI/180)
            camera.upVector = Qt.vector3d( 0.0, 0.0, 1.0 )
            camera.viewCenter = position
            camera.position = Qt.vector3d(x, y, 30).plus(position)
        }
        onAngleChanged: {
            var x = cameraDistance * Math.cos(-(angle-180)*Math.PI/180)
            var y = cameraDistance * Math.sin(-(angle-180)*Math.PI/180)
            camera.upVector = Qt.vector3d( 0.0, 0.0, 1.0 )
            camera.viewCenter = position
            camera.position = Qt.vector3d(x, y, 30).plus(position)
        }
    
        Behavior on angle{
            RotationAnimation { duration: 5000; direction: RotationAnimation.Shortest }
        }
    
        components: [ sphere, diffusematerial, transform ]
    
        DiffuseMapMaterial {
            id: diffusematerial
            ambient: Qt.rgba( 1, 1, 1, 1 )
            diffuse: TextureLoader{ source: "qrc:/assets/textures/sphere.jpg" }
            shininess: 0
            specular: Qt.rgba( 1, 1, 1, 1 )
            textureScale: 4
        }
    
        Transform {
            id: transform
            rotation: fromEulerAngles( angle+180, 90, 90 )
            scale: 10
    
            Behavior on translation {
                Vector3dAnimation { duration: 5000 }
            }
        }
    
        SphereMesh {
            id: sphere
        }
    
    }
    

    Teapot.qml

    import QtQuick 2.0
    import Qt3D.Core 2.0
    import Qt3D.Render 2.0
    import Qt3D.Extras 2.0
    
    Entity {
        property alias position: transform.translation
        property real angle: 0
    
        Behavior on angle{
            RotationAnimation { duration: 5000; direction: RotationAnimation.Shortest }
        }
    
        components: [ mesh, alpha, transform ]
    
        PhongMaterial {
            id: material
            ambient: Qt.rgba( 1, 0, 0, 1 )
            diffuse: Qt.rgba( 1, 0, 0, 1 )
            shininess: 50
        }
    
        PhongAlphaMaterial {
            id: alpha
            alpha: 0.9
            ambient: Qt.rgba( 1, 0, 0, 1 )
            diffuse: Qt.rgba( 1, 0, 0, 1 )
            shininess: 50
        }
    
        Transform {
            id: transform
            rotation: fromEulerAngles( angle+180, 90, 90 )
            scale: 10
    
            Behavior on translation {
                Vector3dAnimation { duration: 5000 }
            }
        }
    
        Mesh {
            id: mesh
            source: "qrc:/assets/mesh/teapot.obj"
        }
    
    }
    

    pic 2. Swapped the Sphere and the Teapot
    0_1505835615385_5.9-forward.png

    Scene.qml

    import QtQuick 2.0
    
    import Qt3D.Core 2.0
    import Qt3D.Render 2.0
    import Qt3D.Extras 2.0
    import Qt3D.Input 2.0
    
    Entity  {
        id: scene
        objectName: "scene"
        property real cameraDistance: 100
    
        function tractorPos(pos, angle) {
            sphere.position = pos;
            sphere.angle = angle;
        }
    
        Camera {
            id: camera
            projectionType: CameraLens.PerspectiveProjection
            fieldOfView: 40
            aspectRatio:  _window.width / _window.height
            nearPlane : 0.1
            farPlane : 1000.0
            position: Qt.vector3d( 0.0, 100.0, 30 )
            upVector: Qt.vector3d( 0.0, 0.0, 1.0 )
            viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
        }
    
        components: [
            RenderSettings {
                activeFrameGraph: ForwardRenderer{
                    camera: camera
                    clearColor: "white"
                }
            }
        ]
    
        Teapot {
    
        }
    
        Sphere {
            id: sphere
        }
    
    }
    
    


  • Why does the order of writing objects in the code affect their display?


  • Qt Champions 2016

    Hi
    Maybe it gets the zorder that way?



  • @mrjj do you mean z buffer?

    By the way, if use a material without transparency (for example: PhongMaterial). Order of objects does not affect the display

    pic 1. Normal order of objects
    0_1505897675710_5.9-back-m.png

    pic 2. Order of objects is changed
    0_1505897738006_5.9-forward-m.png

    I think I need to use custom FrameGraph. But, I do not understand how to write it to ensure, that transparency worked normally.



  • And the most interesting. Everything I described above appears in versions 5.6 and 5.9. And in versions 5.7 and 5.8 the behavior is different.

    pic 1. Normal order of objects (5.7 and 5.8)
    0_1505898303092_5.7-back.png

    pic 2. Order of objects is changed (5.7 and 5.8)
    0_1505898322858_5.7-forward.png


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.