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

Sriharsha Kotcharlakot noreply at git.blender.org
Fri Jun 26 05:42:17 CEST 2020


Commit: 81785514430bc58d346e49f0f45750e24380cd5f
Author: Sriharsha Kotcharlakot
Date:   Fri Jun 26 09:11:28 2020 +0530
Branches: soc-2020-fluid-tools
https://developer.blender.org/rB81785514430bc58d346e49f0f45750e24380cd5f

Fluid: Added display support for flag grid

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

M	release/scripts/startup/bl_ui/properties_physics_fluid.py
M	source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl
M	source/blender/draw/engines/workbench/workbench_volume.c
M	source/blender/gpu/intern/gpu_draw_smoke.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 b9c11d76754..1f4897d5959 100644
--- a/release/scripts/startup/bl_ui/properties_physics_fluid.py
+++ b/release/scripts/startup/bl_ui/properties_physics_fluid.py
@@ -1257,7 +1257,10 @@ class PHYSICS_PT_viewport_display(PhysicButtonsPanel, Panel):
 
         col = flow.column(align=False)
         col.prop(domain, "display_thickness")
-        col.prop(domain, "display_interpolation")
+
+        if (not (domain.use_color_ramp and domain.coba_field == "FLAGS")):
+            col.prop(domain, "display_interpolation")
+        
         col.separator()
 
         col = flow.column()
@@ -1294,11 +1297,13 @@ class PHYSICS_PT_viewport_display_color(PhysicButtonsPanel, Panel):
         col = layout.column()
         col.active = domain.use_color_ramp
         col.prop(domain, "coba_field")
-        col.prop(domain, "coba_field_scale")
+
+        if (not domain.coba_field == "FLAGS"):
+            col.prop(domain, "coba_field_scale")
 
         col.use_property_split = False
 
-        if (not domain.coba_field[:3] == "PHI"):
+        if (not (domain.coba_field[:3] == "PHI" or domain.coba_field == "FLAGS")):
             col = col.column()
             col.template_color_ramp(domain, "color_ramp", expand=True)
 
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 e61d3473f3d..6934c0a1bf3 100644
--- a/source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl
+++ b/source/blender/draw/engines/workbench/shaders/workbench_volume_frag.glsl
@@ -9,6 +9,7 @@ uniform sampler2D depthBuffer;
 uniform sampler3D densityTexture;
 uniform sampler3D shadowTexture;
 uniform sampler3D flameTexture;
+uniform usampler3D flagTexture;
 uniform sampler1D flameColorTexture;
 uniform sampler1D transferTexture;
 uniform mat4 volumeObjectToTexture;
@@ -24,6 +25,7 @@ uniform float slicePosition;
 uniform int sliceAxis; /* -1 is no slice, 0 is X, 1 is Y, 2 is Z. */
 
 uniform bool showPhi;
+uniform bool showFlags;
 
 #ifdef VOLUME_SLICE
 in vec3 localPos;
@@ -117,26 +119,43 @@ void volume_properties(vec3 ls_pos, out vec3 scattering, out float extinction)
 {
   vec3 co = ls_pos * 0.5 + 0.5;
 #ifdef USE_COBA
-  float val = sample_volume_texture(densityTexture, co).r * gridScale;
   vec4 tval;
   if(showPhi) {
     /* Color mapping for level-set representation */
+    float val = sample_volume_texture(densityTexture, co).r * gridScale;
+    
     val = (val * 0.2 < 1.0) ? val * 0.2 : 1.0;
     val = (val >= -1.0) ? val : -1.0;
 
     if (val >= 0.0) {
-      tval.r = val;
-      tval.g = 0.0;
-      tval.b = 0.5;
+      tval = vec4(val, 0.0, 0.5, 0.06);
     }
     else {
-      tval.r = 0.5;
-      tval.g = 1.0 + val;
-      tval.b = 0.0;
+      tval = vec4(0.5, 1.0 + val, 0.0, 0.06);
     }
-    tval.a = 0.06;
   }
+  else if(showFlags) {
+    /* Color mapping for flags */
+    uint val = texture(flagTexture, co).r;
+    /* Cell types: 1 is Fluid, 2 is Obstacle, 4 is Empty, 16 is Outflow */
+    if (val == uint(1)) {
+      tval = vec4(0.0, 0.0, 0.75, 0.06); /* blue */
+    }
+    else if (val == uint(2)) {
+      tval = vec4(0.2, 0.2, 0.2, 0.06); /* dark gray */
+    }
+    else if (val == uint(4)) {
+      tval = vec4(0.25, 0.0, 0.2, 0.06); /* dark purple */
+    }
+    else if (val == uint(16)) {
+      tval = vec4(0.9, 0.3, 0.0, 0.06); /* orange */
+    }
+    else {
+      tval = vec4(0.5, 0.0, 0.0, 0.06); /* medium red */
+    }
+  } 
   else {
+    float val = sample_volume_texture(densityTexture, co).r * gridScale;
     tval = texture(transferTexture, val);
   }
   tval *= densityScale;
diff --git a/source/blender/draw/engines/workbench/workbench_volume.c b/source/blender/draw/engines/workbench/workbench_volume.c
index 499249e62b2..2311a5f4bf3 100644
--- a/source/blender/draw/engines/workbench/workbench_volume.c
+++ b/source/blender/draw/engines/workbench/workbench_volume.c
@@ -99,6 +99,7 @@ static void workbench_volume_modifier_cache_populate(WORKBENCH_Data *vedata,
                          mds->coba_field == FLUID_DOMAIN_FIELD_PHI_IN ||
                          mds->coba_field == FLUID_DOMAIN_FIELD_PHI_OUT ||
                          mds->coba_field == FLUID_DOMAIN_FIELD_PHI_OBSTACLE);
+  const bool show_flags = (mds->coba_field == FLUID_DOMAIN_FIELD_FLAGS);
   GPUShader *sh = workbench_shader_volume_get(use_slice, mds->use_coba, cubic_interp, true);
 
   if (use_slice) {
@@ -140,12 +141,18 @@ static void workbench_volume_modifier_cache_populate(WORKBENCH_Data *vedata,
   }
 
   if (mds->use_coba) {
-    DRW_shgroup_uniform_texture(grp, "densityTexture", mds->tex_field);
-    if (!show_phi) {
+    if (show_flags) {
+      DRW_shgroup_uniform_texture(grp, "flagTexture", mds->tex_field);
+    }
+    else {
+      DRW_shgroup_uniform_texture(grp, "densityTexture", mds->tex_field);
+    }
+    if (!show_phi && !show_flags) {
       DRW_shgroup_uniform_texture(grp, "transferTexture", mds->tex_coba);
     }
     DRW_shgroup_uniform_float_copy(grp, "gridScale", mds->grid_scale);
     DRW_shgroup_uniform_bool_copy(grp, "showPhi", show_phi);
+    DRW_shgroup_uniform_bool_copy(grp, "showFlags", show_flags);
   }
   else {
     static float white[3] = {1.0f, 1.0f, 1.0f};
diff --git a/source/blender/gpu/intern/gpu_draw_smoke.c b/source/blender/gpu/intern/gpu_draw_smoke.c
index b5618a4954b..faecdcc1827 100644
--- a/source/blender/gpu/intern/gpu_draw_smoke.c
+++ b/source/blender/gpu/intern/gpu_draw_smoke.c
@@ -133,7 +133,8 @@ static void swizzle_texture_channel_single(GPUTexture *tex)
 
 static GPUTexture *create_field_texture(FluidDomainSettings *mds)
 {
-  float *field = NULL;
+  void *field = NULL;
+  eGPUDataFormat data_format = GPU_DATA_FLOAT;
   eGPUTextureFormat texture_format = GPU_R8;
 
   switch (mds->coba_field) {
@@ -195,20 +196,17 @@ static GPUTexture *create_field_texture(FluidDomainSettings *mds)
       field = manta_get_phiobs_in(mds->fluid);
       texture_format = GPU_R16F;
       break;
+    case FLUID_DOMAIN_FIELD_FLAGS:
+      field = manta_smoke_get_flags(mds->fluid);
+      data_format = GPU_DATA_INT;
+      texture_format = GPU_R8UI;
+      break;
     default:
       return NULL;
   }
 
-  GPUTexture *tex = GPU_texture_create_nD(mds->res[0],
-                                          mds->res[1],
-                                          mds->res[2],
-                                          3,
-                                          field,
-                                          texture_format,
-                                          GPU_DATA_FLOAT,
-                                          0,
-                                          true,
-                                          NULL);
+  GPUTexture *tex = GPU_texture_create_nD(
+      mds->res[0], mds->res[1], mds->res[2], 3, field, texture_format, data_format, 0, true, NULL);
 
   swizzle_texture_channel_single(tex);
   return tex;
@@ -354,7 +352,8 @@ void GPU_create_smoke_coba_field(FluidModifierData *mmd)
     if (!mds->tex_coba && !(mds->coba_field == FLUID_DOMAIN_FIELD_PHI ||
                             mds->coba_field == FLUID_DOMAIN_FIELD_PHI_IN ||
                             mds->coba_field == FLUID_DOMAIN_FIELD_PHI_OUT ||
-                            mds->coba_field == FLUID_DOMAIN_FIELD_PHI_OBSTACLE)) {
+                            mds->coba_field == FLUID_DOMAIN_FIELD_PHI_OBSTACLE ||
+                            mds->coba_field == FLUID_DOMAIN_FIELD_FLAGS)) {
       mds->tex_coba = create_transfer_function(TFUNC_COLOR_RAMP, mds->coba);
     }
   }
diff --git a/source/blender/makesdna/DNA_fluid_types.h b/source/blender/makesdna/DNA_fluid_types.h
index 0866ce44fb0..fa2363bc66d 100644
--- a/source/blender/makesdna/DNA_fluid_types.h
+++ b/source/blender/makesdna/DNA_fluid_types.h
@@ -130,6 +130,7 @@ enum {
   FLUID_DOMAIN_FIELD_PHI_IN = 15,
   FLUID_DOMAIN_FIELD_PHI_OUT = 16,
   FLUID_DOMAIN_FIELD_PHI_OBSTACLE = 17,
+  FLUID_DOMAIN_FIELD_FLAGS = 18,
 };
 
 /* Fluid domain types. */
@@ -331,8 +332,9 @@ enum {
 #define FLUID_NAME_PP_MESH "pp_mesh"
 #define FLUID_NAME_FLAGS_MESH "flags_mesh"
 #define FLUID_NAME_LMESH "lMesh"
-#define FLUID_NAME_VELOCITYVEC_MESH "vertex_velocities_mesh" /* == OpenVDB grid attribute name. \
-                                                              */
+#define FLUID_NAME_VELOCITYVEC_MESH \
+  "vertex_velocities_mesh" /* == OpenVDB grid attribute name. \
+                            */
 #define FLUID_NAME_VELOCITY_MESH "velocity_mesh"
 #define FLUID_NAME_PINDEX_MESH "pindex_mesh"
 #define FLUID_NAME_GPI_MESH "gpi_mesh"
@@ -356,9 +358,10 @@ enum {
 #define FLUID_NAME_NORMAL_PARTICLES "normal_secondary"
 #define FLUID_NAME_NEIGHBORRATIO_PARTICLES "neighbor_ratio_secondary"
 #define FLUID_NAME_TRAPPEDAIR_PARTICLES \
-  "trapped_air_secondary"                                     /* == OpenVDB grid attribute name. */
-#define FLUID_NAME_WAVECREST_PARTICLES "wave_crest_secondary" /* == OpenVDB grid attribute name. \
-                                                               */
+  "trapped_air_secondary" /* == OpenVDB grid attribute name. */
+#define FLUID_NAME_WAVECREST_PARTICLES \
+  "wave_crest_secondary" /* == OpenVDB grid attribute name. \
+                          */
 #define FLUID_NAME_KINETICENERGY_PARTICLES \
   "kinetic_energy_secondary" /* == OpenVDB grid attribute name. */
 
diff --git a/source/blender/makesrna/intern/rna_fluid.c b/source/blender/makesrna/intern/rna_fluid.c
index 8b3eb96c385..15ab1eb1555 100644
--- a/source/blender/makesrna/intern/rna_fluid.c
+++ b/source/blender/makesrna/intern/rna_fluid.c
@@ -1025,6 +1025,13 @@ static const EnumPropertyItem *rna_Fluid_cobafield_itemf(bContext *UNUSED(C),
   EnumPropertyItem tmp = {0, "", 0, "", ""};
   int totitem = 0;
 
+  tmp.value = FLUID_DOMAIN_FIELD_FLAGS;
+  tmp.identifier = "FLAGS";
+  tmp.icon = 0;
+  tmp.name = "Flags";
+  tmp.description = "Flag grid of the fluid domain";
+  RNA_enum_item_add(&item, &totitem, &tmp);
+
   tmp.value = FLUID_DOMAIN_FIELD_VELOCITY_X;
   tmp.identifier = "VELOCITY_X";
   tmp.icon = 0;



More information about the Bf-blender-cvs mailing list