Hi,
Can I stop an OP from cooking but keep its output alive? I have an expensive operator that I either only want to cook every N frames or only cook it when the user clicks a Pulse button. But I still need the OP output from when it last cooked. How do I do this?
Thanks!
Certainly. First it’s good to realize TD is a pull-based system - meaning nodes only cook when something is interested in their data - which is opposite from most software.
This also means you can control when network chains cook or not, while the output of these nodes stays the same.
For instance if you have two nodes going into a Switch, and the Switch is set to output the second input, that mean the node going into the first input (and its upstream nodes) will not cook. This way you can have many different ‘scenes’ in your project while only the scene which is currently contributing to your visible/audible output is cooking.
Caveat: if you’re not in perform mode, looking at a node if its viewer pane is on, counts as ‘something is interested in my data’ so it will give the node a reason to cook.
Start reading here:
Thanks! In my case I have a glsl compute shader that calculates a reduced color palette from the input image. The input image can change every frame and the output (the reduced palette) will be needed every frame, but I don’t want the shader to run every frame. I want the consumer to basically use a stale result because I don’t need a new palette every frame. How do I set this up? Is there a TOP that can break the cooking chain on demand but cache the data it got?
You’re looking for the Cache TOP. And perhaps Cache Select TOP. See Help→Operator Snippets for practical examples on how to use them.
Thanks again! I was able to freeze the palette using a Cache TOP. However the glsl compute shader never stops cooking. Even when I disable its viewer and disconnect its output completely. Is this a restriction of shaders in particular?
No, there is no such restriction.
See attached a basic example (just drag the toxfile into your existing network) of a compute shader which is not cooking, as nothing is requesting its data, even though its input data keeps changing.
(middle click on the GLSL TOP to see it’s not cooking)
Now in the parameter window of the Cache TOP, click the Pulse button for the replace single parameter. This will cause the Cache TOP to update a single frame, and therefore it will request data of the GLSL TOP, which will cause it to cook once (check the Info CHOP , look at the total cooks channel)
base_compute_shader_only_cooks_when_needed.tox (934 Bytes)
I found out why my shader never stopped cooking. The info OP attached to the main shader OP still had its viewer active. When I deactivated the viewer of the main shader OP and the info OP it stopped cooking when no one is pulling data. Mystery solved. 
1 Like