# How can I offset a wavy pattern that contains matched noise without having to duplicate large parts of the node tree?

Day 3 of my Shader Nodes learning path. This question is a follow-up to these:

I now managed to create a wavy pattern where the added noise approximates the wave pattern:

My next idea is now to repeat the pattern offset, so that the areas shown here in black are also filled with this pattern.

So I thought I would just invert the result of the wave pattern and put the noise there.

However, when I do this, the noise logically no longer matches the wave pattern, since the center of the wave is somewhere else, as you can see here:

So now I just moved the base vector with $$\pi$$ and, and this is the problem, because I just can't think of anything better, duplicated a large part of the node tree ...which I personally don't like at all.

The result I currently achieve with this technique, or what I would like to achieve, looks like this:

(Opposite wave pattern with stronger noise amplitudes)

I wonder if there is not a simplification of this approach.

Any ideas?

This is my current node tree and the corresponding blend file:

(Blender 3.4+)

Of course, some nodes can still be left out here, since some are used in both parts of the node tree, but the question is whether redundancy can be avoided in principle and structurally and performance can be increased. And unfortunately no: Node groups would not be the goal.

Nothing very clever mathematically, here, just restructuring.

Your shader depends on a 'ripple' mask, hidden in the Adds, Subtracts, and thresholds at their ends, to combine two branches with differently oriented noise textures. You can eliminate one branch by using the mask to control the orientation of the noise textures in the first place:

• "just restructuring" is pretty much what maths are all about :D. In maths, however, it's productive to show how to arrive at a solution: here changing the "add" near the end to a mix, using one of the "greater than" nodes as a binary factor. Then you can just look at which parts are shared by both branches, and move the mix node to the left, and remove the nodes that are no longer used. Commented May 30, 2023 at 9:25
• @MarkusvonBroady ... Thanks! Phrased much better than I could, Go ahead and edit it in if you like. In the download, I isolated the masking (Mix > Fac) cluster into group, to make it a bit more explicit. Maybe should have illustrated with that. But I didn't want to use the group in the answer, lest I be accused of cheating :) I guess with a pencil and paper, you might be able to crunch the expression a bit further? But I doubt that would be very generally useful. Commented May 30, 2023 at 9:37
• Exactly, a little localized ;] I think a generalized version of some kind of "node maths" could be written, but that's a little bit over my head right now. A video example of what I mean: streamable.com/i4ylpq then the mix node can be moved further left like so: i.imgur.com/WJzE1W5.png but in this case the frame contents are so similar you only need to move the factor ("factoring out" has double meaning here) controlling cosine outside and you end up with the same contents of both frames" streamable.com/1qqrsj Commented May 30, 2023 at 10:48
• @MarkusvonBroady :) Your procedure looks just like mine.. automatic re-linking is a real pain when editing trees... Alt-X 'delete unused nodes' quite handy for doing stuff like this. Commented May 30, 2023 at 11:01
• Dear Sir Robin, this is absolutely brilliant! Thank you very much for this enlightenment! I am so grateful to all of you for helping me understand this stuff better! Commented May 30, 2023 at 12:25

i am not sure, but you know you can make node groups, don't you?

• Ah, "node groups", great! What is that? ...never heard of it! :D ...no seriously, of course that would be a possibility, but I thought there might be a variant where I can reduce the redundancy even further. Commented May 29, 2023 at 12:38
• i don't no any other way, sorry Commented May 29, 2023 at 14:49
• Thanks anyway @Chris, I'll just ask a better question next time ;-) Commented May 29, 2023 at 14:55