Viewport Shading: StudioLight Intensity
authorJeroen Bakker <j.bakker@atmind.nl>
Wed, 4 Sep 2019 14:22:47 +0000 (16:22 +0200)
committerJeroen Bakker <j.bakker@atmind.nl>
Fri, 6 Sep 2019 06:35:14 +0000 (08:35 +0200)
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

12 files changed:
intern/cycles/blender/addon/ui.py
intern/cycles/blender/blender_shader.cpp
intern/cycles/blender/blender_viewport.cpp
intern/cycles/blender/blender_viewport.h
release/scripts/startup/bl_ui/space_view3d.py
source/blender/blenkernel/intern/screen.c
source/blender/blenloader/intern/versioning_280.c
source/blender/draw/engines/eevee/eevee_lookdev.c
source/blender/draw/engines/eevee/eevee_private.h
source/blender/draw/engines/eevee/shaders/default_world_frag.glsl
source/blender/makesdna/DNA_view3d_types.h
source/blender/makesrna/intern/rna_space.c

index 6f2794531fdd9a7eeb14d3e2e169db9194edc4c0..0af59411c5caf3bbcdb6f88e60a642285e64efb1 100644 (file)
@@ -2086,6 +2086,7 @@ class CYCLES_VIEW3D_PT_shading_lighting(Panel):
             split = layout.split(factor=0.9)
             col = split.column()
             col.prop(shading, "studiolight_rotate_z", text="Rotation")
+            col.prop(shading, "studiolight_intensity")
             col.prop(shading, "studiolight_background_alpha")
 
 
index f5a76002eb6b0137f456dd97af7bf939b8324a83..de04cc7714a94c5ea08cbcc5ae01271b806716bf 100644 (file)
@@ -1347,6 +1347,14 @@ void BlenderSync::sync_world(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d,
       texture_environment->filename = new_viewport_parameters.studiolight_path;
       graph->add(texture_environment);
 
+      MixNode *mix_intensity = new MixNode();
+      mix_intensity->type = NODE_MIX_MUL;
+      mix_intensity->fac = 1.0f;
+      mix_intensity->color2 = make_float3(new_viewport_parameters.studiolight_intensity,
+                                          new_viewport_parameters.studiolight_intensity,
+                                          new_viewport_parameters.studiolight_intensity);
+      graph->add(mix_intensity);
+
       TextureCoordinateNode *texture_coordinate = new TextureCoordinateNode();
       graph->add(texture_coordinate);
 
@@ -1359,10 +1367,10 @@ void BlenderSync::sync_world(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d,
 
       graph->connect(texture_coordinate->output("Generated"),
                      texture_environment->input("Vector"));
+      graph->connect(texture_environment->output("Color"), mix_intensity->input("Color1"));
       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"),
+      graph->connect(mix_intensity->output("Color"), mix_scene_with_background->input("Color1"));
+      graph->connect(mix_intensity->output("Color"),
                      mix_background_with_environment->input("Color2"));
       graph->connect(mix_background_with_environment->output("Color"),
                      mix_scene_with_background->input("Color2"));
index 7af509aab09c9a07cfe2ffff35125c5310a2a5fc..93dd8faa450db57067774ab46d50a5fb72e3a97d 100644 (file)
@@ -21,6 +21,7 @@ BlenderViewportParameters::BlenderViewportParameters()
     : use_scene_world(true),
       use_scene_lights(true),
       studiolight_rotate_z(0.0f),
+      studiolight_intensity(1.0f),
       studiolight_background_alpha(1.0f),
       studiolight_path(ustring())
 {
@@ -36,6 +37,7 @@ BlenderViewportParameters::BlenderViewportParameters(BL::SpaceView3D &b_v3d)
     use_scene_lights = b_v3d.shading().use_scene_lights_render();
     if (!use_scene_world) {
       studiolight_rotate_z = b_v3d.shading().studiolight_rotate_z();
+      studiolight_intensity = b_v3d.shading().studiolight_intensity();
       studiolight_background_alpha = b_v3d.shading().studiolight_background_alpha();
       studiolight_path = b_v3d.shading().selected_studio_light().path();
     }
@@ -47,6 +49,7 @@ const bool BlenderViewportParameters::modified(const BlenderViewportParameters &
 {
   return use_scene_world != other.use_scene_world || use_scene_lights != other.use_scene_lights ||
          studiolight_rotate_z != other.studiolight_rotate_z ||
+         studiolight_intensity != other.studiolight_intensity ||
          studiolight_background_alpha != other.studiolight_background_alpha ||
          studiolight_path != other.studiolight_path;
 }
index bb0d7d7f31412c7a6b9a2adf17b0126461dfbf8e..10e89f16e7bfe29512d764354f14892588a8d311 100644 (file)
@@ -31,6 +31,7 @@ class BlenderViewportParameters {
   bool use_scene_world;
   bool use_scene_lights;
   float studiolight_rotate_z;
+  float studiolight_intensity;
   float studiolight_background_alpha;
   ustring studiolight_path;
 
index 7d9f84d69a2b80f13b37dcbd2b3457be5e3bbf3b..89de137df766b455a6b7065afef21172f9b22ad6 100644 (file)
@@ -5131,6 +5131,7 @@ class VIEW3D_PT_shading_lighting(Panel):
                 split = layout.split(factor=0.9)
                 col = split.column()
                 col.prop(shading, "studiolight_rotate_z", text="Rotation")
+                col.prop(shading, "studiolight_intensity")
                 col.prop(shading, "studiolight_background_alpha")
                 col = split.column()  # to align properly with above
 
@@ -5153,6 +5154,7 @@ class VIEW3D_PT_shading_lighting(Panel):
                 split = layout.split(factor=0.9)
                 col = split.column()
                 col.prop(shading, "studiolight_rotate_z", text="Rotation")
+                col.prop(shading, "studiolight_intensity")
                 col.prop(shading, "studiolight_background_alpha")
                 col = split.column()  # to align properly with above
 
index 4837fa8639edba0534d8758b20a123ec3d2caee9..9f049b61b5a3ab32d9d25c1081f41e383d21eedc 100644 (file)
@@ -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
index 0d108704b4e0572a78d83fc29629875508049eae..ca00e7cc62f5bffe1ca396b384ed485aa11b3a90 100644 (file)
@@ -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;
+            }
+          }
+        }
+      }
+    }
   }
 }
index f52fcf31267a61176cafac54121ef59c82042d3f..94d61a81fcc71a345256cd68908b433c0f9595be 100644 (file)
@@ -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;
index 28a8983cfeecaa6eae2c829d8cd2e10f5576223c..f4f40d40de62532e5c286f509805c79daa0612fc 100644 (file)
@@ -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;
index 70466479a29e4b8f13951af07b74df12ed3d1d27..41e103609f3d992d18cf64ec2d6ec78eec505f52 100644 (file)
@@ -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;
index 6168b00508b0cd495b20f65a84119ebd11dd5e5f..5db0021af224e5c4c1da41fe2706f9552cd94254 100644 (file)
@@ -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. */
index 727745e69dd6970c5807deb017d97ff78421332a..171da61e48373d61af68c520b29970f5e0cb5b79 100644 (file)
@@ -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);