Last active
April 16, 2023 18:06
-
-
Save donhenton/f4c1d6d4de5e0f3bae8ad79eeb04e737 to your computer and use it in GitHub Desktop.
OSL shader for spiral rotating an image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Open shading Language shader that will take an image on a quad (eg blender) and rotate the image in a spiral that | |
is centered on the quad. | |
INPUT: in_UVs In Blender the script tag receives a UV input from a texture coordinate node | |
angle: the angle to rotate, can be animated in blender | |
OUTPUT: out_UVs modified UVs | |
*/ | |
shader UV_rotate( | |
point in_UVs = point(u, v, 0) | |
[[string label = "UVs In"]] , | |
float angle = 359.0 | |
[[string label = "Angle"]] , | |
output point out_UVs = 0 | |
[[string label = "UVs out"]] | |
) | |
{ | |
// adjust the uvs to center | |
out_UVs = point(in_UVs[0]-0.5,in_UVs[1]-0.5 ,0.0); | |
vector axis0 = point(-0.0,-0.0,0); | |
vector axis1 = point(-0.0,-0.0,1); | |
// compute the distance from the center | |
float d = distance(out_UVs ,point(0,0,0)); | |
// further out more rotation | |
float Angrmp = (angle*(d)); | |
float rads = radians(Angrmp); | |
point UVoffset = rotate(out_UVs, rads, axis0, axis1); | |
// return the uvs to the corner | |
UVoffset = point(UVoffset[0]+0.5,UVoffset[1]+0.5 ,0.0); | |
out_UVs = UVoffset; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment