Untitled
Loading...
Searching...
No Matches
bokeh.frag
Go to the documentation of this file.
1#version 430 core
2
3
6
7const vec2 hex_taps[19] = vec2[](
8 vec2( 0.00, 0.00),
9 vec2( 0.50, 0.86), vec2( 1.00, 0.00), vec2( 0.50, -0.86),
10 vec2(-0.50, -0.86), vec2(-1.00, 0.00), vec2(-0.50, 0.86),
11 vec2( 1.00, 1.73), vec2( 2.00, 0.00), vec2( 1.00, -1.73),
12 vec2(-1.00, -1.73), vec2(-2.00, 0.00), vec2(-1.00, 1.73),
13 vec2( 1.50, 0.86), vec2( 1.50, -0.86), vec2( 0.00, -1.73),
14 vec2(-1.50, -0.86), vec2(-1.50, 0.86), vec2( 0.00, 1.73)
15);
16
17uniform sampler2D uCOC;
19
20void main() {
21 vec2 uv = vUV;
22 vec4 center = texture(uCOC, uv);
23 float centerCoC = center.a;
24
25 const float max_blur_pixels = 20.0;
26 float radius = abs(centerCoC) * max_blur_pixels;
27
28 vec3 total_color = vec3(0.0);
29 float total_weight = 0.0;
30
31 for (int i = 0; i < 19; i++) {
32
33 vec2 tap_offset = hex_taps[i] * 0.5 * radius * uTexelSize;
34 vec2 sampleUV = uv + tap_offset;
35
36 vec4 tap = texture(uCOC, sampleUV);
37 float tapCoC = tap.a;
38 float sample_dist = length(hex_taps[i] * 0.5 * radius);
39
40 float weight = 1.0;
41 if (tapCoC > centerCoC) {
42 float tapRadius = abs(tapCoC) * max_blur_pixels;
43 weight = clamp(tapRadius - sample_dist + 1.0, 0.0, 1.0);
44 }
45
46 float r = texture(uCOC, uv + tap_offset).r;
47 float g = texture(uCOC, uv + tap_offset * 2.0).g;
48 float b = texture(uCOC, uv + tap_offset * 1.5).b;
49
50 vec3 tap_color = vec3(r, g, b);
51
52 total_color += tap_color * weight;
53 total_weight += weight;
54 }
55
56 fragColor = vec4(total_color / max(total_weight, 0.0001), 1.0);
57}
void main()
out vec4 fragColor
Definition bloom.frag:6
uniform vec2 uTexelSize
Definition bokeh.frag:18
uniform sampler2D uCOC
Definition bokeh.frag:17
const vec2 hex_taps[19]
Definition bokeh.frag:7
in vec2 uv
in vec2 vUV
Definition lightmap.frag:13
float clamp(float a, float b, float c)
Definition mathf.h:379
Definition types.h:11
Definition types.h:12
Definition types.h:13