CandleFlame - 图1

    1. // OSL Shader by Tomás Atria based on http://glslsandbox.com/ examples
    2. // Modified by Saul Espinosa 7/15/2021 for Redshift 3d
    3. float fract(float x)
    4. {
    5. return (x - floor(x));
    6. }
    7. shader candle_flame
    8. [[ string help = "Candle Flame for 2D Cards",
    9. string label = "Candle Flame" ]]
    10. (
    11. point Po = point(u,v,0),
    12. float Time = 1.0
    13. [[ string label = "Time", float min = 0.0, float max = 1000.0]],
    14. int aces = 0
    15. [[ string widget = "checkBox",
    16. string label = "ACES",
    17. int connectable = 0 ]],
    18. output vector outColor = 0,
    19. )
    20. {
    21. point pos = Po;
    22. //NEW
    23. pos = ( pos ) * 7.7-point(4.,5.,0.);
    24. pos[1] = (pos[1]/.88);
    25. if(pos[1]>-2.*4.2)
    26. {
    27. for(float baud = 1.; baud < 9.; baud += 1.)
    28. {
    29. pos[1] += 0.2*sin(4.20*Time/(1.+baud))/(1.+baud);
    30. pos[0] += 0.1*cos(pos[1]/4.20+2.40*Time/(1.+baud))/(1.+baud);
    31. //NEW
    32. //pos[1] += 3.2*sin(16.*4.555*Time/(1.+baud))/(1.+baud*32);
    33. //pos[0] += 0.03*cos(2.*Time/(1.+0.01*baud*cos(baud*baud)+pos[0]/4e3))/(1.+baud);
    34. }
    35. //pos[1] += 0.04*fract(sin(Time*60.));
    36. //NEW
    37. pos[0] += 0.04*mod((sin(Time*60.)),1.0);
    38. }
    39. vector col = vector(0.,0.,0.);
    40. float p =.004;
    41. float y = -pow(abs(pos[0]), 4.2)/p;
    42. float dir = abs(pos[1] - y)*sin(.3);
    43. //float dir = abs(pos[1] - y)*(0.01*sin(Time)+0.07);
    44. if(dir < 0.7)
    45. {
    46. //color.rg += smoothstep(0.,1.,.75-dir);
    47. //color.g /=2.4;
    48. col[0] += smoothstep(0.0,1.,.75-dir);
    49. col[1] += smoothstep(0.0,1.,.75-dir);
    50. col[1] /=2.4;
    51. }
    52. // ACES sRGB Transform
    53. matrix aces_tm = matrix(
    54. 0.6131, 0.0701, 0.0206, 0,
    55. 0.3395, 0.9164, 0.1096, 0,
    56. 0.0474, 0.0135, 0.8698, 0,
    57. 0, 0, 0, 1);
    58. col *= (0.2 + abs(pos[1]/4.2 + 4.2)/4.2);
    59. col += pow(col[0], 1.1);
    60. col *= cos(-0.5+pos[1]*0.4);
    61. pos[1] += 1.5;
    62. vector dolor = vector(0.,0.,0.0);
    63. y = -pow(abs(pos[0]), 4.2)/(4.2*p)*4.2;
    64. dir = abs(pos[1] - y)*sin(1.1);
    65. if(dir < 0.7)
    66. {
    67. //dolor.bg += smoothstep(0., 1., .75-dir);
    68. //dolor.g /=2.4;
    69. dolor[2] += smoothstep(.0,1.,.75-dir);
    70. dolor[1] += smoothstep(.0,1.,.75-dir);
    71. dolor[1] /= 2.4;
    72. }
    73. dolor *= (0.2 + abs((pos[1]/4.2+4.2))/4.2);
    74. dolor += pow(col[2],1.1);
    75. dolor *= cos(-0.6+pos[1]*0.4);
    76. dolor -= pow(length(dolor)/16., 0.5);
    77. //col = (col+dolor)/2.;
    78. //NEW
    79. col = (col*0.6+dolor)/1.5;
    80. vector Out = vector(col);
    81. float r = Out[0], g = Out[1], b = Out[2];
    82. // ACES Output
    83. if (aces == 0)
    84. outColor = Out;
    85. else
    86. {
    87. outColor = transform(aces_tm, vector(r,g,b));
    88. }
    89. }