Workbench: Make Material transparency part of the rgba color picker
authorClément Foucault <foucault.clem@gmail.com>
Tue, 29 Jan 2019 19:33:51 +0000 (20:33 +0100)
committerClément Foucault <foucault.clem@gmail.com>
Tue, 29 Jan 2019 19:34:37 +0000 (20:34 +0100)
It is only used for solid mode for now but could be used by eevee in the
future.

release/scripts/startup/bl_ui/properties_material.py
source/blender/blenloader/intern/versioning_280.c
source/blender/draw/engines/workbench/workbench_deferred.c
source/blender/makesdna/DNA_material_types.h
source/blender/makesrna/intern/rna_material.c

index ae1cc12ba50275d2f65d4800d5229d61af70795b..8d7e7ac266d9ff1746f169325ffd6adfe78f8904 100644 (file)
@@ -258,7 +258,6 @@ class MATERIAL_PT_viewport(MaterialButtonsPanel, Panel):
         col.prop(mat, "diffuse_color", text="Color")
         col.prop(mat, "metallic")
         col.prop(mat, "roughness")
-        col.prop(mat, "transparency")
 
     def draw(self, context):
         self.draw_shared(self, context.material)
index c5c234580e63f7bafacc60dcb07c17e5421c47d4..e1e821d689760f766f8d8ac883b4854f9df3ce5f 100644 (file)
@@ -2790,5 +2790,11 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
 
        {
                /* Versioning code until next subversion bump goes here. */
+
+               if (!DNA_struct_elem_find(fd->filesdna, "Material", "float", "a")) {
+                       for (Material *mat = bmain->mat.first; mat; mat = mat->id.next) {
+                               mat->a = 1.0f;
+                       }
+               }
        }
 }
index 4e0ec0259c22c4e84bf545a82e14fcc9561696f5..538dca3b87ffe1f2271123ad2b9806af10a0a2c8 100644 (file)
@@ -943,6 +943,7 @@ void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob)
                        if ((ob->col[3] < 1.0f) &&
                            (wpd->shading.color_type == V3D_SHADING_OBJECT_COLOR))
                        {
+                               /* Hack */
                                wpd->shading.xray_alpha = ob->col[3];
                                material = workbench_forward_get_or_create_material_data(vedata, ob, NULL, NULL, wpd->shading.color_type, 0);
                                has_transp_mat = true;
@@ -978,10 +979,9 @@ void workbench_deferred_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob)
                                for (int i = 0; i < materials_len; ++i) {
                                        if (geoms != NULL && geoms[i] != NULL) {
                                                Material *mat = give_current_material(ob, i + 1);
-                                               if (mat != NULL && mat->transparency > 0.0) {
+                                               if (mat != NULL && mat->a < 1.0f) {
                                                        /* Hack */
-                                                       wpd->shading.xray_alpha = 1.0f - mat->transparency;
-                                                       CLAMP(wpd->shading.xray_alpha, 0.0, 1.0);
+                                                       wpd->shading.xray_alpha = mat->a;
                                                        material = workbench_forward_get_or_create_material_data(vedata, ob, mat, NULL, V3D_SHADING_MATERIAL_COLOR, 0);
                                                        has_transp_mat = true;
                                                }
index 10c40cc28a688d48c40b87166a710e2559b7171a..769d4272d7089716a93f7da6034851d92cbb5229 100644 (file)
@@ -145,7 +145,7 @@ typedef struct Material {
        short flag, pad1[7];
 
        /* Colors from Blender Internal that we are still using. */
-       float r, g, b;
+       float r, g, b, a;
        float specr, specg, specb;
        float alpha DNA_DEPRECATED;
        float ray_mirror  DNA_DEPRECATED;
@@ -154,7 +154,6 @@ typedef struct Material {
        float gloss_mir  DNA_DEPRECATED;
        float roughness;
        float metallic;
-       float transparency;
        float pad4;
 
        /* Ror buttons and render. */
index b32d3aa9d78286024d448245e68f3ef905fce085..4a6ab3e88821fa7fd25d619d502967dd508c6902 100644 (file)
@@ -354,7 +354,7 @@ static void rna_def_material_display(StructRNA *srna)
 
        prop = RNA_def_property(srna, "diffuse_color", PROP_FLOAT, PROP_COLOR);
        RNA_def_property_float_sdna(prop, NULL, "r");
-       RNA_def_property_array(prop, 3);
+       RNA_def_property_array(prop, 4);
        RNA_def_property_ui_text(prop, "Diffuse Color", "Diffuse color of the material");
        RNA_def_property_update(prop, 0, "rna_Material_draw_update");
 
@@ -384,12 +384,6 @@ static void rna_def_material_display(StructRNA *srna)
        RNA_def_property_ui_text(prop, "Metallic", "Amount of mirror reflection for raytrace");
        RNA_def_property_update(prop, 0, "rna_Material_update");
 
-       prop = RNA_def_property(srna, "transparency", PROP_FLOAT, PROP_FACTOR);
-       RNA_def_property_float_sdna(prop, NULL, "transparency");
-       RNA_def_property_range(prop, 0.0f, 1.0f);
-       RNA_def_property_ui_text(prop, "Transparency", "Amount of transparency in solid mode");
-       RNA_def_property_update(prop, 0, "rna_Material_draw_update");
-
        /* Freestyle line color */
        prop = RNA_def_property(srna, "line_color", PROP_FLOAT, PROP_COLOR);
        RNA_def_property_float_sdna(prop, NULL, "line_col");