slider.fsh 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #version 110
  2. uniform sampler2D tex;
  3. uniform int style;
  4. uniform float bodyColorSaturation;
  5. uniform float bodyAlphaMultiplier;
  6. uniform float borderSizeMultiplier;
  7. uniform float borderFeather;
  8. uniform vec3 colBorder;
  9. uniform vec3 colBody;
  10. varying vec2 tex_coord;
  11. const float defaultTransitionSize = 0.011;
  12. const float defaultBorderSize = 0.11;
  13. const float outerShadowSize = 0.08;
  14. vec4 getInnerBodyColor(in vec4 bodyColor)
  15. {
  16. float brightnessMultiplier = 0.25;
  17. bodyColor.r = min(1.0, bodyColor.r * (1.0 + 0.5 * brightnessMultiplier) + brightnessMultiplier);
  18. bodyColor.g = min(1.0, bodyColor.g * (1.0 + 0.5 * brightnessMultiplier) + brightnessMultiplier);
  19. bodyColor.b = min(1.0, bodyColor.b * (1.0 + 0.5 * brightnessMultiplier) + brightnessMultiplier);
  20. return vec4(bodyColor);
  21. }
  22. vec4 getOuterBodyColor(in vec4 bodyColor)
  23. {
  24. float darknessMultiplier = 0.1;
  25. bodyColor.r = min(1.0, bodyColor.r / (1.0 + darknessMultiplier));
  26. bodyColor.g = min(1.0, bodyColor.g / (1.0 + darknessMultiplier));
  27. bodyColor.b = min(1.0, bodyColor.b / (1.0 + darknessMultiplier));
  28. return vec4(bodyColor);
  29. }
  30. void main()
  31. {
  32. float borderSize = (defaultBorderSize + borderFeather) * borderSizeMultiplier;
  33. float transitionSize = defaultTransitionSize + borderFeather;
  34. // output var
  35. vec4 out_color = vec4(0.0);
  36. // dynamic color calculations
  37. vec4 borderColor = vec4(colBorder.x, colBorder.y, colBorder.z, 1.0);
  38. vec4 bodyColor = vec4(colBody.x, colBody.y, colBody.z, 0.7*bodyAlphaMultiplier);
  39. vec4 outerShadowColor = vec4(0, 0, 0, 0.25);
  40. vec4 innerBodyColor = getInnerBodyColor(bodyColor);
  41. vec4 outerBodyColor = getOuterBodyColor(bodyColor);
  42. innerBodyColor.rgb *= bodyColorSaturation;
  43. outerBodyColor.rgb *= bodyColorSaturation;
  44. // osu!next style color modifications
  45. if (style == 1)
  46. {
  47. outerBodyColor.rgb = bodyColor.rgb * bodyColorSaturation;
  48. outerBodyColor.a = 1.0*bodyAlphaMultiplier;
  49. innerBodyColor.rgb = bodyColor.rgb * 0.5 * bodyColorSaturation;
  50. innerBodyColor.a = 0.0;
  51. }
  52. // a bit of a hack, but better than rough edges
  53. if (borderSizeMultiplier < 0.01)
  54. borderColor = outerShadowColor;
  55. // conditional variant
  56. if (tex_coord.x < outerShadowSize - transitionSize) // just shadow
  57. {
  58. float delta = tex_coord.x / (outerShadowSize - transitionSize);
  59. out_color = mix(vec4(0), outerShadowColor, delta);
  60. }
  61. if (tex_coord.x > outerShadowSize - transitionSize && tex_coord.x < outerShadowSize + transitionSize) // shadow + border
  62. {
  63. float delta = (tex_coord.x - outerShadowSize + transitionSize) / (2.0*transitionSize);
  64. out_color = mix(outerShadowColor, borderColor, delta);
  65. }
  66. if (tex_coord.x > outerShadowSize + transitionSize && tex_coord.x < outerShadowSize + borderSize - transitionSize) // just border
  67. {
  68. out_color = borderColor;
  69. }
  70. if (tex_coord.x > outerShadowSize + borderSize - transitionSize && tex_coord.x < outerShadowSize + borderSize + transitionSize) // border + outer body
  71. {
  72. float delta = (tex_coord.x - outerShadowSize - borderSize + transitionSize) / (2.0*transitionSize);
  73. out_color = mix(borderColor, outerBodyColor, delta);
  74. }
  75. if (tex_coord.x > outerShadowSize + borderSize + transitionSize) // outer body + inner body
  76. {
  77. float size = outerShadowSize + borderSize + transitionSize;
  78. float delta = ((tex_coord.x - size) / (1.0-size));
  79. out_color = mix(outerBodyColor, innerBodyColor, delta);
  80. }
  81. // linear variant
  82. /*
  83. // just shadow
  84. float delta = tex_coord.x/(outerShadowSize-transitionSize);
  85. out_color += mix(vec4(0.0), outerShadowColor, delta) * clamp(ceil(-delta+1.0), 0.0, 1.0);
  86. // shadow + border
  87. delta = (tex_coord.x - outerShadowSize + transitionSize) / (2.0*transitionSize);
  88. out_color += mix(outerShadowColor, borderColor, delta) * clamp(ceil(tex_coord.x - (outerShadowSize - transitionSize)), 0.0, 1.0) * clamp(ceil(-abs(delta)+1.0), 0.0, 1.0);
  89. // just border
  90. out_color += borderColor * clamp(ceil(tex_coord.x - (outerShadowSize + transitionSize)), 0.0, 1.0) * clamp(ceil(-(tex_coord.x - (outerShadowSize + borderSize - transitionSize))), 0.0, 1.0);
  91. // border + outer body
  92. delta = (tex_coord.x - outerShadowSize - borderSize + transitionSize) / (2.0*transitionSize);
  93. out_color += mix(borderColor, outerBodyColor, delta) * clamp(ceil(tex_coord.x - (outerShadowSize + borderSize - transitionSize)), 0.0, 1.0) * clamp(ceil(-abs(delta)+1.0), 0.0, 1.0);
  94. // outer body + inner body
  95. delta = outerShadowSize + borderSize + transitionSize;
  96. delta = (tex_coord.x - delta) / (1.0-delta); // [VARIABLE REUSING INTENSIFIES]
  97. out_color += mix(outerBodyColor, innerBodyColor, delta) * clamp(ceil(tex_coord.x - (outerShadowSize + borderSize + transitionSize)), 0.0, 1.0);
  98. */
  99. gl_FragColor = out_color;
  100. }