Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- shader_type canvas_item;
- uniform sampler2D tex_gbot;
- // Converts vec4 to float
- float rgba_to_float(vec4 value) {
- return (value.r + value.g + value.b) / 3.0 * value.a;
- }
- // Hash with vec2 input and vec2 output
- vec2 hash22(vec2 seed){
- uvec2 k = uvec2(uint(0x456789ab), uint(0x6789ab45));
- uvec2 n = floatBitsToUint(seed);
- n = n ^ n.yx << uint(9);
- n = n ^ n.yx >> uint(1);
- n = n * k;
- n = n ^ n.yx << uint(1);
- n = n * k;
- return fract(vec2(n) / float(0xffffffff));
- }
- float perlin(vec2 pos) {
- vec2 pi = floor(pos); // Not the 3.14 pi, but "pos integer"
- vec2 pf = fract(pos); // Pos fract
- vec2 w = smoothstep(0.0, 1.0, pf); // Interpolated pf
- return mix (mix(dot(hash22(pi + vec2(0.0, 0.0)) * 2.0 - 1.0, pf - vec2(0.0, 0.0)), // Top Left
- dot(hash22(pi + vec2(1.0, 0.0)) * 2.0 - 1.0, pf - vec2(1.0, 0.0)), w.x), // Top Right
- mix(dot(hash22(pi + vec2(0.0, 1.0)) * 2.0 - 1.0, pf - vec2(0.0, 1.0)), // Bottom Left
- dot(hash22(pi + vec2(1.0, 1.0)) * 2.0 - 1.0, pf - vec2(1.0, 1.0)), w.x), // Bottom Right
- w.y); // Interpolate top and bottom, resulting 2D noise
- }
- float fbm_perlin(vec2 pos, int octaves, float persistence, float lacunarity) {
- float noise = 0.0;
- float sum = 1.0;
- noise += sum * perlin(pos);
- pos = lacunarity * pos;
- for (int i = 0; i < octaves - 1; i++) {
- sum *= persistence;
- noise += sum * perlin(pos);
- pos = lacunarity * pos;
- }
- return noise * 0.5 + 0.5;
- }
- float saturate(float value) {
- return clamp(value, 0.0, 1.0);
- }
- float rectangle(vec2 uv, vec2 size, float softness) {
- uv -= 0.5; // Move UV to center
- uv *= 2.0; // Multiply by 2 so it ranges from -1 to 1, not -0.5 to 0.5
- uv /= size; // Divide by size
- vec2 grad = abs(uv); // Create mirrored gradients, .x for horizontal and .y for vertical
- grad = 1.0 - grad; // Invert gradients
- float rect = min(grad.x, grad.y); // Min operation for 2 gradients, resulting rectangular gradient
- rect /= softness; // Division by number lower than 1 multiplies in reverse, making it looks hard
- rect = clamp(rect, 0.0, 1.0); // Clamp values higher than 1 because it was multiplied
- return rect;
- }
- float alpha_border(vec2 uv, sampler2D tex, float lod) {
- int lodf = int(floor(lod)); // Lod floor
- int lodc = int(ceil(lod)); // Lod ceil
- vec2 lod_resolution = mix(vec2(textureSize(tex, lodf)),
- vec2(textureSize(tex, lodc)),
- fract(lod)
- );
- vec2 pixel_size = 1.0 / lod_resolution; // Size of a pixel in this lod resolution
- pixel_size *= 2.0; // Multiply by 2 because we have left & right and top & down
- return rectangle(uv, 1.0 + pixel_size, pixel_size.x);
- }
- vec3 saturate_rgb(vec3 value) {
- return clamp(value, 0.0, 1.0);
- }
- void fragment() {
- vec4 main_image = vec4(0.0);
- vec2 Aura_UV = UV; // Create UV with transformations
- float Scroll = TIME * -0.51; // Create a variable from the value of TIME
- // Create UV with transformations
- vec2 Distortion_UV = UV;
- Distortion_UV -= vec2(0.0, Scroll);
- float Distortion = fbm_perlin(Distortion_UV * 10.0, 4, 0.5, 2.0); // Create 2D perlin noise variable
- Aura_UV = Aura_UV + (vec2(Distortion, Distortion) - vec2(0.5)) * vec2(0.2, 0.2); // Distort Aura UV
- // Create a texture variable
- vec4 Gbot_Blur = textureLod(tex_gbot, Aura_UV, 4.7);
- Gbot_Blur.a *= alpha_border(Aura_UV, tex_gbot, 4.7);
- // Get alpha channel of Gbot Blur
- vec4 Gbot_Bluralpha = vec4(1.0, 1.0, 1.0, Gbot_Blur.a);
- // Colorize Gbot Blur.alpha
- float new_colorized_value_offsets[3] = {0.020672, 0.077519, 0.462532};
- vec4 new_colorized_value_colors[3] = { vec4(0.0, 0.976471, 1.0, 0.0),
- vec4(0.0, 0.976471, 1.0, 1.0),
- vec4(0.0, 0.486275, 0.631373, 0.654902)
- };
- vec4 new_colorized_value_grad = new_colorized_value_colors[0];
- for (int i = 0; i < 2; i++) {
- float base = rgba_to_float(Gbot_Bluralpha); // Base gradient
- base -= new_colorized_value_offsets[i]; // Offset base gradient to current point
- base /= new_colorized_value_offsets[i + 1] - new_colorized_value_offsets[i]; // Resize gradient to next point
- base = saturate(base); // Make sure this value is only between 0.0 to 1.0
- new_colorized_value_grad = mix(new_colorized_value_grad, new_colorized_value_colors[i + 1], base);
- }
- main_image.rgb = new_colorized_value_grad.rgb;
- main_image.a = new_colorized_value_grad.a;
- // Draw a texture on the main image
- vec4 gbot2 = textureLod(tex_gbot, UV, 0.0);
- gbot2.a *= alpha_border(UV, tex_gbot, 0.0);
- main_image.rgb = mix(main_image.rgb, gbot2.rgb, gbot2.a);
- main_image.a = mix(main_image.a, 1.0, gbot2.a);
- // Create UV with transformations
- vec2 Noise_UV = UV;
- Noise_UV -= vec2(0.0, Scroll);
- Noise_UV -= vec2(0.5);
- Noise_UV /= vec2(0.32, 1.38);
- Noise_UV += vec2(0.5);
- // Create 2D perlin noise variable
- float Noise = fbm_perlin(Noise_UV * 10.0, 4, 0.5, 2.0);
- // Colorize Noise
- float Colored_Noise_offsets[2] = {0.589147, 1.0};
- vec4 Colored_Noise_colors[2] = {vec4(0.0, 1.0, 0.976471, 0.176471),
- vec4(0.0, 1.0, 0.976471, 0.635294)
- };
- vec4 Colored_Noise_grad = Colored_Noise_colors[0];
- for (int i = 0; i < 1; i++) {
- float base = Noise; // Base gradient
- base -= Colored_Noise_offsets[i]; // Offset base gradient to current point
- base /= Colored_Noise_offsets[i + 1] - Colored_Noise_offsets[i]; // Resize gradient to next point
- base = saturate(base); // Make sure this value is only between 0.0 to 1.0
- Colored_Noise_grad = mix(Colored_Noise_grad, Colored_Noise_colors[i + 1], base);
- }
- vec4 Colored_Noise = Colored_Noise_grad;
- // Blend Main Image with Colored Noise
- main_image.rgb = mix(main_image.rgb, Colored_Noise.rgb, Colored_Noise.a);
- main_image.a = main_image.a;
- COLOR = main_image;
- }
Advertisement
Add Comment
Please, Sign In to add comment