[Bf-blender-cvs] [c913a643d0f] soc-2020-fluid-tools: Fluid: Added cell filtering options for range highlighting

Sriharsha Kotcharlakot noreply at git.blender.org
Fri Jul 17 10:32:54 CEST 2020


Commit: c913a643d0ff7f0e30cb579e3a33666abc60305a
Author: Sriharsha Kotcharlakot
Date:   Fri Jul 17 14:02:06 2020 +0530
Branches: soc-2020-fluid-tools
https://developer.blender.org/rBc913a643d0ff7f0e30cb579e3a33666abc60305a

Fluid: Added cell filtering options for range highlighting

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

M	release/scripts/startup/bl_ui/properties_physics_fluid.py
M	source/blender/blenkernel/intern/fluid.c
M	source/blender/draw/engines/overlay/overlay_extra.c
M	source/blender/draw/engines/overlay/shaders/volume_gridlines_vert.glsl
M	source/blender/makesdna/DNA_fluid_types.h
M	source/blender/makesrna/intern/rna_fluid.c

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

diff --git a/release/scripts/startup/bl_ui/properties_physics_fluid.py b/release/scripts/startup/bl_ui/properties_physics_fluid.py
index 1070b0976d9..3fe40cac956 100644
--- a/release/scripts/startup/bl_ui/properties_physics_fluid.py
+++ b/release/scripts/startup/bl_ui/properties_physics_fluid.py
@@ -1366,6 +1366,7 @@ class PHYSICS_PT_viewport_display_advanced(PhysicButtonsPanel, Panel):
                 col.prop(domain, "gridlines_lower_bound")
                 col.prop(domain, "gridlines_upper_bound")
                 col.prop(domain, "gridlines_range_color")
+                col.prop(domain, "gridlines_cell_filter")
             else:
                 note = layout.split()
                 if (not domain.use_color_ramp):
diff --git a/source/blender/blenkernel/intern/fluid.c b/source/blender/blenkernel/intern/fluid.c
index cfa4328c5ab..d88f0b2ebd0 100644
--- a/source/blender/blenkernel/intern/fluid.c
+++ b/source/blender/blenkernel/intern/fluid.c
@@ -5006,6 +5006,7 @@ void BKE_fluid_modifier_create_type_data(struct FluidModifierData *fmd)
     fmd->domain->gridlines_range_color[1] = 0.0f;
     fmd->domain->gridlines_range_color[2] = 0.0f;
     fmd->domain->gridlines_range_color[3] = 1.0f;
+    fmd->domain->gridlines_cell_filter = FLUID_CELL_TYPE_NONE;
 
     /* -- Deprecated / unsed options (below)-- */
 
@@ -5255,6 +5256,7 @@ void BKE_fluid_modifier_copy(const struct FluidModifierData *fmd,
     tfds->gridlines_range_color[1] = fds->gridlines_range_color[1];
     tfds->gridlines_range_color[2] = fds->gridlines_range_color[2];
     tfds->gridlines_range_color[3] = fds->gridlines_range_color[3];
+    tfds->gridlines_cell_filter = fds->gridlines_cell_filter;
 
     /* -- Deprecated / unsed options (below)-- */
 
diff --git a/source/blender/draw/engines/overlay/overlay_extra.c b/source/blender/draw/engines/overlay/overlay_extra.c
index 178f9d12cbd..67d6c97d88f 100644
--- a/source/blender/draw/engines/overlay/overlay_extra.c
+++ b/source/blender/draw/engines/overlay/overlay_extra.c
@@ -1443,7 +1443,7 @@ static void OVERLAY_volume_extra(OVERLAY_ExtraCallBuffers *cb,
     DRW_shgroup_uniform_ivec3_copy(grp, "adaptiveCellOffset", fds->res_min);
     DRW_shgroup_uniform_int_copy(grp, "sliceAxis", slice_axis);
 
-    if (color_with_flags) {
+    if (color_with_flags || color_range) {
       GPU_create_fluid_flags(fmd);
       DRW_shgroup_uniform_texture(grp, "flagTexture", fds->tex_flags);
     }
@@ -1454,6 +1454,7 @@ static void OVERLAY_volume_extra(OVERLAY_ExtraCallBuffers *cb,
       DRW_shgroup_uniform_float_copy(grp, "lowerBound", fds->gridlines_lower_bound);
       DRW_shgroup_uniform_float_copy(grp, "upperBound", fds->gridlines_upper_bound);
       DRW_shgroup_uniform_vec4_copy(grp, "rangeColor", fds->gridlines_range_color);
+      DRW_shgroup_uniform_int_copy(grp, "cellFilter", fds->gridlines_cell_filter);
     }
 
     DRW_shgroup_call_procedural_lines(grp, ob, line_count);
diff --git a/source/blender/draw/engines/overlay/shaders/volume_gridlines_vert.glsl b/source/blender/draw/engines/overlay/shaders/volume_gridlines_vert.glsl
index 9af3a1e667d..163c273daaa 100644
--- a/source/blender/draw/engines/overlay/shaders/volume_gridlines_vert.glsl
+++ b/source/blender/draw/engines/overlay/shaders/volume_gridlines_vert.glsl
@@ -10,7 +10,7 @@ uniform vec3 domainOriginOffset;
 /* FluidDomainSettings.res_min */
 uniform ivec3 adaptiveCellOffset;
 
-#ifdef SHOW_FLAGS
+#if defined(SHOW_FLAGS) || defined(SHOW_RANGE)
 uniform usampler3D flagTexture;
 #endif
 
@@ -19,6 +19,7 @@ uniform sampler3D fieldTexture;
 uniform float lowerBound = 0.0;
 uniform float upperBound = 0.0;
 uniform vec4 rangeColor;
+uniform int cellFilter;
 #endif
 
 flat out vec4 finalColor;
@@ -92,15 +93,20 @@ void main()
 
   finalColor = vec4(0.0, 0.0, 0.0, 1.0);
 
-#ifdef SHOW_FLAGS
-  uint flag = texelFetch(flagTexture, cell_co + ivec3(cell_offset), 0).r; 
+#if defined(SHOW_FLAGS) || defined(SHOW_RANGE)
+  uint flag = texelFetch(flagTexture, cell_co + ivec3(cell_offset), 0).r;
+#endif
+
+#ifdef SHOW_FLAGS 
   finalColor = flag_to_color(flag);
 #endif
 
 #ifdef SHOW_RANGE
   float value = texelFetch(fieldTexture, cell_co + ivec3(cell_offset), 0).r;
   if (value >= lowerBound && value <= upperBound) {
-    finalColor = rangeColor;
+    if (cellFilter == 0 || bool(uint(cellFilter) & flag)) {
+      finalColor = rangeColor;
+    }
   }
 #endif
 
diff --git a/source/blender/makesdna/DNA_fluid_types.h b/source/blender/makesdna/DNA_fluid_types.h
index 805149ab128..91d4e91f96e 100644
--- a/source/blender/makesdna/DNA_fluid_types.h
+++ b/source/blender/makesdna/DNA_fluid_types.h
@@ -139,6 +139,16 @@ enum {
   FLUID_GRIDLINE_COLOR_TYPE_RANGE = 2,
 };
 
+/* Fluid cell types  */
+enum {
+  FLUID_CELL_TYPE_NONE = 0,
+  FLUID_CELL_TYPE_FLUID = (1 << 0),
+  FLUID_CELL_TYPE_OBSTACLE = (1 << 1),
+  FLUID_CELL_TYPE_EMPTY = (1 << 2),
+  FLUID_CELL_TYPE_INFLOW = (1 << 3),
+  FLUID_CELL_TYPE_OUTFLOW = (1 << 4),
+};
+
 /* Fluid domain types. */
 enum {
   FLUID_DOMAIN_TYPE_GAS = 0,
@@ -635,7 +645,8 @@ typedef struct FluidDomainSettings {
   char coba_field; /* Simulation field used for the color mapping. */
   char interp_method;
   char gridlines_color_field; /* Simulation field used to color map onto gridlines. */
-  char _pad9[2];              /* Unused. */
+  char gridlines_cell_filter;
+  char _pad9[1]; /* Unused. */
 
   /* OpenVDB cache options. */
   int openvdb_compression;
diff --git a/source/blender/makesrna/intern/rna_fluid.c b/source/blender/makesrna/intern/rna_fluid.c
index 874d672e240..605a13fee58 100644
--- a/source/blender/makesrna/intern/rna_fluid.c
+++ b/source/blender/makesrna/intern/rna_fluid.c
@@ -1310,6 +1310,24 @@ static void rna_def_fluid_domain_settings(BlenderRNA *brna)
       {0, NULL, 0, NULL, NULL},
   };
 
+  static const EnumPropertyItem gridlines_cell_filter_items[] = {
+      {FLUID_CELL_TYPE_NONE, "NONE", 0, "None", "Highlight the cells regardless of their type"},
+      {FLUID_CELL_TYPE_FLUID, "FLUID", 0, "Fluid", "Highlight only the cells of type Fluid"},
+      {FLUID_CELL_TYPE_OBSTACLE,
+       "OBSTACLE",
+       0,
+       "Obstacle",
+       "Highlight only the cells of type Obstacle"},
+      {FLUID_CELL_TYPE_EMPTY, "EMPTY", 0, "Empty", "Highlight only the cells of type Empty"},
+      {FLUID_CELL_TYPE_INFLOW, "INFLOW", 0, "Inflow", "Highlight only the cells of type Inflow"},
+      {FLUID_CELL_TYPE_OUTFLOW,
+       "OUTFLOW",
+       0,
+       "Outflow",
+       "Highlight only the cells of type Outflow"},
+      {0, NULL, 0, NULL, NULL},
+  };
+
   static const EnumPropertyItem sndparticle_boundary_items[] = {
       {SNDPARTICLE_BOUNDARY_DELETE,
        "DELETE",
@@ -2491,6 +2509,12 @@ static void rna_def_fluid_domain_settings(BlenderRNA *brna)
   RNA_def_property_ui_text(prop, "Color", "Color used to highlight the range");
   RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, NULL);
 
+  prop = RNA_def_property(srna, "gridlines_cell_filter", PROP_ENUM, PROP_NONE);
+  RNA_def_property_enum_sdna(prop, NULL, "gridlines_cell_filter");
+  RNA_def_property_enum_items(prop, gridlines_cell_filter_items);
+  RNA_def_property_ui_text(prop, "Cell Type", "Cell type to be highlighted");
+  RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
+
   /* -- Deprecated / unsed options (below)-- */
 
   /* pointcache options */



More information about the Bf-blender-cvs mailing list