beep

Tex tiling OSL Octane

Feb 9th, 2018
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. // Shader : Texture Tiling OSL shader
  2. // Author : Hayssam Keilany
  3. //
  4. // Description :
  5. //
  6. // Meant to "break" the repeating patterns on textures
  7. // Very simple version, could be improved by anyone if they feel like it :)
  8.  
  9. // REMINDER : YOU NEED TO USE "OSL UV" IN THE PROJECTION NODE
  10.  
  11. #include <octane-oslintrin.h>
  12.  
  13. color dissolve(color tex1, color tex2, float mix, float noisescale)
  14. {
  15. float rnd = noise("noise", P * noisescale);
  16. color c;
  17.  
  18. if(rnd < mix)
  19. c = tex2;
  20. else
  21. c = tex1;
  22.  
  23. return c;
  24. }
  25.  
  26. shader Texture_Tiling
  27. (
  28. color texinput = color(1,1,1)
  29. [[string label = "Input (Texture)"]],
  30.  
  31. float scale=4.0
  32. [[string label = "Tiling Scale", float min=0.0, float sliderexponent=4,float max=10]],
  33.  
  34. int pixelate = 1
  35. [[string label = "Enable Pixelation",string widget = "boolean"]],
  36.  
  37. int blurmode = 0
  38. [[string label = "Enable Blur Mode",string widget = "boolean"]],
  39.  
  40. float blursize = 0.5
  41. [[string label = "Blur Size",float min = 0.0, float sliderexponent=4, float max=1]],
  42.  
  43. float noisescale = 6
  44. [[string label = "Noise Size",float min = 0.0, float sliderexponent=4, float max=100]],
  45.  
  46. output color c=0
  47. )
  48. {
  49. float u_tile; float v_tile;
  50.  
  51. // "pixelize" the texture
  52. if (pixelate)
  53. {
  54. u_tile = floor(u * scale);
  55. v_tile = floor(v * scale);
  56. }
  57. else
  58. {
  59. u_tile = u;
  60. v_tile = v;
  61. }
  62. // offset it
  63. // can be changed to "cell" but voronoi looks more natural
  64. float u_jit = noise("voronoi", u, v_tile * scale + v_tile);
  65. float v_jit = noise("voronoi", v, u_tile * scale + u_tile);
  66.  
  67. // add with untouched UV
  68. float xoffset = u + u_jit;
  69. float yoffset = v + v_jit;
  70.  
  71. // declare the textures to blur
  72. color tex1 = _evaluateDelayed(texinput, xoffset , yoffset );
  73. color tex2 = _evaluateDelayed(texinput, xoffset+blursize , yoffset );
  74. color tex3 = _evaluateDelayed(texinput, xoffset , yoffset + blursize);
  75. color tex4 = _evaluateDelayed(texinput, xoffset - blursize, yoffset - blursize);
  76.  
  77. // choose between dissolve or blur
  78. if (blurmode) c = (tex1 + tex2 + tex3 + tex4) / 4;
  79. else
  80. {
  81. color c1 = dissolve(tex1, tex2, 0.5, noisescale);
  82. color c2 = dissolve(c1 , tex3, 0.5, noisescale);
  83. c = dissolve(c2 , tex4, 0.5, noisescale);
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment