Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Kim <pk15950@gmail.com>2022-09-08 07:00:12 +0300
committerPeter Kim <pk15950@gmail.com>2022-09-08 07:00:12 +0300
commit00dcfdf916c69672210b006e62d966f1bc2fbeb7 (patch)
tree0cbb1b91fe26c750197126085b74224a795a103c /source/blender/draw/engines/eevee_next/shaders/eevee_depth_of_field_scatter_frag.glsl
parenta39532670f6b668da7be5810fb1f844b82feeba3 (diff)
parentd5934974219135102f364f57c45a8b1465e2b8d9 (diff)
Merge branch 'master' into xr-devxr-dev
Diffstat (limited to 'source/blender/draw/engines/eevee_next/shaders/eevee_depth_of_field_scatter_frag.glsl')
-rw-r--r--source/blender/draw/engines/eevee_next/shaders/eevee_depth_of_field_scatter_frag.glsl62
1 files changed, 62 insertions, 0 deletions
diff --git a/source/blender/draw/engines/eevee_next/shaders/eevee_depth_of_field_scatter_frag.glsl b/source/blender/draw/engines/eevee_next/shaders/eevee_depth_of_field_scatter_frag.glsl
new file mode 100644
index 00000000000..cfb7fd2568b
--- /dev/null
+++ b/source/blender/draw/engines/eevee_next/shaders/eevee_depth_of_field_scatter_frag.glsl
@@ -0,0 +1,62 @@
+
+/**
+ * Scatter pass: Use sprites to scatter the color of very bright pixel to have higher quality blur.
+ *
+ * We only scatter one quad per sprite and one sprite per 4 pixels to reduce vertex shader
+ * invocations and overdraw.
+ */
+
+#pragma BLENDER_REQUIRE(eevee_depth_of_field_lib.glsl)
+
+#define linearstep(p0, p1, v) (clamp(((v) - (p0)) / abs((p1) - (p0)), 0.0, 1.0))
+
+void main()
+{
+ vec4 coc4 = vec4(interp.color_and_coc1.w,
+ interp.color_and_coc2.w,
+ interp.color_and_coc3.w,
+ interp.color_and_coc4.w);
+ vec4 shapes;
+ if (use_bokeh_lut) {
+ shapes = vec4(texture(bokeh_lut_tx, interp.rect_uv1).r,
+ texture(bokeh_lut_tx, interp.rect_uv2).r,
+ texture(bokeh_lut_tx, interp.rect_uv3).r,
+ texture(bokeh_lut_tx, interp.rect_uv4).r);
+ }
+ else {
+ shapes = vec4(length(interp.rect_uv1),
+ length(interp.rect_uv2),
+ length(interp.rect_uv3),
+ length(interp.rect_uv4));
+ }
+ shapes *= interp.distance_scale;
+ /* Becomes signed distance field in pixel units. */
+ shapes -= coc4;
+ /* Smooth the edges a bit to fade out the undersampling artifacts. */
+ shapes = saturate(1.0 - linearstep(-0.8, 0.8, shapes));
+ /* Outside of bokeh shape. Try to avoid overloading ROPs. */
+ if (max_v4(shapes) == 0.0) {
+ discard;
+ }
+
+ if (!no_scatter_occlusion) {
+ /* Works because target is the same size as occlusion_tx. */
+ vec2 uv = gl_FragCoord.xy / vec2(textureSize(occlusion_tx, 0).xy);
+ vec2 occlusion_data = texture(occlusion_tx, uv).rg;
+ /* Fix tilling artifacts. (Slide 90) */
+ const float correction_fac = 1.0 - DOF_FAST_GATHER_COC_ERROR;
+ /* Occlude the sprite with geometry from the same field using a chebychev test (slide 85). */
+ float mean = occlusion_data.x;
+ float variance = occlusion_data.y;
+ shapes *= variance * safe_rcp(variance + sqr(max(coc4 * correction_fac - mean, 0.0)));
+ }
+
+ out_color = (interp.color_and_coc1 * shapes[0] + interp.color_and_coc2 * shapes[1] +
+ interp.color_and_coc3 * shapes[2] + interp.color_and_coc4 * shapes[3]);
+ /* Do not accumulate alpha. This has already been accumulated by the gather pass. */
+ out_color.a = 0.0;
+
+ if (debug_scatter_perf) {
+ out_color.rgb = avg(out_color.rgb) * vec3(1.0, 0.0, 0.0);
+ }
+}