Max Rose avatar image
Max Rose asked

How to rotate a texture using OSL

I have a simple OSl script that renders a Matcap texture created in Photoshop. I want to be able to rotate the texture, so that - for example - if I have a Matcap that fakes a rim light I can rotate it to make it look like the rim is coming from another direction.

I followed a tutorial from this page, but the result I got isn't what I wanted.

Is there a way to simply rotate the incoming texture using OSL?

Here's the code I got so far (pieced together from several sources...)

shader SimpleMatCap

string filename = "" [[ string widget = "filename" ]],

float Gamma = 1.0,

float s = 0 [[int lockgeom = 0]],
float t = 0 [[int lockgeom = 0]],
float angle = 0,
float pivot_s = 0.5,
float pivot_t = 0.5,

output color result = color(0, 0, 0),
output float resultS = 0,
output float resultT = 0

vector Normal_camera = transform ("world", "camera", N);
float norU = clamp (Normal_camera[0] * 0.5 + 0.5, 0.0, 1.0);
float norV = clamp (Normal_camera[1] * -0.5 + 0.5, 0.0, 1.0);
color c_out = texture (filename, norU+s, norV+t);

result=pow(c_out, 1/Gamma);

point pntST = point(s, t, 0);

point p1 = point(pivot_s, 0, pivot_t);
point p2 = point(pivot_s, 1, pivot_t);
point rotatedImg = rotate(pntST, radians(angle), p1, p2);

resultS = rotatedImg[0];
resultT = rotatedImg[2];

10 |600

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

0 Answers

· Write an Answer

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Welcome to the Arnold Answers community.

This is the place for Arnold renderer users everywhere to ask and answer rendering questions, and share knowledge about using Arnold, Arnold plugins, workflows and developing tools with Arnold.

If you are a new user to Arnold Answers, please first check out our FAQ and User Guide for more information.

When posting questions, please be sure to select the appropriate Space for your Arnold plugin and include the plugin version you are using.

Please include images, scene and log files whenever possible as this helps the community answer your questions.

Instructions for generating full verbosity log files are available for MtoA, MaxtoA, C4DtoA, HtoA, KtoA, and Kick.

If you are looking for Arnold Documentation and Support please visit the Arnold Support site.

To try Arnold please visit the Arnold Trial page.

Bottom No panel present for this section.