Qt Quick 예제 - 셰이더 효과
셰이더 효과의 사용을 보여주는 Qt Quick 예제입니다.
이 예는 Qt Quick 에서 셰이더로 수행할 수 있는 몇 가지 시각 효과를 보여줍니다. 텍스트와 몇 개의 이미지에 5가지 효과를 적용합니다. 자세한 내용은 Qt Quick - 중요 개념에서 확인하세요 . Graphical Effects
예제 실행하기
에서 예제를 실행하려면 Qt Creator에서 Welcome 모드를 열고 Examples 에서 예제를 선택합니다. 자세한 내용은 예제 빌드 및 실행을 참조하세요.
셰이더 효과 사용
ShaderEffect 유형은 일반적으로 ShaderEffectSource 을 사용하여 다른 유형에서 작동합니다:
ShaderEffectSource { id: theSource sourceItem: theItem }
위의 스니펫에서 theItem
은 파일에 있는 복잡한 QML 객체의 ID입니다.
ShaderEffects는 이 ShaderEffectSource 를 조각 셰이더의 텍스처로 사용할 수 있습니다:
fragmentShader: "content/shaders/wobble.frag.qsb"
OpenGL뿐만 아니라 여러 그래픽 API를 지원하기 위해 셰이더 소스는 QML에 임베드되지 않습니다. 참조된 .qsb
파일은 셰이더 코드의 여러 변형이 포함된 미리 생성된 셰이더 팩입니다. 그런 다음 런타임에 사용되는 그래픽 API(Vulkan, Metal, Direct3D 11 또는 OpenGL)에 따라 런타임에 Qt Quick 에서 적절한 셰이더를 선택합니다. .qsb 파일은 오프라인으로 생성되며 Qt 리소스 시스템을 통해 실행 파일과 함께 번들로 제공됩니다.
셰이더의 ShaderEffect 에서 사용자 지정 프로퍼티를 사용할 수 있습니다. 이렇게 하면 애니메이션 셰이더 코드를 매우 쉽게 만들 수 있습니다:
property variant source: theSource property real bend property real minimize property real side: genieSlider.value SequentialAnimation on bend { loops: Animation.Infinite NumberAnimation { to: 1; duration: 700; easing.type: Easing.InOutSine } PauseAnimation { duration: 1600 } NumberAnimation { to: 0; duration: 700; easing.type: Easing.InOutSine } PauseAnimation { duration: 1000 } } SequentialAnimation on minimize { loops: Animation.Infinite PauseAnimation { duration: 300 } NumberAnimation { to: 1; duration: 700; easing.type: Easing.InOutSine } PauseAnimation { duration: 1000 } NumberAnimation { to: 0; duration: 700; easing.type: Easing.InOutSine } PauseAnimation { duration: 1300 } }
셰이더이펙트는 커스텀 버텍스 셰이더를 가질 수도 있습니다. ShaderEffect 에서 메시 프로퍼티를 설정하면 조작할 수 있는 버텍스가 더 많아져 더 많은 효과를 구현할 수 있습니다.
mesh: Qt.size(10, 10) vertexShader: "content/shaders/genie.vert.qsb"
© 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.