From 1b287230a46d98f7cdfe6cbfd6c86e43c7e14968 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Wed, 4 Sep 2019 16:22:47 +0200 Subject: Viewport Shading: StudioLight Intensity Add option to change the Intensity of the HDRI in the 3d viewport. This works for both EEVEE and Cycles Reviewed By: brecht, fclem Differential Revision: https://developer.blender.org/D5674 --- source/blender/blenkernel/intern/screen.c | 1 + source/blender/blenloader/intern/versioning_280.c | 15 ++++++++++++++- source/blender/draw/engines/eevee/eevee_lookdev.c | 5 +++++ source/blender/draw/engines/eevee/eevee_private.h | 1 + .../draw/engines/eevee/shaders/default_world_frag.glsl | 2 ++ source/blender/makesdna/DNA_view3d_types.h | 4 ++-- source/blender/makesrna/intern/rna_space.c | 11 ++++++++++- 7 files changed, 35 insertions(+), 4 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c index 4837fa8639e..9f049b61b5a 100644 --- a/source/blender/blenkernel/intern/screen.c +++ b/source/blender/blenkernel/intern/screen.c @@ -869,6 +869,7 @@ void BKE_screen_view3d_shading_init(View3DShading *shading) shading->curvature_valley_factor = 1.0f; copy_v3_fl(shading->single_color, 0.8f); copy_v3_fl(shading->background_color, 0.05f); + shading->studiolight_intensity = 1.0f; } /* magic zoom calculation, no idea what diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c index 0d108704b4e..ca00e7cc62f 100644 --- a/source/blender/blenloader/intern/versioning_280.c +++ b/source/blender/blenloader/intern/versioning_280.c @@ -3767,7 +3767,6 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) { /* Versioning code until next subversion bump goes here. */ - 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) { @@ -3820,5 +3819,19 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) } } } + + /* Added studiolight intensity */ + if (!DNA_struct_elem_find(fd->filesdna, "View3DShading", "float", "studiolight_intensity")) { + 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.studiolight_intensity = 1.0f; + } + } + } + } + } } } diff --git a/source/blender/draw/engines/eevee/eevee_lookdev.c b/source/blender/draw/engines/eevee/eevee_lookdev.c index f52fcf31267..94d61a81fcc 100644 --- a/source/blender/draw/engines/eevee/eevee_lookdev.c +++ b/source/blender/draw/engines/eevee/eevee_lookdev.c @@ -151,6 +151,9 @@ void EEVEE_lookdev_cache_init(EEVEE_Data *vedata, stl->g_data->studiolight_matrix, 'Z', v3d->shading.studiolight_rot_z); DRW_shgroup_uniform_mat3(*grp, "StudioLightMatrix", stl->g_data->studiolight_matrix); DRW_shgroup_uniform_float_copy(*grp, "backgroundAlpha", background_alpha); + DRW_shgroup_uniform_float( + *grp, "studioLightIntensity", &v3d->shading.studiolight_intensity, 1); + DRW_shgroup_uniform_vec3(*grp, "color", background_color, 1); DRW_shgroup_call(*grp, geom, NULL); if (!pinfo) { @@ -170,12 +173,14 @@ void EEVEE_lookdev_cache_init(EEVEE_Data *vedata, /* Do we need to recalc the lightprobes? */ if (g_data->studiolight_index != sl->index || g_data->studiolight_rot_z != v3d->shading.studiolight_rot_z || + g_data->studiolight_intensity != v3d->shading.studiolight_intensity || g_data->studiolight_cubemap_res != scene->eevee.gi_cubemap_resolution || g_data->studiolight_glossy_clamp != scene->eevee.gi_glossy_clamp || g_data->studiolight_filter_quality != scene->eevee.gi_filter_quality) { stl->lookdev_lightcache->flag |= LIGHTCACHE_UPDATE_WORLD; g_data->studiolight_index = sl->index; g_data->studiolight_rot_z = v3d->shading.studiolight_rot_z; + g_data->studiolight_intensity = v3d->shading.studiolight_intensity; g_data->studiolight_cubemap_res = scene->eevee.gi_cubemap_resolution; g_data->studiolight_glossy_clamp = scene->eevee.gi_glossy_clamp; g_data->studiolight_filter_quality = scene->eevee.gi_filter_quality; diff --git a/source/blender/draw/engines/eevee/eevee_private.h b/source/blender/draw/engines/eevee/eevee_private.h index 28a8983cfee..f4f40d40de6 100644 --- a/source/blender/draw/engines/eevee/eevee_private.h +++ b/source/blender/draw/engines/eevee/eevee_private.h @@ -789,6 +789,7 @@ typedef struct EEVEE_PrivateData { /* LookDev Settings */ int studiolight_index; float studiolight_rot_z; + float studiolight_intensity; int studiolight_cubemap_res; float studiolight_glossy_clamp; float studiolight_filter_quality; diff --git a/source/blender/draw/engines/eevee/shaders/default_world_frag.glsl b/source/blender/draw/engines/eevee/shaders/default_world_frag.glsl index 70466479a29..41e103609f3 100644 --- a/source/blender/draw/engines/eevee/shaders/default_world_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/default_world_frag.glsl @@ -8,6 +8,7 @@ out vec4 FragColor; uniform mat3 StudioLightMatrix; uniform sampler2D image; uniform float studioLightBackground = 1.0; +uniform float studioLightIntensity = 1.0; in vec3 viewPosition; # define M_PI 3.14159265358979323846 @@ -51,6 +52,7 @@ void main() #ifdef LOOKDEV vec3 worldvec = background_transform_to_world(viewPosition); background_color = node_tex_environment_equirectangular(StudioLightMatrix * worldvec, image).rgb; + background_color *= studioLightIntensity; background_color = mix(color, background_color, studioLightBackground); #else background_color = color; diff --git a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h index 6168b00508b..5db0021af22 100644 --- a/source/blender/makesdna/DNA_view3d_types.h +++ b/source/blender/makesdna/DNA_view3d_types.h @@ -152,7 +152,7 @@ typedef struct View3DShading { char background_type; char cavity_type; char wire_color_type; - char _pad[6]; + char _pad[2]; /** FILE_MAXFILE. */ char studio_light[256]; @@ -166,6 +166,7 @@ typedef struct View3DShading { float studiolight_rot_z; float studiolight_background; + float studiolight_intensity; float object_outline_color[3]; float xray_alpha; @@ -178,7 +179,6 @@ typedef struct View3DShading { float curvature_ridge_factor; float curvature_valley_factor; - } View3DShading; /** 3D Viewport Overlay settings. */ diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index 727745e69dd..171da61e483 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -3112,9 +3112,18 @@ 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_intensity", PROP_FLOAT, PROP_FACTOR); + RNA_def_property_float_sdna(prop, NULL, "studiolight_intensity"); + RNA_def_property_float_default(prop, 1.0f); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_ui_text(prop, "Strength", "Strength of the studiolight"); + RNA_def_property_range(prop, 0.0f, FLT_MAX); + RNA_def_property_ui_range(prop, 0.0f, 2.0f, 1, 3); + 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_float_default(prop, 0.0f); 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); -- cgit v1.2.3