How do I create QtQuick class using custom shaders in Qt Quick Scene Graph rendering?



  • Hi. i'm developing desktop app targeting Windows, and it's constructed by QML for UI and C++ for backend. (Qt 6)

    Let me assume my app is a FPS game to simplify explaining my situation. In C++ parts, there are an image of game scene and a vertex which represents a cross-hair. And I want to show the composition of game scene and the cross-hair through QML.

    So I just draw the cross-hair directly in the game scene in C++ part and let QML's viewport to read this image as a property and show. It works fine.

    But from now on I need to apply custom shader to the game scene. Of course, this shader should not be applied in the cross-hair.

    So I've found Qt Quick Scene Graph but still can't figure it out. As far as I understand, I have to make my QML's viewport to read a texture of the game scene and the cross-hair vertex as a properties, and when the Qt Quick scene graph rendering is called, the viewport needs to render each of these two properties with a custom shader.

    If I'm right, which class should I inherit from and override to use my custom shaders in QML?

    Any advice will be appreciated. Thanks.



  • I found a great example that might be helpful for my problem.

    https://doc.qt.io/qt-6/qtquick-scenegraph-custommaterial-example.html

    If I’m success I’ll post it here.


    I couldn't make it cuz the scene graph of Qt Quick2 can't have more than one shader for its nodes.


Log in to reply