diff options
Diffstat (limited to 'source/blender/gpu/shaders/gpu_shader_fx_dof_hq_frag.glsl')
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_fx_dof_hq_frag.glsl | 68 |
1 files changed, 37 insertions, 31 deletions
diff --git a/source/blender/gpu/shaders/gpu_shader_fx_dof_hq_frag.glsl b/source/blender/gpu/shaders/gpu_shader_fx_dof_hq_frag.glsl index 182113367d3..c41c1d0820b 100644 --- a/source/blender/gpu/shaders/gpu_shader_fx_dof_hq_frag.glsl +++ b/source/blender/gpu/shaders/gpu_shader_fx_dof_hq_frag.glsl @@ -14,24 +14,28 @@ uniform sampler2D depthbuffer; uniform sampler2D cocbuffer; -/* this includes focal distance in x and aperture size in y */ +/* this includes aperture size in x and focal distance in y */ uniform vec4 dof_params; /* viewvectors for reconstruction of world space */ uniform vec4 viewvecs[3]; /* initial uv coordinate */ -varying vec2 uvcoord; +in vec2 uvcoord; /* coordinate used for calculating radius et al set in geometry shader */ -varying vec2 particlecoord; -varying vec4 color; +in vec2 particlecoord; +flat in vec4 color; /* downsampling coordinates */ -varying vec2 downsample1; -varying vec2 downsample2; -varying vec2 downsample3; -varying vec2 downsample4; +in vec2 downsample1; +in vec2 downsample2; +in vec2 downsample3; +in vec2 downsample4; + +layout(location = 0) out vec4 fragData0; +layout(location = 1) out vec4 fragData1; +layout(location = 2) out vec4 fragData2; #define M_PI 3.1415926535897932384626433832795 @@ -55,15 +59,15 @@ void downsample_pass() float far_coc, near_coc; /* custom downsampling. We need to be careful to sample nearest here to avoid leaks */ - vec4 color1 = texture2D(colorbuffer, downsample1); - vec4 color2 = texture2D(colorbuffer, downsample2); - vec4 color3 = texture2D(colorbuffer, downsample3); - vec4 color4 = texture2D(colorbuffer, downsample4); + vec4 color1 = texture(colorbuffer, downsample1); + vec4 color2 = texture(colorbuffer, downsample2); + vec4 color3 = texture(colorbuffer, downsample3); + vec4 color4 = texture(colorbuffer, downsample4); - depth.r = texture2D(depthbuffer, downsample1).r; - depth.g = texture2D(depthbuffer, downsample2).r; - depth.b = texture2D(depthbuffer, downsample3).r; - depth.a = texture2D(depthbuffer, downsample4).r; + depth.r = texture(depthbuffer, downsample1).r; + depth.g = texture(depthbuffer, downsample2).r; + depth.b = texture(depthbuffer, downsample3).r; + depth.a = texture(depthbuffer, downsample4).r; zdepth = get_view_space_z_from_depth(vec4(viewvecs[0].z), vec4(viewvecs[1].z), depth); coc = calculate_coc(zdepth); @@ -82,16 +86,16 @@ void downsample_pass() float norm_far = dot(far_weights, vec4(1.0)); /* now write output to weighted buffers. */ - gl_FragData[0] = color1 * near_weights.x + color2 * near_weights.y + color3 * near_weights.z + + fragData0 = color1 * near_weights.x + color2 * near_weights.y + color3 * near_weights.z + color4 * near_weights.w; - gl_FragData[1] = color1 * far_weights.x + color2 * far_weights.y + color3 * far_weights.z + + fragData1 = color1 * far_weights.x + color2 * far_weights.y + color3 * far_weights.z + color4 * far_weights.w; if (norm_near > 0.0) - gl_FragData[0] /= norm_near; + fragData0 /= norm_near; if (norm_far > 0.0) - gl_FragData[1] /= norm_far; - gl_FragData[2] = vec4(near_coc, far_coc, 0.0, 1.0); + fragData1 /= norm_far; + fragData2 = vec4(near_coc, far_coc, 0.0, 1.0); } /* accumulate color in the near/far blur buffers */ @@ -102,36 +106,36 @@ void accumulate_pass(void) { if (dof_params.w == 0.0) r = 1.0; else - r = cos(M_PI / dof_params.w) / - (cos(theta - (2.0 * M_PI / dof_params.w) * floor((dof_params.w * theta + M_PI) / (2.0 * M_PI)))); + r = cos(M_PI / dof_params.w) / + (cos(theta - (2.0 * M_PI / dof_params.w) * floor((dof_params.w * theta + M_PI) / (2.0 * M_PI)))); if (dot(particlecoord, particlecoord) > r * r) discard; - gl_FragData[0] = color; + fragData0 = color; } -#define MERGE_THRESHOLD 4.0 +#define MERGE_THRESHOLD 4.0 /* combine the passes, */ void final_pass(void) { vec4 finalcolor; float totalweight; - float depth = texture2D(depthbuffer, uvcoord).r; + float depth = texture(depthbuffer, uvcoord).r; vec4 zdepth = get_view_space_z_from_depth(vec4(viewvecs[0].z), vec4(viewvecs[1].z), vec4(depth)); float coc_near = calculate_coc(zdepth).r; float coc_far = max(-coc_near, 0.0); coc_near = max(coc_near, 0.0); - vec4 farcolor = texture2D(farbuffer, uvcoord); + vec4 farcolor = texture(farbuffer, uvcoord); float farweight = farcolor.a; if (farweight > 0.0) farcolor /= farweight; - vec4 nearcolor = texture2D(nearbuffer, uvcoord); + vec4 nearcolor = texture(nearbuffer, uvcoord); - vec4 srccolor = texture2D(colorbuffer, uvcoord); + vec4 srccolor = texture(colorbuffer, uvcoord); - vec4 coc = texture2D(cocbuffer, uvcoord); + vec4 coc = texture(cocbuffer, uvcoord); float mixfac = smoothstep(1.0, MERGE_THRESHOLD, coc_far); finalcolor = mix(srccolor, farcolor, mixfac); @@ -152,7 +156,9 @@ void final_pass(void) { finalcolor = mix(finalcolor, nearcolor, nearweight / totalweight); } - gl_FragData[0] = finalcolor; + fragData0 = finalcolor; + // fragData0 = vec4(nearweight, farweight, 0.0, 1.0); + // fragData0 = vec4(nearcolor.rgb, 1.0); } void main() |