blob: 25aa20ecb169ce1e9d8eb50f67b24184e55e7264 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
/**
* Bokeh Look Up Table: This outputs a radius multiplier to shape the sampling in gather pass or
* the scatter sprite appearance. This is only used if bokeh shape is either anamorphic or is not
* a perfect circle.
* We correct samples spacing for polygonal bokeh shapes. However, we do not for anamorphic bokeh
* as it is way more complex and expensive to do.
**/
#pragma BLENDER_REQUIRE(eevee_depth_of_field_lib.glsl)
void main()
{
/* Center uv in range [-1..1]. */
vec2 uv = uvcoordsvar.xy * 2.0 - 1.0;
float radius = length(uv);
vec2 texel = floor(gl_FragCoord.xy) - float(dof_max_slight_focus_radius);
if (dof_buf.bokeh_blades > 0.0) {
/* NOTE: atan(y,x) has output range [-M_PI..M_PI], so add 2pi to avoid negative angles. */
float theta = atan(uv.y, uv.x) + M_2PI;
float r = length(uv);
radius /= circle_to_polygon_radius(dof_buf.bokeh_blades, theta - dof_buf.bokeh_rotation);
float theta_new = circle_to_polygon_angle(dof_buf.bokeh_blades, theta);
float r_new = circle_to_polygon_radius(dof_buf.bokeh_blades, theta_new);
theta_new -= dof_buf.bokeh_rotation;
uv = r_new * vec2(-cos(theta_new), sin(theta_new));
{
/* Slight focus distance */
texel *= dof_buf.bokeh_anisotropic_scale_inv;
float theta = atan(texel.y, -texel.x) + M_2PI;
texel /= circle_to_polygon_radius(dof_buf.bokeh_blades, theta + dof_buf.bokeh_rotation);
}
}
else {
uv *= safe_rcp(length(uv));
}
/* For gather store the normalized UV. */
out_gather_lut = uv;
/* For scatter store distance. */
out_scatter_lut = radius;
/* For slight focus gather store pixel perfect distance. */
out_resolve_lut = length(texel);
}
|