home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 18759 / ROE.7z / ColorShifting.h < prev    next >
Encoding:
C/C++ Source or Header  |  2020-09-17  |  1.9 KB  |  62 lines

  1. #ifndef ColorShifting_h__
  2. #define ColorShifting_h__
  3.  
  4. float3        ShiftingColor1;
  5. float3        ShiftingColor2;
  6. float        SpecIntensity;
  7. float        ColorShiftMode;
  8.  
  9. #define INVALID_COLOR 666.0f
  10.  
  11. void CustomColor(inout float3 color )
  12. {
  13.     float3 ohsl = RgbToHsl(color);
  14.     ohsl.r = ShiftingColor1.r==INVALID_COLOR?ohsl.r: ShiftingColor1.r;
  15.     ohsl.g = ShiftingColor1.g==INVALID_COLOR?ohsl.g:(ShiftingColor1.g*ohsl.g*(1-ColorShiftMode))+ColorShiftMode*saturate(ohsl.g+(ShiftingColor1.g-0.5f)*2.0f);
  16.     ohsl.b = ShiftingColor1.b==INVALID_COLOR?ohsl.b:((ShiftingColor1.b*ohsl.b)*(1-ColorShiftMode))+ColorShiftMode*saturate(ohsl.b+(ShiftingColor1.b-0.5f)*2.0f);
  17.     color = HslToRgb(ohsl); 
  18. }
  19. void CustomSpec(inout float3 specColor)
  20. {
  21.     float3 oHsl = RgbToHsl(specColor);
  22.     oHsl.r = ShiftingColor1.r==INVALID_COLOR?oHsl.r: ShiftingColor1.r;
  23.     oHsl.g = ShiftingColor1.g==INVALID_COLOR?oHsl.g: ShiftingColor1.g*oHsl.g;
  24.     oHsl.b = ShiftingColor1.b==INVALID_COLOR?oHsl.b:SpecIntensity==INVALID_COLOR?oHsl.b:(SpecIntensity*oHsl.b + oHsl.b);
  25.     specColor = HslToRgb(oHsl);
  26. }
  27. void CustomHue(inout float3 color )
  28. {
  29.     if(ShiftingColor1.r!=INVALID_COLOR )
  30.     {
  31.         float3 ohsl = RgbToHsl(color);
  32.         ohsl.r = ShiftingColor1.r;
  33.         color = HslToRgb(ohsl);
  34.     }
  35. }
  36.  
  37. void ShiftColor(inout float3 srcColor, int channel, float mask)
  38. {
  39.     if (mask > 0.5f)
  40.     {
  41.         float3 shiftColor = channel == 0 ? ShiftingColor1 : ShiftingColor2;
  42.         float3 ohsl = RgbToHsl(srcColor);
  43.         ohsl.r = shiftColor.r;
  44.         ohsl.g = saturate(shiftColor.g);
  45.         ohsl.b = saturate(ohsl.b * shiftColor.b);
  46.         srcColor = HslToRgb(ohsl);
  47.     }
  48. }
  49.  
  50. void ShiftSpec(inout float3 srcSpec, float3 shiftColor, float mask)
  51. {
  52.     if (mask > 0.5f)
  53.     {
  54.         float3 ohsl = RgbToHsl(srcSpec);
  55.         ohsl.r = shiftColor.r;
  56.         ohsl.g = saturate(shiftColor.g*SpecIntensity);
  57.         ohsl.b = saturate(ohsl.b * shiftColor.b);
  58.         srcSpec = HslToRgb(ohsl);
  59.     }
  60. }
  61. #endif // ColorShifting_h__
  62.