문제

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