Guest User

Shaderblocks Generated Output: Aura

a guest
Oct 14th, 2022
512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. shader_type canvas_item;
  2.  
  3. uniform sampler2D tex_gbot;
  4.  
  5. // Converts vec4 to float
  6. float rgba_to_float(vec4 value) {
  7.     return (value.r + value.g + value.b) / 3.0 * value.a;
  8. }
  9.  
  10. // Hash with vec2 input and vec2 output
  11. vec2 hash22(vec2 seed){
  12.     uvec2 k = uvec2(uint(0x456789ab), uint(0x6789ab45));
  13.     uvec2 n = floatBitsToUint(seed);
  14.     n = n ^ n.yx << uint(9);
  15.     n = n ^ n.yx >> uint(1);
  16.     n = n * k;
  17.     n = n ^ n.yx << uint(1);
  18.     n = n * k;
  19.     return fract(vec2(n) / float(0xffffffff));
  20. }
  21.  
  22. float perlin(vec2 pos) {
  23.     vec2 pi = floor(pos); // Not the 3.14 pi, but "pos integer"
  24.     vec2 pf = fract(pos); // Pos fract
  25.    
  26.     vec2 w = smoothstep(0.0, 1.0, pf); // Interpolated pf
  27.    
  28.     return mix (mix(dot(hash22(pi + vec2(0.0, 0.0)) * 2.0 - 1.0, pf - vec2(0.0, 0.0)), // Top Left
  29.                     dot(hash22(pi + vec2(1.0, 0.0)) * 2.0 - 1.0, pf - vec2(1.0, 0.0)), w.x), // Top Right
  30.                 mix(dot(hash22(pi + vec2(0.0, 1.0)) * 2.0 - 1.0, pf - vec2(0.0, 1.0)), // Bottom Left
  31.                     dot(hash22(pi + vec2(1.0, 1.0)) * 2.0 - 1.0, pf - vec2(1.0, 1.0)), w.x), // Bottom Right
  32.                 w.y); // Interpolate top and bottom, resulting 2D noise
  33. }
  34.  
  35. float fbm_perlin(vec2 pos, int octaves, float persistence, float lacunarity) {
  36.     float noise = 0.0;
  37.     float sum = 1.0;
  38.     noise += sum * perlin(pos);
  39.     pos = lacunarity * pos;
  40.     for (int i = 0; i < octaves - 1; i++) {
  41.         sum *= persistence;
  42.         noise += sum * perlin(pos);
  43.         pos = lacunarity * pos;
  44.     }
  45.     return noise * 0.5 + 0.5;
  46. }
  47.  
  48. float saturate(float value) {
  49.     return clamp(value, 0.0, 1.0);
  50. }
  51.  
  52. float rectangle(vec2 uv, vec2 size, float softness) {
  53.     uv -= 0.5;  // Move UV to center
  54.     uv *= 2.0;  // Multiply by 2 so it ranges from -1 to 1, not -0.5 to 0.5
  55.     uv /= size;  // Divide by size
  56.    
  57.     vec2 grad = abs(uv);  // Create mirrored gradients, .x for horizontal and .y for vertical
  58.     grad = 1.0 - grad;  // Invert gradients
  59.    
  60.     float rect = min(grad.x, grad.y);  // Min operation for 2 gradients, resulting rectangular gradient
  61.     rect /= softness;  // Division by number lower than 1 multiplies in reverse, making it looks hard
  62.     rect = clamp(rect, 0.0, 1.0);  // Clamp values higher than 1 because it was multiplied
  63.     return rect;
  64. }
  65.  
  66. float alpha_border(vec2 uv, sampler2D tex, float lod) {
  67.     int lodf = int(floor(lod));  // Lod floor
  68.     int lodc = int(ceil(lod));  // Lod ceil
  69.     vec2 lod_resolution = mix(vec2(textureSize(tex, lodf)),
  70.                             vec2(textureSize(tex, lodc)),
  71.                             fract(lod)
  72.                         );
  73.     vec2 pixel_size = 1.0 / lod_resolution;  // Size of a pixel in this lod resolution
  74.     pixel_size *= 2.0;  // Multiply by 2 because we have left & right and top & down
  75.     return rectangle(uv, 1.0 + pixel_size, pixel_size.x);
  76. }
  77.  
  78. vec3 saturate_rgb(vec3 value) {
  79.     return clamp(value, 0.0, 1.0);
  80. }
  81.  
  82. void fragment() {
  83.     vec4 main_image = vec4(0.0);
  84.  
  85.     vec2 Aura_UV = UV;  // Create UV with transformations
  86.     float Scroll = TIME * -0.51;  // Create a variable from the value of TIME
  87.  
  88.     // Create UV with transformations
  89.     vec2 Distortion_UV = UV;
  90.     Distortion_UV -= vec2(0.0, Scroll);
  91.  
  92.     float Distortion = fbm_perlin(Distortion_UV * 10.0, 4, 0.5, 2.0);  // Create 2D perlin noise variable
  93.     Aura_UV = Aura_UV + (vec2(Distortion, Distortion) - vec2(0.5)) * vec2(0.2, 0.2);  // Distort Aura UV
  94.  
  95.     // Create a texture variable
  96.     vec4 Gbot_Blur = textureLod(tex_gbot, Aura_UV, 4.7);
  97.     Gbot_Blur.a *= alpha_border(Aura_UV, tex_gbot, 4.7);
  98.  
  99.     // Get alpha channel of Gbot Blur
  100.     vec4 Gbot_Bluralpha = vec4(1.0, 1.0, 1.0, Gbot_Blur.a);
  101.  
  102.     // Colorize Gbot Blur.alpha
  103.     float new_colorized_value_offsets[3] = {0.020672, 0.077519, 0.462532};
  104.     vec4 new_colorized_value_colors[3] = {  vec4(0.0, 0.976471, 1.0, 0.0),
  105.                                             vec4(0.0, 0.976471, 1.0, 1.0),
  106.                                             vec4(0.0, 0.486275, 0.631373, 0.654902)
  107.                                             };
  108.     vec4 new_colorized_value_grad = new_colorized_value_colors[0];
  109.     for (int i = 0; i < 2; i++) {
  110.         float base = rgba_to_float(Gbot_Bluralpha);  // Base gradient
  111.         base -= new_colorized_value_offsets[i];  // Offset base gradient to current point
  112.         base /= new_colorized_value_offsets[i + 1] - new_colorized_value_offsets[i];  // Resize gradient to next point
  113.         base  = saturate(base);  // Make sure this value is only between 0.0 to 1.0
  114.         new_colorized_value_grad = mix(new_colorized_value_grad, new_colorized_value_colors[i + 1], base);
  115.     }
  116.     main_image.rgb = new_colorized_value_grad.rgb;
  117.     main_image.a = new_colorized_value_grad.a;
  118.  
  119.     // Draw a texture on the main image
  120.     vec4 gbot2 = textureLod(tex_gbot, UV, 0.0);
  121.     gbot2.a *= alpha_border(UV, tex_gbot, 0.0);
  122.     main_image.rgb = mix(main_image.rgb, gbot2.rgb, gbot2.a);
  123.     main_image.a = mix(main_image.a, 1.0, gbot2.a);
  124.  
  125.     // Create UV with transformations
  126.     vec2 Noise_UV = UV;
  127.     Noise_UV -= vec2(0.0, Scroll);
  128.     Noise_UV -= vec2(0.5);
  129.     Noise_UV /= vec2(0.32, 1.38);
  130.     Noise_UV += vec2(0.5);
  131.  
  132.     // Create 2D perlin noise variable
  133.     float Noise = fbm_perlin(Noise_UV * 10.0, 4, 0.5, 2.0);
  134.  
  135.     // Colorize Noise
  136.     float Colored_Noise_offsets[2] = {0.589147, 1.0};
  137.     vec4 Colored_Noise_colors[2] = {vec4(0.0, 1.0, 0.976471, 0.176471),
  138.                                     vec4(0.0, 1.0, 0.976471, 0.635294)
  139.                                     };
  140.     vec4 Colored_Noise_grad = Colored_Noise_colors[0];
  141.     for (int i = 0; i < 1; i++) {
  142.         float base = Noise;  // Base gradient
  143.         base -= Colored_Noise_offsets[i];  // Offset base gradient to current point
  144.         base /= Colored_Noise_offsets[i + 1] - Colored_Noise_offsets[i];  // Resize gradient to next point
  145.         base  = saturate(base);  // Make sure this value is only between 0.0 to 1.0
  146.         Colored_Noise_grad = mix(Colored_Noise_grad, Colored_Noise_colors[i + 1], base);
  147.     }
  148.     vec4 Colored_Noise = Colored_Noise_grad;
  149.  
  150.     // Blend Main Image with Colored Noise
  151.     main_image.rgb = mix(main_image.rgb, Colored_Noise.rgb, Colored_Noise.a);
  152.     main_image.a = main_image.a;
  153.     COLOR = main_image;
  154. }
Advertisement
Add Comment
Please, Sign In to add comment