demotool/blur-pass.glsl

32 lines
1.3 KiB
GLSL

#version 450 core
layout( location = 0 ) uniform sampler2D u_InputTexture;
layout( location = 1 ) uniform vec2 u_OutputSize;
layout( location = 2 ) uniform vec2 u_InputSize;
layout( location = 3 ) uniform int u_SourceLOD;
layout( location = 4 ) uniform vec2 u_Direction;
layout( location = 5 ) uniform vec4 u_Weights;
layout( location = 0 ) out vec3 color;
void main( void )
{
vec2 tmp = gl_FragCoord.xy / u_OutputSize;
const float disp = 4;
vec2 displace1 = vec2( disp * 1 ) * u_Direction / u_OutputSize;
vec2 displace2 = vec2( disp * 2 ) * u_Direction / u_OutputSize;
vec2 displace3 = vec2( disp * 3 ) * u_Direction / u_OutputSize;
float wt = u_Weights.x + u_Weights.y * 2 + u_Weights.z * 2 + u_Weights.w * 2;
color = u_Weights.x * textureLod( u_InputTexture , tmp , u_SourceLOD ).xyz
+ u_Weights.y * (
textureLod( u_InputTexture , tmp + displace1 , u_SourceLOD ).xyz
+ textureLod( u_InputTexture , tmp - displace1 , u_SourceLOD ).xyz )
+ u_Weights.z * (
textureLod( u_InputTexture , tmp + displace2 , u_SourceLOD ).xyz
+ textureLod( u_InputTexture , tmp - displace2 , u_SourceLOD ).xyz )
+ u_Weights.w * (
textureLod( u_InputTexture , tmp + displace3 , u_SourceLOD ).xyz
+ textureLod( u_InputTexture , tmp - displace3 , u_SourceLOD ).xyz )
;
color /= wt;
}