Commit: ce5d079a490841ea52736dacf418357a9bbc5923
Author: Brecht Van Lommel
Date:   Fri Feb 8 12:31:28 2019 +0100
Branches: master
https://developer.blender.org/rBce5d079a490841ea52736dacf418357a9bbc5923

Units: add support for light power units in Watt. Use for Eevee lights.

This affects point, spot and area lights. Sun light strength remains without
a unit. This change does not affect .blend file compatibility in any way, as
with the rest of the unit system it's purely a display and editing feature.

Not used for Cycles yet, that will be done after unifying the settings with
Eevee.

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

M       source/blender/blenkernel/BKE_unit.h
M       source/blender/blenkernel/intern/scene.c
M       source/blender/blenkernel/intern/unit.c
M       source/blender/makesrna/RNA_types.h
M       source/blender/makesrna/intern/makesrna.c
M       source/blender/makesrna/intern/rna_lamp.c
M       source/blender/makesrna/intern/rna_rna.c
M       source/blender/python/intern/bpy_props.c
M       source/blender/python/intern/bpy_utils_units.c

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

diff --git a/source/blender/blenkernel/BKE_unit.h 
b/source/blender/blenkernel/BKE_unit.h
index 8fb7c41ad55..4a6f8a63d5d 100644
--- a/source/blender/blenkernel/BKE_unit.h
+++ b/source/blender/blenkernel/BKE_unit.h
@@ -77,7 +77,8 @@ enum {
        B_UNIT_VELOCITY         = 7,
        B_UNIT_ACCELERATION     = 8,
        B_UNIT_CAMERA           = 9,
-       B_UNIT_TYPE_TOT         = 10,
+       B_UNIT_POWER            = 10,
+       B_UNIT_TYPE_TOT         = 11,
 };
 
 #ifdef __cplusplus
diff --git a/source/blender/blenkernel/intern/scene.c 
b/source/blender/blenkernel/intern/scene.c
index 432538f96ff..0ce17573caf 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -1801,6 +1801,7 @@ double BKE_scene_unit_scale(const UnitSettings *unit, 
const int unit_type, doubl
                case B_UNIT_LENGTH:
                        return value * (double)unit->scale_length;
                case B_UNIT_AREA:
+               case B_UNIT_POWER:
                        return value * pow(unit->scale_length, 2);
                case B_UNIT_VOLUME:
                        return value * pow(unit->scale_length, 3);
diff --git a/source/blender/blenkernel/intern/unit.c 
b/source/blender/blenkernel/intern/unit.c
index 241a8327190..369bf2e1389 100644
--- a/source/blender/blenkernel/intern/unit.c
+++ b/source/blender/blenkernel/intern/unit.c
@@ -299,13 +299,25 @@ static struct bUnitDef buCameraLenDef[] = {
 };
 static struct bUnitCollection buCameraLenCollection = {buCameraLenDef, 3, 0, 
UNIT_COLLECTION_LENGTH(buCameraLenDef)};
 
+/* (Light) Power */
+static struct bUnitDef buPowerDef[] = {
+       {"gigawatt",  "gigawatts",  "GW", NULL, "Gigawatts",  NULL, 1e9f,  0.0, 
B_UNIT_DEF_NONE},
+       {"megawatt",  "megawatts",  "MW", NULL, "Megawatts",  NULL, 1e6f,  0.0, 
B_UNIT_DEF_NONE},
+       {"kilowatt",  "kilowatts",  "kW", NULL, "Kilowatts",  NULL, 1e3f,  0.0, 
B_UNIT_DEF_SUPPRESS},
+       {"watt",      "watts",      "W",  NULL, "Watts",      NULL, 1.0f,  0.0, 
B_UNIT_DEF_NONE},
+       {"milliwatt", "milliwatts", "mW", NULL, "Milliwatts", NULL, 1e-3f, 0.0, 
B_UNIT_DEF_NONE},
+       {"microwatt", "microwatts", "µW", "uW", "Microwatts", NULL, 1e-6f, 0.0, 
B_UNIT_DEF_NONE},
+       {"nanowatt",  "nanowatts",  "nW", NULL, "Nannowatts", NULL, 1e-9f, 0.0, 
B_UNIT_DEF_NONE},
+};
+static struct bUnitCollection buPowerCollection = {buPowerDef, 3, 0, 
UNIT_COLLECTION_LENGTH(buPowerDef)};
+
 
 #define UNIT_SYSTEM_TOT (((sizeof(bUnitSystems) / B_UNIT_TYPE_TOT) / 
sizeof(void *)) - 1)
 static const struct bUnitCollection *bUnitSystems[][B_UNIT_TYPE_TOT] = {
-       {NULL, NULL, NULL, NULL, NULL, &buNaturalRotCollection, 
&buNaturalTimeCollection, NULL, NULL, NULL},
-       {NULL, &buMetricLenCollection, &buMetricAreaCollection, 
&buMetricVolCollection, &buMetricMassCollection, &buNaturalRotCollection, 
&buNaturalTimeCollection, &buMetricVelCollection, &buMetricAclCollection, 
&buCameraLenCollection}, /* metric */
-       {NULL, &buImperialLenCollection, &buImperialAreaCollection, 
&buImperialVolCollection, &buImperialMassCollection, &buNaturalRotCollection, 
&buNaturalTimeCollection, &buImperialVelCollection, &buImperialAclCollection, 
&buCameraLenCollection}, /* imperial */
-       {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
+       {NULL, NULL, NULL, NULL, NULL, &buNaturalRotCollection, 
&buNaturalTimeCollection, NULL, NULL, NULL, NULL},
+       {NULL, &buMetricLenCollection, &buMetricAreaCollection, 
&buMetricVolCollection, &buMetricMassCollection, &buNaturalRotCollection, 
&buNaturalTimeCollection, &buMetricVelCollection, &buMetricAclCollection, 
&buCameraLenCollection, &buPowerCollection}, /* metric */
+       {NULL, &buImperialLenCollection, &buImperialAreaCollection, 
&buImperialVolCollection, &buImperialMassCollection, &buNaturalRotCollection, 
&buNaturalTimeCollection, &buImperialVelCollection, &buImperialAclCollection, 
&buCameraLenCollection, &buPowerCollection}, /* imperial */
+       {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
 };
 
 
@@ -570,7 +582,8 @@ static const char *unit_find_str(const char *str, const 
char *substr)
 {
        if (substr && substr[0] != '\0') {
                while (true) {
-                       const char *str_found = strstr(str, substr);
+                       /* Unit detection is case insensitive. */
+                       const char *str_found = BLI_strcasestr(str, substr);
 
                        if (str_found) {
                                /* Previous char cannot be a letter. */
@@ -774,7 +787,7 @@ bool bUnit_ReplaceString(char *str, int len_max, const char 
*str_prev, double sc
        char str_tmp[TEMP_STR_SIZE];
        bool changed = false;
 
-       /* make lowercase */
+       /* Convert to lowercase, to make unit detection case insensitive. */
        BLI_str_tolower_ascii(str, len_max);
 
        /* Try to find a default unit from current or previous string. */
diff --git a/source/blender/makesrna/RNA_types.h 
b/source/blender/makesrna/RNA_types.h
index 1742e8b8795..a02bf644620 100644
--- a/source/blender/makesrna/RNA_types.h
+++ b/source/blender/makesrna/RNA_types.h
@@ -90,6 +90,7 @@ typedef enum PropertyUnit {
        PROP_UNIT_VELOCITY     = (7 << 16),   /* m/s */
        PROP_UNIT_ACCELERATION = (8 << 16),   /* m/(s^2) */
        PROP_UNIT_CAMERA       = (9 << 16),   /* mm */
+       PROP_UNIT_POWER        = (10 << 16),  /* W */
 } PropertyUnit;
 
 #define RNA_SUBTYPE_UNIT(subtype)       ((subtype) &  0x00FF0000)
@@ -146,6 +147,9 @@ typedef enum PropertySubType {
        /* booleans */
        PROP_LAYER             = 40,
        PROP_LAYER_MEMBER      = 41,
+
+       /* light */
+       PROP_POWER             = 42 | PROP_UNIT_POWER,
 } PropertySubType;
 
 /* Make sure enums are updated with these */
diff --git a/source/blender/makesrna/intern/makesrna.c 
b/source/blender/makesrna/intern/makesrna.c
index 7230b65738b..df8911f425c 100644
--- a/source/blender/makesrna/intern/makesrna.c
+++ b/source/blender/makesrna/intern/makesrna.c
@@ -2579,6 +2579,7 @@ static const char 
*rna_property_subtypename(PropertySubType type)
                case PROP_LAYER: return "PROP_LAYER";
                case PROP_LAYER_MEMBER: return "PROP_LAYER_MEMBER";
                case PROP_PASSWORD: return "PROP_PASSWORD";
+               case PROP_POWER: return "PROP_POWER";
                default:
                {
                        /* in case we don't have a type preset that includes 
the subtype */
@@ -2605,6 +2606,7 @@ static const char 
*rna_property_subtype_unit(PropertySubType type)
                case PROP_UNIT_VELOCITY:     return "PROP_UNIT_VELOCITY";
                case PROP_UNIT_ACCELERATION: return "PROP_UNIT_ACCELERATION";
                case PROP_UNIT_CAMERA:       return "PROP_UNIT_CAMERA";
+               case PROP_UNIT_POWER:        return "PROP_UNIT_POWER";
                default:                     return "PROP_UNIT_UNKNOWN";
        }
 }
diff --git a/source/blender/makesrna/intern/rna_lamp.c 
b/source/blender/makesrna/intern/rna_lamp.c
index dc82e8b28f8..c15186399e7 100644
--- a/source/blender/makesrna/intern/rna_lamp.c
+++ b/source/blender/makesrna/intern/rna_lamp.c
@@ -137,12 +137,6 @@ static void rna_def_light(BlenderRNA *brna)
                                 "Falloff distance - the light is at half the 
original intensity at this point");
        RNA_def_property_update(prop, 0, "rna_Light_draw_update");
 
-       prop = RNA_def_property(srna, "energy", PROP_FLOAT, PROP_NONE);
-       RNA_def_property_float_default(prop, 10.0f);
-       RNA_def_property_ui_range(prop, 0, 1000000.0f, 1, 3);
-       RNA_def_property_ui_text(prop, "Energy", "Amount of light emitted");
-       RNA_def_property_update(prop, 0, "rna_Light_draw_update");
-
        prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR);
        RNA_def_property_float_sdna(prop, NULL, "r");
        RNA_def_property_array(prop, 3);
@@ -187,6 +181,30 @@ static void rna_def_light(BlenderRNA *brna)
        rna_def_animdata_common(srna);
 }
 
+static void rna_def_light_energy(StructRNA *srna, bool distant)
+{
+       PropertyRNA *prop;
+
+       if(distant) {
+               /* Distant light strength has no unit defined, it's 
proportional to
+                * Watt/m^2 and is not sensitive to scene unit scale. */
+               prop = RNA_def_property(srna, "energy", PROP_FLOAT, PROP_NONE);
+               RNA_def_property_float_default(prop, 10.0f);
+               RNA_def_property_ui_range(prop, 0.0f, 10.0f, 1, 3);
+               RNA_def_property_ui_text(prop, "Strength", "Amount of light 
emitted");
+               RNA_def_property_update(prop, 0, "rna_Light_draw_update");
+       }
+       else {
+               /* Lights with a location have power in Watt, which is 
sensitive to
+                * scene unit scale. */
+               prop = RNA_def_property(srna, "energy", PROP_FLOAT, PROP_POWER);
+               RNA_def_property_float_default(prop, 10.0f);
+               RNA_def_property_ui_range(prop, 0.0f, 1000000.0f, 1, 5);
+               RNA_def_property_ui_text(prop, "Power", "Amount of light 
emitted");
+               RNA_def_property_update(prop, 0, "rna_Light_draw_update");
+       }
+}
+
 static void rna_def_light_falloff(StructRNA *srna)
 {
        PropertyRNA *prop;
@@ -245,7 +263,7 @@ static void rna_def_light_falloff(StructRNA *srna)
        RNA_def_property_update(prop, 0, "rna_Light_draw_update");
 }
 
-static void rna_def_light_shadow(StructRNA *srna, int sun)
+static void rna_def_light_shadow(StructRNA *srna, bool sun)
 {
        PropertyRNA *prop;
 
@@ -405,8 +423,9 @@ static void rna_def_point_light(BlenderRNA *brna)
        RNA_def_struct_ui_text(srna, "Point Light", "Omnidirectional point 
Light");
        RNA_def_struct_ui_icon(srna, ICON_LIGHT_POINT);
 
+       rna_def_light_energy(srna, false);
        rna_def_light_falloff(srna);
-       rna_def_light_shadow(srna, 0);
+       rna_def_light_shadow(srna, false);
 }
 
 static void rna_def_area_light(BlenderRNA *brna)
@@ -427,7 +446,8 @@ static void rna_def_area_light(BlenderRNA *brna)
        RNA_def_struct_ui_text(srna, "Area Light", "Directional area Light");
        RNA_def_struct_ui_icon(srna, ICON_LIGHT_AREA);
 
-       rna_def_light_shadow(srna, 0);
+       rna_def_light_energy(srna, false);
+       rna_def_light_shadow(srna, false);
        rna_def_light_falloff(srna);
 
        prop = RNA_def_property(srna, "shape", PROP_ENUM, PROP_NONE);
@@ -464,8 +484,9 @@ static void rna_def_spot_light(BlenderRNA *brna)
        RNA_def_struct_ui_text(srna, "Spot Light", "Directional cone Light");
        RNA_def_struct_ui_icon(srna, ICON_LIGHT_SPOT);
 
+       rna_def_light_energy(srna, false);
        rna_def_light_falloff(srna);
-       rna_def_light_shadow(srna, 0);
+       rna_def_light_shadow(srna, false);
 
        prop = RNA_def_property(srna, "use_square", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "mode", LA_SQUARE);
@@ -502,7 +523,8 @@ static void rna_def_sun_light(BlenderRNA *brna)
        RNA_def_struct_ui_text(srna, "Sun Light", "Constant direction parallel 
ray Light");
        RNA_def_struct_ui_icon(srna, ICON_LIGHT_SUN);
 
-       rna_def_light_shadow(srna, 1);
+       rna_def_light_energy(srna, true);
+       rna_

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to