Guest User

past bloom shader

a guest
Sep 21st, 2025
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Godot GLSL 4.80 KB | Source Code | 0 0
  1. shader_type canvas_item;
  2.  
  3. uniform float hueadd;
  4. uniform float valuemult;
  5. uniform float blur;
  6. uniform vec2 drift;
  7. uniform vec2 world_pos;
  8.  
  9. uniform vec2 vignete = vec2(0.25);
  10. uniform sampler2D vignete_sampler;
  11.  
  12. vec3 rgb2hsv(vec3 c) {
  13.     vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
  14.     vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
  15.     vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
  16.  
  17.     float d = q.x - min(q.w, q.y);
  18.     float e = 1.0e-10;
  19.     return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
  20. }
  21.  
  22. vec3 hsv2rgb(vec3 c) {
  23.     vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
  24.     vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
  25.     return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
  26. }
  27.  
  28. uniform float outline_lod = 2.0;
  29. uniform float outline_distance = 2.0;
  30.  
  31.  
  32. vec4 permute(vec4 x){return mod(((x*34.0)+1.0)*x, 289.0);}
  33. vec4 taylorInvSqrt(vec4 r) { return 1.79284291400159 - 0.85373472095314 * r; }
  34.  
  35. float vignete_mult(vec2 uv){
  36.     float dist_x = min(min(uv.x, 1.0 - uv.x) / vignete.x, 1.0);
  37.     float dist_y = min(min(uv.y, 1.0 - uv.y) / vignete.y, 1.0);
  38.  
  39.     return texture(vignete_sampler, vec2(min(dist_x, dist_y))).r;
  40. }
  41.  
  42.  
  43. float snoise(vec3 v){
  44.     vec2 C = vec2(1.0/6.0, 1.0/3.0) ;
  45.     vec3 cccx = vec3(C.x);
  46.     vec3 cccy = vec3(C.y);
  47.     vec4 D = vec4(0.0, 0.5, 1.0, 2.0);
  48.  
  49. // First corner
  50.   vec3 i  = floor(v + dot(v, cccy) );
  51.   vec3 x0 =   v - i + dot(i, cccx) ;
  52.  
  53. // Other corners
  54.   vec3 g = step(x0.yzx, x0.xyz);
  55.   vec3 l = 1.0 - g;
  56.   vec3 i1 = min( g.xyz, l.zxy );
  57.   vec3 i2 = max( g.xyz, l.zxy );
  58.  
  59.   //  x0 = x0 - 0. + 0.0 * C
  60.   vec3 x1 = x0 - i1 + 1.0 * cccx;
  61.   vec3 x2 = x0 - i2 + 2.0 * cccx;
  62.   vec3 x3 = x0 - 1.0 + 3.0 * cccx;
  63.  
  64. // Permutations
  65.   i = mod(i, 289.0 );
  66.   vec4 p = permute( permute( permute(
  67.              i.z + vec4(0.0, i1.z, i2.z, 1.0 ))
  68.            + i.y + vec4(0.0, i1.y, i2.y, 1.0 ))
  69.            + i.x + vec4(0.0, i1.x, i2.x, 1.0 ));
  70.  
  71. // Gradients
  72. // ( N*N points uniformly over a square, mapped onto an octahedron.)
  73.   float n_ = 1.0/7.0; // N=7
  74.   vec3  ns = n_ * D.wyz - D.xzx;
  75.  
  76.   vec4 j = p - 49.0 * floor(p * ns.z *ns.z);  //  mod(p,N*N)
  77.  
  78.   vec4 x_ = floor(j * ns.z);
  79.   vec4 y_ = floor(j - 7.0 * x_ );    // mod(j,N)
  80.  
  81.   vec4 x = x_ *ns.x + vec4(ns.y);
  82.   vec4 y = y_ *ns.x + vec4(ns.y);
  83.   vec4 h = 1.0 - abs(x) - abs(y);
  84.  
  85.   vec4 b0 = vec4( x.xy, y.xy );
  86.   vec4 b1 = vec4( x.zw, y.zw );
  87.  
  88.   vec4 s0 = floor(b0)*2.0 + 1.0;
  89.   vec4 s1 = floor(b1)*2.0 + 1.0;
  90.   vec4 sh = -step(h, vec4(0.0));
  91.  
  92.   vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ;
  93.   vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ;
  94.  
  95.   vec3 p0 = vec3(a0.xy,h.x);
  96.   vec3 p1 = vec3(a0.zw,h.y);
  97.   vec3 p2 = vec3(a1.xy,h.z);
  98.   vec3 p3 = vec3(a1.zw,h.w);
  99.  
  100. //Normalise gradients
  101.   vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));
  102.   p0 *= norm.x;
  103.   p1 *= norm.y;
  104.   p2 *= norm.z;
  105.   p3 *= norm.w;
  106.  
  107. // Mix final noise value
  108.   vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), vec4(0.0));
  109.   m = m * m;
  110.   return 42.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1),
  111.                                 dot(p2,x2), dot(p3,x3) ) );
  112. }
  113.  
  114. uniform float noisescale = 1.0;
  115. uniform float noisespeed = 1.0;
  116. uniform float noiseamp = 1.0;
  117.  
  118. uniform float period = 4.0;
  119. const float PI = 3.14159;
  120.  
  121. void fragment(){
  122.     vec2 worlduv = world_pos + UV;
  123.     vec2 inuv = UV + vec2(1.0, 0.0) * noiseamp * snoise( vec3((worlduv.x + sin(noisespeed * TIME * PI * 2.0 / period)) * noisescale, (worlduv.y * (SCREEN_PIXEL_SIZE.x / SCREEN_PIXEL_SIZE.y) + cos(noisespeed * TIME * PI * 2.0 / period)) * noisescale, sin(noisespeed * TIME * PI * 1.0 / period) * noisescale));
  124.     inuv += vec2(0.0, 1.0) * noiseamp * snoise( vec3((worlduv.x + sin(- noisespeed * TIME * PI * 2.0 / period)) * noisescale + 1000.0, (worlduv.y + cos(-noisespeed * TIME * PI * 2.0 / period)) * noisescale, sin(-noisespeed * TIME * PI * 1.0 / period) * noisescale));
  125.     vec3 preprocess = texture(TEXTURE, UV).rgb;
  126.     vec3 right = texture(TEXTURE, UV + TEXTURE_PIXEL_SIZE * vec2(outline_distance,0)).rgb;
  127.     vec3 top = texture(TEXTURE, UV + TEXTURE_PIXEL_SIZE * vec2(0,outline_distance)).rgb;
  128.    
  129.     preprocess.r = min(abs(preprocess.r - right.r) + abs(preprocess.r - top.r), 1.0);
  130.     preprocess.g = min(abs(preprocess.g - right.g) + abs(preprocess.g - top.g), 1.0);
  131.     preprocess.b = min(abs(preprocess.b - right.b) + abs(preprocess.b - top.b), 1.0);
  132.    
  133.     vec3 hueshift = rgb2hsv(textureLod(SCREEN_TEXTURE, inuv + drift, blur).rgb);
  134.     float one = 1.0;
  135.     hueshift.x = modf(hueshift.x + hueadd, one);
  136.     hueshift.z *= valuemult;
  137. //  vec4 original = textureLod(TEXTURE, UV, 2.0) + (textureLod(TEXTURE, UV, 2.0) - textureLod(TEXTURE, UV, 0.0)) * 10.0;
  138. //  vec4 original = textureLod(TEXTURE, UV, 2.0);
  139.     COLOR.rgb = max(hsv2rgb(hueshift), preprocess*valuemult) * vignete_mult(UV);
  140. //  COLOR = original;
  141. }
Advertisement
Add Comment
Please, Sign In to add comment