Cycles: add python render engine option to use new shading nodes or not, instead
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Tue, 11 Oct 2011 17:19:55 +0000 (17:19 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Tue, 11 Oct 2011 17:19:55 +0000 (17:19 +0000)
of hardcoded check for cycles. Also some other minor code cleaning tweaks.

25 files changed:
CMakeLists.txt
intern/CMakeLists.txt
intern/cycles/blender/addon/__init__.py
release/scripts/startup/bl_ui/properties_particle.py
release/scripts/startup/bl_ui/properties_texture.py
release/scripts/startup/bl_ui/space_node.py
release/scripts/startup/bl_ui/space_view3d.py
source/blender/blenkernel/BKE_scene.h
source/blender/blenkernel/intern/scene.c
source/blender/editors/sculpt_paint/paint_image.c
source/blender/editors/space_image/space_image.c
source/blender/editors/space_node/node_header.c
source/blender/editors/space_view3d/drawmesh.c
source/blender/editors/space_view3d/drawobject.c
source/blender/editors/space_view3d/view3d_draw.c
source/blender/editors/uvedit/uvedit_ops.c
source/blender/makesdna/DNA_image_types.h
source/blender/makesdna/DNA_node_types.h
source/blender/makesdna/DNA_view3d_types.h
source/blender/makesrna/intern/rna_access.c
source/blender/makesrna/intern/rna_render.c
source/blender/makesrna/intern/rna_scene.c
source/blender/makesrna/intern/rna_space.c
source/blender/render/extern/include/RE_engine.h
source/blender/render/intern/pipeline/engine.c

index 09acb9e77c9889b270ff32bace81b129e4858ee7..6bada40cd03e73317ea118dacdf4d4e0b40e2994 100644 (file)
@@ -1462,12 +1462,6 @@ add_subdirectory(source)
 add_subdirectory(intern)
 add_subdirectory(extern)
 
-#-----------------------------------------------------------------------------
-# Cycles
-
-if(WITH_CYCLES)
-       add_subdirectory(intern/cycles)
-endif()
 
 #-----------------------------------------------------------------------------
 # Blender Application
index fe30d6cfa0ca24a34cea22a09e77ebe726d0d56b..b38b6e11fd74f37238a0a792d5c484ba49489843 100644 (file)
@@ -58,3 +58,8 @@ endif()
 if(WITH_IK_ITASC)
        add_subdirectory(itasc)
 endif()
+
+if(WITH_CYCLES)
+       add_subdirectory(cycles)
+endif()
+
index 3ff1a8f3d41013f9bbf2929e370f4d388c409e87..4a5b78300bf1f7d84135955d3284621453bd0f86 100644 (file)
@@ -40,6 +40,7 @@ from cycles import presets
 class CyclesRender(bpy.types.RenderEngine):
     bl_idname = 'CYCLES'
     bl_label = "Cycles"
+    bl_use_shading_nodes = True
 
     def __init__(self):
         engine.init()
index da4cb05ee8c939f2465766e85ca22c9980e4f49e..7f97239aa68ab477d5d29f8956841972dfe43622 100644 (file)
@@ -41,7 +41,6 @@ def particle_panel_enabled(context, psys):
 
 def particle_panel_poll(cls, context):
     psys = context.particle_system
-    engine = context.scene.render.engine
     settings = 0
 
     if psys:
@@ -79,7 +78,6 @@ class PARTICLE_PT_context_particles(ParticleButtonsPanel, Panel):
 
     @classmethod
     def poll(cls, context):
-        engine = context.scene.render.engine
         return (context.particle_system or context.object or context.space_data.pin_id)
 
     def draw(self, context):
@@ -251,7 +249,6 @@ class PARTICLE_PT_hair_dynamics(ParticleButtonsPanel, Panel):
     @classmethod
     def poll(cls, context):
         psys = context.particle_system
-        engine = context.scene.render.engine
         if psys is None:
             return False
         if psys.settings is None:
@@ -647,7 +644,6 @@ class PARTICLE_PT_boidbrain(ParticleButtonsPanel, Panel):
     def poll(cls, context):
         psys = context.particle_system
         settings = particle_get_settings(context)
-        engine = context.scene.render.engine
 
         if settings is None:
             return False
@@ -746,11 +742,7 @@ class PARTICLE_PT_render(ParticleButtonsPanel, Panel):
     @classmethod
     def poll(cls, context):
         settings = particle_get_settings(context)
-        engine = context.scene.render.engine
-        if settings is None:
-            return False
-
-        return True
+        return settings is not None
 
     def draw(self, context):
         layout = self.layout
@@ -931,10 +923,7 @@ class PARTICLE_PT_draw(ParticleButtonsPanel, Panel):
     @classmethod
     def poll(cls, context):
         settings = particle_get_settings(context)
-        engine = context.scene.render.engine
-        if settings is None:
-            return False
-        return True
+        return settings is not None
 
     def draw(self, context):
         layout = self.layout
index 38697c569daf03bf5d5aba2fcda431e2bc2fba0f..34f5a948ee7fa2b559ef1a2180a612518e3529e2 100644 (file)
@@ -410,7 +410,6 @@ class TEXTURE_PT_image_sampling(TextureTypePanel, Panel):
 
         #Only for Material based textures, not for Lamp/World...
         if slot and isinstance(idblock, bpy.types.Material):
-            slot = context.texture_slot
             col.prop(tex, "use_normal_map")
             row = col.row()
             row.active = tex.use_normal_map
index d46ca25c57d2b39f5af8e418db073a564cdf4f79..69766b54e9755c54db9943fc9ee5da98f1bf4570 100644 (file)
@@ -27,6 +27,7 @@ class NODE_HT_header(Header):
     def draw(self, context):
         layout = self.layout
 
+        scene = context.scene
         snode = context.space_data
         snode_id = snode.id
         id_from = snode.id_from
@@ -43,9 +44,10 @@ class NODE_HT_header(Header):
         layout.prop(snode, "tree_type", text="", expand=True)
 
         if snode.tree_type == 'SHADER':
-            row.prop(snode, "shader_type", text="", expand=True)
+            if scene.render.use_shading_nodes:
+                layout.prop(snode, "shader_type", text="", expand=True)
 
-            if snode.shader_type == 'OBJECT':
+            if not scene.render.use_shading_nodes or snode.shader_type == 'OBJECT':
                 if id_from:
                     layout.template_ID(id_from, "active_material", new="material.new")
                 if snode_id:
index c35b765c7951726eb13ef5ae592fcdd612b06605..e2fe8c9fb82af32ce5a14e98bd588af9e10cd306 100644 (file)
@@ -2142,9 +2142,11 @@ class VIEW3D_PT_view3d_display(Panel):
         subsub.active = scene.unit_settings.system == 'NONE'
         subsub.prop(view, "grid_subdivisions", text="Subdivisions")
 
-        col = layout.column()
-        col.label(text="Shading:")
-        col.prop(gs, "material_mode", text="")
+        if not scene.render.use_shading_nodes:
+            col = layout.column()
+            col.label(text="Shading:")
+            col.prop(gs, "material_mode", text="")
+            col.prop(view, "show_textured_solid")
 
         layout.separator()
 
index 8f85f14306f39e95a050f45adb58570b896fc5f2..1b12f2dd4bef9dc155476f9b2340cd95abda071a 100644 (file)
@@ -102,7 +102,7 @@ int get_render_child_particle_number(struct RenderData *r, int num);
 int get_render_shadow_samples(struct RenderData *r, int samples);
 float get_render_aosss_error(struct RenderData *r, float error);
 
-int scene_use_new_shading_system(struct Scene *scene);
+int scene_use_new_shading_nodes(struct Scene *scene);
 
 #ifdef __cplusplus
 }
index 7dc5a2228143de76bcf02660db3b368cd34abcf1..101a10903c853bc26b97d411c45ac5bab7822026 100644 (file)
@@ -74,6 +74,8 @@
 
 #include "BKE_sound.h"
 
+#include "RE_engine.h"
+
 //XXX #include "BIF_previewrender.h"
 //XXX #include "BIF_editseq.h"
 
@@ -1137,8 +1139,9 @@ Base *_setlooper_base_step(Scene **sce_iter, Base *base)
        return NULL;
 }
 
-int scene_use_new_shading_system(Scene *scene)
+int scene_use_new_shading_nodes(Scene *scene)
 {
-       return (strcmp(scene->r.engine, "CYCLES") == 0);
+       RenderEngineType *type= RE_engines_find(scene->r.engine);
+       return (type->flag & RE_USE_SHADING_NODES);
 }
 
index c0ced572515ff0b22e224f2d80fd2c072095e7bc..9e12aa64065ccfba70d88a748bf281ad4669f709 100644 (file)
@@ -487,7 +487,7 @@ static Image *imapaint_face_image(const ImagePaintState *s, int face_index)
 {
        Image *ima;
 
-       if(scene_use_new_shading_system(s->scene)) {
+       if(scene_use_new_shading_nodes(s->scene)) {
                MFace *mf = s->me->mface+face_index;
                ED_object_get_active_image(s->ob, mf->mat_nr, &ima, NULL);
        }
@@ -503,7 +503,7 @@ static Image *project_paint_face_image(const ProjPaintState *ps, int face_index)
 {
        Image *ima;
 
-       if(scene_use_new_shading_system(ps->scene)) {
+       if(scene_use_new_shading_nodes(ps->scene)) {
                MFace *mf = ps->dm_mface+face_index;
                ED_object_get_active_image(ps->ob, mf->mat_nr, &ima, NULL);
        }
index f0709e056ecd3040c53b5fd546039d0097bb3d14..b02b8fd856ca7ffc0e98a5b15dc52ceb47556be7 100644 (file)
@@ -594,7 +594,7 @@ static void image_refresh(const bContext *C, ScrArea *UNUSED(sa))
                EditMesh *em= BKE_mesh_get_editmesh(me);
                int sloppy= 1; /* partially selected face is ok */
 
-               if(scene_use_new_shading_system(scene)) {
+               if(scene_use_new_shading_nodes(scene)) {
                        /* new shading system, get image from material */
                        EditFace *efa= EM_get_actFace(em, sloppy);
 
index 084570d905d2e2225cd948c50fb3e8b10b6753ad..d5d7929faa3b24057e503fc619deb1c30b64189d 100644 (file)
@@ -232,7 +232,7 @@ static void node_menu_add(const bContext *C, Menu *menu)
        if(snode->treetype==NTREE_SHADER) {
                uiItemMenuF(layout, IFACE_(N_("Input")), 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_INPUT));
                uiItemMenuF(layout, IFACE_(N_("Output")), 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_OUTPUT));
-               if(scene_use_new_shading_system(scene)) {
+               if(scene_use_new_shading_nodes(scene)) {
                        uiItemMenuF(layout, IFACE_(N_("Shader")), 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_SHADER));
                        uiItemMenuF(layout, IFACE_(N_("Texture")), 0, node_add_menu, SET_INT_IN_POINTER(NODE_CLASS_TEXTURE));
                }
index b749538b742b25da61ad3243e294dadc2efffdb9..6cad8f3487a74f0fd0243f596ec92596bd125b7e 100644 (file)
@@ -775,7 +775,7 @@ static int tex_mat_set_face_editmesh_cb(void *UNUSED(userData), int index)
 
 void draw_mesh_textured(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, DerivedMesh *dm, int faceselect)
 {
-       if(!scene_use_new_shading_system(scene)) {
+       if(!scene_use_new_shading_nodes(scene)) {
                draw_mesh_textured_old(scene, v3d, rv3d, ob, dm, faceselect);
                return;
        }
index 09ddfd7dc2c86b93123ddfc373aa99750808ee5e..5521460ac14f150a9bb7e75745d479923f8385a8 100644 (file)
 
 /* this condition has been made more complex since editmode can draw textures */
 #define CHECK_OB_DRAWTEXTURE(vd, dt) \
-       ((ELEM(vd->drawtype, OB_TEXTURE, OB_MATERIAL) && dt>OB_SOLID))
+       ((ELEM(vd->drawtype, OB_TEXTURE, OB_MATERIAL) && dt>OB_SOLID) || \
+       (vd->drawtype==OB_SOLID && vd->flag2 & V3D_SOLID_TEX))
 
 static void draw_bounding_volume(Scene *scene, Object *ob);
 
@@ -131,6 +132,9 @@ static int check_ob_drawface_dot(Scene *sce, View3D *vd, char dt)
        if(dt==OB_TEXTURE && vd->drawtype==OB_TEXTURE)
                return 0;
 
+       if(vd->drawtype>=OB_SOLID && vd->flag2 & V3D_SOLID_TEX)
+               return 0;
+
        return 1;
 }
 
@@ -213,7 +217,7 @@ int draw_glsl_material(Scene *scene, Object *ob, View3D *v3d, int dt)
                return 0;
        if(ob==OBACT && (ob && ob->mode & OB_MODE_WEIGHT_PAINT))
                return 0;
-       if(scene_use_new_shading_system(scene))
+       if(scene_use_new_shading_nodes(scene))
                return 0;
        
        return (scene->gm.matmode == GAME_MAT_GLSL) && (dt > OB_SOLID);
index e4346101b78eb0261f6e70d24ca0ca3d9d2b4078..dba594acf713fc87e86e6c995941cc8d0cb92759 100644 (file)
@@ -2122,6 +2122,7 @@ static void gpu_update_lamps_shadows(Scene *scene, View3D *v3d)
                
                v3d->drawtype = OB_SOLID;
                v3d->lay &= GPU_lamp_shadow_layer(shadow->lamp);
+               v3d->flag2 &= ~V3D_SOLID_TEX;
                v3d->flag2 |= V3D_RENDER_OVERRIDE | V3D_RENDER_SHADOW;
                
                GPU_lamp_shadow_buffer_bind(shadow->lamp, viewmat, &winsize, winmat);
@@ -2152,7 +2153,7 @@ CustomDataMask ED_view3d_datamask(Scene *scene, View3D *v3d)
 {
        CustomDataMask mask= 0;
 
-       if(ELEM(v3d->drawtype, OB_TEXTURE, OB_MATERIAL)) {
+       if(ELEM(v3d->drawtype, OB_TEXTURE, OB_MATERIAL) || ((v3d->drawtype == OB_SOLID) && (v3d->flag2 & V3D_SOLID_TEX))) {
                mask |= CD_MASK_MTFACE | CD_MASK_MCOL;
 
                if(v3d->drawtype == OB_MATERIAL || scene->gm.matmode == GAME_MAT_GLSL)
index e80b63b4eea008daab82a92fca688f5f6c339bc3..568445b31121815f5f9424ca756331620dcb2529 100644 (file)
@@ -154,7 +154,7 @@ void ED_uvedit_assign_image(Main *bmain, Scene *scene, Object *obedit, Image *im
                return;
        }
 
-       if(scene_use_new_shading_system(scene)) {
+       if(scene_use_new_shading_nodes(scene)) {
                /* new shading system, assign image in material */
                int sloppy= 1;
                EditFace *efa= EM_get_actFace(em, sloppy);
index e090abe39bb320d56dbce16b25c4c1778de5507a..dd033339ca4292ac5d8e58909a81e2034a7d365f 100644 (file)
@@ -42,6 +42,7 @@ struct ImBuf;
 struct RenderResult;
 struct GPUTexture;
 
+
 /* ImageUser is in Texture, in Nodes, Background Image, Image Window, .... */
 /* should be used in conjunction with an ID * to Image. */
 typedef struct ImageUser {
index 3477be4234f6600e0b045cce7154d994d5431a23..6d1ff8dae598733601e47d2549159f0bf0ebfb5a 100644 (file)
@@ -104,7 +104,7 @@ typedef struct bNodeSocket {
 #define SOCK_FLOAT                     0
 #define SOCK_VECTOR                    1
 #define SOCK_RGBA                      2
-#define        SOCK_SHADER                     3
+#define SOCK_SHADER                    3
 #define SOCK_BOOLEAN           4
 #define SOCK_MESH                      5
 #define SOCK_INT                       6
index 6d4a845c5b083d147d82e899dd234e4cd11d85cc..2b7f54e04973cd07e68de75fccb6af8338bff3a4 100644 (file)
@@ -246,7 +246,7 @@ typedef struct View3D {
 
 /* View3d->flag2 (short) */
 #define V3D_RENDER_OVERRIDE            4
-#define V3D_SOLID_TEX                  8       /* deprecated */
+#define V3D_SOLID_TEX                  8
 #define V3D_DISPGP                             16
 #define V3D_LOCK_CAMERA                        32
 #define V3D_RENDER_SHADOW              64 /* This is a runtime only flag that's used to tell draw_mesh_object() that we're doing a shadow pass instead of a regular draw */
index e64c5fd670d8137bf06dbfba8ceac6c036d2c398..8047b2df2268f58993aa97798e2bbba1b3be900e 100644 (file)
@@ -1454,7 +1454,7 @@ static void rna_property_update(bContext *C, Main *bmain, Scene *scene, PointerR
  * but this isnt likely to be a performance problem. */
 int RNA_property_update_check(PropertyRNA *prop)
 {
-       return ((prop->magic != RNA_MAGIC) || prop->update || prop->noteflag);
+       return (prop->magic != RNA_MAGIC || prop->update || prop->noteflag);
 }
 
 void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
index 460d7ce1c45c52cb32784273715906666d0d050a..ef2e97c442756081a384f618f2be90ca03ad6fff 100644 (file)
@@ -397,11 +397,15 @@ static void rna_def_render_engine(BlenderRNA *brna)
        RNA_def_property_flag(prop, PROP_REGISTER);
 
        prop= RNA_def_property(srna, "bl_use_preview", PROP_BOOLEAN, PROP_NONE);
-       RNA_def_property_boolean_sdna(prop, NULL, "type->flag", RE_DO_PREVIEW);
+       RNA_def_property_boolean_sdna(prop, NULL, "type->flag", RE_USE_PREVIEW);
        RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
 
        prop= RNA_def_property(srna, "bl_use_postprocess", PROP_BOOLEAN, PROP_NONE);
-       RNA_def_property_boolean_negative_sdna(prop, NULL, "type->flag", RE_DO_ALL);
+       RNA_def_property_boolean_negative_sdna(prop, NULL, "type->flag", RE_USE_POSTPROCESS);
+       RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
+
+       prop= RNA_def_property(srna, "bl_use_shading_nodes", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "type->flag", RE_USE_SHADING_NODES);
        RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
 
        RNA_define_verify_sdna(1);
index c7a5d2c8f65548555d1bf6148cb48072d48b1851..42ebdcbc5823f7067a3f7af151b7cb4acbdafb13 100644 (file)
@@ -841,6 +841,12 @@ static int rna_RenderSettings_multiple_engines_get(PointerRNA *UNUSED(ptr))
        return (BLI_countlist(&R_engines) > 1);
 }
 
+static int rna_RenderSettings_use_shading_nodes_get(PointerRNA *ptr)
+{
+       Scene *scene= (Scene*)ptr->id.data;
+       return scene_use_new_shading_nodes(scene);
+}
+
 static int rna_RenderSettings_use_game_engine_get(PointerRNA *ptr)
 {
        RenderData *rd= (RenderData*)ptr->data;
@@ -3230,6 +3236,11 @@ static void rna_def_scene_render_data(BlenderRNA *brna)
        RNA_def_property_clear_flag(prop, PROP_EDITABLE);
        RNA_def_property_ui_text(prop, "Multiple Engines", "More than one rendering engine is available");
 
+       prop= RNA_def_property(srna, "use_shading_nodes", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_funcs(prop, "rna_RenderSettings_use_shading_nodes_get", NULL);
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+       RNA_def_property_ui_text(prop, "Use Shading Nodes", "Active render engine uses new shading nodes system");
+
        prop= RNA_def_property(srna, "use_game_engine", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_funcs(prop, "rna_RenderSettings_use_game_engine_get", NULL);
        RNA_def_property_clear_flag(prop, PROP_EDITABLE);
index b4bda045a708e76314020577841a17a2ace722d4..8279bdc4a91d60aea0c055313161f4346f7b89ce 100644 (file)
@@ -1373,6 +1373,11 @@ static void rna_def_space_view3d(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Relationship Lines", "Show dashed lines indicating parent or constraint relationships");
        RNA_def_property_update(prop, NC_SPACE|ND_SPACE_VIEW3D, NULL);
        
+       prop= RNA_def_property(srna, "show_textured_solid", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "flag2", V3D_SOLID_TEX);
+       RNA_def_property_ui_text(prop, "Textured Solid", "Display face-assigned textures in solid view");
+       RNA_def_property_update(prop, NC_SPACE|ND_SPACE_VIEW3D, NULL);
+
        prop= RNA_def_property(srna, "lock_camera", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "flag2", V3D_LOCK_CAMERA);
        RNA_def_property_ui_text(prop, "Lock Camera to View", "Enable view navigation within the camera view");
index 7f01bc673d24ee7116fe4a1c9af8cbbe9deea573..7d5ba28cfa6e5d6a40e1a3836fe989bc882fcf58 100644 (file)
@@ -48,10 +48,11 @@ struct Scene;
 
 /* External Engine */
 
-#define RE_INTERNAL                    1
-#define RE_GAME                                2
-#define RE_DO_PREVIEW          4
-#define RE_DO_ALL                      8
+#define RE_INTERNAL                            1
+#define RE_GAME                                        2
+#define RE_USE_PREVIEW                 4
+#define RE_USE_POSTPROCESS             8
+#define RE_USE_SHADING_NODES   16
 
 extern ListBase R_engines;
 
index 0fc6a0320c8e3648065bf1d9b433b616febb1e13..d67cd3cb88f365b52389241158eeb0eaf38cf2aa 100644 (file)
@@ -268,11 +268,11 @@ int RE_engine_render(Render *re, int do_all)
        /* verify if we can render */
        if(!type->render)
                return 0;
-       if((re->r.scemode & R_PREVIEWBUTS) && !(type->flag & RE_DO_PREVIEW))
+       if((re->r.scemode & R_PREVIEWBUTS) && !(type->flag & RE_USE_PREVIEW))
                return 0;
-       if(do_all && !(type->flag & RE_DO_ALL))
+       if(do_all && !(type->flag & RE_USE_POSTPROCESS))
                return 0;
-       if(!do_all && (type->flag & RE_DO_ALL))
+       if(!do_all && (type->flag & RE_USE_POSTPROCESS))
                return 0;
 
        /* create render result */