auto_toon2.glsl 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. void main()
  2. {
  3. //Changethis to increase the number of colors.
  4. int numColors =8;
  5. float4 to_gray = float4(0.3,0.59,0.11,0);
  6. float x1 = dot(to_gray, SampleOffset(int2( 1, 1)));
  7. float x0 = dot(to_gray, SampleOffset(int2(-1,-1)));
  8. float x3 = dot(to_gray, SampleOffset(int2( 1,-1)));
  9. float x2 = dot(to_gray, SampleOffset(int2(-1, 1)));
  10. float edge = (x1 - x0) * (x1 - x0) + (x3 - x2) * (x3 - x2);
  11. float4 color = Sample();
  12. float4 c0 = color - float4(edge, edge, edge, edge) * 12.0;
  13. float red = 0.0;
  14. float green = 0.0;
  15. float blue = 0.0;
  16. bool rr = false;
  17. bool bb = false;
  18. bool gg = false;
  19. int count = 1;
  20. float colorN = 0.0;
  21. float colorB = 0.0;
  22. for (count = 1; count <= numColors; count++)
  23. {
  24. colorN = float(count / numColors);
  25. if ( c0.r <= colorN && c0.r >= colorB && rr == false )
  26. {
  27. if (count == 1)
  28. {
  29. if (colorN >= 0.1)
  30. red = 0.01;
  31. else
  32. red = colorN;
  33. }
  34. else if (count == numColors)
  35. red = 0.95;
  36. else
  37. red = colorN;
  38. rr = true;
  39. }
  40. if (c0.b <= colorN && c0.b >= colorB && bb == false)
  41. {
  42. if (count == 1)
  43. {
  44. if (colorN >= 0.1)
  45. blue = 0.01;
  46. else
  47. blue = colorN;
  48. }
  49. else if (count == numColors)
  50. blue = 0.95;
  51. else
  52. blue = colorN ;
  53. bb = true;
  54. }
  55. if (c0.g <= colorN && c0.g >= colorB && gg == false)
  56. {
  57. if (count == 1)
  58. {
  59. if (colorN >= 0.1)
  60. green = 0.01;
  61. else
  62. green = colorN;
  63. }
  64. else if (count == numColors)
  65. green = 0.95;
  66. else
  67. green = colorN;
  68. gg = true;
  69. }
  70. colorB = float(count / numColors);
  71. if (rr == true && bb == true && gg == true)
  72. break;
  73. }
  74. SetOutput(float4(red, green, blue, c0.a));
  75. }