[Bf-blender-cvs] [23e634f1b57] soc-2020-fluid-tools: Volume: Added slicing options in 'Viewport Display' for Volume Object

Sriharsha Kotcharlakot noreply at git.blender.org
Wed Jul 8 15:28:51 CEST 2020


Commit: 23e634f1b570b6744a47fe202dc387e2c39dec6e
Author: Sriharsha Kotcharlakot
Date:   Wed Jul 8 18:58:15 2020 +0530
Branches: soc-2020-fluid-tools
https://developer.blender.org/rB23e634f1b570b6744a47fe202dc387e2c39dec6e

Volume: Added slicing options in 'Viewport Display' for Volume Object

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

M	release/scripts/startup/bl_ui/properties_data_volume.py
M	source/blender/draw/engines/workbench/workbench_volume.c
M	source/blender/makesdna/DNA_volume_defaults.h
M	source/blender/makesdna/DNA_volume_types.h
M	source/blender/makesrna/intern/rna_volume.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_volume.py b/release/scripts/startup/bl_ui/properties_data_volume.py
index b10bb808edd..6e2285405e8 100644
--- a/release/scripts/startup/bl_ui/properties_data_volume.py
+++ b/release/scripts/startup/bl_ui/properties_data_volume.py
@@ -149,7 +149,12 @@ class DATA_PT_volume_viewport_display(DataButtonsPanel, Panel):
         sub.active = display.wireframe_type in {'BOXES', 'POINTS'}
         sub.prop(display, "wireframe_detail", text="Detail")
 
-        layout.prop(display, "density")
+        col = layout.column(align=True)
+        col.prop(display, "density")
+        col.prop(display, "interpolation_method")
+        col.prop(display, "axis_slice_method")
+        col.prop(display, "slice_axis")
+        col.prop(display, "slice_depth")
 
 
 class DATA_PT_custom_props_volume(DataButtonsPanel, PropertyPanel, Panel):
diff --git a/source/blender/draw/engines/workbench/workbench_volume.c b/source/blender/draw/engines/workbench/workbench_volume.c
index 28ba220627b..10c49e8c8cf 100644
--- a/source/blender/draw/engines/workbench/workbench_volume.c
+++ b/source/blender/draw/engines/workbench/workbench_volume.c
@@ -211,11 +211,14 @@ static void workbench_volume_object_cache_populate(WORKBENCH_Data *vedata,
   WORKBENCH_PrivateData *wpd = vedata->stl->wpd;
   WORKBENCH_TextureList *txl = vedata->txl;
   DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+  DRWShadingGroup *grp = NULL;
 
   wpd->volumes_do = true;
+  const bool use_slice = (volume->display.axis_slice_method == AXIS_SLICE_SINGLE);
+  const InterpType interpolation_method = (InterpType)volume->display.interpolation_method;
 
   /* Create shader. */
-  GPUShader *sh = workbench_shader_volume_get(false, false, false, false);
+  GPUShader *sh = workbench_shader_volume_get(use_slice, false, interpolation_method, false);
 
   /* Compute color. */
   float color[3];
@@ -225,36 +228,59 @@ static void workbench_volume_object_cache_populate(WORKBENCH_Data *vedata,
   float texture_to_world[4][4];
   mul_m4_m4m4(texture_to_world, ob->obmat, grid->texture_to_object);
 
-  /* Compute world space dimensions for step size. */
-  float world_size[3];
-  mat4_to_size(world_size, texture_to_world);
-  abs_v3(world_size);
-
-  /* Compute step parameters. */
-  double noise_ofs;
-  BLI_halton_1d(3, 0.0, wpd->taa_sample, &noise_ofs);
-  float step_length, max_slice;
-  int resolution[3];
-  GPU_texture_get_mipmap_size(grid->texture, 0, resolution);
-  float slice_ct[3] = {resolution[0], resolution[1], resolution[2]};
-  mul_v3_fl(slice_ct, max_ff(0.001f, 5.0f));
-  max_slice = max_fff(slice_ct[0], slice_ct[1], slice_ct[2]);
-  invert_v3(slice_ct);
-  mul_v3_v3(slice_ct, world_size);
-  step_length = len_v3(slice_ct);
+  if (use_slice) {
+    float invviewmat[4][4];
+    DRW_view_viewmat_get(NULL, invviewmat, true);
+
+    const int axis = (volume->display.slice_axis == SLICE_AXIS_AUTO) ?
+                         axis_dominant_v3_single(invviewmat[2]) :
+                         volume->display.slice_axis - 1;
+
+    float dim[3];
+    BKE_object_dimensions_get(ob, dim);
+    /* 0.05f to achieve somewhat the same opacity as the full view.  */
+    float step_length = max_ff(1e-16f, dim[axis] * 0.05f);
+
+    const float slice_position = volume->display.slice_depth;
+
+    grp = DRW_shgroup_create(sh, vedata->psl->volume_ps);
+    DRW_shgroup_uniform_float_copy(grp, "slicePosition", slice_position);
+    DRW_shgroup_uniform_int_copy(grp, "sliceAxis", axis);
+    DRW_shgroup_uniform_float_copy(grp, "stepLength", step_length);
+    DRW_shgroup_state_disable(grp, DRW_STATE_CULL_FRONT);
+  }
+  else {
+    /* Compute world space dimensions for step size. */
+    float world_size[3];
+    mat4_to_size(world_size, texture_to_world);
+    abs_v3(world_size);
+
+    /* Compute step parameters. */
+    double noise_ofs;
+    BLI_halton_1d(3, 0.0, wpd->taa_sample, &noise_ofs);
+    float step_length, max_slice;
+    int resolution[3];
+    GPU_texture_get_mipmap_size(grid->texture, 0, resolution);
+    float slice_ct[3] = {resolution[0], resolution[1], resolution[2]};
+    mul_v3_fl(slice_ct, max_ff(0.001f, 5.0f));
+    max_slice = max_fff(slice_ct[0], slice_ct[1], slice_ct[2]);
+    invert_v3(slice_ct);
+    mul_v3_v3(slice_ct, world_size);
+    step_length = len_v3(slice_ct);
+
+    /* Set uniforms. */
+    grp = DRW_shgroup_create(sh, vedata->psl->volume_ps);
+    DRW_shgroup_uniform_block(grp, "world_block", wpd->world_ubo);
+    DRW_shgroup_uniform_int_copy(grp, "samplesLen", max_slice);
+    DRW_shgroup_uniform_float_copy(grp, "stepLength", step_length);
+    DRW_shgroup_uniform_float_copy(grp, "noiseOfs", noise_ofs);
+    DRW_shgroup_state_enable(grp, DRW_STATE_CULL_FRONT);
+  }
 
   /* Compute density scale. */
   const float density_scale = volume->display.density *
                               BKE_volume_density_scale(volume, ob->obmat);
 
-  /* Set uniforms. */
-  DRWShadingGroup *grp = DRW_shgroup_create(sh, vedata->psl->volume_ps);
-  DRW_shgroup_uniform_block(grp, "world_block", wpd->world_ubo);
-  DRW_shgroup_uniform_int_copy(grp, "samplesLen", max_slice);
-  DRW_shgroup_uniform_float_copy(grp, "stepLength", step_length);
-  DRW_shgroup_uniform_float_copy(grp, "noiseOfs", noise_ofs);
-  DRW_shgroup_state_enable(grp, DRW_STATE_CULL_FRONT);
-
   DRW_shgroup_uniform_texture(grp, "densityTexture", grid->texture);
   /* TODO: implement shadow texture, see manta_smoke_calc_transparency. */
   DRW_shgroup_uniform_texture(grp, "shadowTexture", txl->dummy_shadow_tx);
diff --git a/source/blender/makesdna/DNA_volume_defaults.h b/source/blender/makesdna/DNA_volume_defaults.h
index 3a0373851da..76cbffd5c3b 100644
--- a/source/blender/makesdna/DNA_volume_defaults.h
+++ b/source/blender/makesdna/DNA_volume_defaults.h
@@ -33,6 +33,7 @@
     .density = 1.0f, \
     .wireframe_type = VOLUME_WIREFRAME_BOXES, \
     .wireframe_detail = VOLUME_WIREFRAME_COARSE, \
+    .slice_depth = 0.5f, \
   }
 
 #define _DNA_DEFAULT_VolumeRender \
diff --git a/source/blender/makesdna/DNA_volume_types.h b/source/blender/makesdna/DNA_volume_types.h
index b3615e87a50..1e4467d17c4 100644
--- a/source/blender/makesdna/DNA_volume_types.h
+++ b/source/blender/makesdna/DNA_volume_types.h
@@ -39,6 +39,10 @@ typedef struct VolumeDisplay {
   float density;
   int wireframe_type;
   int wireframe_detail;
+  int interpolation_method;
+  int axis_slice_method;
+  int slice_axis;
+  float slice_depth;
   int _pad[1];
 } VolumeDisplay;
 
@@ -120,6 +124,27 @@ typedef enum VolumeRenderSpace {
   VOLUME_SPACE_WORLD = 1,
 } VolumeRenderSpace;
 
+/* VolumeDisplay.interpolation_method */
+typedef enum VolumeInterpolationMethod {
+  VOLUME_INTERPOLATION_LINEAR = 0,
+  VOLUME_INTERPOLATION_CUBIC = 1,
+  VOLUME_INTERPOLATION_RAW = 2,
+} VolumeInterpolationMethod;
+
+/* VolumeDisplay.axis_slice_method */
+typedef enum AxisAlignedSlicingMethod {
+  VOLUME_AXIS_SLICE_FULL = 0,
+  VOLUME_AXIS_SLICE_SINGLE = 1,
+} AxisAlignedSlicingMethod;
+
+/* VolumeDisplay.slice_axis */
+typedef enum SliceAxis {
+  VOLUME_SLICE_AXIS_AUTO = 0,
+  VOLUME_SLICE_AXIS_X = 1,
+  VOLUME_SLICE_AXIS_Y = 2,
+  VOLUME_SLICE_AXIS_Z = 3,
+} SliceAxis;
+
 /* Only one material supported currently. */
 #define VOLUME_MATERIAL_NR 1
 
diff --git a/source/blender/makesrna/intern/rna_volume.c b/source/blender/makesrna/intern/rna_volume.c
index b03d6082cea..3c5ded79cfd 100644
--- a/source/blender/makesrna/intern/rna_volume.c
+++ b/source/blender/makesrna/intern/rna_volume.c
@@ -395,6 +395,39 @@ static void rna_def_volume_display(BlenderRNA *brna)
       {0, NULL, 0, NULL, NULL},
   };
 
+  static const EnumPropertyItem interpolation_method_items[] = {
+      {VOLUME_INTERPOLATION_LINEAR, "LINEAR", 0, "Linear", "Good smoothness and speed"},
+      {VOLUME_INTERPOLATION_CUBIC,
+       "CUBIC",
+       0,
+       "Cubic",
+       "Smoothed high quality interpolation, but slower"},
+      {VOLUME_INTERPOLATION_RAW, "RAW", 0, "Raw", "No interpolation"},
+      {0, NULL, 0, NULL, NULL},
+  };
+
+  static const EnumPropertyItem axis_slice_method_items[] = {
+      {VOLUME_AXIS_SLICE_FULL, "FULL", 0, "Full", "Slice the whole domain object"},
+      {VOLUME_AXIS_SLICE_SINGLE,
+       "SINGLE",
+       0,
+       "Single",
+       "Perform a single slice of the domain object"},
+      {0, NULL, 0, NULL, NULL},
+  };
+
+  static const EnumPropertyItem axis_slice_position_items[] = {
+      {VOLUME_SLICE_AXIS_AUTO,
+       "AUTO",
+       0,
+       "Auto",
+       "Adjust slice direction according to the view direction"},
+      {VOLUME_SLICE_AXIS_X, "X", 0, "X", "Slice along the X axis"},
+      {VOLUME_SLICE_AXIS_Y, "Y", 0, "Y", "Slice along the Y axis"},
+      {VOLUME_SLICE_AXIS_Z, "Z", 0, "Z", "Slice along the Z axis"},
+      {0, NULL, 0, NULL, NULL},
+  };
+
   prop = RNA_def_property(srna, "wireframe_type", PROP_ENUM, PROP_NONE);
   RNA_def_property_enum_items(prop, wireframe_type_items);
   RNA_def_property_ui_text(prop, "Wireframe", "Type of wireframe display");
@@ -404,6 +437,27 @@ static void rna_def_volume_display(BlenderRNA *brna)
   RNA_def_property_enum_items(prop, wireframe_detail_items);
   RNA_def_property_ui_text(prop, "Wireframe Detail", "Amount of detail for wireframe display");
   RNA_def_property_update(prop, 0, "rna_Volume_update_display");
+
+  prop = RNA_def_property(srna, "interpolation_method", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_items(prop, interpolation_method_items);
+  RNA_def_property_ui_text(
+      prop, "Interpolation", "Interpolation method to use for volumes in solid mode");
+  RNA_def_property_update(prop, 0, "rna_Volume_update_display");
+
+  prop = RNA_def_property(srna, "axis_slice_method", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_items(prop, axis_slice_method_items);
+  RNA_def_property_ui_text(prop, "Method", "");
+  RNA_def_property_update(prop, 0, "rna_Volume_update_display");
+
+  prop = RNA_def_property(srna, "slice_axis", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_items(prop, axis_slice_position_items);
+  RNA_def_property_ui_text(prop, "Axis", "");
+
+  prop = RNA_def_property(srna, "slice_depth", PROP_FLOAT, PROP_FACTOR);
+  RNA_def_property_range(prop, 0.0, 1.0);
+  R

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list