Delegates with Textures

Hi everyone,

I’m trying to use Invoke (Delegate 2 → 1) to trigger a texture-processing operation, but I can’t get it to work.

The patch is fairly simple:

  • A FileTexture loads an image, which is resized.

  • BubbleNoise, driven by a Stopwatch, generates an animated noise texture.

  • Both textures feed into an Invoke node connected to a delegate containing ColorMap, Convert, SetAlpha and Blend.

  • The same processing chain works when patched directly, without the delegate.

However, when I try to run it through Invoke, I get no output.

I’ve attached a screenshot showing both setups.

Am I misunderstanding how delegates and Invoke work in this context? Is there something specific I need to do to get the texture-processing operation to execute?

Thanks for any ideas!

Mm, not sure why you need delegate in this place, but there are few reasons to understand it better.

Fundamentally you should answer yourself a few questions:

  • What is a shader/texturefx node?
  • What is delegate?

So when we say shader, we expect it to be some code, but when we say shader node, it’s already something that is wrapping the shader for us, it’s not a function, or operation it’s kind of self contained class instance that vvvv manages a lifetime: create, update, dispose.

What is delegate, a delegate is a stateless function that can be a property, it’s kind of instruction that maybe invoked, but it does not manages it’s lifetime, it’s something to be called and forget.

So the reason for this explanation is, that this way of piping may work but not like you did it… e.g. you stored something that should be created, update and disposed inside of a function. So when function is over - it’s over, e.g. everything inside is gone.

Speaking simpler, to make it work properly you have to Create few a pad`s with color, blend, convert (e.g. create instances) and then you would need to pass thouse pads (references) to delegate, and inside you should call methods/operations (e.g. SetTexture, SetAlpha ) on them via the reference (e.g. it’s called inside, but stored outside). Then it would work.

But… I’m not sure it was planned to make it workable like that…

So the next question is what you expect from that Invoke, and why you did it that way?

The warnings on the nodes inside the delegate tell you why it doesn’t work - those nodes get created and immediately disposed of by the invoke - they don’t survive until the actual render call from downstream comes along.

We do nowadays offer ways to solve this puzzle by using custom regions. The graybook has some documentation on it. Please have a look at it first if it doesn’t help I guess we can upload a patch tomorrow.

Thanks both for the explanations! I am about to see why the TextureFX nodes don’t work inside a delegate…

Maybe I should explain what I’m trying to do.

I’d like to build a real-time video system where I can switch and blend between different effects. Eventually, there might be quite a few effects, so I’m looking for a way to keep things simple and organised.

My idea was to put each effect into a delegate and use Switch and Invoke to select between them. Ideally, I’d also like to combine effects and blend between them.

I’ve attached another screenshot to show the idea.

Would Custom Regions be the best way to do this, or is there a simpler solution using Process nodes?

Thanks again for your help!

This is one of the things in vvvv I up to this day somehow refuse to accept that it does not work like you propose @vincent.now, my confusion is documented here:

Naive questions about textures and delegates

I kind of get from a software engineering point of view that it is not possible. But from a user perspective (somebody whose knowledge or interest is not high enough to care about abstract concepts like stateless / stateful functions) it is just very strange, that you can not use Delegates to “shoot in” any kind of patch from the outside, but only stateless nodes…

You see the problem here, is not even a delagate it’s a process node concept, you have a wrapper for shaders that cannot be used like that, like delegate is an atom where process is a malecule, and you are trying to fit molecule inside atom. Instead you have to atomize malecule and work on atomic level.

The tonfilm correctly stated:

Now you can use custom regions an pass them in a switch and you can define interface on it with something like

Invoke(in Texture, in Noise Texture, out Texture) 

It would look nice but needs a custom region piping…

I quickly sketched something together for you:

RealTimeVideoSystem.vl (43.8 KB)

that would be a great helppatch in the help browser!

@Elias Any way to make it spreadable?

RealTimeVideoSystemSpreaded.vl (78.6 KB)

I guess so yes - assuming one invocation per frame we could track how many instances we need internally and manage them accordingly. On each update set a counter to zero and then for each invocation increase and fetch from a list - if the slice (IVideoEffect) does not exist create it. Then call Update on it. But maybe that should be a second implementation .