Distort Shining
I modified “Shining Sprite Effect” by making it more distorted, this shader is to be applied directly to a sprite. It will animate based on TIME and use luminance to determine which part of the sprite to highlight.
Shader code
shader_type canvas_item;
const float PI = 3.141516;
uniform float speed = 1.0;
uniform vec4 tint : hint_color = vec4(1.0, 1.0, 0.0, 1.0);
uniform float span : hint_range(0.1, 1.0) = 0.3;
float luminance(vec4 colour) {
return 1.0 - sqrt(0.299 * colour.r * colour.r + 0.587 * colour.g * colour.g + 0.114 * colour.b * colour.b);
}
void fragment() {
vec4 colour = texture(TEXTURE, UV);
float target = abs(sin(TIME * PI * speed) * (1.0 + span));
if (colour.a > 0.0) {
float lum = luminance(colour);
float diff = abs(lum - target);
float mx = clamp(1.0 - diff / span, 0.0, 1.0);
// Generate a random animation type
int animation_type = int(fract(sin(dot(UV, vec2(12.3456, 78.9876))) * 43758.5453) * 4.0);
if (animation_type == 0) {
// Animation Type 0: Original animation
colour = mix(colour, tint, mx);
} else if (animation_type == 1) {
// Animation Type 1: Vertical animation
float y_offset = sin(TIME * PI * speed) * 0.5 + 0.5;
vec2 uv_offset = vec2(0.0, y_offset);
colour = texture(TEXTURE, UV + uv_offset);
} else if (animation_type == 2) {
// Animation Type 2: Horizontal animation
float x_offset = sin(TIME * PI * speed) * 0.5 + 0.5;
vec2 uv_offset = vec2(x_offset, 0.0);
colour = texture(TEXTURE, UV + uv_offset);
} else if (animation_type == 3) {
// Animation Type 3: Color shift animation
float r = colour.r;
float g = colour.g;
float b = colour.b;
colour.r = g;
colour.g = b;
colour.b = r;
}
}
COLOR = colour;
}