How to feed output of ShaderEffect back into the same ShaderEffect in QML/QtQuick2

StackOverflow https://stackoverflow.com/questions/22600846

  •  19-06-2023
  •  | 
  •  

سؤال

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

هل كانت مفيدة؟

المحلول

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
}

نصائح أخرى

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top