Advertisement
Guest User

Blur Shader

a guest
May 17th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. shader_type canvas_item;
  2. void fragment()
  3. {
  4.     float Pi = 6.28318530718; // Pi*2
  5.  
  6.     // GAUSSIAN BLUR SETTINGS {{{
  7.     float Directions = 16.0; // BLUR DIRECTIONS (Default 16.0 - More is better but slower)
  8.     float Quality = 4.0; // BLUR QUALITY (Default 4.0 - More is better but slower)
  9.     float Size = 20.0; // BLUR SIZE (Radius)
  10.     // GAUSSIAN BLUR SETTINGS }}}
  11.  
  12.     vec2 Radius = Size/(1.0 / SCREEN_PIXEL_SIZE).xy;
  13.  
  14.     // Normalized pixel coordinates (from 0 to 1)
  15.     vec2 uv = FRAGCOORD.xy/(1.0 / SCREEN_PIXEL_SIZE).xy;
  16.     // Pixel colour
  17.     vec4 Color = texture(SCREEN_TEXTURE, uv);
  18.  
  19.     // Blur calculations
  20.     for( float d=0.0; d<Pi; d+=Pi/Directions)
  21.     {
  22.         for(float i=1.0/Quality; i<=1.0; i+=1.0/Quality)
  23.         {
  24.             Color += texture(SCREEN_TEXTURE, uv+vec2(cos(d),sin(d))*Radius*i);     
  25.         }
  26.     }
  27.  
  28.     // Output to screen
  29.     Color /= Quality * Directions - 15.0;
  30.     Color.r/=1.5;
  31.     Color.g/=1.5;
  32.     Color.b/=1.5;
  33.     COLOR =  Color;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement