MelaninColor - 图1

    1. // Melanin Color Generator OSL node based on Weta's Melanin research paper.
    2. // This was made for Redshift 3D, by Saul Espinosa v.2.1
    3. // Modified : 3/15/2021 - Added ACEScg Output Support
    4. // outColor should be input into the Transmission, Internal Reflection inputs of the rsHair and Diffuse if used.
    5. // This file is licensed under Apache 2.0 license
    6. shader MelaninColor
    7. [[ string help = "Generates Melanin Output Colors",
    8. string label = "Melanin Color" ]]
    9. (
    10. float melanin = 0.5 [[float min = 0, float max = 1, string label = "Melanin"]],
    11. color dyeColor = 1 [[string label = "Dye Color"]],
    12. float redness = 0 [[float min = 0, float max = 1, string label = "Melanin Redness"]],
    13. float dyeMix = 0 [[float min = 0, float max = 1, string label = "Dye Mix"]],
    14. int convToAces = 0 [[ string widget = "checkBox", string label = "ACES", int connectable = 0 ]],
    15. output color outColor = 0
    16. )
    17. {
    18. // ACES Transform
    19. matrix srgbToAcesAP1 = {
    20. 0.6131, 0.0701, 0.0206, 0,
    21. 0.3395, 0.9164, 0.1096, 0,
    22. 0.0474, 0.0135, 0.8698, 0,
    23. 0, 0, 0, 1 };
    24. float w = max( pow(melanin, 2.0) * 33.0, 0.02);
    25. color pheomelanin = exp(w * -vector(0.187, 0.4, 1.05));
    26. color eumelanin = exp(w * -vector(0.419, 0.697, 1.37));
    27. color mel_out = mix(mix(eumelanin, pheomelanin, redness), dyeColor, dyeMix);
    28. float sR = mel_out[0];
    29. float sG = mel_out[1];
    30. float sB = mel_out[2];
    31. if (convToAces == 1){
    32. outColor = transform(srgbToAcesAP1, vector(sR, sG, sB));
    33. }
    34. else {
    35. outColor = mel_out;
    36. }
    37. }