random based uv mover


it is possible to make osl node, that picks UV map (from external attribute or internal “getattribute”),
and then moving for example 20px right and 60px down vertices in UV map??

And then passing to output result - changed UV map.

I have made pixilated image that has dimensions 2000x2000px, and smallest random block has 10x10px.
UV map in object contains faces that each covers one block.

This is only small preview.

I have trying to pass thru only uv map from attribute but I have failed.

#include "stdosl.h"
#include "node_color.h"

shader windowlight(
    /*matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),*/
    normal NormalIn = N,
    point Vector = P,
    output point UV = point(0.0, 0.0, 0.0),
    output normal Normal = normal(0.0, 0.0, 0.0),
    output point VectorOut = 0
    point p = Vector;
    /*p = transform(mapping, p);*/
    getattribute("std::uv", UV);
    Normal = transform("world", "object", NormalIn);
    VectorOut = p;

Even VectorOut and UV does not work properly.

Goal is to make that UV work in output. And then shift in some regular distances that will cover blocks of image.


ps how can I debug osl code?? Print some statements, variables in console. For me “printf()” does not work at all.

although I cannot help you with the code i can suggest a little trick that you may be able to use.

connect the uv output from the texture coordinates node to a ‘serperate RGB’ node. then you can use math nodes on the seperated R G B components of the uv coordinates and use a ‘combine RGB’ node to rebuild the uv map and apply it to the texture.
you can also use the ‘random’ output of the ‘object info’ node to randomise it a bit.
hope this helps

I found this trick useful when building node groups as the ‘mapping’ node doesn’t have separate inputs for its values.