Re-organising shaders
This commit is contained in:
parent
d64e9f9a2e
commit
b75cee8638
7 changed files with 82 additions and 65 deletions
shaders/lib
43
shaders/lib/dof.glsl
Normal file
43
shaders/lib/dof.glsl
Normal file
|
@ -0,0 +1,43 @@
|
|||
//!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;
|
||||
}
|
||||
|
11
shaders/lib/utils.glsl
Normal file
11
shaders/lib/utils.glsl
Normal file
|
@ -0,0 +1,11 @@
|
|||
//! type library
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
float M_Hash( in vec2 p )
|
||||
{
|
||||
p = fract(p * vec2(5.3987, 5.4421));
|
||||
p += dot(p.yx, p.xy + vec2(21.5351, 14.3137));
|
||||
return fract(p.x * p.y * 95.4307);
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue