Posterize - 图1

    1. /*
    2. * Posterise.osl by Charlie (c)2012
    3. * from https://github.com/sambler/osl-shaders
    4. *
    5. * license: public domain
    6. *
    7. * original script from -
    8. * http://blenderartists.org/forum/showthread.php?270332-OSL-Goodness/page5
    9. * Modified 1/4/2020 by Saul Espinosa for Redshift 3D
    10. */
    11. shader posterise
    12. [[ string help = "Posterize Filter Effect",
    13. string label = "Posterize" ]]
    14. (
    15. int Range = 8
    16. [[
    17. int min = 0, int max = 50
    18. ]],
    19. color Color = 1
    20. [[
    21. string label = "Input"
    22. ]],
    23. output color Output = 0 )
    24. {
    25. float posterise(float Value){
    26. if( Range > 1 ) {
    27. return floor(Value * Range) / (Range-1);
    28. }
    29. else if(Range == 1) {
    30. return 0;
    31. }
    32. else {
    33. return Value;
    34. }
    35. }
    36. Output[0] = posterise(Color[0]);
    37. Output[1] = posterise(Color[1]);
    38. Output[2] = posterise(Color[2]);
    39. }