From 5855f317a7070d69dbb94761c5a2c2f53b058a6e Mon Sep 17 00:00:00 2001 From: Pablo Dobarro Date: Fri, 18 Sep 2020 00:42:24 +0200 Subject: LookDev: Lock HDRI rotation to View This adds an option for the HDRI rotation to follow the view rotation. When this option is enabled, this allows EEVEE materials to be used as matcaps for sculpting and painting. This has an extra performance cost when orbiting around the model as the lookdev cache needs to be recalculated, but in my test it is barely noticeable. Reviewed By: fclem Differential Revision: https://developer.blender.org/D8566 --- source/blender/draw/engines/eevee/eevee_lookdev.c | 17 +++++++++++++++++ source/blender/makesdna/DNA_view3d_types.h | 1 + source/blender/makesrna/intern/rna_space.c | 9 +++++++++ 3 files changed, 27 insertions(+) (limited to 'source') diff --git a/source/blender/draw/engines/eevee/eevee_lookdev.c b/source/blender/draw/engines/eevee/eevee_lookdev.c index 2ca234ad5bd..5deaf4d4d68 100644 --- a/source/blender/draw/engines/eevee/eevee_lookdev.c +++ b/source/blender/draw/engines/eevee/eevee_lookdev.c @@ -198,6 +198,20 @@ void EEVEE_lookdev_cache_init(EEVEE_Data *vedata, DRWShadingGroup *grp = DRW_shgroup_create(shader, pass); axis_angle_to_mat3_single(g_data->studiolight_matrix, 'Z', shading->studiolight_rot_z); + + float studiolight_matrix[3][3] = {{0.0f}}; + if (shading->flag & V3D_SHADING_STUDIOLIGHT_VIEW_ROTATION) { + float view_matrix[4][4]; + float view_rot_matrix[3][3]; + float x_rot_matrix[3][3]; + DRW_view_viewmat_get(NULL, view_matrix, false); + copy_m3_m4(view_rot_matrix, view_matrix); + axis_angle_to_mat3_single(x_rot_matrix, 'X', M_PI / 2.0f); + mul_m3_m3m3(view_rot_matrix, x_rot_matrix, view_rot_matrix); + mul_m3_m3m3(view_rot_matrix, g_data->studiolight_matrix, view_rot_matrix); + copy_m3_m3(studiolight_matrix, view_rot_matrix); + } + DRW_shgroup_uniform_mat3(grp, "StudioLightMatrix", g_data->studiolight_matrix); if (probe_render) { @@ -222,6 +236,8 @@ void EEVEE_lookdev_cache_init(EEVEE_Data *vedata, /* Do we need to recalc the lightprobes? */ if (g_data->studiolight_index != sl->index || + (shading->flag & V3D_SHADING_STUDIOLIGHT_VIEW_ROTATION && + !equals_m3m3(g_data->studiolight_matrix, studiolight_matrix)) || g_data->studiolight_rot_z != shading->studiolight_rot_z || g_data->studiolight_intensity != shading->studiolight_intensity || g_data->studiolight_cubemap_res != scene->eevee.gi_cubemap_resolution || @@ -229,6 +245,7 @@ void EEVEE_lookdev_cache_init(EEVEE_Data *vedata, g_data->studiolight_filter_quality != scene->eevee.gi_filter_quality) { stl->lookdev_lightcache->flag |= LIGHTCACHE_UPDATE_WORLD; g_data->studiolight_index = sl->index; + copy_m3_m3(g_data->studiolight_matrix, studiolight_matrix); g_data->studiolight_rot_z = shading->studiolight_rot_z; g_data->studiolight_intensity = shading->studiolight_intensity; g_data->studiolight_cubemap_res = scene->eevee.gi_cubemap_resolution; diff --git a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h index 7bfdc14d25c..64f26a756db 100644 --- a/source/blender/makesdna/DNA_view3d_types.h +++ b/source/blender/makesdna/DNA_view3d_types.h @@ -479,6 +479,7 @@ enum { V3D_SHADING_DEPTH_OF_FIELD = (1 << 11), V3D_SHADING_SCENE_LIGHTS_RENDER = (1 << 12), V3D_SHADING_SCENE_WORLD_RENDER = (1 << 13), + V3D_SHADING_STUDIOLIGHT_VIEW_ROTATION = (1 << 14), }; /** #View3DShading.cavity_type */ diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index d33939724ef..213326eff8c 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -3345,6 +3345,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 | NS_VIEW3D_SHADING, NULL); + prop = RNA_def_property(srna, "use_studiolight_view_rotation", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_negative_sdna( + prop, NULL, "flag", V3D_SHADING_STUDIOLIGHT_VIEW_ROTATION); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_boolean_default(prop, false); + RNA_def_property_ui_text( + prop, "World Space Lighting", "Make the HDR rotation fixed and not follow the camera"); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D | NS_VIEW3D_SHADING, 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); -- cgit v1.2.3