[Bf-blender-cvs] [d723443821c] soc-2020-fluid-tools: Fluid: Added display support for grid lines

Sriharsha Kotcharlakot noreply at git.blender.org
Sat Jun 27 20:27:07 CEST 2020


Commit: d723443821ca8046b62a2c230e554e091be3f246
Author: Sriharsha Kotcharlakot
Date:   Sat Jun 27 23:56:40 2020 +0530
Branches: soc-2020-fluid-tools
https://developer.blender.org/rBd723443821ca8046b62a2c230e554e091be3f246

Fluid: Added display support for grid lines

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

M	release/scripts/startup/bl_ui/properties_physics_fluid.py
M	source/blender/blenkernel/intern/fluid.c
M	source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl
M	source/blender/draw/engines/workbench/workbench_volume.c
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 1f4897d5959..2aeb56d1ae7 100644
--- a/release/scripts/startup/bl_ui/properties_physics_fluid.py
+++ b/release/scripts/startup/bl_ui/properties_physics_fluid.py
@@ -1269,6 +1269,7 @@ class PHYSICS_PT_viewport_display(PhysicButtonsPanel, Panel):
         if not do_full_slicing:
             col.prop(domain, "slice_axis")
             col.prop(domain, "slice_depth")
+            col.prop(domain, "show_gridlines", text="Show Gridlines")
 
         col = col.column()
         col.active = do_full_slicing
diff --git a/source/blender/blenkernel/intern/fluid.c b/source/blender/blenkernel/intern/fluid.c
index 8be354b5401..ddd51b015fe 100644
--- a/source/blender/blenkernel/intern/fluid.c
+++ b/source/blender/blenkernel/intern/fluid.c
@@ -4960,6 +4960,7 @@ void BKE_fluid_modifier_create_type_data(struct FluidModifierData *mmd)
     mmd->domain->slice_per_voxel = 5.0f;
     mmd->domain->slice_depth = 0.5f;
     mmd->domain->display_thickness = 1.0f;
+    mmd->domain->show_gridlines = false;
     mmd->domain->coba = NULL;
     mmd->domain->grid_scale = 1.0f;
     mmd->domain->vector_scale = 1.0f;
@@ -5198,6 +5199,7 @@ void BKE_fluid_modifier_copy(const struct FluidModifierData *mmd,
     tmds->slice_per_voxel = mds->slice_per_voxel;
     tmds->slice_depth = mds->slice_depth;
     tmds->display_thickness = mds->display_thickness;
+    tmds->show_gridlines = mds->show_gridlines;
     if (mds->coba) {
       tmds->coba = MEM_dupallocN(mds->coba);
     }
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl b/source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl
index c349a7475b7..0c4ede901b3 100644
--- a/source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl
+++ b/source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl
@@ -26,6 +26,7 @@ uniform int sliceAxis; /* -1 is no slice, 0 is X, 1 is Y, 2 is Z. */
 
 uniform bool showPhi;
 uniform bool showFlags;
+uniform bool showGridlines;
 
 #ifdef VOLUME_SLICE
 in vec3 localPos;
@@ -53,6 +54,25 @@ float line_unit_box_intersect_dist(vec3 lineorigin, vec3 linedirection)
   return max_v3(furthestplane);
 }
 
+bool on_gridline(sampler3D ima, vec3 co)
+{
+  if (!showGridlines) {
+    return false;
+  }
+  vec3 texel_size = 1.0 / vec3(textureSize(ima, 0).xyz);
+  vec3 offset = mod(co, texel_size);
+  offset = min(offset, texel_size - offset);
+  vec3 gridline_thickness = 0.05 * texel_size;
+  if (((sliceAxis == 0) && (offset.y < gridline_thickness.y || offset.z < gridline_thickness.z)) ||
+      ((sliceAxis == 1) && (offset.x < gridline_thickness.x || offset.z < gridline_thickness.z)) ||
+      ((sliceAxis == 2) && (offset.x < gridline_thickness.x || offset.y < gridline_thickness.y))) {
+    return true;
+  }
+  else {
+    return false;
+  }
+}
+
 #define sample_trilinear(ima, co) texture(ima, co)
 
 vec4 sample_tricubic(sampler3D ima, vec3 co)
@@ -118,6 +138,14 @@ vec4 sample_raw(sampler3D ima, vec3 co)
 void volume_properties(vec3 ls_pos, out vec3 scattering, out float extinction)
 {
   vec3 co = ls_pos * 0.5 + 0.5;
+#ifdef VOLUME_SLICE
+  bool gridline = (showFlags) ? on_gridline(flagTexture, co) : on_gridline(densityTexture, co);
+  if (gridline) {
+    scattering = vec3(0.0, 0.0, 0.0);
+    extinction = 50.0;
+    return;
+  }
+#endif
 #ifdef USE_COBA
   vec4 tval;
   if(showPhi) {
diff --git a/source/blender/draw/engines/workbench/workbench_volume.c b/source/blender/draw/engines/workbench/workbench_volume.c
index 2311a5f4bf3..8dc60a7f72c 100644
--- a/source/blender/draw/engines/workbench/workbench_volume.c
+++ b/source/blender/draw/engines/workbench/workbench_volume.c
@@ -118,6 +118,7 @@ static void workbench_volume_modifier_cache_populate(WORKBENCH_Data *vedata,
     DRW_shgroup_uniform_float_copy(grp, "slicePosition", mds->slice_depth);
     DRW_shgroup_uniform_int_copy(grp, "sliceAxis", axis);
     DRW_shgroup_uniform_float_copy(grp, "stepLength", step_length);
+    DRW_shgroup_uniform_bool_copy(grp, "showGridlines", mds->show_gridlines);
     DRW_shgroup_state_disable(grp, DRW_STATE_CULL_FRONT);
   }
   else {
diff --git a/source/blender/makesdna/DNA_fluid_types.h b/source/blender/makesdna/DNA_fluid_types.h
index fa2363bc66d..8300151d88d 100644
--- a/source/blender/makesdna/DNA_fluid_types.h
+++ b/source/blender/makesdna/DNA_fluid_types.h
@@ -616,13 +616,14 @@ typedef struct FluidDomainSettings {
   float vector_scale;
   char axis_slice_method;
   char slice_axis;
+  char show_gridlines;
   char draw_velocity;
   char vector_draw_type;
   char vector_draw_grid_type;
   char use_coba;
   char coba_field; /* Simulation field used for the color mapping. */
   char interp_method;
-  char _pad9[4]; /* Unused. */
+  char _pad9[3]; /* 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 15ab1eb1555..995fb0f06f0 100644
--- a/source/blender/makesrna/intern/rna_fluid.c
+++ b/source/blender/makesrna/intern/rna_fluid.c
@@ -2360,6 +2360,11 @@ static void rna_def_fluid_domain_settings(BlenderRNA *brna)
       prop, "Interpolation", "Interpolation method to use for smoke/fire volumes in solid mode");
   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
 
+  prop = RNA_def_property(srna, "show_gridlines", PROP_BOOLEAN, PROP_NONE);
+  RNA_def_property_boolean_sdna(prop, NULL, "show_gridlines", 0);
+  RNA_def_property_ui_text(prop, "Gridlines", "Show gridlines");
+  RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
+
   prop = RNA_def_property(srna, "show_velocity", PROP_BOOLEAN, PROP_NONE);
   RNA_def_property_boolean_sdna(prop, NULL, "draw_velocity", 0);
   RNA_def_property_ui_text(



More information about the Bf-blender-cvs mailing list