rainbow_gradient_shader.tres 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. [gd_resource type="ShaderMaterial" load_steps=2 format=2]
  2. [sub_resource type="Shader" id=63]
  3. code = "// HSV to RBG from https://www.rapidtables.com/convert/color/hsv-to-rgb.html
  4. // Rotation matrix from https://en.wikipedia.org/wiki/Rotation_matrix
  5. shader_type canvas_item;
  6. const float PI = 3.1415926535;
  7. uniform float strength: hint_range(0., 1.) = 0.5;
  8. uniform float speed: hint_range(0., 10.) = 0.5;
  9. uniform float angle: hint_range(0., 360.) = 0.;
  10. void fragment() {
  11. float hue = UV.x * cos(radians(angle)) - UV.y * sin(radians(angle));
  12. hue = fract(hue + fract(TIME * speed));
  13. float x = 1. - abs(mod(hue / (1./ 6.), 2.) - 1.);
  14. vec3 rainbow;
  15. if(hue < 1./6.){
  16. rainbow = vec3(1., x, 0.);
  17. } else if (hue < 1./3.) {
  18. rainbow = vec3(x, 1., 0);
  19. } else if (hue < 0.5) {
  20. rainbow = vec3(0, 1., x);
  21. } else if (hue < 2./3.) {
  22. rainbow = vec3(0., x, 1.);
  23. } else if (hue < 5./6.) {
  24. rainbow = vec3(x, 0., 1.);
  25. } else {
  26. rainbow = vec3(1., 0., x);
  27. }
  28. vec4 color = texture(TEXTURE, UV);
  29. COLOR = mix(color, vec4(rainbow, color.a), strength);
  30. }"
  31. [resource]
  32. shader = SubResource( 63 )
  33. shader_param/strength = 0.5
  34. shader_param/speed = 0.5
  35. shader_param/angle = 0.0