Question

Question

I want to feed the output of a ShaderEffect into itself, effectively generating a feedback loop.

My naive attempts has included simply linking a ShaderEffectSource and a ShaderEffect like so:

    ShaderEffectSource {
        id:buf1;
        sourceItem:  effect;
    }

    ShaderEffect {
        id:effect;
        property variant src: buf1;
        //fragment shader then uses src as texture
    }

My next naive approach included introducing a second ShaderEffectSource into the mix like so:

    ShaderEffectSource {
        id:buf1;
        sourceItem:  effect;
    }

    ShaderEffectSource {
        id:buf2;
        sourceItem:  buf1;
    }

    ShaderEffect {
        id:effect;
        property variant src: buf2;
        //fragment shader then uses src as texture
    }

Neither of these approaches work however. It seems to work in one step but never feeds back in the end.

I have a feeling this is possible, but I am fairly new to QML and the quite possibly very logical and simple solution has eluded me. Any hints are welcome!

Answer

Answers with short working copy-pastable snippets are preferred :-)

Was it helpful?

Solution

This was solved easily. From the documentation I found that there is a recursive property that makes it possible with recursive shaders (duh)! So for example code:

ShaderEffectSource {
    id:buf1;
    recursive:true;
    sourceItem:  effect;
}

ShaderEffect {
    id:effect;
    property variant src: buf1;
    //fragment shader then uses src as texture
}

OTHER TIPS

There's some examples of using recursive ShaderEffectSource to do reaction-diffusion and fluid-dynamics effects on the UI linked from here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top