Advertisement
Guest User

Vermillion Hue Shader

a guest
Jul 17th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. varying vec2 v_vTexcoord;
  2. varying vec4 v_vColour;
  3.  
  4. uniform float xhueval;
  5. uniform float xsatval;
  6.  
  7. void main()
  8. {
  9. vec2 tmp_coord = v_vTexcoord;
  10. vec4 tmp_col = texture2D( gm_BaseTexture, tmp_coord );
  11.  
  12. //rgb to hsl
  13. float colr = tmp_col.r;
  14. float colg = tmp_col.g;
  15. float colb = tmp_col.b;
  16. float xmin = min(min(colr, colg), colb);
  17. float xmax = max(max(colr, colg), colb);
  18. float hslh;
  19. float hsls;
  20. float hsll = (xmin+xmax)/2.;
  21. if (xmin == xmax) {
  22. hsls = 0.;
  23. hslh = 0.;
  24. }
  25. else {
  26. if (hsll < 0.5) hsls = (xmax-xmin)/(xmax+xmin);
  27. else hsls = (xmax-xmin)/(2.-xmax-xmin);
  28. if (colr == xmax) hslh = (colg-colb)/(xmax-xmin);
  29. if (colg == xmax) hslh = 2.+(colb-colr)/(xmax-xmin);
  30. if (colb == xmax) hslh = 4.+(colr-colg)/(xmax-xmin);
  31. hslh = hslh*60.;
  32. if (hslh < 0.) hslh += 360.;
  33. }
  34.  
  35. //change hsl values
  36. hslh += xhueval;
  37. if (hslh >= 360.) hslh -= 360.;
  38. if (hslh < 0.) hslh += 360.;
  39. hsls = xsatval*hsls;
  40.  
  41. //hsl to rgb
  42. if (hsls == 0.) {
  43. colr = hsll;
  44. colg = colr;
  45. colb = colr;
  46. }
  47. else {
  48. float varc = (1.-abs(2.*hsll-1.))*hsls;
  49. float varx = varc*(1.-abs(mod(hslh/60., 2.) - 1.));
  50. float varm = hsll - varc/2.;
  51. if ((hslh >= 0.) && (hslh < 60.)) {
  52. colr = varc + varm;
  53. colg = varx + varm;
  54. colb = varm;
  55. }
  56. if ((hslh >= 60.) && (hslh < 120.)) {
  57. colr = varx + varm;
  58. colg = varc + varm;
  59. colb = varm;
  60. }
  61. if ((hslh >= 120.) && (hslh < 180.)) {
  62. colr = varm;
  63. colg = varc + varm;
  64. colb = varx + varm;
  65. }
  66. if ((hslh >= 180.) && (hslh < 240.)) {
  67. colr = varm;
  68. colg = varx + varm;
  69. colb = varc + varm;
  70. }
  71. if ((hslh >= 240.) && (hslh < 300.)) {
  72. colr = varx + varm;
  73. colg = varm;
  74. colb = varc + varm;
  75. }
  76. if ((hslh >= 300.) && (hslh < 360.)) {
  77. colr = varc + varm;
  78. colg = varm;
  79. colb = varx + varm;
  80. }
  81. }
  82.  
  83. //change rgb values
  84. tmp_col.r = colr;
  85. tmp_col.g = colg;
  86. tmp_col.b = colb;
  87.  
  88. gl_FragColor = tmp_col * v_vColour;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement