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.
http://www.fundza.com/rfm/osl/tex_rotate/index.html
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];
}