Cycles/Eeeve: unify film transparent setting
authorJeroen Bakker <j.bakker@atmind.nl>
Thu, 16 May 2019 15:03:16 +0000 (17:03 +0200)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Thu, 16 May 2019 15:40:13 +0000 (17:40 +0200)
For existing files, it will use the setting from Cycles or Eevee depending on
the render engine in the scene.

Differential Revision: https://developer.blender.org/D4874

intern/cycles/blender/addon/properties.py
intern/cycles/blender/addon/ui.py
intern/cycles/blender/blender_shader.cpp
release/scripts/modules/bl_previews_utils/bl_previews_render.py
release/scripts/startup/bl_operators/clip.py
release/scripts/startup/bl_ui/properties_render.py
source/blender/blenkernel/BKE_blender_version.h
source/blender/blenloader/intern/versioning_cycles.c
source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
source/blender/makesrna/intern/rna_scene.c

index f376eb8..35f9e17 100644 (file)
@@ -417,11 +417,6 @@ class CyclesRenderSettings(bpy.types.PropertyGroup):
         min=0.0, max=10.0,
         default=1.0,
     )
-    film_transparent: BoolProperty(
-        name="Transparent",
-        description="World background is transparent, for compositing the render over another background",
-        default=False,
-    )
     film_transparent_glass: BoolProperty(
         name="Transparent Glass",
         description="Render transmissive surfaces as transparent, for compositing glass over another background",
index 5ff8836..86f5876 100644 (file)
@@ -528,31 +528,32 @@ class CYCLES_RENDER_PT_film(CyclesButtonsPanel, Panel):
 
 
 class CYCLES_RENDER_PT_film_transparency(CyclesButtonsPanel, Panel):
-    bl_label = "Transparency"
+    bl_label = "Transparent"
     bl_parent_id = "CYCLES_RENDER_PT_film"
 
     def draw_header(self, context):
         layout = self.layout
 
         scene = context.scene
-        cscene = scene.cycles
+        rd = scene.render
 
-        layout.prop(cscene, "film_transparent", text="")
+        layout.prop(rd, "film_transparent", text="")
 
     def draw(self, context):
         layout = self.layout
         layout.use_property_split = True
         layout.use_property_decorate = False
         scene = context.scene
+        rd = scene.render
         cscene = scene.cycles
 
-        layout.active = cscene.film_transparent
+        layout.active = rd.film_transparent
 
         col = layout.column()
         col.prop(cscene, "film_transparent_glass", text="Transparent Glass")
 
         sub = col.column()
-        sub.active = cscene.film_transparent and cscene.film_transparent_glass
+        sub.active = rd.film_transparent and cscene.film_transparent_glass
         sub.prop(cscene, "film_transparent_roughness", text="Roughness Threshold")
 
 
index 8321d0c..f42a157 100644 (file)
@@ -1354,16 +1354,7 @@ void BlenderSync::sync_world(BL::Depsgraph &b_depsgraph, bool update_all)
   }
 
   PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
-
-  /* when doing preview render check for BI's transparency settings,
-   * this is so because Blender's preview render routines are not able
-   * to tweak all cycles's settings depending on different circumstances
-   */
-  if (b_engine.is_preview() == false)
-    background->transparent = get_boolean(cscene, "film_transparent");
-  else
-    background->transparent = b_scene.render().alpha_mode() ==
-                              BL::RenderSettings::alpha_mode_TRANSPARENT;
+  background->transparent = b_scene.render().film_transparent();
 
   if (background->transparent) {
     background->transparent_glass = get_boolean(cscene, "film_transparent_glass");
index 804bf24..a20e5f4 100644 (file)
@@ -123,7 +123,7 @@ def do_previews(do_objects, do_collections, do_scenes, do_data_intern):
             scene.collection.objects.link(light)
 
             scene.render.engine = 'CYCLES'
-            scene.cycles.film_transparent = True
+            scene.render.film_transparent = True
             # TODO: define Cycles world?
 
         scene.render.image_settings.file_format = 'PNG'
index 664684c..e857d85 100644 (file)
@@ -850,9 +850,6 @@ class CLIP_OT_setup_tracking_scene(Operator):
         # Ensure no nodes were created on the position of existing node.
         self._offsetNodes(tree)
 
-        if hasattr(scene, "cycles"):
-            scene.cycles.film_transparent = True
-
     @staticmethod
     def _createMesh(collection, name, vertices, faces):
         from bpy_extras.io_utils import unpack_list
index 56784cd..18ef034 100644 (file)
@@ -495,7 +495,7 @@ class RENDER_PT_eevee_film(RenderButtonsPanel, Panel):
 
         col = layout.column()
         col.prop(rd, "filter_size")
-        col.prop(rd, "alpha_mode", text="Alpha")
+        col.prop(rd, "film_transparent", text="Transparent")
 
 
 class RENDER_PT_eevee_film_overscan(RenderButtonsPanel, Panel):
@@ -573,7 +573,7 @@ class RENDER_PT_opengl_film(RenderButtonsPanel, Panel):
         layout.use_property_decorate = False  # No animation.
 
         rd = context.scene.render
-        layout.prop(rd, "alpha_mode")
+        layout.prop(rd, "film_transparent", text="Transparent")
 
 
 class RENDER_PT_opengl_lighting(RenderButtonsPanel, Panel):
index e669295..0afcd37 100644 (file)
@@ -27,7 +27,7 @@
  * \note Use #STRINGIFY() rather than defining with quotes.
  */
 #define BLENDER_VERSION 280
-#define BLENDER_SUBVERSION 67
+#define BLENDER_SUBVERSION 68
 /** Several breakages with 280, e.g. collections vs layers. */
 #define BLENDER_MINVERSION 280
 #define BLENDER_MINSUBVERSION 0
index ace9035..3fc6d98 100644 (file)
@@ -396,6 +396,20 @@ void blo_do_versions_cycles(FileData *UNUSED(fd), Library *UNUSED(lib), Main *bm
       }
     }
   }
+
+  if (!MAIN_VERSION_ATLEAST(bmain, 280, 68)) {
+    /* Unify Cycles and EEVEE Film Transparency. */
+    for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
+      if (STREQ(scene->r.engine, RE_engine_id_CYCLES)) {
+        IDProperty *cscene = cycles_properties_from_ID(&scene->id);
+        if (cscene) {
+          bool cycles_film_transparency = cycles_property_boolean(
+              cscene, "film_transparent", false);
+          scene->r.alphamode = cycles_film_transparency ? R_ALPHAPREMUL : R_ADDSKY;
+        }
+      }
+    }
+  }
 }
 
 void do_versions_after_linking_cycles(Main *bmain)
index 082ed34..dbd770e 100644 (file)
@@ -125,13 +125,6 @@ BlenderStrokeRenderer::BlenderStrokeRenderer(Render *re, int render_count) : Str
   /* Render with transparent background. */
   freestyle_scene->r.alphamode = R_ALPHAPREMUL;
 
-  if (STREQ(freestyle_scene->r.engine, RE_engine_id_CYCLES)) {
-    PointerRNA freestyle_scene_ptr;
-    RNA_id_pointer_create(&freestyle_scene->id, &freestyle_scene_ptr);
-    PointerRNA freestyle_cycles_ptr = RNA_pointer_get(&freestyle_scene_ptr, "cycles");
-    RNA_boolean_set(&freestyle_cycles_ptr, "film_transparent", 1);
-  }
-
   if (G.debug & G_DEBUG_FREESTYLE) {
     printf("%s: %d thread(s)\n", __func__, BKE_render_num_threads(&freestyle_scene->r));
   }
index b739920..c91b32b 100644 (file)
@@ -5498,16 +5498,6 @@ static void rna_def_scene_render_data(BlenderRNA *brna)
   StructRNA *srna;
   PropertyRNA *prop;
 
-  static const EnumPropertyItem alpha_mode_items[] = {
-      {R_ADDSKY, "SKY", 0, "Sky", "Transparent pixels are filled with sky color"},
-      {R_ALPHAPREMUL,
-       "TRANSPARENT",
-       0,
-       "Transparent",
-       "World background is transparent with premultiplied alpha"},
-      {0, NULL, 0, NULL, NULL},
-  };
-
   static const EnumPropertyItem display_mode_items[] = {
       {R_OUTPUT_SCREEN,
        "SCREEN",
@@ -5735,11 +5725,12 @@ static void rna_def_scene_render_data(BlenderRNA *brna)
       prop, "Filter Size", "Width over which the reconstruction filter combines samples");
   RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
 
-  prop = RNA_def_property(srna, "alpha_mode", PROP_ENUM, PROP_NONE);
-  RNA_def_property_enum_sdna(prop, NULL, "alphamode");
-  RNA_def_property_enum_items(prop, alpha_mode_items);
+  prop = RNA_def_property(srna, "film_transparent", PROP_BOOLEAN, PROP_NONE);
+  RNA_def_property_boolean_sdna(prop, NULL, "alphamode", R_ALPHAPREMUL);
   RNA_def_property_ui_text(
-      prop, "Alpha Mode", "Representation of alpha information in the RGBA pixels");
+      prop,
+      "Transparent",
+      "World background is transparent, for compositing the render over another background");
   RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_glsl_update");
 
   prop = RNA_def_property(srna, "use_freestyle", PROP_BOOLEAN, PROP_NONE);