Workbench: Add option to have world space lighting in studio light mode

This option is per viewport.

Having view space shading make sense when working on isolated objects like
if you were holding them in your hands. But for entire scene work, it is
better to have the lighting fixed to have a better spatial representation.
This commit is contained in:
Clément Foucault 2018-11-29 20:57:09 +01:00
parent 844788a36c
commit 48a7785fd4
5 changed files with 22 additions and 7 deletions

View File

@ -4189,14 +4189,22 @@ class VIEW3D_PT_shading_lighting(Panel):
sub.scale_y = 0.6 # smaller matcap/hdri preview
if shading.light == 'STUDIO':
# Not implemented right now
userpref = context.user_preferences
system = userpref.system
sub.template_icon_view(shading, "studio_light", scale=3)
# if shading.selected_studio_light.type == 'WORLD':
# col.prop(shading, "studiolight_rotate_z", text="Rotation")
col = split.column()
# col.operator('wm.studiolight_userpref_show', emboss=False, text="", icon='PREFERENCES')
col.operator('wm.studiolight_userpref_show', emboss=False, text="", icon='PREFERENCES')
split = layout.split(factor=0.9)
col = split.column()
row = col.row()
row.prop(shading, "use_world_space_lighting", text="", icon="WORLD", toggle=True)
row = row.row()
row.active = shading.use_world_space_lighting
row.prop(shading, "studiolight_rotate_z", text="Rotation")
col = split.column() # to align properly with above
elif shading.light == 'MATCAP':
sub.template_icon_view(shading, "studio_light", scale=3)

View File

@ -46,6 +46,7 @@
#define FLAT_ENABLED(wpd) (wpd->shading.light == V3D_LIGHTING_FLAT)
#define STUDIOLIGHT_ENABLED(wpd) (wpd->shading.light == V3D_LIGHTING_STUDIO)
#define MATCAP_ENABLED(wpd) (wpd->shading.light == V3D_LIGHTING_MATCAP)
#define USE_WORLD_ORIENTATION(wpd) ((wpd->shading.flag & V3D_SHADING_WORLD_ORIENTATION) != 0)
#define STUDIOLIGHT_TYPE_WORLD_ENABLED(wpd) (STUDIOLIGHT_ENABLED(wpd) && (wpd->studio_light->flag & STUDIOLIGHT_TYPE_WORLD))
#define STUDIOLIGHT_TYPE_STUDIO_ENABLED(wpd) (STUDIOLIGHT_ENABLED(wpd) && (wpd->studio_light->flag & STUDIOLIGHT_TYPE_STUDIO))
#define STUDIOLIGHT_TYPE_MATCAP_ENABLED(wpd) (MATCAP_ENABLED(wpd) && (wpd->studio_light->flag & STUDIOLIGHT_TYPE_MATCAP))

View File

@ -37,8 +37,7 @@ void studiolight_update_world(WORKBENCH_PrivateData *wpd, StudioLight *studiolig
float view_matrix[4][4], rot_matrix[4][4];
DRW_viewport_matrix_get(view_matrix, DRW_MAT_VIEW);
/* TODO enable when we support studiolight presets. */
if (STUDIOLIGHT_TYPE_WORLD_ENABLED(wpd) && false) {
if (USE_WORLD_ORIENTATION(wpd)) {
axis_angle_to_mat4_single(rot_matrix, 'Y', -wpd->shading.studiolight_rot_z);
mul_m4_m4m4(rot_matrix, rot_matrix, view_matrix);
swap_v3_v3(rot_matrix[2], rot_matrix[1]);

View File

@ -395,6 +395,7 @@ enum {
V3D_SHADING_MATCAP_FLIP_X = (1 << 6),
V3D_SHADING_SCENE_WORLD = (1 << 7),
V3D_SHADING_XRAY_BONE = (1 << 8),
V3D_SHADING_WORLD_ORIENTATION = (1 << 9),
};
/* View3DShading->color_type */

View File

@ -2441,6 +2441,12 @@ static void rna_def_space_view3d_shading(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Studiolight", "Studio lighting setup");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
prop = RNA_def_property(srna, "use_world_space_lighting", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_SHADING_WORLD_ORIENTATION);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_ui_text(prop, "World Space Lighting", "Make the lighting fixed and not follow the camera");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
prop = RNA_def_property(srna, "show_cavity", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_SHADING_CAVITY);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);