[Bf-blender-cvs] [d73b481baeb] soc-2020-fluid-tools: Fluid: Added option to control the scaling of display vectors with their magnitudes

Sriharsha Kotcharlakot noreply at git.blender.org
Thu Jul 30 10:00:41 CEST 2020


Commit: d73b481baeb931fea33a5441dc5c699adebd7003
Author: Sriharsha Kotcharlakot
Date:   Thu Jul 30 13:30:20 2020 +0530
Branches: soc-2020-fluid-tools
https://developer.blender.org/rBd73b481baeb931fea33a5441dc5c699adebd7003

Fluid: Added option to control the scaling of display vectors with their magnitudes

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

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_velocity_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 ecf1a62b23c..360d604403d 100644
--- a/release/scripts/startup/bl_ui/properties_physics_fluid.py
+++ b/release/scripts/startup/bl_ui/properties_physics_fluid.py
@@ -1342,6 +1342,7 @@ class PHYSICS_PT_viewport_display_debug(PhysicButtonsPanel, Panel):
         if ((not domain.use_guide) and domain.vector_grid_type == 'GUIDE_VELOCITY'):
             note = layout.split()
             note.label(icon='INFO', text="Enable Guides first! Defaulting to Fluid Velocity.")
+        col.prop(domain, "vector_scale_with_magnitude")
         col.prop(domain, "vector_scale")
 
 class PHYSICS_PT_viewport_display_advanced(PhysicButtonsPanel, Panel):
diff --git a/source/blender/blenkernel/intern/fluid.c b/source/blender/blenkernel/intern/fluid.c
index 8a56cc0a105..ccf4ed8acc3 100644
--- a/source/blender/blenkernel/intern/fluid.c
+++ b/source/blender/blenkernel/intern/fluid.c
@@ -4971,6 +4971,7 @@ void BKE_fluid_modifier_create_type_data(struct FluidModifierData *fmd)
     fmd->domain->vector_scale = 1.0f;
     fmd->domain->vector_draw_type = VECTOR_DRAW_NEEDLE;
     fmd->domain->vector_draw_grid_type = VECTOR_DRAW_GRID_FLUID_VELOCITY;
+    fmd->domain->vector_scale_with_magnitude = true;
     fmd->domain->use_coba = false;
     fmd->domain->coba_field = FLUID_DOMAIN_FIELD_DENSITY;
     fmd->domain->gridlines_color_field = 0;
@@ -5221,6 +5222,7 @@ void BKE_fluid_modifier_copy(const struct FluidModifierData *fmd,
     tfds->vector_scale = fds->vector_scale;
     tfds->vector_draw_type = fds->vector_draw_type;
     tfds->vector_draw_grid_type = fds->vector_draw_grid_type;
+    tfds->vector_scale_with_magnitude = fds->vector_scale_with_magnitude;
     tfds->use_coba = fds->use_coba;
     tfds->coba_field = fds->coba_field;
     tfds->grid_scale = fds->grid_scale;
diff --git a/source/blender/draw/engines/overlay/overlay_extra.c b/source/blender/draw/engines/overlay/overlay_extra.c
index a1754cb91ec..4cf7f958426 100644
--- a/source/blender/draw/engines/overlay/overlay_extra.c
+++ b/source/blender/draw/engines/overlay/overlay_extra.c
@@ -1449,6 +1449,7 @@ static void OVERLAY_volume_extra(OVERLAY_ExtraCallBuffers *cb,
     DRW_shgroup_uniform_vec3_copy(grp, "domainOriginOffset", fds->p0);
     DRW_shgroup_uniform_ivec3_copy(grp, "adaptiveCellOffset", fds->res_min);
     DRW_shgroup_uniform_int_copy(grp, "sliceAxis", slice_axis);
+    DRW_shgroup_uniform_bool_copy(grp, "scaleWithMagnitude", fds->vector_scale_with_magnitude);
     DRW_shgroup_call_procedural_lines(grp, ob, line_count);
   }
 
diff --git a/source/blender/draw/engines/overlay/shaders/volume_velocity_vert.glsl b/source/blender/draw/engines/overlay/shaders/volume_velocity_vert.glsl
index 752694301f7..4cfd2ca500e 100644
--- a/source/blender/draw/engines/overlay/shaders/volume_velocity_vert.glsl
+++ b/source/blender/draw/engines/overlay/shaders/volume_velocity_vert.glsl
@@ -5,6 +5,7 @@ uniform sampler3D velocityZ;
 uniform float displaySize = 1.0;
 uniform float slicePosition;
 uniform int sliceAxis; /* -1 is no slice, 0 is X, 1 is Y, 2 is Z. */
+uniform bool scaleWithMagnitude = false;
 
 /* FluidDomainSettings.cell_size */
 uniform vec3 cellSize;
@@ -104,12 +105,24 @@ void main()
 
   finalColor = vec4(weight_to_color(length(velocity)), 1.0);
 
-#ifdef USE_NEEDLE
+  float vector_length = 1.0;
+
+  if (scaleWithMagnitude) {
+    vector_length = length(velocity);
+  }
+  else if (length(velocity) == 0.0) {
+    vector_length = 0.0;
+  }
+
   mat3 rot_mat = rotation_from_vector(velocity);
+
+#ifdef USE_NEEDLE
   vec3 rotated_pos = rot_mat * corners[indices[gl_VertexID % 12]];
-  pos += rotated_pos * length(velocity) * displaySize * cellSize;
+  pos += rotated_pos * vector_length * displaySize * cellSize;
 #else
-  pos += ((gl_VertexID % 2) == 1) ? velocity * displaySize * cellSize : vec3(0.0);
+  vec3 rotated_pos = rot_mat * vec3(0.0, 0.0, 1.0);
+  pos += ((gl_VertexID % 2) == 1) ? rotated_pos * vector_length * displaySize * cellSize :
+                                    vec3(0.0);
 #endif
 
   vec3 world_pos = point_object_to_world(pos);
diff --git a/source/blender/makesdna/DNA_fluid_types.h b/source/blender/makesdna/DNA_fluid_types.h
index fd72f29ce57..c539418dc6a 100644
--- a/source/blender/makesdna/DNA_fluid_types.h
+++ b/source/blender/makesdna/DNA_fluid_types.h
@@ -644,24 +644,24 @@ typedef struct FluidDomainSettings {
   char draw_velocity;
   char vector_draw_type;
   char vector_draw_grid_type;
+  char vector_scale_with_magnitude;
   char use_coba;
   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 gridlines_cell_filter;
-  char _pad9[1]; /* Unused. */
 
   /* OpenVDB cache options. */
   int openvdb_compression;
   float clipping;
   char openvdb_data_depth;
-  char _pad10[7]; /* Unused. */
+  char _pad9[7]; /* Unused. */
 
   /* -- Deprecated / unsed options (below). -- */
 
   /* View options. */
   int viewsettings;
-  char _pad11[4]; /* Unused. */
+  char _pad10[4]; /* Unused. */
 
   /* Pointcache options. */
   /* Smoke uses only one cache from now on (index [0]), but keeping the array for now for reading
@@ -671,7 +671,7 @@ typedef struct FluidDomainSettings {
   int cache_comp;
   int cache_high_comp;
   char cache_file_format;
-  char _pad12[7]; /* Unused. */
+  char _pad11[7]; /* Unused. */
 
 } FluidDomainSettings;
 
diff --git a/source/blender/makesrna/intern/rna_fluid.c b/source/blender/makesrna/intern/rna_fluid.c
index 767ac218ec4..01a95bca01c 100644
--- a/source/blender/makesrna/intern/rna_fluid.c
+++ b/source/blender/makesrna/intern/rna_fluid.c
@@ -2498,6 +2498,11 @@ static void rna_def_fluid_domain_settings(BlenderRNA *brna)
   RNA_def_property_ui_text(prop, "Grid Type", "Type of vector grid to be displayed");
   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
 
+  prop = RNA_def_property(srna, "vector_scale_with_magnitude", PROP_BOOLEAN, PROP_NONE);
+  RNA_def_property_boolean_sdna(prop, NULL, "vector_scale_with_magnitude", 0);
+  RNA_def_property_ui_text(prop, "Magnitude", "Scale vectors with their magnitudes");
+  RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
+
   prop = RNA_def_property(srna, "vector_scale", PROP_FLOAT, PROP_NONE);
   RNA_def_property_float_sdna(prop, NULL, "vector_scale");
   RNA_def_property_range(prop, 0.0, 1000.0);



More information about the Bf-blender-cvs mailing list