ShineHighlight.gdshader 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // Author: ACB_Gamez
  2. // Source: https://godotshaders.com/author/acb_gamez/
  3. // License: CC-0
  4. shader_type canvas_item;
  5. uniform vec4 shine_color : source_color = vec4(1.0);
  6. uniform float shine_size : hint_range(0.01, 1.0, 0.01) = 0.1;
  7. uniform float shine_angle : hint_range(0.0, 89.9, 0.1) = 45.0;
  8. uniform float progress : hint_range(0.0, 1.0, 0.001) = -1.0;
  9. uniform vec4 modulate : source_color = vec4(1.0);
  10. float scale(float value, float inMin, float inMax, float outMin, float outMax)
  11. {
  12. return (value - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
  13. }
  14. void fragment() {
  15. vec4 tex_color = texture(TEXTURE, UV);
  16. vec4 final_color;
  17. if (progress < 0.0)
  18. {
  19. final_color = tex_color;
  20. }
  21. else
  22. {
  23. float slope = tan(radians(shine_angle));
  24. float shine_size_scaled = shine_size * (1.0 + slope);
  25. float scaled_progress = scale(progress, 0.0, 1.0, -1.0 - shine_size_scaled, 1.0 + shine_size_scaled);
  26. float shine_line = slope * UV.x - UV.y;
  27. float shine = step(shine_line, scaled_progress + shine_size_scaled) - step(shine_line, scaled_progress);
  28. final_color = vec4(mix(tex_color.rgb, shine_color.rgb, shine * shine_color.a), tex_color.a);
  29. }
  30. COLOR = final_color * modulate;
  31. }