[Bf-blender-cvs] [eb2a512c9ce] soc-2020-fluid-tools: Fluid: Added Color Mapping options for liquid domain

Sriharsha Kotcharlakot noreply at git.blender.org
Thu Jun 4 16:24:58 CEST 2020


Commit: eb2a512c9cead8828b560afb573879e82678f9cd
Author: Sriharsha Kotcharlakot
Date:   Thu Jun 4 19:54:23 2020 +0530
Branches: soc-2020-fluid-tools
https://developer.blender.org/rBeb2a512c9cead8828b560afb573879e82678f9cd

Fluid: Added Color Mapping options for liquid domain

Added display support for phi grid.

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

M	intern/mantaflow/extern/manta_fluid_API.h
M	intern/mantaflow/intern/manta_fluid_API.cpp
M	release/scripts/startup/bl_ui/properties_physics_fluid.py
M	source/blender/blenlib/BLI_math_color.h
M	source/blender/blenlib/intern/math_color.c
M	source/blender/draw/engines/workbench/workbench_engine.c
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/intern/mantaflow/extern/manta_fluid_API.h b/intern/mantaflow/extern/manta_fluid_API.h
index 7825ad14d7d..3632455d576 100644
--- a/intern/mantaflow/extern/manta_fluid_API.h
+++ b/intern/mantaflow/extern/manta_fluid_API.h
@@ -108,6 +108,7 @@ float *manta_get_phiobs_in(struct MANTA *fluid);
 float *manta_get_phiobsstatic_in(struct MANTA *fluid);
 float *manta_get_phiout_in(struct MANTA *fluid);
 float *manta_get_phioutstatic_in(struct MANTA *fluid);
+float *manta_get_phi(struct MANTA *fluid);
 
 /* Smoke functions */
 void manta_smoke_export_script(struct MANTA *smoke, struct FluidModifierData *mmd);
diff --git a/intern/mantaflow/intern/manta_fluid_API.cpp b/intern/mantaflow/intern/manta_fluid_API.cpp
index 49bc224b3fa..4e1c3bddd9f 100644
--- a/intern/mantaflow/intern/manta_fluid_API.cpp
+++ b/intern/mantaflow/intern/manta_fluid_API.cpp
@@ -394,6 +394,10 @@ float *manta_get_phioutstatic_in(MANTA *fluid)
 {
   return fluid->getPhiOutStaticIn();
 }
+float *manta_get_phi(MANTA *fluid)
+{
+  return fluid->getPhi();
+}
 
 /* Smoke functions */
 void manta_smoke_export_script(MANTA *smoke, FluidModifierData *mmd)
diff --git a/release/scripts/startup/bl_ui/properties_physics_fluid.py b/release/scripts/startup/bl_ui/properties_physics_fluid.py
index 3834cffb4e3..76c52c80a34 100644
--- a/release/scripts/startup/bl_ui/properties_physics_fluid.py
+++ b/release/scripts/startup/bl_ui/properties_physics_fluid.py
@@ -1278,7 +1278,7 @@ class PHYSICS_PT_viewport_display_color(PhysicButtonsPanel, Panel):
 
     @classmethod
     def poll(cls, context):
-        return (PhysicButtonsPanel.poll_gas_domain(context))
+        return (PhysicButtonsPanel.poll_fluid_domain(context))
 
     def draw_header(self, context):
         md = context.fluid.domain_settings
@@ -1292,12 +1292,16 @@ class PHYSICS_PT_viewport_display_color(PhysicButtonsPanel, Panel):
         domain = context.fluid.domain_settings
         col = layout.column()
         col.active = domain.use_color_ramp
-        col.prop(domain, "coba_field")
+        if (domain.domain_type == "GAS"):
+            col.prop(domain, "coba_field_gas")
+        else:
+            col.prop(domain, "coba_field_liquid")
 
         col.use_property_split = False
 
-        col = col.column()
-        col.template_color_ramp(domain, "color_ramp", expand=True)
+        if (domain.domain_type == "GAS" or (not domain.coba_field_liquid == "PHI")):
+            col = col.column()
+            col.template_color_ramp(domain, "color_ramp", expand=True)
 
 
 class PHYSICS_PT_viewport_display_debug(PhysicButtonsPanel, Panel):
diff --git a/source/blender/blenlib/BLI_math_color.h b/source/blender/blenlib/BLI_math_color.h
index f247e09a83b..2b563cba80c 100644
--- a/source/blender/blenlib/BLI_math_color.h
+++ b/source/blender/blenlib/BLI_math_color.h
@@ -145,6 +145,7 @@ MINLINE void rgba_uchar_args_test_set(unsigned char col[4],
 MINLINE void cpack_cpy_3ub(unsigned char r_col[3], const unsigned int pack);
 
 void blackbody_temperature_to_rgb_table(float *r_table, int width, float min, float max);
+void phi_to_rgb(float *r_table, int width, float min, float max);
 
 /********* lift/gamma/gain / ASC-CDL conversion ***********/
 
diff --git a/source/blender/blenlib/intern/math_color.c b/source/blender/blenlib/intern/math_color.c
index cc29ebe4f20..fd33d508aa1 100644
--- a/source/blender/blenlib/intern/math_color.c
+++ b/source/blender/blenlib/intern/math_color.c
@@ -711,3 +711,29 @@ void blackbody_temperature_to_rgb_table(float *r_table, int width, float min, fl
     r_table[i * 4 + 3] = 0.0f;
   }
 }
+
+void phi_to_rgb(float *r_table, int width, float min, float max)
+{
+  for(int i = 0; i < width; i++) {
+    float value = min + (max - min) / (float)width * (float)i;
+
+    float rgb[3];
+
+    value = (value * 0.2 < 1.0f) ? value * 0.2f : 1.0f;
+    value = (value >= -1.0f) ? value : -1.0f;
+
+    if (value >= 0.0f) {
+      rgb[0] = value;
+      rgb[1] = 0.0f;
+      rgb[2] = 0.5f;
+    }
+    else {
+      rgb[0] = 0.5f;
+      rgb[1] = 1.0f + value;
+      rgb[2] = 0.0f;
+    }
+
+    copy_v3_v3(&r_table[i * 4], rgb);
+    r_table[i * 4 + 3] = 0.0f;
+  }
+}
\ No newline at end of file
diff --git a/source/blender/draw/engines/workbench/workbench_engine.c b/source/blender/draw/engines/workbench/workbench_engine.c
index 511dd563b46..c3084c0ed0b 100644
--- a/source/blender/draw/engines/workbench/workbench_engine.c
+++ b/source/blender/draw/engines/workbench/workbench_engine.c
@@ -324,9 +324,11 @@ void workbench_cache_populate(void *ved, Object *ob)
     ModifierData *md = BKE_modifiers_findby_type(ob, eModifierType_Fluid);
     if (md && BKE_modifier_is_enabled(wpd->scene, md, eModifierMode_Realtime)) {
       FluidModifierData *fmd = (FluidModifierData *)md;
-      if (fmd->domain && fmd->domain->type == FLUID_DOMAIN_TYPE_GAS) {
+      if (fmd->domain) {
         workbench_volume_cache_populate(vedata, wpd->scene, ob, md, V3D_SHADING_SINGLE_COLOR);
-        return; /* Do not draw solid in this case. */
+        if (fmd->domain->type == FLUID_DOMAIN_TYPE_GAS) {
+          return; /* Do not draw solid in this case. */
+        }
       }
     }
   }
diff --git a/source/blender/draw/engines/workbench/workbench_volume.c b/source/blender/draw/engines/workbench/workbench_volume.c
index 21cb567aaae..6ed29ee5f16 100644
--- a/source/blender/draw/engines/workbench/workbench_volume.c
+++ b/source/blender/draw/engines/workbench/workbench_volume.c
@@ -73,7 +73,7 @@ static void workbench_volume_modifier_cache_populate(WORKBENCH_Data *vedata,
   DRWShadingGroup *grp = NULL;
 
   /* Don't try to show liquid domains here */
-  if (!mds->fluid || !(mds->type == FLUID_DOMAIN_TYPE_GAS)) {
+  if (!mds->fluid) {
     return;
   }
 
@@ -81,10 +81,10 @@ static void workbench_volume_modifier_cache_populate(WORKBENCH_Data *vedata,
   if (mds->use_coba) {
     GPU_create_smoke_coba_field(mmd);
   }
-  else if (!(mds->flags & FLUID_DOMAIN_USE_NOISE)) {
+  else if (!(mds->flags & FLUID_DOMAIN_USE_NOISE) && (mds->type == FLUID_DOMAIN_TYPE_GAS)) {
     GPU_create_smoke(mmd, 0);
   }
-  else if (mds->flags & FLUID_DOMAIN_USE_NOISE) {
+  else if ((mds->flags & FLUID_DOMAIN_USE_NOISE) && (mds->type == FLUID_DOMAIN_TYPE_GAS)) {
     GPU_create_smoke(mmd, 1);
   }
 
diff --git a/source/blender/gpu/intern/gpu_draw_smoke.c b/source/blender/gpu/intern/gpu_draw_smoke.c
index 9fb5c345584..f218ff3283b 100644
--- a/source/blender/gpu/intern/gpu_draw_smoke.c
+++ b/source/blender/gpu/intern/gpu_draw_smoke.c
@@ -52,6 +52,7 @@
 enum {
   TFUNC_FLAME_SPECTRUM = 0,
   TFUNC_COLOR_RAMP = 1,
+  TFUNC_PHI_SPECTRUM = 2,
 };
 
 #  define TFUNC_WIDTH 256
@@ -102,6 +103,35 @@ static void create_color_ramp(const struct ColorBand *coba, float *data)
   }
 }
 
+static void create_phi_spectrum_texture(float *data)
+{
+#  define MAX_PHI_VALUE 7.0f
+#  define MIN_PHI_VALUE -7.0f
+
+  float *spec_pixels = MEM_mallocN(TFUNC_WIDTH * 4 * 16 * 16 * sizeof(float), "spec_pixels");
+
+  phi_to_rgb(data, TFUNC_WIDTH, MIN_PHI_VALUE, MAX_PHI_VALUE);
+
+  for (int i = 0; i < 16; i++) {
+    for (int j = 0; j < 16; j++) {
+      for (int k = 0; k < TFUNC_WIDTH; k++) {
+        int index = (j * TFUNC_WIDTH * 16 + i * TFUNC_WIDTH + k) * 4;
+        spec_pixels[index] = (data[k * 4]);
+        spec_pixels[index + 1] = (data[k * 4 + 1]);
+        spec_pixels[index + 2] = (data[k * 4 + 2]);
+        spec_pixels[index + 3] = 0.06f;
+      }
+    }
+  }
+
+  memcpy(data, spec_pixels, sizeof(float) * 4 * TFUNC_WIDTH);
+
+  MEM_freeN(spec_pixels);
+
+#  undef MAX_PHI_VALUE
+#  undef MIN_PHI_VALUE
+}
+
 static GPUTexture *create_transfer_function(int type, const struct ColorBand *coba)
 {
   float *data = MEM_mallocN(sizeof(float) * 4 * TFUNC_WIDTH, __func__);
@@ -113,6 +143,9 @@ static GPUTexture *create_transfer_function(int type, const struct ColorBand *co
     case TFUNC_COLOR_RAMP:
       create_color_ramp(coba, data);
       break;
+    case TFUNC_PHI_SPECTRUM:
+      create_phi_spectrum_texture(data);
+      break;
   }
 
   GPUTexture *tex = GPU_texture_create_1d(TFUNC_WIDTH, GPU_RGBA8, data, NULL);
@@ -178,6 +211,9 @@ static GPUTexture *create_field_texture(FluidDomainSettings *mds)
     case FLUID_DOMAIN_FIELD_FORCE_Z:
       field = manta_get_force_z(mds->fluid);
       break;
+    case FLUID_DOMAIN_FIELD_PHI:
+      field = manta_get_phi(mds->fluid);
+      break;
     default:
       return NULL;
   }
@@ -327,7 +363,12 @@ void GPU_create_smoke_coba_field(FluidModifierData *mmd)
       mds->tex_field = create_field_texture(mds);
     }
     if (!mds->tex_coba) {
-      mds->tex_coba = create_transfer_function(TFUNC_COLOR_RAMP, mds->coba);
+      if (mds->coba_field == FLUID_DOMAIN_FIELD_PHI) {
+        mds->tex_coba = create_transfer_function(TFUNC_PHI_SPECTRUM, mds->coba);
+      }
+      else {
+        mds->tex_coba = create_transfer_function(TFUNC_COLOR_RAMP, mds->coba);
+      }
     }
   }
 #endif
diff --git a/source/blender/makesdna/DNA_fluid_types.h b/source/blender/makesdna/DNA_fluid_types.h
index 41408486641..8e6a129a167 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_FORCE_X = 11,
   FLUID_DOMAIN_FIELD_FORCE_Y = 12,
   FLUID_DOMAIN_FIELD_FORCE_Z = 13,
+  FLUID_DOMAIN_FIELD_PHI = 14,
 };
 
 /* Fluid domain types. */
diff --git a/source/blender/makesrna/intern/rna_fluid.c b/source/blender/makesrna/intern/rna_fluid.c
index 67d34f2ddb3..2eb5415e953 100644
--- a/source/blender/makesrna/intern/rna_fluid.c
+++ b/source/blender/makesrna/intern/rna_fluid.c
@@ -2274,7 +2274,7 @@ static void rna_def_fluid_domain_settings(BlenderRNA *brna)
       "Render a simulation field while mapping its voxels values to the colors of a ramp");
   RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
 
-  static const EnumPropertyItem coba_field_items[] = {
+  static const EnumPropertyItem coba_field_gas_items[] = {
       {FLUID_DOMAIN_FIELD_COLOR_R, "COLOR_R", 0, "Red", "Red component of the color field"},
       {FLUID_DOMAIN_FIELD_COLOR_G, "COLOR_G", 0, "Green", "Green component of the color field"},
       {FLUID_DOMAIN_FIELD_COLOR_B, "COLOR_B", 0, "Blue", "Blue component of the color field"},
@@ -23

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list