demotool/test/fx-dof/dof-lib.glsl
Emmanuel BENOîT 68d01ca42e Shaders - Relative paths
Shaders are no longer found under /shaders in the project; they can be
anywhere. In addition, paths for both (program) instructions in the
script and include directives in shader source code are relative to the
file which contains them.
2017-12-29 11:33:15 +01:00

43 lines
964 B
GLSL

//!type library
//!include /lib/utils.glsl
float DOF_CoC(
in float z )
{
return uMaxBlur * min( 1 ,
max( 0 , abs( z - uSharpDist ) - uSharpRange ) / uBlurFalloff );
}
// z: z at UV
// coc: blur radius at UV
// uv: initial coordinate
// blurvec: smudge direction
vec3 DOF_Blur(
in float z ,
in float coc ,
in vec2 uv ,
in vec2 blurvec )
{
vec3 sumcol = vec3( 0. );
for ( int i = 0 ; i < u_Samples ; i++ ) {
float r = i;
#ifdef DOF_USE_RANDOM
r += M_Hash( uv + float( i + uTime ) ) - .5;
#endif
r = r / float( u_Samples - 1 ) - .5;
vec2 p = uv + r * coc * blurvec;
vec3 smpl = texture( u_Input , p ).xyz;
float sz = texture( u_Depth , p ).x;
if ( sz < z ) {
// if sample is closer consider it's CoC
p = uv + r * min( coc , DOF_CoC( sz ) ) * blurvec;
p = uv + r * DOF_CoC( sz ) * blurvec;
smpl = texture( u_Input , p ).xyz;
}
sumcol += smpl;
}
sumcol /= float( u_Samples );
sumcol = max( sumcol , 0. );
return sumcol;
}