1

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 :-)

Mr. Developerdude
  • 9,118
  • 10
  • 57
  • 95

2 Answers2

1

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
}
Mr. Developerdude
  • 9,118
  • 10
  • 57
  • 95
1

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

timday
  • 24,582
  • 12
  • 83
  • 135
  • Actually I have been looking for that fluid dynamics code for a while now, but you kinda didn't answer the question so I kinda couldn't accept your answer. But thanks a lot anyways! – Mr. Developerdude Sep 23 '14 at 21:29
  • No problem, this was already ticked answered when I posted this; just thought it might give other folks stumbling on this question some inspiration what can be done with recursive shaders. – timday Sep 24 '14 at 07:37