Differential D16990 Diff 60050 source/blender/draw/engines/eevee_next/shaders/eevee_depth_of_field_stabilize_comp.glsl
Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/eevee_next/shaders/eevee_depth_of_field_stabilize_comp.glsl
| Show All 16 Lines | |||||
| #pragma BLENDER_REQUIRE(common_math_geom_lib.glsl) | #pragma BLENDER_REQUIRE(common_math_geom_lib.glsl) | ||||
| #pragma BLENDER_REQUIRE(eevee_colorspace_lib.glsl) | #pragma BLENDER_REQUIRE(eevee_colorspace_lib.glsl) | ||||
| #pragma BLENDER_REQUIRE(eevee_depth_of_field_lib.glsl) | #pragma BLENDER_REQUIRE(eevee_depth_of_field_lib.glsl) | ||||
| #pragma BLENDER_REQUIRE(eevee_velocity_lib.glsl) | #pragma BLENDER_REQUIRE(eevee_velocity_lib.glsl) | ||||
| struct DofSample { | struct DofSample { | ||||
| vec4 color; | vec4 color; | ||||
| float coc; | float coc; | ||||
| #ifdef GPU_METAL | |||||
| /* Explicit constructors -- To support GLSL syntax. */ | |||||
| inline DofSample() = default; | |||||
| inline DofSample(vec4 in_color, float in_coc) : color(in_color), coc(in_coc) | |||||
| { | |||||
| } | |||||
| #endif | |||||
| }; | }; | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name LDS Cache | /** \name LDS Cache | ||||
| * \{ */ | * \{ */ | ||||
| #define cache_size (gl_WorkGroupSize.x + 2) | |||||
| const uint cache_size = gl_WorkGroupSize.x + 2; | |||||
| shared vec4 color_cache[cache_size][cache_size]; | shared vec4 color_cache[cache_size][cache_size]; | ||||
| shared float coc_cache[cache_size][cache_size]; | shared float coc_cache[cache_size][cache_size]; | ||||
| /* Need 2 pixel border for depth. */ | /* Need 2 pixel border for depth. */ | ||||
| const uint cache_depth_size = gl_WorkGroupSize.x + 4; | #define cache_depth_size (gl_WorkGroupSize.x + 4) | ||||
| shared float depth_cache[cache_depth_size][cache_depth_size]; | shared float depth_cache[cache_depth_size][cache_depth_size]; | ||||
| void dof_cache_init() | void dof_cache_init() | ||||
| { | { | ||||
| /** | /** | ||||
| * Load enough values into LDS to perform the filter. | * Load enough values into LDS to perform the filter. | ||||
| * | * | ||||
| * ┌──────────────────────────────┐ | * ┌──────────────────────────────┐ | ||||
| ▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | DofSample dof_spatial_filtering() | ||||
| accum.color *= rcp_weight; | accum.color *= rcp_weight; | ||||
| accum.coc *= rcp_weight; | accum.coc *= rcp_weight; | ||||
| return accum; | return accum; | ||||
| } | } | ||||
| struct DofNeighborhoodMinMax { | struct DofNeighborhoodMinMax { | ||||
| DofSample min; | DofSample min; | ||||
| DofSample max; | DofSample max; | ||||
| #ifdef GPU_METAL | |||||
| /* Explicit constructors -- To support GLSL syntax. */ | |||||
| inline DofNeighborhoodMinMax() = default; | |||||
| inline DofNeighborhoodMinMax(DofSample in_min, DofSample in_max) : min(in_min), max(in_max) | |||||
| { | |||||
| } | |||||
| #endif | |||||
| }; | }; | ||||
| /* Return history clipping bounding box in YCoCg color space. */ | /* Return history clipping bounding box in YCoCg color space. */ | ||||
| DofNeighborhoodMinMax dof_neighbor_boundbox() | DofNeighborhoodMinMax dof_neighbor_boundbox() | ||||
| { | { | ||||
| /* Plus (+) shape offsets. */ | /* Plus (+) shape offsets. */ | ||||
| const ivec2 plus_offsets[4] = ivec2[4](ivec2(-1, 0), ivec2(0, -1), ivec2(1, 0), ivec2(0, 1)); | const ivec2 plus_offsets[4] = ivec2[4](ivec2(-1, 0), ivec2(0, -1), ivec2(1, 0), ivec2(0, 1)); | ||||
| /** | /** | ||||
| ▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | vec2 dof_pixel_history_motion_vector(ivec2 texel_sample) | ||||
| return vector.xy * vec2(textureSize(color_tx, 0)); | return vector.xy * vec2(textureSize(color_tx, 0)); | ||||
| } | } | ||||
| /* Load color using a special filter to avoid losing detail. | /* Load color using a special filter to avoid losing detail. | ||||
| * \a texel is sample position with subpixel accuracy. */ | * \a texel is sample position with subpixel accuracy. */ | ||||
| DofSample dof_sample_history(vec2 input_texel) | DofSample dof_sample_history(vec2 input_texel) | ||||
| { | { | ||||
| #if 1 /* Bilinar. */ | #if 1 /* Bilinar. */ | ||||
| vec2 uv = vec2(input_texel + 0.5) / textureSize(in_history_tx, 0); | vec2 uv = vec2(input_texel + 0.5) / vec2(textureSize(in_history_tx, 0)); | ||||
| vec4 color = textureLod(in_history_tx, uv, 0.0); | vec4 color = textureLod(in_history_tx, uv, 0.0); | ||||
| #else /* Catmull Rom interpolation. 5 Bilinear Taps. */ | #else /* Catmull Rom interpolation. 5 Bilinear Taps. */ | ||||
| vec2 center_texel; | vec2 center_texel; | ||||
| vec2 inter_texel = modf(input_texel, center_texel); | vec2 inter_texel = modf(input_texel, center_texel); | ||||
| vec2 weights[4]; | vec2 weights[4]; | ||||
| film_get_catmull_rom_weights(inter_texel, weights); | film_get_catmull_rom_weights(inter_texel, weights); | ||||
| ▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | float dof_history_blend_factor( | ||||
| float coc_diff_ratio = saturate(abs(src.coc - dst.coc) / max(1.0, abs(src.coc))); | float coc_diff_ratio = saturate(abs(src.coc - dst.coc) / max(1.0, abs(src.coc))); | ||||
| blend = mix(blend, 1.0, coc_diff_ratio); | blend = mix(blend, 1.0, coc_diff_ratio); | ||||
| /* Discard out of view history. */ | /* Discard out of view history. */ | ||||
| if (any(lessThan(texel, vec2(0))) || | if (any(lessThan(texel, vec2(0))) || | ||||
| any(greaterThanEqual(texel, vec2(imageSize(out_history_img))))) { | any(greaterThanEqual(texel, vec2(imageSize(out_history_img))))) { | ||||
| blend = 1.0; | blend = 1.0; | ||||
| } | } | ||||
| /* Discard history if invalid. */ | /* Discard history if invalid. */ | ||||
| if (use_history == false) { | if (u_use_history == false) { | ||||
| blend = 1.0; | blend = 1.0; | ||||
| } | } | ||||
| return blend; | return blend; | ||||
| } | } | ||||
| void main() | void main() | ||||
| { | { | ||||
| dof_cache_init(); | dof_cache_init(); | ||||
| ▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines | |||||