[Bf-blender-cvs] [c38bdceb682] tmp-workbench-rewrite2: Merge branch 'master' into tmp-workbench-rewrite2

Miguel Pozo noreply at git.blender.org
Mon Dec 19 15:35:35 CET 2022


Commit: c38bdceb682530ece568159719d3e35b9848b918
Author: Miguel Pozo
Date:   Mon Dec 19 13:58:06 2022 +0100
Branches: tmp-workbench-rewrite2
https://developer.blender.org/rBc38bdceb682530ece568159719d3e35b9848b918

Merge branch 'master' into tmp-workbench-rewrite2

===================================================================



===================================================================

diff --cc source/blender/draw/CMakeLists.txt
index 7e51319e681,2093c8a2331..39428d1b93f
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@@ -493,7 -482,7 +498,8 @@@ set(GLSL_SR
    engines/workbench/shaders/workbench_shadow_debug_frag.glsl
    engines/workbench/shaders/workbench_shadow_geom.glsl
    engines/workbench/shaders/workbench_shadow_vert.glsl
 +  engines/workbench/shaders/workbench_shadow_visibility_comp.glsl
+   engines/workbench/shaders/workbench_shadow_vert_no_geom.glsl
    engines/workbench/shaders/workbench_transparent_accum_frag.glsl
    engines/workbench/shaders/workbench_transparent_resolve_frag.glsl
    engines/workbench/shaders/workbench_volume_frag.glsl
diff --cc source/blender/draw/engines/workbench/shaders/infos/workbench_shadow_info.hh
index 04fd4349d65,3d86ef6e78c..d1e7e0046d8
--- a/source/blender/draw/engines/workbench/shaders/infos/workbench_shadow_info.hh
+++ b/source/blender/draw/engines/workbench/shaders/infos/workbench_shadow_info.hh
@@@ -15,50 -13,17 +15,54 @@@ GPU_SHADER_INTERFACE_INFO(workbench_sha
  
  GPU_SHADER_CREATE_INFO(workbench_shadow_common)
      .vertex_in(0, Type::VEC3, "pos")
-     .vertex_out(workbench_shadow_iface)
      .push_constant(Type::FLOAT, "lightDistance")
      .push_constant(Type::VEC3, "lightDirection")
-     .vertex_source("workbench_shadow_vert.glsl")
      .additional_info("draw_mesh");
  
+ /* `workbench_shadow_vert.glsl` only used by geometry shader path.
+  * Vertex output iface not needed by non-geometry shader variants,
+  * as only gl_Position is returned. */
+ GPU_SHADER_CREATE_INFO(workbench_shadow_common_geom)
+     .vertex_out(workbench_shadow_iface)
+     .vertex_source("workbench_shadow_vert.glsl");
+ 
 +GPU_SHADER_CREATE_INFO(workbench_next_shadow_common)
 +    .vertex_in(0, Type::VEC3, "pos")
 +    .vertex_out(workbench_shadow_iface)
 +    .define("WORKBENCH_NEXT")
 +    .uniform_buf(1, "ShadowPassData", "pass_data")
 +    .push_constant(Type::VEC3, "lightDirection")
 +    .typedef_source("workbench_shader_shared.h")
-     .vertex_source("workbench_shadow_vert.glsl")
 +    .additional_info("draw_view")
 +    .additional_info("draw_modelmat_new")
 +    .additional_info("draw_resource_handle_new");
 +
 +GPU_SHADER_CREATE_INFO(workbench_next_shadow_visibility_compute_common)
 +    .local_group_size(DRW_VISIBILITY_GROUP_SIZE)
 +    .define("DRW_VIEW_LEN", "64")
 +    .storage_buf(0, Qualifier::READ, "ObjectBounds", "bounds_buf[]")
 +    .uniform_buf(2, "ExtrudedFrustum", "extruded_frustum")
 +    .push_constant(Type::INT, "resource_len")
 +    .push_constant(Type::INT, "view_len")
 +    .push_constant(Type::INT, "visibility_word_per_draw")
 +    .push_constant(Type::BOOL, "force_fail_method")
 +    .push_constant(Type::VEC3, "shadow_direction")
 +    .typedef_source("workbench_shader_shared.h")
 +    .compute_source("workbench_shadow_visibility_comp.glsl")
 +    .additional_info("draw_view", "draw_view_culling");
 +
 +GPU_SHADER_CREATE_INFO(workbench_next_shadow_visibility_compute_dynamic_pass_type)
 +    .additional_info("workbench_next_shadow_visibility_compute_common")
 +    .define("DYNAMIC_PASS_SELECTION")
 +    .storage_buf(1, Qualifier::READ_WRITE, "uint", "pass_visibility_buf[]")
 +    .storage_buf(2, Qualifier::READ_WRITE, "uint", "fail_visibility_buf[]")
 +    .do_static_compilation(true);
 +
 +GPU_SHADER_CREATE_INFO(workbench_next_shadow_visibility_compute_static_pass_type)
 +    .additional_info("workbench_next_shadow_visibility_compute_common")
 +    .storage_buf(1, Qualifier::READ_WRITE, "uint", "visibility_buf[]")
 +    .do_static_compilation(true);
 +
  /** \} */
  
  /* -------------------------------------------------------------------- */
diff --cc source/blender/draw/engines/workbench/workbench_effect_dof.cc
index 413cb41d45e,00000000000..e5282166c26
mode 100644,000000..100644
--- a/source/blender/draw/engines/workbench/workbench_effect_dof.cc
+++ b/source/blender/draw/engines/workbench/workbench_effect_dof.cc
@@@ -1,271 -1,0 +1,271 @@@
 +/* SPDX-License-Identifier: GPL-2.0-or-later
 + * Copyright 2016 Blender Foundation. */
 +
 +/** \file
 + * \ingroup draw_engine
 + *
 + * Depth of Field Effect:
 + *
 + * We use a gather approach by sampling a lowres version of the color buffer.
 + * The process can be summarized like this:
 + * - down-sample the color buffer using a COC (Circle of Confusion) aware down-sample algorithm.
 + * - do a gather pass using the COC computed in the previous pass.
 + * - do a median filter to reduce noise amount.
 + * - composite on top of main color buffer.
 + *
 + * This is done after all passes and affects every surfaces.
 + */
 +
 +#include "workbench_private.hh"
 +
 +#include "BKE_camera.h"
 +#include "DEG_depsgraph_query.h"
 +
 +namespace blender::workbench {
 +/**
 + * Transform [-1..1] square to unit circle.
 + */
 +static void square_to_circle(float x, float y, float &r, float &T)
 +{
 +  if (x > -y) {
 +    if (x > y) {
 +      r = x;
 +      T = M_PI_4 * (y / x);
 +    }
 +    else {
 +      r = y;
 +      T = M_PI_4 * (2 - (x / y));
 +    }
 +  }
 +  else {
 +    if (x < y) {
 +      r = -x;
 +      T = M_PI_4 * (4 + (y / x));
 +    }
 +    else {
 +      r = -y;
 +      if (y != 0) {
 +        T = M_PI_4 * (6 - (x / y));
 +      }
 +      else {
 +        T = 0.0f;
 +      }
 +    }
 +  }
 +}
 +
 +void DofPass::setup_samples()
 +{
 +  float4 *sample = samples_buf_.begin();
 +  for (int i = 0; i <= kernel_radius_; i++) {
 +    for (int j = -kernel_radius_; j <= kernel_radius_; j++) {
 +      for (int k = -kernel_radius_; k <= kernel_radius_; k++) {
 +        if (abs(j) > i || abs(k) > i) {
 +          continue;
 +        }
 +        if (abs(j) < i && abs(k) < i) {
 +          continue;
 +        }
 +
 +        float2 coord = float2(j, k) / float2(kernel_radius_);
 +        float r = 0;
 +        float T = 0;
 +        square_to_circle(coord.x, coord.y, r, T);
 +        sample->z = r;
 +
 +        /* Bokeh shape parameterization. */
 +        if (blades_ > 1.0f) {
 +          float denom = T - (2.0 * M_PI / blades_) * floorf((blades_ * T + M_PI) / (2.0 * M_PI));
 +          r *= cosf(M_PI / blades_) / cosf(denom);
 +        }
 +
 +        T += rotation_;
 +
 +        sample->x = r * cosf(T) * ratio_;
 +        sample->y = r * sinf(T);
 +        sample->w = 0;
 +        sample++;
 +      }
 +    }
 +  }
 +  samples_buf_.push_update();
 +}
 +
 +void DofPass::init(const SceneState &scene_state)
 +{
 +  enabled_ = scene_state.draw_dof;
 +
 +  if (!enabled_) {
 +    source_tx_.free();
 +    coc_halfres_tx_.free();
 +    return;
 +  }
 +
 +  if (prepare_sh_ == nullptr) {
 +    prepare_sh_ = GPU_shader_create_from_info_name("workbench_effect_dof_prepare");
 +    downsample_sh_ = GPU_shader_create_from_info_name("workbench_effect_dof_downsample");
 +    blur1_sh_ = GPU_shader_create_from_info_name("workbench_effect_dof_blur1");
 +    blur2_sh_ = GPU_shader_create_from_info_name("workbench_effect_dof_blur2");
 +    resolve_sh_ = GPU_shader_create_from_info_name("workbench_effect_dof_resolve");
 +  }
 +
 +  offset_ = scene_state.sample / (float)scene_state.samples_len;
 +
 +  int2 half_res = scene_state.resolution / 2;
 +  half_res = {max_ii(half_res.x, 1), max_ii(half_res.y, 1)};
 +
-   source_tx_.ensure_2d(GPU_RGBA16F, half_res, nullptr, 3);
++  source_tx_.ensure_2d(GPU_RGBA16F, half_res, GPU_TEXTURE_USAGE_SHADER_READ, nullptr, 3);
 +  source_tx_.ensure_mip_views();
 +  source_tx_.filter_mode(true);
-   coc_halfres_tx_.ensure_2d(GPU_RG8, half_res, nullptr, 3);
++  coc_halfres_tx_.ensure_2d(GPU_RG8, half_res, GPU_TEXTURE_USAGE_SHADER_READ, nullptr, 3);
 +  coc_halfres_tx_.ensure_mip_views();
 +  coc_halfres_tx_.filter_mode(true);
 +
 +  Camera *camera = scene_state.camera;
 +
 +  /* Parameters */
 +  float fstop = camera->dof.aperture_fstop;
 +  float sensor = BKE_camera_sensor_size(camera->sensor_fit, camera->sensor_x, camera->sensor_y);
 +  float focus_dist = BKE_camera_object_dof_distance(scene_state.camera_object);
 +  float focal_len = camera->lens;
 +
 +  /* TODO(fclem): de-duplicate with EEVEE. */
 +  const float scale_camera = 0.001f;
 +  /* We want radius here for the aperture number. */
 +  float aperture = 0.5f * scale_camera * focal_len / fstop;
 +  float focal_len_scaled = scale_camera * focal_len;
 +  float sensor_scaled = scale_camera * sensor;
 +
 +  if (RegionView3D *rv3d = DRW_context_state_get()->rv3d) {
 +    sensor_scaled *= rv3d->viewcamtexcofac[0];
 +  }
 +
 +  aperture_size_ = aperture * fabsf(focal_len_scaled / (focus_dist - focal_len_scaled));
 +  distance_ = -focus_dist;
 +  invsensor_size_ = scene_state.resolution.x / sensor_scaled;
 +
 +  near_ = -camera->clip_start;
 +  far_ = -camera->clip_end;
 +
 +  float blades = camera->dof.aperture_blades;
 +  float rotation = camera->dof.aperture_rotation;
 +  float ratio = 1.0f / camera->dof.aperture_ratio;
 +
 +  if (blades_ != blades || rotation_ != rotation || ratio_ != ratio) {
 +    blades_ = blades;
 +    rotation_ = rotation;
 +    ratio_ = ratio;
 +    setup_samples();
 +  }
 +}
 +
 +void DofPass::sync(SceneResources &resources)
 +{
 +  if (!enabled_) {
 +    return;
 +  }
 +
 +  eGPUSamplerState sampler_state = GPU_SAMPLER_FILTER | GPU_SAMPLER_MIPMAP;
 +
 +  down_ps_.init();
 +  down_ps_.state_set(DRW_STATE_WRITE_COLOR);
 +  down_ps_.shader_set(prepare_sh_);
 +  down_ps_.bind_texture("sceneColorTex", &resources.color_tx);
 +  down_ps_.bind_texture("sceneDepthTex", &resources.depth_tx);
 +  down_ps_.push_constant("invertedViewportSize", float2(DRW_viewport_invert_size_get()));
 +  down_ps_.push_constant("dofParams", float3(aperture_size_, distance_, invsensor_size_));
 +  down_ps_.push_constant("nearFar", float2(near_, far_));
 +  down_ps_.draw_procedural(GPU_PRIM_TRIS, 1, 3);
 +
 +  down2_ps_.init();
 +  down2_ps_.state_set(DRW_STATE_WRITE_COLOR);
 +  down2_ps_.shader_set(downsample_sh_);
 +  down2_ps_.bind_texture("sceneColorTex", &source_tx_, sampler_state);
 +  down2_ps_.bind_texture("inputCocTex", &coc_halfres_tx_, sampler_state);
 +  down2_ps_.draw_procedural(GPU_PRIM_TRIS, 1, 3);
 +
 +  blur_ps_.init();
 +  blur_ps_.state_set(DRW_STATE_WRITE_COLOR);
 +  blur_ps_.shader_set(blur1_sh_);
 +  blur_ps_.bind_ubo

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list