Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// Vertex (vsh)
- // ATTRIBUTION: This shader uses elements from DukeSoft's "Simple bloom shader"
- // which can be found here (https://marketplace.yoyogames.com/assets/4729/simple-bloom-shader).
- //
- // Simple passthrough vertex shader
- //
- attribute vec3 in_Position; // (x,y,z)
- //attribute vec3 in_Normal; // (x,y,z) unused in this shader.
- attribute vec4 in_Colour; // (r,g,b,a)
- attribute vec2 in_TextureCoord; // (u,v)
- varying vec2 v_vTexcoord;
- varying vec4 v_vColour;
- void main()
- {
- vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0);
- gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;
- v_vColour = in_Colour;
- v_vTexcoord = in_TextureCoord;
- }
- /// Fragment (fsh)
- varying vec2 v_vTexcoord;
- varying vec4 v_vColour;
- uniform vec3 size;//width,height,radius
- uniform float blurSize;
- uniform float intensity;
- const int Quality = 8;
- const int Directions = 16;
- const float Pi = 6.28318530718;//pi * 2
- void main()
- {
- vec4 sum = vec4(0);
- int j;
- int i;
- // take nine samples, with the distance blurSize between them
- sum += texture2D(gm_BaseTexture, vec2(v_vTexcoord.x - 4.0*blurSize, v_vTexcoord.y)) * 0.05;
- sum += texture2D(gm_BaseTexture, vec2(v_vTexcoord.x - 3.0*blurSize, v_vTexcoord.y)) * 0.09;
- sum += texture2D(gm_BaseTexture, vec2(v_vTexcoord.x - 2.0*blurSize, v_vTexcoord.y)) * 0.12;
- sum += texture2D(gm_BaseTexture, vec2(v_vTexcoord.x - blurSize, v_vTexcoord.y)) * 0.15;
- sum += texture2D(gm_BaseTexture, vec2(v_vTexcoord.x, v_vTexcoord.y)) * 0.16;
- sum += texture2D(gm_BaseTexture, vec2(v_vTexcoord.x + blurSize, v_vTexcoord.y)) * 0.15;
- sum += texture2D(gm_BaseTexture, vec2(v_vTexcoord.x + 2.0*blurSize, v_vTexcoord.y)) * 0.12;
- sum += texture2D(gm_BaseTexture, vec2(v_vTexcoord.x + 3.0*blurSize, v_vTexcoord.y)) * 0.09;
- sum += texture2D(gm_BaseTexture, vec2(v_vTexcoord.x + 4.0*blurSize, v_vTexcoord.y)) * 0.05;
- // take nine samples, with the distance blurSize between them
- sum += texture2D(gm_BaseTexture, vec2(v_vTexcoord.x, v_vTexcoord.y - 4.0*blurSize)) * 0.05;
- sum += texture2D(gm_BaseTexture, vec2(v_vTexcoord.x, v_vTexcoord.y - 3.0*blurSize)) * 0.09;
- sum += texture2D(gm_BaseTexture, vec2(v_vTexcoord.x, v_vTexcoord.y - 2.0*blurSize)) * 0.12;
- sum += texture2D(gm_BaseTexture, vec2(v_vTexcoord.x, v_vTexcoord.y - blurSize)) * 0.15;
- sum += texture2D(gm_BaseTexture, vec2(v_vTexcoord.x, v_vTexcoord.y)) * 0.16;
- sum += texture2D(gm_BaseTexture, vec2(v_vTexcoord.x, v_vTexcoord.y + blurSize)) * 0.15;
- sum += texture2D(gm_BaseTexture, vec2(v_vTexcoord.x, v_vTexcoord.y + 2.0*blurSize)) * 0.12;
- sum += texture2D(gm_BaseTexture, vec2(v_vTexcoord.x, v_vTexcoord.y + 3.0*blurSize)) * 0.09;
- sum += texture2D(gm_BaseTexture, vec2(v_vTexcoord.x, v_vTexcoord.y + 4.0*blurSize)) * 0.05;
- vec2 radius = size.z/size.xy;
- vec4 Color = texture2D( gm_BaseTexture, v_vTexcoord);
- for( float d=0.0;d<Pi;d+=Pi/float(Directions) )
- {
- for( float i=1.0/float(Quality);i<=1.0;i+=1.0/float(Quality) )
- {
- Color += texture2D( gm_BaseTexture, v_vTexcoord+vec2(cos(d),sin(d))*radius*i);
- }
- }
- Color /= float(Quality)*float(Directions)+1.0;
- gl_FragColor = (sum * intensity + Color) * v_vColour;
- }
Add Comment
Please, Sign In to add comment