Shapes - 图1

    1. // Compiled after a small session between Martin Breidt & Mads Drøschler Based on a WebGL function.
    2. // 14.10.2018
    3. // License: https://creativecommons.org/licenses/by-nc-sa/3.0/
    4. // Modified : 03.22.2021 by Saul Espinosa For Redshift 3d
    5. float lPolygon(vector p, int n)
    6. {
    7. float a = atan2(p[0], p[1]) + M_PI;
    8. float r = 2*M_PI/float(n);
    9. return cos(floor(0.5 + a/r) * r - a) * length(p);
    10. }
    11. shader Shapes
    12. [[ string help = "Generates Procedural Shapes",
    13. string label = "Shapes" ]]
    14. (
    15. point Po = point(u, v, 0),
    16. int nSides = 3
    17. [[ string help = "Number of polygon sides",
    18. string label = "UVW",
    19. int max = 25,
    20. int min = 3
    21. ]],
    22. float Softness = 0.09
    23. [[
    24. float min = 0.0,
    25. float max = 2.0
    26. ]],
    27. float Radius = 0.4
    28. [[
    29. float min = 0.001,
    30. float max = 1
    31. ]],
    32. float Stretch_U = 1.0
    33. [[
    34. float min = 0,
    35. float max = 2
    36. ]],
    37. float Stretch_V = 1.0
    38. [[
    39. float min = 0,
    40. float max = 2
    41. ]],
    42. float Star_Effect = 1.0
    43. [[ string help = "A value > 0 will cause the shape to become more star-like along the W coordinate",
    44. float min = 0,
    45. float max = 2
    46. ]],
    47. vector Offset = 0.0
    48. [[ string help = "Translation of pattern. Use a Z value > 0 to move towards a star-like pattern" ]],
    49. color Color_Shape = color(1),
    50. color Color_Background = color(0),
    51. output color Out = 0,
    52. )
    53. {
    54. vector p = abs(Po-floor(Po));
    55. p = p - vector(0.5, 0.5, 0);
    56. p = (p - Offset) * vector(Stretch_U, Stretch_V, Star_Effect )/ Radius;
    57. float d = lPolygon(p, int(mod(nSides-3, 60.)+3.));
    58. Out = color(smoothstep(Radius, Radius+Softness, d));
    59. Out = (1-Out)*Color_Shape+(Out*Color_Background); // added colors for shape and background //Mads
    60. }