JawbreakerNoise - 图1

    1. // Created by Jerome Stephan (@jstephan828) 22/08/2021 for Redshift3D
    2. // Modified by Saul Espinosa 09/23/2021 to add OCIO Color Management & Page Meta Data
    3. // Using colors based on https://github.com/redshift3d/RedshiftOSLShaders/blob/main/NoiseColor.osl
    4. #include <vector2.h>
    5. #define vec2 vector2
    6. #define vec3 vector
    7. #include <vector4.h>
    8. #define vec4 vector4
    9. float fract(float x){return mod(x, 1.0);}
    10. vec3 fract(point x){return vec3(mod(x.x, 1.0),mod(x.y, 1.0),mod(x.z, 1.0)) ;}
    11. point matrix_mul(point matx, point maty, point matz, point px){
    12. point result;
    13. result.x = matx[0]*px.x+matx[1]*px.y+matx[2]*px.z;
    14. result.y = maty[0]*px.x+maty[1]*px.y+maty[2]*px.z;
    15. result.z = matz[0]*px.x+matz[1]*px.y+matz[2]*px.z;
    16. return result;
    17. }
    18. float def_turbulence(point x){
    19. point px = x;
    20. point mx = point( 1.6, 1.2, -1.2);
    21. point my = point( -1.6, 1.5, 1.2);
    22. point mz = point( 1.6, -1.2, 1.8);
    23. float f = 0.0;
    24. f = 0.5000*noise( px ); px = matrix_mul(mx, my, mz, px);
    25. f += 0.2500*noise( px ); px = matrix_mul(mx, my, mz, px);
    26. f += 0.1250*noise( px ); px = matrix_mul(mx, my, mz, px);
    27. f += 0.0625*noise( px ); px = matrix_mul(mx, my, mz, px);
    28. f += 0.0313*noise( px ); px = matrix_mul(mx, my, mz, px);
    29. //f = 0.5 + 0.5*f;
    30. return f;
    31. }
    32. shader JawbreakerNoise
    33. [[ string help = "Jawbreaker-like color layer Noise",
    34. string label = "Jawbreaker Noise" ]]
    35. (
    36. point Po = P
    37. [[ string label = "Position", string page = "Position" ]],
    38. point Pcent = vec3(0)
    39. [[string label = "Center", string page = "Position"]],
    40. float Scale = 1.0
    41. [[ string label = "Overall Scale", float min = 0.0, float max = 20.0, string page = "Noise Color"]],
    42. float Time = 1.0
    43. [[ string label = "Color Time", float min = 0.0, float max = 1000.0, string page = "Noise Color"]],
    44. float ColIntens = 0.5
    45. [[ string label = "Color Brightness", float min = 0.0, float max = 10.0, string page = "Noise Color"]],
    46. float ColComplex = 1.0
    47. [[ string label = "Color Complexity", float min = 0.0, float max = 5.0, string page = "Noise Color"]],
    48. float NoiseTime = 0.0
    49. [[ string label = "Noise Time", float min = 0.0, float max = 10.0, string page = "Noise Shape"]],
    50. float NoiseAmount = 8.0
    51. [[ string label = "Noise Amount", float min = 0.0, float max = 80.0, string page = "Noise Shape"]],
    52. float Layers = 15.0
    53. [[ string label = "Layers", float min = 1.0, float max = 150.0, string page = "Noise Shape"]],
    54. string toSpace = ""
    55. [[ string label = "Output Color Space", string widget = "colorspace", string page = "OCIO Colorspace"]],
    56. output color outColor = 0
    57. )
    58. {
    59. float Pi = 10.;
    60. int complexity = 10; // More points of color.
    61. float fluid_speed = 600.0; // Drives speed, higher number will make it slower.
    62. float color_intensity = ColIntens;
    63. point puv = Po*Scale;
    64. point p = Po*Scale;
    65. p.x += (def_turbulence(p*0.1+NoiseTime)-0.5)*NoiseAmount;
    66. p.y += (def_turbulence(p*0.1+NoiseTime+0.5)-0.5)*NoiseAmount;
    67. p.z += (def_turbulence(p*0.1+NoiseTime+1.5)-0.5)*NoiseAmount;
    68. float layers_adj = Layers/10.0;
    69. float steps = floor(layers_adj*distance(Pcent, p));
    70. steps = mix(steps, layers_adj*distance(Pcent, p), 0.2);
    71. p = vec3(steps);
    72. p+=noise(puv*0.005);
    73. for(int i=1;i<complexity;i++){
    74. point newp=p + Time*0.001;
    75. newp[0]+=ColComplex*(0.6/float(i)*sin(float(i)*p[1]+Time/fluid_speed+2.3*float(i)) + 0.5);
    76. newp[1]+=ColComplex*(0.6/float(i)*sin(float(i)*p[0]+Time/fluid_speed+0.3*float(i)) - 0.5);
    77. p=newp;
    78. }
    79. color Out= color(color_intensity*sin(5.0*p[0])+color_intensity,color_intensity*sin(3.0*p[1])+color_intensity,color_intensity*sin((p[0]+p[1]))+color_intensity);
    80. {
    81. outColor = linearstep (0, 2, (transformc( toSpace, Out)));
    82. }
    83. }