auto_toon2.glsl 1.8 KB

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