Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. ShaderEffect shader variable scope
Forum Update on Monday, May 27th 2025

ShaderEffect shader variable scope

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 161 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    eagl
    wrote on 2 Dec 2022, 15:52 last edited by
    #1

    Basically I have a component that looks something like this:

    //Shader.qml
    ColumnLayout {
        property string fragPath
    
        (...)
    
        ShaderEffect {
            (...)
            id: shader
            fragmentShader: "shadereffects/" + fragPath + ".frag.qsb"
        }
    }
    

    Let's say the shader that I want to use is supposed to display a single color, so we can call it "color", and it uses a property also called color that the fragment shader uses.

    //main.qml
    Shader {
        property color color: Qt.rgba(0.5, 0.5, 0.5, 1.0)
        fragPath: "color"
    }
    

    The problem I'm having is that the fragmentShader doesn't have access to all variables in the ShaderEffect's scope. So I get an error ("ShaderEffect: 'color' does not have a matching property") that color doesn't exist. In this case I could of course make another property called color that references the property color in the ColumnLayout or make an alias. But if I want to make another Shader with a different fragmentShader, that uses other variables, that won't work anymore. I would prefer to not have to rewrite the whole Shader component for every different ShaderEffect.

    Is there any way I can make qml define the properties in Shader in the ShaderEffect instead? Is there for example something like property alias content: shader.children but for properties?

    1 Reply Last reply
    0

    1/1

    2 Dec 2022, 15:52

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved