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;
}"
}
}
}
QML 倒影实现
最新推荐文章于 2024-09-29 22:27:19 发布