Making a Pynode to reapply a texture mapping

Why we need to do this, instead of another approach

So a bunch of node groups for various projects we’ve seen around have back and forth redrawing the same image with various vector changes, and it’s a pain to mess with multiple copies of the same nested node group as you have to basically reimport the whole thing over and over again to correctly duplicate it.

Plus with using procedural textures you end up regenerating the texture for every deformation step. For a setup like parallax this can get pretty inefficient and laggy in the view port.

So our solution to both of these (that we can’t seem to figure out how to implement) is to pass the original image along from outside the node group to a custom pynode that reapplies texture mapping/ standing in as a proxy, allowing the entire group to be duplicated easily, and saving our poor computer from constant regenerating of various noise textures and such.

The Implementation

Sooo… we don’t know what we’re doing to be honest after tons of digging into this we’re no closer than when we started, except now we have an idea of sorta maybe what we need to do, so we made an account to ask since information on Pynodes is… lacking.

So we need to run existing mapped color data through the texturemapping function (the internal one shader texture nodes use, not the node that maps vectors) like it was drawing and image texture.

We thought about just forcing an internal node tree imagetexture node to read texture data from import, but we don’t know how to do that or if it’ll work. We don’t want to learn to write a node to do this in c and then figure out how to work that with a pynode to connect it… becuase it’d be a pain and we don’t know how too.
We saw someone trying something like this with @Secrop 's Tools for Cycles Pynodes, but we still wouldn’t know how to work that out.

Creating python nodes is not that complicated.

If the your ‘paralax’ setup remains the same in every project, apart from the texture source inside, the simplest solution is to add a ‘layout.template_image’ to the node’s draw function, and update all ‘image texture’ nodes in the inner nodetree.

Oohh, okay so the simplest option is to just build the entire parallax effect mapping as a node group script and have it only take images.
Which… does uhh invalidate the point of this though. The ideal is to stick a any existing texture node in an input socket and have it used, and so we can use this for building other projects that might need it.
(Ie, that’s a good solution if we weren’t using procedural textures from the shader node tree)

You can use both methods… but they require a different approach.
If you want for the node to have an ‘Image selector’ in the UI, you add it to the draw function; and on change, you loop over all inner ‘image texture’ nodes and update their image property.

If you want to plug an image into the node through a socket, then you need to create fake sockets, that check which node is connected to them to grab the ‘image’ (if they are ‘image texture’ nodes); and update the inner nodes.

1 Like

Thanks, uhh what if we want to do this with color data inputs like say a chain of noise textures and mix nodes , do we just have to bake that to a texture?

Probably yes.
Python nodes are just a way to automatize some tasks, but they are still based on node_groups. Therefore, they are unfolded as a normal nodegroup.

When a color reaches a socket, it’s a color! It’s not a texture information. So you are sticked to whatever the coordinates that color uses (or whatever procedure produces that color).
The only way to change this is to recreate everything inside the python node, and change your coordinates there. (this is quite more difficult than dealing with just images).

Another solution is to have your textures as a node_group and feed them to the python node… I used a similar approach in the ‘loop node’. Then, in the inner node_tree, you can duplicate that nodegroup and use it as if an ‘image texture’.

1 Like

So just to reiterate initial solution we came up with in the topic is impossible unless we can somehow completely recreate the way colors are mapped with just existing nodes or write a node in c that does that.
But there’s much easier ways to handle that by just taking in a node_group or an image instead of that.

Here’s an illustration of the problem:

1 Like