Last active
March 22, 2022 22:05
-
-
Save alepez/5935099 to your computer and use it in GitHub Desktop.
Ogre3d compositor and glsl shaders for Gaussian blur. It use a combination of horizontal blue and vertical blur.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
compositor SceneCameraBlend | |
{ | |
technique | |
{ | |
texture scene target_width target_height PF_A8R8G8B8 | |
target scene | |
{ | |
input previous | |
} | |
target scene | |
{ | |
input none | |
pass render_quad | |
{ | |
material VBlurMat | |
input 0 scene | |
} | |
} | |
target_output | |
{ | |
input none | |
pass render_quad | |
{ | |
material HBlurMat | |
input 0 blurred | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// | |
/// Vertical e Horizontal blur, combinati assieme danno | |
/// un blur gaussiano. | |
/// | |
fragment_program VBlur_frag glsl | |
{ | |
source VBlur_frag.glsl | |
} | |
fragment_program HBlur_frag glsl | |
{ | |
source HBlur_frag.glsl | |
} | |
fragment_program Blur_frag glsl | |
{ | |
source Blur_frag.glsl | |
} | |
material VBlurMat | |
{ | |
technique | |
{ | |
pass | |
{ | |
lighting off | |
fragment_program_ref VBlur_frag | |
{ | |
param_named tex int 0 | |
param_named blurSize float 4.0 | |
} | |
texture_unit | |
{ | |
tex_coord_set 0 | |
tex_address_mode clamp | |
filtering linear linear linear | |
} | |
} | |
} | |
} | |
material HBlurMat | |
{ | |
technique | |
{ | |
pass | |
{ | |
lighting off | |
fragment_program_ref HBlur_frag | |
{ | |
param_named tex int 0 | |
param_named blurSize float 4.0 | |
} | |
texture_unit | |
{ | |
tex_coord_set 0 | |
tex_address_mode clamp | |
filtering linear linear linear | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#version 120 | |
/// | |
/// Blur gaussiano orizzontale | |
/// Da utilizzare in catena con quello verticale per un blur completo | |
/// | |
uniform sampler2D tex; | |
uniform float blurSize; | |
vec2 pos[11] = vec2[]( | |
vec2(-5.0, 0.0), | |
vec2(-4.0, 0.0), | |
vec2(-3.0, 0.0), | |
vec2(-2.0, 0.0), | |
vec2(-1.0, 0.0), | |
vec2( 0.0, 0.0), | |
vec2( 1.0, 0.0), | |
vec2( 2.0, 0.0), | |
vec2( 3.0, 0.0), | |
vec2( 4.0, 0.0), | |
vec2( 5.0, 0.0) | |
); | |
float samples[11] = float[]( | |
0.01222447, | |
0.02783468, | |
0.06559061, | |
0.12097757, | |
0.17466632, | |
0.19741265, | |
0.17466632, | |
0.12097757, | |
0.06559061, | |
0.02783468, | |
0.01222447 | |
); | |
void main() { | |
vec2 coord = vec2(gl_TexCoord[0]); | |
vec4 sum = vec4( 0 ); | |
float bs = blurSize / 1024.0; | |
for(int i = 0; i != 11; ++i) { | |
sum += texture2D(tex, coord + (pos[i] * bs)) * samples[i]; | |
} | |
gl_FragColor = sum; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#version 120 | |
/// | |
/// Blur gaussiano verticale | |
/// Da utilizzare in catena con quello orizzontale per un blur completo | |
/// | |
uniform sampler2D tex; | |
uniform float blurSize; | |
vec2 pos[11] = vec2[]( | |
vec2(0.0, -5.0), | |
vec2(0.0, -4.0), | |
vec2(0.0, -3.0), | |
vec2(0.0, -2.0), | |
vec2(0.0, -1.0), | |
vec2(0.0, 0.0), | |
vec2(0.0, 1.0), | |
vec2(0.0, 2.0), | |
vec2(0.0, 3.0), | |
vec2(0.0, 4.0), | |
vec2(0.0, 5.0) | |
); | |
float samples[11] = float[]( | |
0.01222447, | |
0.02783468, | |
0.06559061, | |
0.12097757, | |
0.17466632, | |
0.19741265, | |
0.17466632, | |
0.12097757, | |
0.06559061, | |
0.02783468, | |
0.01222447 | |
); | |
void main() { | |
vec2 coord = vec2(gl_TexCoord[0]); | |
vec4 sum = vec4( 0 ); | |
float bs = blurSize / 1024.0; | |
int i = 0; | |
for(; i != 11; ++i) { | |
sum += texture2D(tex, coord + (pos[i] * bs)) * samples[i]; | |
} | |
gl_FragColor = sum; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment