beep

OSL random UVs on instances

Jan 25th, 2021
491
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. //OSL Projection node for OctaneRender 3.08/4 and above//
  2. //Random position scale and rotation uvs for scattered objects, by Beppe Gullotta//
  3. //Use a Random Color Texture node in the RandomColorTex pin to drive the changes //
  4. shader BGrandomUVproj(
  5. color rndm = 0 [[string label = "RandomColorTex",]],
  6. float offset_multiplay = 2 [[float min = 0, float slidermax = 10, float sliderexponent = 1, string label = "Offset",]],
  7. float scale_factor = 0 [[float min = 0, float slidermax = 10, float sliderexponent = 4, string label = "Scale Factor",]],
  8. float scale_multiplay = 1 [[float min = 0.01, float slidermax = 10, float sliderexponent = 4, string label = "Scale Multiply",]],
  9. float angle = 0 [[float min = 0, float slidermax = 360, float sliderexponent = 4, string label = "Rotation Angle",]],
  10. int EqRot = 0 [[string widget="checkBox", string label = "90° Rotation",]],
  11. int FlipX = 0 [[string widget="checkBox", string label = "Flip X",]],
  12. int FlipY = 0 [[string widget="checkBox", string label = "Flip Y",]],
  13. int FlipSinc = 0 [[string widget="checkBox", string label = "Flip Sincro",]],
  14. output point uvw = 0,)
  15. {
  16. //Scaling
  17.  
  18. u = u/(scale_multiplay+rndm[0]*scale_factor);
  19. v = v/(scale_multiplay+rndm[0]*scale_factor);
  20.  
  21. //Flip axis
  22. if (FlipX == 1 && rndm[0] < 0.5) { u = -u; }
  23. if (FlipY == 1 && FlipSinc == 0 && rndm[0] > 0.5) { v = -v; }
  24. if (FlipY == 1 && FlipSinc == 1 && rndm[0] < 0.5) { v = -v; }
  25. //Sign
  26. color signR = 0;
  27. if (rndm[0] < 0.5) {signR[0] = rndm[0]*-1;}
  28. if (rndm[0] > 0.5) {signR[0] = rndm[0];}
  29.  
  30. //Offset
  31. point p = point (u + signR[0]*offset_multiplay, v + signR[0]*offset_multiplay, 0);
  32.  
  33. //Rotation
  34. point p1 = point(0.5, 0.5, 0);
  35. point p2 = point(0.5, 0.5, 1);
  36.  
  37. point rotatedST = rotate(p, radians(angle*signR[0]), p1, p2);
  38.  
  39. //90° Rotation
  40.  
  41. if (EqRot == 1 && angle == 0) {
  42.  
  43. if (rndm[0] < 0.25) { rotatedST = rotate(p, radians(0), p1, p2); }
  44. if (rndm[0] > 0.25 && rndm[0] < 0.50) { rotatedST = rotate(p, radians(90), p1, p2); }
  45. if (rndm[0] > 0.50 && rndm[0] < 0.75) { rotatedST = rotate(p, radians(180), p1, p2); }
  46. if (rndm[0] > 0.75) { rotatedST = rotate(p, radians(270), p1, p2); }
  47. }
  48. if (EqRot == 1 && angle > 0) {
  49.  
  50. if (rndm[0] < 0.25) { rotatedST = rotate(p, radians(0+angle*signR[0]), p1, p2); }
  51. if (rndm[0] > 0.25 && rndm[0] < 0.50) { rotatedST = rotate(p, radians(90+angle*signR[0]), p1, p2); }
  52. if (rndm[0] > 0.50 && rndm[0] < 0.75) { rotatedST = rotate(p, radians(180+angle*signR[0]), p1, p2); }
  53. if (rndm[0] > 0.75) { rotatedST = rotate(p, radians(270+angle*signR[0]), p1, p2); }
  54. }
  55.  
  56. //END
  57. uvw = rotatedST;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment