Test - Converted DoF to compute shaders
It doesn't work too well, however. Other algorithms need to be checked out.
This commit is contained in:
parent
eb2e83a568
commit
c3ccc9403a
4 changed files with 165 additions and 25 deletions
test/shaders/chunks
67
test/shaders/chunks/dof-cs.glsl
Normal file
67
test/shaders/chunks/dof-cs.glsl
Normal file
|
@ -0,0 +1,67 @@
|
|||
//! type chunk
|
||||
|
||||
layout(
|
||||
local_size_x = 64 ,
|
||||
local_size_y = 16
|
||||
) in;
|
||||
|
||||
//#define DOF_USE_RANDOM
|
||||
|
||||
layout( location = 0 ) uniform sampler2D u_Input;
|
||||
layout( location = 2 ) uniform vec4 u_Parameters;
|
||||
layout( location = 3 ) uniform float u_Samples;
|
||||
layout( location = 4 ) uniform vec3 u_ResolutionTime;
|
||||
|
||||
#define uSharpDist (u_Parameters.x)
|
||||
#define uSharpRange (u_Parameters.y)
|
||||
#define uBlurFalloff (u_Parameters.z)
|
||||
#define uMaxBlur (u_Parameters.w)
|
||||
|
||||
#define uResolution (u_ResolutionTime.xy)
|
||||
#define uTime (u_ResolutionTime.z)
|
||||
|
||||
layout( binding = 0 , rgba16f ) writeonly uniform image2D u_Output;
|
||||
|
||||
//!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;
|
||||
vec4 d = textureLod( u_Input , p , 0 );
|
||||
vec3 smpl = d.xyz;
|
||||
float sz = d.w;
|
||||
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 = textureLod( u_Input , p , 0 ).xyz;
|
||||
}
|
||||
sumcol += smpl;
|
||||
}
|
||||
sumcol /= float( u_Samples );
|
||||
sumcol = max( sumcol , 0. );
|
||||
return sumcol;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue