Displace QML Type

根据给定的位移贴图移动源项的像素。更多

Import Statement: import Qt5Compat.GraphicalEffects
Since: QtGraphicalEffects 1.0
Inherits:

Item

属性

详细说明

来源位移源应用的效果

示例

下面的示例展示了如何应用效果。

import QtQuick
import Qt5Compat.GraphicalEffects

Item {
    width: 300
    height: 300

    Image {
        id: bug
        source: "images/bug.jpg"
        sourceSize: Qt.size(parent.width, parent.height)
        smooth: true
        visible: false
    }

    Rectangle {
        id: displacement
        color: Qt.rgba(0.5, 0.5, 1.0, 1.0)
        anchors.fill: parent
        visible: false
        Image {
            anchors.centerIn: parent
            source: "images/glass_normal.png"
            sourceSize: Qt.size(parent.width/2, parent.height/2)
            smooth: true
        }
    }

    Displace {
        anchors.fill: bug
        source: bug
        displacementSource: displacement
        displacement: 0.1
    }
}

属性文档

cached : bool

此属性允许缓存效果输出像素,以提高渲染性能。

每次更改源或效果属性时,都必须更新缓存中的像素。由于需要额外的内存缓冲区来存储效果输出,因此会增加内存消耗。

建议在动画源或特效属性时禁用缓存。

默认情况下,该属性设置为false


displacement : real

该属性定义了位移的比例。比例越大,像素的位移越大。设置为 0.0 时不会产生位移。

该值范围为-1.0(最大位移倒置,根据displacementSource )至 1.0(最大位移,根据displacementSource )。默认情况下,该属性设置为0.0 (无位移)。

不同位移值的输出示例

位移:-0.2 位移0.0 displacement:0.2

displacementSource : variant

此属性定义了用作位移贴图的项目。位移源项会被渲染到中间像素缓冲区中。结果中的红色和绿色分量值决定了像素与源项目的位移。

位移贴图的格式与切线空间法线贴图类似,大多数三维建模工具都可以创建位移贴图。许多图像处理工具都支持生成法线贴图。另外,这种效果的位移贴图也可以是一个 QML 元素,并对其进行适当着色。与任何 QML 元素一样,它也可以被动画化。建议位移贴图的大小与source 的大小相匹配。

置换数据以 RGBA 格式解释。对于每个像素:红色通道存储 x 轴位移,绿色通道存储 y 轴位移。蓝色和阿尔法通道将被忽略。

假设红色通道值 1.0 为全红(0.0 为无红),则此效果认为像素分量值 0.5 不会产生任何位移。高于 0.5 的值会使像素向左移动,低于 0.5 的值会使像素向右移动。同样,绿色通道值高于 0.5 会使像素向上位移,而低于 0.5 则会使像素向下位移。实际的像素位移量取决于displacement 属性。


source : variant

该属性根据displacementSource 中的数据定义了像素位移的源项。

注: 不支持让效果包含自身,例如将源设置为效果的父项。


© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.