QML 倒影实现

import QtQuick 2.15
import QtQuick.Shapes 1.15

Item {
    width: 1280
    height: 720

    Rectangle{
        id: object1
//        rotation: 30
        x:300
        y: 0
        width: 500
        height: 400
        color: "lightsteelblue"



        gradient: Gradient {
            orientation:Gradient.Horizontal
            GradientStop { position: 0.0; color: "lightsteelblue" }
            GradientStop { position: 0.5; color: "blue" }
            GradientStop { position: 1.0; color: "black" }
        }



        Image {
            id: img
//            rotation: 30
            x: 50
            y: 26
            width: 319
            height: 192
            source: "D:/workspace/qt/Test1/image/fish.jpg"
//            source: "file:///D:/workspace/qt/Test1/image/fish.jpg"
//            source: "qrc:/image/fish.jpg"
//            source: "" //相对路径?
            sourceClipRect: Qt.rect(50, 26, 369, 218)
        }

        ShaderEffect {

            width: img.width
            height: img.height

            anchors.top: img.bottom
            anchors.left: img.left

            property variant source: img
            property size sourceSize: Qt.size(0.5 / img.width, 0.5 / img.height)

            fragmentShader: "
                    varying highp vec2 qt_TexCoord0;
                    uniform lowp sampler2D source;
                    uniform lowp vec2 sourceSize;
                    uniform lowp float qt_Opacity;
                    void main() {

                        lowp vec2 tc = qt_TexCoord0 * vec2(1, -1) + vec2(0, 1);
                        lowp vec4 col = 0.25 * (texture2D(source, tc + sourceSize)
                                                + texture2D(source, tc- sourceSize)
                                                + texture2D(source, tc + sourceSize * vec2(1, -1))
                                                + texture2D(source, tc + sourceSize * vec2(-1, 1))
                                               );
                        gl_FragColor = col * qt_Opacity * (1.0 - qt_TexCoord0.y) * 0.2;
                    }"
        }
    }




}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值