TextureNoTile - 图1

    1. // Non-Tiling Texture Shader
    2. // TextureNoTile.osl, by Zap Andersson
    3. // Modified: 2020-03-28
    4. // Copyright 2020 Autodesk Inc, All rights reserved. This file is licensed under Apache 2.0 license
    5. // https://github.com/ADN-DevTech/3dsMax-OSL-Shaders/blob/master/LICENSE.txt
    6. // Modified by Saul Espinosa for Redshift OSL Support 2020-12-28
    7. float sum( color col ) { return col[0]+col[1]+col[2]; }
    8. color textureNoTile( string FileName, point UV, float GradientScale, float Offset, float Rescale, float Rotate, int LevelCount, int Debug, int Seed )
    9. {
    10. float k = noise("uperlin", UV / GradientScale, Seed);
    11. float l = k*LevelCount + UV[1] / GradientScale;
    12. float i = floor( l );
    13. float f = l - i;
    14. vector offa = cellnoise(i + 0.0, Seed) * vector(Offset, Offset, 1.0);
    15. vector offb = cellnoise(i + 1.0, Seed) * vector(Offset, Offset, 1.0);
    16. float sca = 1.0 / (1.0 + (offa[2] - 0.5) * Rescale);
    17. float scb = 1.0 / (1.0 + (offb[2] - 0.5) * Rescale);
    18. float rota = offa[2] * Rotate;
    19. float rotb = offb[2] * Rotate;
    20. point rotA = rotate(UV, rota, vector(0.5,0.5,0), vector(0.5,0.5,1.0));
    21. point rotB = rotate(UV, rotb, vector(0.5,0.5,0), vector(0.5,0.5,1.0));
    22. color cola = texture(FileName, rotA[0] * sca + offa[0], 1.0 - (rotA[1] * sca + offa[1]), "wrap", "periodic" );
    23. color colb = texture(FileName, rotB[0] * scb + offb[0], 1.0 - (rotB[1] * scb + offb[1]), "wrap", "periodic" );
    24. if (Debug)
    25. {
    26. cola = offa;
    27. colb = offb;
    28. }
    29. return mix( cola, colb, smoothstep(0.1,0.9,f-0.1*sum(cola-colb)) );
    30. }
    31. shader NoTile
    32. [[ string help = "Non-Tiling Bitmap Lookup, based on an OpenGL Technique",
    33. string label = "Non-Tiling Bitmap Lookup",
    34. string URL = "http://www.iquilezles.org/www/articles/texturerepetition/texturerepetition.htm" ]]
    35. (
    36. // Texture Input
    37. point uvw = point(u,v,0)
    38. [[ string label= "UV Coordinate",
    39. string help = "The 2D coordiante at which the texture is looked up." ]],
    40. string Filename = "" [[ string widget="filename", string page = "Image" ]],
    41. string fromSpace = ""
    42. [[ string label = "Input Space", string widget = "colorspace", string page = "Image"]],
    43. string toSpace = ""
    44. [[ string label = "Output Space", string widget = "colorspace", string page = "Image"]],
    45. float gainMul = 1
    46. [[ string label = "Gain",
    47. string page = "Image",
    48. float softmin = 0,
    49. float softmax = 10,
    50. float slidermin = 0,
    51. float slidermax = 10,
    52. float sensitivity = 0.001 ]],
    53. // Noise Options
    54. float GradientScale = 2.0
    55. [[ float min = 0,
    56. float max = 25,
    57. string page = "Noise"
    58. ]],
    59. float Offset = 1.0
    60. [[ float min = 0,
    61. float max = 25,
    62. string page = "Noise"
    63. ]],
    64. float Rescale = 0.0
    65. [[ float min = 0,
    66. float max = 25,
    67. string page = "Noise"
    68. ]],
    69. float Rotate = 0.0
    70. [[ float min = -180,
    71. float max = 180,
    72. string page = "Noise"
    73. ]],
    74. int LevelCount = 8
    75. [[ int min = 0,
    76. int max = 25,
    77. string page = "Noise"
    78. ]],
    79. int Seed = 0
    80. [[ int min = 0,
    81. int max = 100,
    82. string page = "Noise"
    83. ]],
    84. int Debug = 0
    85. [[ string widget = "checkBox",
    86. string help = "Shows the regions that are being mixed", string page = "Utility" ]],
    87. int Bypass = 0
    88. [[ string widget = "checkBox",
    89. string help = "Turns the effect off, to compare", string page = "Utility" ]],
    90. output color outColor = 0
    91. )
    92. {
    93. int s = Seed;
    94. point Pos = select(vector(u,v,0), uvw, isconnected(uvw));
    95. if (Bypass)
    96. color Col = texture(Filename, Pos[0], 1.0 - Pos[1], "wrap", "periodic");
    97. else
    98. Col = textureNoTile( Filename, Pos, GradientScale, Offset, Rescale, Rotate, LevelCount, Debug, s );
    99. outColor = transformc( fromSpace, toSpace, Col) * gainMul;
    100. }