diff options
19 files changed, 403 insertions, 90 deletions
diff --git a/intern/cycles/blender/CMakeLists.txt b/intern/cycles/blender/CMakeLists.txt index 9658c7b4a62..66d955768a3 100644 --- a/intern/cycles/blender/CMakeLists.txt +++ b/intern/cycles/blender/CMakeLists.txt @@ -29,6 +29,7 @@ set(SRC blender_shader.cpp blender_sync.cpp blender_texture.cpp + blender_viewport.cpp CCL_api.h blender_object_cull.h @@ -36,6 +37,7 @@ set(SRC blender_session.h blender_texture.h blender_util.h + blender_viewport.h ) set(LIB diff --git a/intern/cycles/blender/addon/ui.py b/intern/cycles/blender/addon/ui.py index b072d9e583e..6f2794531fd 100644 --- a/intern/cycles/blender/addon/ui.py +++ b/intern/cycles/blender/addon/ui.py @@ -2050,6 +2050,45 @@ class CYCLES_RENDER_PT_simplify_culling(CyclesButtonsPanel, Panel): sub.prop(cscene, "distance_cull_margin", text="Distance") +class CYCLES_VIEW3D_PT_shading_lighting(Panel): + bl_space_type = 'VIEW_3D' + bl_region_type = 'HEADER' + bl_label = "Lighting" + bl_parent_id = 'VIEW3D_PT_shading' + COMPAT_ENGINES = {'CYCLES'} + + @classmethod + def poll(cls, context): + return (context.engine in cls.COMPAT_ENGINES + and context.space_data.shading.type == 'RENDERED') + + def draw(self, context): + layout = self.layout + col = layout.column() + split = col.split(factor=0.9) + + shading = context.space_data.shading + col.prop(shading, "use_scene_lights_render") + col.prop(shading, "use_scene_world_render") + + if not shading.use_scene_world_render: + col = layout.column() + split = col.split(factor=0.9) + + col = split.column() + sub = col.row() + sub.scale_y = 0.6 + sub.template_icon_view(shading, "studio_light", scale_popup=3) + + col = split.column() + col.operator("preferences.studiolight_show", emboss=False, text="", icon='PREFERENCES') + + split = layout.split(factor=0.9) + col = split.column() + col.prop(shading, "studiolight_rotate_z", text="Rotation") + col.prop(shading, "studiolight_background_alpha") + + def draw_device(self, context): scene = context.scene layout = self.layout @@ -2131,6 +2170,7 @@ classes = ( CYCLES_RENDER_PT_simplify_viewport, CYCLES_RENDER_PT_simplify_render, CYCLES_RENDER_PT_simplify_culling, + CYCLES_VIEW3D_PT_shading_lighting, CYCLES_RENDER_PT_motion_blur, CYCLES_RENDER_PT_motion_blur_curve, CYCLES_RENDER_PT_film, diff --git a/intern/cycles/blender/blender_object.cpp b/intern/cycles/blender/blender_object.cpp index b670922ac88..b0599546244 100644 --- a/intern/cycles/blender/blender_object.cpp +++ b/intern/cycles/blender/blender_object.cpp @@ -239,7 +239,7 @@ void BlenderSync::sync_light(BL::Object &b_parent, light->tag_update(scene); } -void BlenderSync::sync_background_light(bool use_portal) +void BlenderSync::sync_background_light(BL::SpaceView3D &b_v3d, bool use_portal) { BL::World b_world = b_scene.world(); @@ -283,6 +283,7 @@ void BlenderSync::sync_background_light(bool use_portal) world_map = b_world.ptr.data; world_recalc = false; + viewport_parameters = BlenderViewportParameters(b_v3d); } /* Object */ @@ -293,6 +294,7 @@ Object *BlenderSync::sync_object(BL::Depsgraph &b_depsgraph, float motion_time, bool show_self, bool show_particles, + bool show_lights, BlenderObjectCulling &culling, bool *use_portal) { @@ -311,6 +313,10 @@ Object *BlenderSync::sync_object(BL::Depsgraph &b_depsgraph, /* light is handled separately */ if (!motion && object_is_light(b_ob)) { + if (!show_lights) { + return NULL; + } + /* TODO: don't use lights for excluded layers used as mask layer, * when dynamic overrides are back. */ #if 0 @@ -507,7 +513,9 @@ Object *BlenderSync::sync_object(BL::Depsgraph &b_depsgraph, /* Object Loop */ -void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph, float motion_time) +void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph, + BL::SpaceView3D &b_v3d, + float motion_time) { /* layer data */ bool motion = motion_time != 0.0f; @@ -530,6 +538,7 @@ void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph, float motion_time) /* object loop */ bool cancel = false; bool use_portal = false; + const bool show_lights = BlenderViewportParameters(b_v3d).use_scene_lights; BL::ViewLayer b_view_layer = b_depsgraph.view_layer_eval(); @@ -555,6 +564,7 @@ void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph, float motion_time) motion_time, show_self, show_particles, + show_lights, culling, &use_portal); } @@ -565,7 +575,7 @@ void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph, float motion_time) progress.set_sync_status(""); if (!cancel && !motion) { - sync_background_light(use_portal); + sync_background_light(b_v3d, use_portal); /* handle removed data and modified pointers */ if (light_map.post_sync()) @@ -584,6 +594,7 @@ void BlenderSync::sync_objects(BL::Depsgraph &b_depsgraph, float motion_time) void BlenderSync::sync_motion(BL::RenderSettings &b_render, BL::Depsgraph &b_depsgraph, + BL::SpaceView3D &b_v3d, BL::Object &b_override, int width, int height, @@ -621,7 +632,7 @@ void BlenderSync::sync_motion(BL::RenderSettings &b_render, b_engine.frame_set(frame, subframe); python_thread_state_save(python_thread_state); sync_camera_motion(b_render, b_cam, width, height, 0.0f); - sync_objects(b_depsgraph, 0.0f); + sync_objects(b_depsgraph, b_v3d, 0.0f); } /* always sample these times for camera motion */ @@ -657,7 +668,7 @@ void BlenderSync::sync_motion(BL::RenderSettings &b_render, } /* sync object */ - sync_objects(b_depsgraph, relative_time); + sync_objects(b_depsgraph, b_v3d, relative_time); } /* we need to set the python thread state again because this diff --git a/intern/cycles/blender/blender_session.cpp b/intern/cycles/blender/blender_session.cpp index 8923450c469..1f0816a6edb 100644 --- a/intern/cycles/blender/blender_session.cpp +++ b/intern/cycles/blender/blender_session.cpp @@ -861,7 +861,7 @@ void BlenderSession::synchronize(BL::Depsgraph &b_depsgraph_) /* copy recalc flags, outside of mutex so we can decide to do the real * synchronization at a later time to not block on running updates */ - sync->sync_recalc(b_depsgraph_); + sync->sync_recalc(b_depsgraph_, b_v3d); /* don't do synchronization if on pause */ if (session_pause) { diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp index 720f521c589..ca51482c98e 100644 --- a/intern/cycles/blender/blender_shader.cpp +++ b/intern/cycles/blender/blender_shader.cpp @@ -1314,19 +1314,23 @@ void BlenderSync::sync_materials(BL::Depsgraph &b_depsgraph, bool update_all) /* Sync World */ -void BlenderSync::sync_world(BL::Depsgraph &b_depsgraph, bool update_all) +void BlenderSync::sync_world(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d, bool update_all) { Background *background = scene->background; Background prevbackground = *background; BL::World b_world = b_scene.world(); - if (world_recalc || update_all || b_world.ptr.data != world_map) { + BlenderViewportParameters new_viewport_parameters(b_v3d); + + if (world_recalc || update_all || b_world.ptr.data != world_map || + viewport_parameters.modified(new_viewport_parameters)) { Shader *shader = scene->default_background; ShaderGraph *graph = new ShaderGraph(); /* create nodes */ - if (b_world && b_world.use_nodes() && b_world.node_tree()) { + if (new_viewport_parameters.use_scene_world && b_world && b_world.use_nodes() && + b_world.node_tree()) { BL::ShaderNodeTree b_ntree(b_world.node_tree()); add_nodes(scene, b_engine, b_data, b_depsgraph, b_scene, graph, b_ntree); @@ -1337,7 +1341,7 @@ void BlenderSync::sync_world(BL::Depsgraph &b_depsgraph, bool update_all) shader->volume_sampling_method = get_volume_sampling(cworld); shader->volume_interpolation_method = get_volume_interpolation(cworld); } - else if (b_world) { + else if (new_viewport_parameters.use_scene_world && b_world) { BackgroundNode *background = new BackgroundNode(); background->color = get_float3(b_world.color()); graph->add(background); @@ -1345,6 +1349,45 @@ void BlenderSync::sync_world(BL::Depsgraph &b_depsgraph, bool update_all) ShaderNode *out = graph->output(); graph->connect(background->output("Background"), out->input("Surface")); } + else if (!new_viewport_parameters.use_scene_world) { + BackgroundNode *background = new BackgroundNode(); + graph->add(background); + + LightPathNode *light_path = new LightPathNode(); + graph->add(light_path); + + MixNode *mix_scene_with_background = new MixNode(); + mix_scene_with_background->color2 = get_float3(b_world.color()); + graph->add(mix_scene_with_background); + + EnvironmentTextureNode *texture_environment = new EnvironmentTextureNode(); + texture_environment->tex_mapping.type = TextureMapping::VECTOR; + texture_environment->tex_mapping.rotation[2] = new_viewport_parameters.studiolight_rotate_z; + texture_environment->filename = new_viewport_parameters.studiolight_path; + graph->add(texture_environment); + + TextureCoordinateNode *texture_coordinate = new TextureCoordinateNode(); + graph->add(texture_coordinate); + + MixNode *mix_background_with_environment = new MixNode(); + mix_background_with_environment->fac = new_viewport_parameters.studiolight_background_alpha; + mix_background_with_environment->color1 = get_float3(b_world.color()); + graph->add(mix_background_with_environment); + + ShaderNode *out = graph->output(); + + graph->connect(texture_coordinate->output("Generated"), + texture_environment->input("Vector")); + graph->connect(light_path->output("Is Camera Ray"), mix_scene_with_background->input("Fac")); + graph->connect(texture_environment->output("Color"), + mix_scene_with_background->input("Color1")); + graph->connect(texture_environment->output("Color"), + mix_background_with_environment->input("Color2")); + graph->connect(mix_background_with_environment->output("Color"), + mix_scene_with_background->input("Color2")); + graph->connect(mix_scene_with_background->output("Color"), background->input("Color")); + graph->connect(background->output("Background"), out->input("Surface")); + } if (b_world) { /* AO */ @@ -1389,7 +1432,8 @@ void BlenderSync::sync_world(BL::Depsgraph &b_depsgraph, bool update_all) background->transparent_roughness_threshold = 0.0f; } - background->use_shader = view_layer.use_background_shader; + background->use_shader = view_layer.use_background_shader | + viewport_parameters.custom_viewport_parameters(); background->use_ao = background->use_ao && view_layer.use_background_ao; if (background->modified(prevbackground)) @@ -1439,7 +1483,7 @@ void BlenderSync::sync_lights(BL::Depsgraph &b_depsgraph, bool update_all) } } -void BlenderSync::sync_shaders(BL::Depsgraph &b_depsgraph) +void BlenderSync::sync_shaders(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d) { /* for auto refresh images */ bool auto_refresh_update = false; @@ -1452,7 +1496,7 @@ void BlenderSync::sync_shaders(BL::Depsgraph &b_depsgraph) shader_map.pre_sync(); - sync_world(b_depsgraph, auto_refresh_update); + sync_world(b_depsgraph, b_v3d, auto_refresh_update); sync_lights(b_depsgraph, auto_refresh_update); sync_materials(b_depsgraph, auto_refresh_update); } diff --git a/intern/cycles/blender/blender_sync.cpp b/intern/cycles/blender/blender_sync.cpp index aec21887088..e50d96cf345 100644 --- a/intern/cycles/blender/blender_sync.cpp +++ b/intern/cycles/blender/blender_sync.cpp @@ -80,7 +80,7 @@ BlenderSync::~BlenderSync() /* Sync */ -void BlenderSync::sync_recalc(BL::Depsgraph &b_depsgraph) +void BlenderSync::sync_recalc(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d) { /* Sync recalc flags from blender to cycles. Actual update is done separate, * so we can do it later on if doing it immediate is not suitable. */ @@ -175,6 +175,11 @@ void BlenderSync::sync_recalc(BL::Depsgraph &b_depsgraph) } } + BlenderViewportParameters new_viewport_parameters(b_v3d); + if (viewport_parameters.modified(new_viewport_parameters)) { + world_recalc = true; + } + /* Updates shader with object dependency if objects changed. */ if (has_updated_objects) { if (scene->default_background->has_object_dependency) { @@ -202,7 +207,7 @@ void BlenderSync::sync_data(BL::RenderSettings &b_render, sync_view_layer(b_v3d, b_view_layer); sync_integrator(); sync_film(); - sync_shaders(b_depsgraph); + sync_shaders(b_depsgraph, b_v3d); sync_images(); sync_curve_settings(); @@ -210,9 +215,9 @@ void BlenderSync::sync_data(BL::RenderSettings &b_render, if (scene->need_motion() == Scene::MOTION_PASS || scene->need_motion() == Scene::MOTION_NONE || scene->camera->motion_position == Camera::MOTION_POSITION_CENTER) { - sync_objects(b_depsgraph); + sync_objects(b_depsgraph, b_v3d); } - sync_motion(b_render, b_depsgraph, b_override, width, height, python_thread_state); + sync_motion(b_render, b_depsgraph, b_v3d, b_override, width, height, python_thread_state); mesh_synced.clear(); diff --git a/intern/cycles/blender/blender_sync.h b/intern/cycles/blender/blender_sync.h index 00afceebde3..c6c7b7549cf 100644 --- a/intern/cycles/blender/blender_sync.h +++ b/intern/cycles/blender/blender_sync.h @@ -23,6 +23,7 @@ #include "RNA_blender_cpp.h" #include "blender/blender_util.h" +#include "blender/blender_viewport.h" #include "render/scene.h" #include "render/session.h" @@ -36,6 +37,7 @@ CCL_NAMESPACE_BEGIN class Background; class BlenderObjectCulling; +class BlenderViewportParameters; class Camera; class Film; class Light; @@ -59,7 +61,7 @@ class BlenderSync { ~BlenderSync(); /* sync */ - void sync_recalc(BL::Depsgraph &b_depsgraph); + void sync_recalc(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d); void sync_data(BL::RenderSettings &b_render, BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d, @@ -106,17 +108,18 @@ class BlenderSync { /* sync */ void sync_lights(BL::Depsgraph &b_depsgraph, bool update_all); void sync_materials(BL::Depsgraph &b_depsgraph, bool update_all); - void sync_objects(BL::Depsgraph &b_depsgraph, float motion_time = 0.0f); + void sync_objects(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d, float motion_time = 0.0f); void sync_motion(BL::RenderSettings &b_render, BL::Depsgraph &b_depsgraph, + BL::SpaceView3D &b_v3d, BL::Object &b_override, int width, int height, void **python_thread_state); void sync_film(); void sync_view(); - void sync_world(BL::Depsgraph &b_depsgraph, bool update_all); - void sync_shaders(BL::Depsgraph &b_depsgraph); + void sync_world(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d, bool update_all); + void sync_shaders(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d); void sync_curve_settings(); void sync_nodes(Shader *shader, BL::ShaderNodeTree &b_ntree); @@ -134,6 +137,7 @@ class BlenderSync { float motion_time, bool show_self, bool show_particles, + bool show_lights, BlenderObjectCulling &culling, bool *use_portal); void sync_light(BL::Object &b_parent, @@ -143,7 +147,7 @@ class BlenderSync { int random_id, Transform &tfm, bool *use_portal); - void sync_background_light(bool use_portal); + void sync_background_light(BL::SpaceView3D &b_v3d, bool use_portal); void sync_mesh_motion(BL::Depsgraph &b_depsgraph, BL::Object &b_ob, Object *object, @@ -183,6 +187,7 @@ class BlenderSync { set<float> motion_times; void *world_map; bool world_recalc; + BlenderViewportParameters viewport_parameters; Scene *scene; bool preview; diff --git a/intern/cycles/blender/blender_viewport.cpp b/intern/cycles/blender/blender_viewport.cpp new file mode 100644 index 00000000000..7af509aab09 --- /dev/null +++ b/intern/cycles/blender/blender_viewport.cpp @@ -0,0 +1,59 @@ +/* + * Copyright 2019 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "blender_viewport.h" + +CCL_NAMESPACE_BEGIN + +BlenderViewportParameters::BlenderViewportParameters() + : use_scene_world(true), + use_scene_lights(true), + studiolight_rotate_z(0.0f), + studiolight_background_alpha(1.0f), + studiolight_path(ustring()) +{ +} + +BlenderViewportParameters::BlenderViewportParameters(BL::SpaceView3D &b_v3d) + : BlenderViewportParameters() +{ + /* We only copy the parameters if we are in look dev mode. otherwise + * defaults are being used. These defaults mimic normal render settings */ + if (b_v3d && b_v3d.shading().type() == BL::View3DShading::type_RENDERED) { + use_scene_world = b_v3d.shading().use_scene_world_render(); + use_scene_lights = b_v3d.shading().use_scene_lights_render(); + if (!use_scene_world) { + studiolight_rotate_z = b_v3d.shading().studiolight_rotate_z(); + studiolight_background_alpha = b_v3d.shading().studiolight_background_alpha(); + studiolight_path = b_v3d.shading().selected_studio_light().path(); + } + } +} + +/* Check if two instances are different. */ +const bool BlenderViewportParameters::modified(const BlenderViewportParameters &other) const +{ + return use_scene_world != other.use_scene_world || use_scene_lights != other.use_scene_lights || + studiolight_rotate_z != other.studiolight_rotate_z || + studiolight_background_alpha != other.studiolight_background_alpha || + studiolight_path != other.studiolight_path; +} + +const bool BlenderViewportParameters::custom_viewport_parameters() const +{ + return !(use_scene_world && use_scene_lights); +} + +CCL_NAMESPACE_END diff --git a/intern/cycles/blender/blender_viewport.h b/intern/cycles/blender/blender_viewport.h new file mode 100644 index 00000000000..bb0d7d7f314 --- /dev/null +++ b/intern/cycles/blender/blender_viewport.h @@ -0,0 +1,47 @@ +/* + * Copyright 2019 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __BLENDER_VIEWPORT_H__ +#define __BLENDER_VIEWPORT_H__ + +#include "MEM_guardedalloc.h" +#include "RNA_types.h" +#include "RNA_access.h" +#include "RNA_blender_cpp.h" + +#include "util/util_param.h" + +CCL_NAMESPACE_BEGIN + +class BlenderViewportParameters { + private: + bool use_scene_world; + bool use_scene_lights; + float studiolight_rotate_z; + float studiolight_background_alpha; + ustring studiolight_path; + + BlenderViewportParameters(); + BlenderViewportParameters(BL::SpaceView3D &b_v3d); + + const bool modified(const BlenderViewportParameters &other) const; + const bool custom_viewport_parameters() const; + friend class BlenderSync; +}; + +CCL_NAMESPACE_END + +#endif
\ No newline at end of file diff --git a/release/scripts/startup/bl_ui/properties_material.py b/release/scripts/startup/bl_ui/properties_material.py index f3c34cf4660..0849437b680 100644 --- a/release/scripts/startup/bl_ui/properties_material.py +++ b/release/scripts/startup/bl_ui/properties_material.py @@ -202,33 +202,47 @@ class EEVEE_MATERIAL_PT_volume(MaterialButtonsPanel, Panel): panel_node_draw(layout, mat.node_tree, 'OUTPUT_MATERIAL', "Volume") +def draw_material_settings(self, context): + layout = self.layout + layout.use_property_split = True + layout.use_property_decorate = False + + mat = context.material + + layout.prop(mat, "use_backface_culling") + layout.prop(mat, "blend_method") + layout.prop(mat, "shadow_method") + + row = layout.row() + row.active = ((mat.blend_method == 'CLIP') or (mat.shadow_method == 'CLIP')) + row.prop(mat, "alpha_threshold") + + if mat.blend_method not in {'OPAQUE', 'CLIP', 'HASHED'}: + layout.prop(mat, "show_transparent_back") + + layout.prop(mat, "use_screen_refraction") + layout.prop(mat, "refraction_depth") + layout.prop(mat, "use_sss_translucency") + layout.prop(mat, "pass_index") + + class EEVEE_MATERIAL_PT_settings(MaterialButtonsPanel, Panel): bl_label = "Settings" bl_context = "material" COMPAT_ENGINES = {'BLENDER_EEVEE'} def draw(self, context): - layout = self.layout - layout.use_property_split = True - layout.use_property_decorate = False - - mat = context.material - - layout.prop(mat, "use_backface_culling") - layout.prop(mat, "blend_method") - layout.prop(mat, "shadow_method") + draw_material_settings(self, context) - row = layout.row() - row.active = ((mat.blend_method == 'CLIP') or (mat.shadow_method == 'CLIP')) - row.prop(mat, "alpha_threshold") - if mat.blend_method not in {'OPAQUE', 'CLIP', 'HASHED'}: - layout.prop(mat, "show_transparent_back") +class EEVEE_MATERIAL_PT_viewport_settings(MaterialButtonsPanel, Panel): + bl_label = "Settings" + bl_context = "material" + bl_parent_id = "MATERIAL_PT_viewport" + COMPAT_ENGINES = {'BLENDER_RENDER'} - layout.prop(mat, "use_screen_refraction") - layout.prop(mat, "refraction_depth") - layout.prop(mat, "use_sss_translucency") - layout.prop(mat, "pass_index") + def draw(self, context): + draw_material_settings(self, context) class MATERIAL_PT_viewport(MaterialButtonsPanel, Panel): @@ -263,6 +277,7 @@ classes = ( EEVEE_MATERIAL_PT_volume, EEVEE_MATERIAL_PT_settings, MATERIAL_PT_viewport, + EEVEE_MATERIAL_PT_viewport_settings, MATERIAL_PT_custom_props, ) diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py index fdf683c16ea..1544cf3e140 100644 --- a/release/scripts/startup/bl_ui/space_view3d.py +++ b/release/scripts/startup/bl_ui/space_view3d.py @@ -5057,7 +5057,8 @@ class VIEW3D_PT_shading_lighting(Panel): @classmethod def poll(cls, context): shading = VIEW3D_PT_shading.get_shading(context) - return shading.type in {'SOLID', 'MATERIAL'} + engine = context.scene.render.engine + return shading.type in {'SOLID', 'MATERIAL'} or engine == 'BLENDER_EEVEE' and shading.type == 'RENDERED' def draw(self, context): layout = self.layout @@ -5105,7 +5106,6 @@ class VIEW3D_PT_shading_lighting(Panel): elif shading.light == 'MATCAP': sub.scale_y = 0.6 # smaller matcap preview - sub.template_icon_view(shading, "studio_light", scale_popup=3.0) col = split.column() @@ -5115,8 +5115,29 @@ class VIEW3D_PT_shading_lighting(Panel): elif shading.type == 'MATERIAL': col.prop(shading, "use_scene_lights") col.prop(shading, "use_scene_world") + col = layout.column() + split = col.split(factor=0.9) if not shading.use_scene_world: + col = split.column() + sub = col.row() + sub.scale_y = 0.6 + sub.template_icon_view(shading, "studio_light", scale_popup=3) + + col = split.column() + col.operator("preferences.studiolight_show", emboss=False, text="", icon='PREFERENCES') + + split = layout.split(factor=0.9) + col = split.column() + col.prop(shading, "studiolight_rotate_z", text="Rotation") + col.prop(shading, "studiolight_background_alpha") + col = split.column() # to align properly with above + + elif shading.type == 'RENDERED': + col.prop(shading, "use_scene_lights_render") + col.prop(shading, "use_scene_world_render") + + if not shading.use_scene_world_render: col = layout.column() split = col.split(factor=0.9) @@ -5128,12 +5149,11 @@ class VIEW3D_PT_shading_lighting(Panel): col = split.column() col.operator("preferences.studiolight_show", emboss=False, text="", icon='PREFERENCES') - if shading.selected_studio_light.type == 'WORLD': - split = layout.split(factor=0.9) - col = split.column() - col.prop(shading, "studiolight_rotate_z", text="Rotation") - col.prop(shading, "studiolight_background_alpha") - col = split.column() # to align properly with above + split = layout.split(factor=0.9) + col = split.column() + col.prop(shading, "studiolight_rotate_z", text="Rotation") + col.prop(shading, "studiolight_background_alpha") + col = split.column() # to align properly with above class VIEW3D_PT_shading_color(Panel): diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h index 65086f57616..1451f0c0d51 100644 --- a/source/blender/blenkernel/BKE_blender_version.h +++ b/source/blender/blenkernel/BKE_blender_version.h @@ -27,7 +27,7 @@ * \note Use #STRINGIFY() rather than defining with quotes. */ #define BLENDER_VERSION 281 -#define BLENDER_SUBVERSION 5 +#define BLENDER_SUBVERSION 6 /** Several breakages with 280, e.g. collections vs layers. */ #define BLENDER_MINVERSION 280 #define BLENDER_MINSUBVERSION 0 diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c index 619845c9ecb..4837fa8639e 100644 --- a/source/blender/blenkernel/intern/screen.c +++ b/source/blender/blenkernel/intern/screen.c @@ -856,7 +856,8 @@ void BKE_screen_view3d_shading_init(View3DShading *shading) shading->type = OB_SOLID; shading->prev_type = OB_SOLID; - shading->flag = V3D_SHADING_SPECULAR_HIGHLIGHT | V3D_SHADING_XRAY_WIREFRAME; + shading->flag = V3D_SHADING_SPECULAR_HIGHLIGHT | V3D_SHADING_XRAY_WIREFRAME | + V3D_SHADING_SCENE_LIGHTS_RENDER | V3D_SHADING_SCENE_WORLD_RENDER; shading->light = V3D_LIGHTING_STUDIO; shading->shadow_intensity = 0.5f; shading->xray_alpha = 0.5f; diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c index 45276181102..a735b399ce3 100644 --- a/source/blender/blenloader/intern/versioning_280.c +++ b/source/blender/blenloader/intern/versioning_280.c @@ -3732,6 +3732,28 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) } } + if (!MAIN_VERSION_ATLEAST(bmain, 281, 6)) { + for (bScreen *screen = bmain->screens.first; screen; screen = screen->id.next) { + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) { + if (sl->spacetype == SPACE_VIEW3D) { + View3D *v3d = (View3D *)sl; + v3d->shading.flag |= V3D_SHADING_SCENE_LIGHTS_RENDER | V3D_SHADING_SCENE_WORLD_RENDER; + + /* files by default don't have studio lights selected unless interacted + * with the shading popover. When no studiolight could be read, we will + * select the default world one. */ + StudioLight *studio_light = BKE_studiolight_find(v3d->shading.lookdev_light, + STUDIOLIGHT_TYPE_WORLD); + if (studio_light != NULL) { + STRNCPY(v3d->shading.lookdev_light, studio_light->name); + } + } + } + } + } + } + { /* Versioning code until next subversion bump goes here. */ diff --git a/source/blender/draw/engines/eevee/eevee_private.h b/source/blender/draw/engines/eevee/eevee_private.h index 3cdafee95a2..fefdaef970a 100644 --- a/source/blender/draw/engines/eevee/eevee_private.h +++ b/source/blender/draw/engines/eevee/eevee_private.h @@ -118,16 +118,19 @@ extern struct DrawEngineType draw_engine_eevee_type; } \ ((void)0) -#define OVERLAY_ENABLED(v3d) ((v3d) && (v3d->flag2 & V3D_HIDE_OVERLAYS) == 0) -#define LOOK_DEV_MODE_ENABLED(v3d) ((v3d) && (v3d->shading.type == OB_MATERIAL)) +#define MATERIAL_PREVIEW_MODE_ENABLED(v3d) ((v3d) && (v3d->shading.type == OB_MATERIAL)) #define LOOK_DEV_OVERLAY_ENABLED(v3d) \ - (LOOK_DEV_MODE_ENABLED(v3d) && OVERLAY_ENABLED(v3d) && \ + ((v3d) && (v3d->shading.type == OB_MATERIAL) && ((v3d->flag2 & V3D_HIDE_OVERLAYS) == 0) && \ (v3d->overlay.flag & V3D_OVERLAY_LOOK_DEV)) #define USE_SCENE_LIGHT(v3d) \ - ((!v3d) || (!LOOK_DEV_MODE_ENABLED(v3d)) || \ - ((LOOK_DEV_MODE_ENABLED(v3d) && (v3d->shading.flag & V3D_SHADING_SCENE_LIGHTS)))) + ((!v3d) || \ + ((v3d->shading.type == OB_MATERIAL) && (v3d->shading.flag & V3D_SHADING_SCENE_LIGHTS)) || \ + ((v3d->shading.type == OB_RENDER) && (v3d->shading.flag & V3D_SHADING_SCENE_LIGHTS_RENDER))) #define LOOK_DEV_STUDIO_LIGHT_ENABLED(v3d) \ - (LOOK_DEV_MODE_ENABLED(v3d) && !(v3d->shading.flag & V3D_SHADING_SCENE_WORLD)) + ((v3d) && (((v3d->shading.type == OB_MATERIAL) && \ + ((v3d->shading.flag & V3D_SHADING_SCENE_WORLD) == 0)) || \ + ((v3d->shading.type == OB_RENDER) && \ + ((v3d->shading.flag & V3D_SHADING_SCENE_WORLD_RENDER) == 0)))) #define OCTAHEDRAL_SIZE_FROM_CUBESIZE(cube_size) \ ((int)ceilf(sqrtf((cube_size * cube_size) * 6.0f))) diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index f6afa112f08..7cd38c95a7b 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -39,6 +39,7 @@ #include "BKE_scene.h" #include "BKE_object.h" #include "BKE_paint.h" +#include "BKE_studiolight.h" #include "BKE_unit.h" #include "BLF_api.h" @@ -1860,6 +1861,9 @@ ImBuf *ED_view3d_draw_offscreen_imbuf_simple(Depsgraph *depsgraph, if (drawtype == OB_MATERIAL) { v3d.shading.flag = V3D_SHADING_SCENE_WORLD | V3D_SHADING_SCENE_LIGHTS; } + else if (drawtype == OB_RENDER) { + v3d.shading.flag = V3D_SHADING_SCENE_WORLD_RENDER | V3D_SHADING_SCENE_LIGHTS_RENDER; + } v3d.flag2 = V3D_HIDE_OVERLAYS; diff --git a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h index 51655790fbd..6168b00508b 100644 --- a/source/blender/makesdna/DNA_view3d_types.h +++ b/source/blender/makesdna/DNA_view3d_types.h @@ -418,6 +418,8 @@ enum { V3D_SHADING_WORLD_ORIENTATION = (1 << 9), V3D_SHADING_BACKFACE_CULLING = (1 << 10), V3D_SHADING_DEPTH_OF_FIELD = (1 << 11), + V3D_SHADING_SCENE_LIGHTS_RENDER = (1 << 12), + V3D_SHADING_SCENE_WORLD_RENDER = (1 << 13), }; /** #View3DShading.color_type */ diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index ca857fb7be8..7ad0401b0a4 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -343,7 +343,11 @@ static const EnumPropertyItem autosnap_items[] = { const EnumPropertyItem rna_enum_shading_type_items[] = { {OB_WIRE, "WIREFRAME", ICON_SHADING_WIRE, "Wireframe", "Display the object as wire edges"}, {OB_SOLID, "SOLID", ICON_SHADING_SOLID, "Solid", "Display in solid mode"}, - {OB_MATERIAL, "MATERIAL", ICON_SHADING_TEXTURE, "Look Dev", "Display in Look Dev mode"}, + {OB_MATERIAL, + "MATERIAL", + ICON_SHADING_TEXTURE, + "Material Preview", + "Display in Material Preview mode"}, {OB_RENDER, "RENDERED", ICON_SHADING_RENDERED, "Rendered", "Display render preview"}, {0, NULL, 0, NULL, NULL}, }; @@ -967,6 +971,11 @@ static Scene *rna_3DViewShading_scene(PointerRNA *ptr) { /* Get scene, depends if using 3D view or OpenGL render settings. */ ID *id = ptr->owner_id; + if (!id) { + /* When accessed from an external render engine the id.data is NULL + * This might be missing from the RNA CPP Api */ + return NULL; + } if (GS(id->name) == ID_SCE) { return (Scene *)id; } @@ -1054,6 +1063,7 @@ static PointerRNA rna_View3DShading_selected_studio_light_get(PointerRNA *ptr) sl = BKE_studiolight_find(shading->studio_light, STUDIOLIGHT_FLAG_ALL); } else { + /* OB_MATERIAL and OB_RENDER */ sl = BKE_studiolight_find(shading->lookdev_light, STUDIOLIGHT_FLAG_ALL); } return rna_pointer_inherit_refine(ptr, &RNA_StudioLight, sl); @@ -1088,21 +1098,32 @@ static const EnumPropertyItem *rna_View3DShading_color_type_itemf(bContext *UNUS } } -/* Studio light */ -static int rna_View3DShading_studio_light_get(PointerRNA *ptr) +static void rna_View3DShading_studio_light_get_storage(View3DShading *shading, + char **dna_storage, + int *flag) { - View3DShading *shading = (View3DShading *)ptr->data; - char *dna_storage = shading->studio_light; + *dna_storage = shading->studio_light; - int flag = STUDIOLIGHT_TYPE_STUDIO; - if (shading->type == OB_SOLID && shading->light == V3D_LIGHTING_MATCAP) { - flag = STUDIOLIGHT_TYPE_MATCAP; - dna_storage = shading->matcap; + *flag = STUDIOLIGHT_TYPE_STUDIO; + if (shading->type == OB_SOLID) { + if (shading->light == V3D_LIGHTING_MATCAP) { + *flag = STUDIOLIGHT_TYPE_MATCAP; + *dna_storage = shading->matcap; + } } - else if (shading->type == OB_MATERIAL) { - flag = STUDIOLIGHT_TYPE_WORLD; - dna_storage = shading->lookdev_light; + else { + *flag = STUDIOLIGHT_TYPE_WORLD; + *dna_storage = shading->lookdev_light; } +} + +static int rna_View3DShading_studio_light_get(PointerRNA *ptr) +{ + View3DShading *shading = (View3DShading *)ptr->data; + char *dna_storage; + int flag; + + rna_View3DShading_studio_light_get_storage(shading, &dna_storage, &flag); StudioLight *sl = BKE_studiolight_find(dna_storage, flag); if (sl) { BLI_strncpy(dna_storage, sl->name, FILE_MAXFILE); @@ -1116,17 +1137,10 @@ static int rna_View3DShading_studio_light_get(PointerRNA *ptr) static void rna_View3DShading_studio_light_set(PointerRNA *ptr, int value) { View3DShading *shading = (View3DShading *)ptr->data; - char *dna_storage = shading->studio_light; + char *dna_storage; + int flag; - int flag = STUDIOLIGHT_TYPE_STUDIO; - if (shading->type == OB_SOLID && shading->light == V3D_LIGHTING_MATCAP) { - flag = STUDIOLIGHT_TYPE_MATCAP; - dna_storage = shading->matcap; - } - else if (shading->type == OB_MATERIAL) { - flag = STUDIOLIGHT_TYPE_WORLD; - dna_storage = shading->lookdev_light; - } + rna_View3DShading_studio_light_get_storage(shading, &dna_storage, &flag); StudioLight *sl = BKE_studiolight_findindex(value, flag); if (sl) { BLI_strncpy(dna_storage, sl->name, FILE_MAXFILE); @@ -1173,6 +1187,7 @@ static const EnumPropertyItem *rna_View3DShading_studio_light_itemf(bContext *UN break; case OB_MATERIAL: + case OB_RENDER: show_studiolight = ((sl->flag & STUDIOLIGHT_TYPE_WORLD) != 0); icon_id = sl->icon_id_radiance; break; @@ -3093,6 +3108,15 @@ static void rna_def_space_view3d_shading(BlenderRNA *brna) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); + prop = RNA_def_property(srna, "studiolight_background_alpha", PROP_FLOAT, PROP_FACTOR); + RNA_def_property_float_sdna(prop, NULL, "studiolight_background"); + RNA_def_property_float_default(prop, 0.0); + RNA_def_property_ui_text(prop, "Background", "Show the studiolight in the background"); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_ui_range(prop, 0.00f, 1.0f, 1, 3); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); + prop = RNA_def_property(srna, "color_type", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "color_type"); RNA_def_property_enum_items(prop, rna_enum_shading_color_type_items); @@ -3172,12 +3196,28 @@ static void rna_def_space_view3d_shading(BlenderRNA *brna) prop = RNA_def_property(srna, "use_scene_lights", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_SHADING_SCENE_LIGHTS); + RNA_def_property_boolean_default(prop, false); RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_ui_text(prop, "Scene Lights", "Render lights and light probes of the scene"); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); prop = RNA_def_property(srna, "use_scene_world", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_SHADING_SCENE_WORLD); + RNA_def_property_boolean_default(prop, false); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_ui_text(prop, "Scene World", "Use scene world for lighting"); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); + + prop = RNA_def_property(srna, "use_scene_lights_render", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_SHADING_SCENE_LIGHTS_RENDER); + RNA_def_property_boolean_default(prop, true); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_ui_text(prop, "Scene Lights", "Render lights and light probes of the scene"); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); + + prop = RNA_def_property(srna, "use_scene_world_render", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_SHADING_SCENE_WORLD_RENDER); + RNA_def_property_boolean_default(prop, true); RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_ui_text(prop, "Scene World", "Use scene world for lighting"); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); @@ -3203,15 +3243,6 @@ static void rna_def_space_view3d_shading(BlenderRNA *brna) RNA_def_property_ui_range(prop, 0.00f, 1.0f, 1, 3); RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); - - prop = RNA_def_property(srna, "studiolight_background_alpha", PROP_FLOAT, PROP_FACTOR); - RNA_def_property_float_sdna(prop, NULL, "studiolight_background"); - RNA_def_property_float_default(prop, 0.0); - RNA_def_property_ui_text(prop, "Background", "Show the studiolight in the background"); - RNA_def_property_range(prop, 0.0f, 1.0f); - RNA_def_property_ui_range(prop, 0.00f, 1.0f, 1, 3); - RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); - RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); } static void rna_def_space_view3d_overlay(BlenderRNA *brna) @@ -3371,7 +3402,7 @@ static void rna_def_space_view3d_overlay(BlenderRNA *brna) prop = RNA_def_property(srna, "show_look_dev", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "overlay.flag", V3D_OVERLAY_LOOK_DEV); RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); - RNA_def_property_ui_text(prop, "Look Dev Preview", "Show look development spheres and palette"); + RNA_def_property_ui_text(prop, "Look Dev Preview", "Show look development spheres"); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); prop = RNA_def_property(srna, "show_wireframes", PROP_BOOLEAN, PROP_NONE); diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index d08f4e236ee..bdc89f2bf2b 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -288,6 +288,10 @@ void WM_init(bContext *C, int argc, const char **argv) const bool use_data = true; const bool use_userdef = true; + /* Studiolights needs to be init before we read the homefile, otherwise the versioning cannot + * find the default studiolight.*/ + BKE_studiolight_init(); + wm_homefile_read(C, NULL, G.factory_startup, @@ -315,8 +319,6 @@ void WM_init(bContext *C, int argc, const char **argv) UI_init(); } - BKE_studiolight_init(); - ED_spacemacros_init(); /* note: there is a bug where python needs initializing before loading the |