26#define MAX_COC_SIZE 100.0f
43 return (val0 * weights[0] + val1 * weights[1] + val2 * weights[2] + val3 * weights[3]) *
44 safe_rcp(weights[0] + weights[1] + weights[2] + weights[3]);
59 return aperture_size * (
distance / z_depth - 1.0f) * invsensor_size;
106 depths.
x =
texelFetch(srt.scene_depth_tx, texel.xy, 0).x;
107 depths.
y =
texelFetch(srt.scene_depth_tx, texel.zw, 0).x;
108 depths.
z =
texelFetch(srt.scene_depth_tx, texel.zy, 0).x;
109 depths.
w =
texelFetch(srt.scene_depth_tx, texel.xw, 0).x;
117 float4 cocs_near =
dof.calculate_coc(zdepths);
118 float4 cocs_far = -cocs_near;
126 clamp(1.0f -
abs(coc_near - cocs_near), 0.0f, 1.0f);
127 float4 far_weights =
step(0.0f, cocs_far) *
clamp(1.0f -
abs(coc_far - cocs_far), 0.0f, 1.0f);
133 out.half_res_color =
clamp(
out.half_res_color, 0.0f, 3.0f);
182 clamp(1.0f -
abs(coc_near - cocs_near), 0.0f, 1.0f);
183 float4 far_weights =
step(0.0f, cocs_far) *
clamp(1.0f -
abs(coc_far - cocs_far), 0.0f, 1.0f);
210 float ign =
fract(offset +
211 52.9829189f *
fract(0.06711056f * frag_co.
x + 0.00583715f * frag_co.
y));
213 float ang =
M_PI * 2.0f *
fract(bn + offset);
227 float2 uv = frag_co.xy *
dof.inverted_viewport_size * 2.0f;
236 float max_radius = coc;
237 float2 noise = srt.get_random_vector(frag_co.xy,
dof.noise_offset) * 0.2f *
238 clamp(max_radius * 0.2f - 4.0f, 0.0f, 1.0f);
240 float2 tc = uv + (
noise + srt.samples[i].xy) *
dof.inverted_viewport_size * max_radius;
245 float lod =
log2(
clamp((coc +
min(coc, max_radius)) * 0.5f - 21.0f, 0.0f, 16.0f) * 0.25f);
248 float radius = srt.samples[i].z * max_radius;
249 float weight =
abs(coc) *
smoothstep(radius - 0.5f, radius + 0.5f,
abs(coc));
251 color += samp * weight;
338 float2 uv = frag_co.xy * pixel_size.xy;
343 float rad =
clamp(coc - 9.0f, 0.0f, 1.0f);
348 for (
int dX = -1; dX <= 1; dX++) [[
unroll]] {
349 for (
int dY = -1; dY <= 1; dY++) [[
unroll]] {
354 v[(dX + 1) * 3 + (dY + 1)] =
texture(srt.blur_tx, uv + offset * pixel_size * rad);
359 mnmx6(v[0], v[1], v[2], v[3], v[4], v[5]);
360 mnmx5(v[1], v[2], v[3], v[4], v[6]);
361 mnmx4(v[2], v[3], v[4], v[7]);
362 mnmx3(v[3], v[4], v[8]);
388 float2 uv = frag_co.xy * pixel_size;
395 float coc =
dof.calculate_coc(zdepth);
398 out.color_add =
texture(srt.half_res_color_tx, uv) * blend;
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
VecBase< bool, D > notEqual(VecOp< T, D >, VecOp< T, D >) RET
T smoothstep(T, T, T) RET
bool any(VecOp< bool, D >) RET
float distance(float, float) RET
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
constexpr T clamp(T, U, U) RET
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
TEX_TEMPLATE DataVec texelFetch(T, IntCoord, int) RET
TEX_TEMPLATE DataVec textureLod(T, FltCoord, float) RET
SamplerBase< float, 2 > sampler2D
TEX_TEMPLATE SizeVec textureSize(T, int) RET
void fullscreen_vertex(int vertex_id, float4 &out_position)
float reduce_max(float2 a)
void vert(const int vert_id, float4 &position)
static constexpr int dof_sample_count
float2 dof_encode_coc(float near, float far)
float4 sum_weighted(float4 val0, float4 val1, float4 val2, float4 val3, float4 weights)
float dof_decode_signed_coc(float2 cocs)
void mnmx3(float4 &a, float4 &b, float4 &c)
void mn3(float4 &a, float4 &b, float4 &c)
void downsample(DownSample &srt, DownSampleOut &out, const float4 frag_co)
float dof_decode_coc(float2 cocs)
void blur2(Blur2 &srt, Blur2Out &out, const float4 frag_co)
void mnmx6(float4 &a, float4 &b, float4 &c, float4 &d, float4 &e, float4 &f)
void resolve(DepthOfField &dof, Resolve &srt, draw::View &views, ResolveOut &out, const float4 frag_co)
void mnmx4(float4 &a, float4 &b, float4 &c, float4 &d)
void mnmx5(float4 &a, float4 &b, float4 &c, float4 &d, float4 &e)
void s2(float4 &a, float4 &b)
void blur1(DepthOfField &dof, Blur1 &srt, Blur1Out &out, const float4 frag_co)
void prepare(DepthOfField &dof, Prepare &srt, draw::View &views, PrepareOut &out, const float4 frag_co)
void mx3(float4 &a, float4 &b, float4 &c)
float depth_screen_to_view(float ss_depth) const
float4 samples[dof_sample_count]
float2 get_random_vector(float2 frag_co, float offset) const
sampler2D half_res_color_tx
T calculate_coc(T z_depth)
float2 inverted_viewport_size
sampler2D half_res_color_tx
PipelineGraphic workbench_effect_dof_blur2(workbench::dof::vert, workbench::dof::blur2)
PipelineGraphic workbench_effect_dof_blur1(workbench::dof::vert, workbench::dof::blur1)
PipelineGraphic workbench_effect_dof_resolve(workbench::dof::vert, workbench::dof::resolve)
PipelineGraphic workbench_effect_dof_prepare(workbench::dof::vert, workbench::dof::prepare)
PipelineGraphic workbench_effect_dof_downsample(workbench::dof::vert, workbench::dof::downsample)