Smoke: add temperature grid, with values 0..1 corresponding to 0..1000K.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Sun, 18 Feb 2018 02:13:07 +0000 (03:13 +0100)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Fri, 23 Feb 2018 17:57:58 +0000 (18:57 +0100)
intern/cycles/blender/blender_mesh.cpp
intern/cycles/blender/blender_session.cpp
intern/cycles/kernel/kernel_types.h
intern/cycles/render/attribute.cpp
source/blender/makesrna/intern/rna_smoke.c

index 6f1c49774f2b1e5a08107ca3ea09dfc90afadd2c..c87329711e739ac11c103f55901e39fbc9af95ac 100644 (file)
@@ -367,6 +367,8 @@ static void create_mesh_volume_attributes(Scene *scene,
                create_mesh_volume_attribute(b_ob, mesh, scene->image_manager, ATTR_STD_VOLUME_FLAME, frame);
        if(mesh->need_attribute(scene, ATTR_STD_VOLUME_HEAT))
                create_mesh_volume_attribute(b_ob, mesh, scene->image_manager, ATTR_STD_VOLUME_HEAT, frame);
+       if(mesh->need_attribute(scene, ATTR_STD_VOLUME_TEMPERATURE))
+               create_mesh_volume_attribute(b_ob, mesh, scene->image_manager, ATTR_STD_VOLUME_TEMPERATURE, frame);
        if(mesh->need_attribute(scene, ATTR_STD_VOLUME_VELOCITY))
                create_mesh_volume_attribute(b_ob, mesh, scene->image_manager, ATTR_STD_VOLUME_VELOCITY, frame);
 }
index d9301125641ca178f4e42db1672b81f334056abf..679221fc18b8d7b2faf40e7b4cd7f88aed0f6314 100644 (file)
@@ -1066,7 +1066,8 @@ void BlenderSession::builtin_image_info(const string &builtin_name,
 
                if(builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_DENSITY) ||
                   builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_FLAME) ||
-                  builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_HEAT))
+                  builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_HEAT) ||
+                  builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_TEMPERATURE))
                        channels = 1;
                else if(builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_COLOR))
                        channels = 4;
@@ -1287,6 +1288,13 @@ bool BlenderSession::builtin_image_float_pixels(const string &builtin_name,
                                return true;
                        }
                }
+               else if(builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_TEMPERATURE)) {
+                       SmokeDomainSettings_temperature_grid_get_length(&b_domain.ptr, &length);
+                       if(length == num_pixels) {
+                               SmokeDomainSettings_temperature_grid_get(&b_domain.ptr, pixels);
+                               return true;
+                       }
+               }
                else {
                        fprintf(stderr,
                                "Cycles error: unknown volume attribute %s, skipping\n",
index 44e7fd46adc87037608718902a55de609df30c89..26b5a27807ce107d91638b7d015d588a9182ce52 100644 (file)
@@ -798,6 +798,7 @@ typedef enum AttributeStandard {
        ATTR_STD_VOLUME_COLOR,
        ATTR_STD_VOLUME_FLAME,
        ATTR_STD_VOLUME_HEAT,
+       ATTR_STD_VOLUME_TEMPERATURE,
        ATTR_STD_VOLUME_VELOCITY,
        ATTR_STD_POINTINESS,
        ATTR_STD_NUM,
index 2c22db8189dbc481c43e68a21294fc5214b702cf..f959b1fef8b165cce1b23b9c7ef74636ac4da28d 100644 (file)
@@ -281,6 +281,8 @@ const char *Attribute::standard_name(AttributeStandard std)
                        return "flame";
                case ATTR_STD_VOLUME_HEAT:
                        return "heat";
+               case ATTR_STD_VOLUME_TEMPERATURE:
+                       return "temperature";
                case ATTR_STD_VOLUME_VELOCITY:
                        return "velocity";
                case ATTR_STD_POINTINESS:
@@ -425,6 +427,7 @@ Attribute *AttributeSet::add(AttributeStandard std, ustring name)
                        case ATTR_STD_VOLUME_DENSITY:
                        case ATTR_STD_VOLUME_FLAME:
                        case ATTR_STD_VOLUME_HEAT:
+                       case ATTR_STD_VOLUME_TEMPERATURE:
                                attr = add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_VOXEL);
                                break;
                        case ATTR_STD_VOLUME_COLOR:
index 08665f3007a8b51a5902ea7a1be66fba248574a3..1db64100d9406b14497663445cc9b02ea590aada 100644 (file)
@@ -362,6 +362,42 @@ static void rna_SmokeModifier_heat_grid_get(PointerRNA *ptr, float *values)
 #endif
 }
 
+static void rna_SmokeModifier_temperature_grid_get(PointerRNA *ptr, float *values)
+{
+#ifdef WITH_SMOKE
+       SmokeDomainSettings *sds = (SmokeDomainSettings *)ptr->data;
+       int length[RNA_MAX_ARRAY_DIMENSION];
+       int size = rna_SmokeModifier_grid_get_length(ptr, length);
+       float *flame;
+
+       BLI_rw_mutex_lock(sds->fluid_mutex, THREAD_LOCK_READ);
+
+       if (sds->flags & MOD_SMOKE_HIGHRES && sds->wt) {
+               flame = smoke_turbulence_get_flame(sds->wt);
+       }
+       else {
+               flame = smoke_get_flame(sds->fluid);
+       }
+
+       if (flame) {
+               /* Output is such that 0..1 maps to 0..1000K */
+               float offset = sds->flame_ignition;
+               float scale = sds->flame_max_temp - sds->flame_ignition;
+
+               for (int i = 0; i < size; i++) {
+                       values[i] = (flame[i] > 0.01f) ? offset + flame[i] * scale : 0.0f;
+               }
+       }
+       else {
+               memset(values, 0, size * sizeof(float));
+       }
+
+       BLI_rw_mutex_unlock(sds->fluid_mutex);
+#else
+       UNUSED_VARS(ptr, values);
+#endif
+}
+
 static void rna_SmokeFlow_density_vgroup_get(PointerRNA *ptr, char *value)
 {
        SmokeFlowSettings *flow = (SmokeFlowSettings *)ptr->data;
@@ -677,6 +713,14 @@ static void rna_def_smoke_domain_settings(BlenderRNA *brna)
        RNA_def_property_float_funcs(prop, "rna_SmokeModifier_heat_grid_get", NULL, NULL);
        RNA_def_property_ui_text(prop, "Heat Grid", "Smoke heat grid");
 
+       prop = RNA_def_property(srna, "temperature_grid", PROP_FLOAT, PROP_NONE);
+       RNA_def_property_array(prop, 32);
+       RNA_def_property_flag(prop, PROP_DYNAMIC);
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+       RNA_def_property_dynamic_array_funcs(prop, "rna_SmokeModifier_grid_get_length");
+       RNA_def_property_float_funcs(prop, "rna_SmokeModifier_temperature_grid_get", NULL, NULL);
+       RNA_def_property_ui_text(prop, "Temperature Grid", "Smoke temperature grid, range 0..1 represents 0..1000K");
+
        prop = RNA_def_property(srna, "cell_size", PROP_FLOAT, PROP_XYZ); /* can change each frame when using adaptive domain */
        RNA_def_property_clear_flag(prop, PROP_EDITABLE);
        RNA_def_property_ui_text(prop, "cell_size", "Cell Size");