[Bf-blender-cvs] [2d720f51cd7] blender2.8: Workbench: Change Studio lighting

Clément Foucault noreply at git.blender.org
Wed Nov 28 16:00:01 CET 2018


Commit: 2d720f51cd786f3e0924602efb6ec89ef8ed077f
Author: Clément Foucault
Date:   Wed Nov 28 15:57:40 2018 +0100
Branches: blender2.8
https://developer.blender.org/rB2d720f51cd786f3e0924602efb6ec89ef8ed077f

Workbench: Change Studio lighting

This is in order to have more flexible ligthing presets in the future.
The diffuse lighting from hdris was nice but lacked the corresponding
specular information. This is an attempt to make it possible to customize
the lighting and have a cheap/easy/nice-looking pseudo-PBR workflow.

* Add cheap PBR to Workbench with fresnel and better roughness support.
  This improves the look of the metallic surfaces and is easier to control.
* Add ambient light to studio lights settings: just a constant color added
  to the shading.
* Add Smooth option to studio lights settings: This option fakes the
  effect of making the light bigger making the lighting smoother for this
  light. Smoother lights gets reflected like a background hdri.
* Change default light settings to include the smooth params.
* Remove specular highlights from flat shading. (could be added back but
  how do we make it good looking?)
* If specular lighting is disabled, use base color without using metallic.
* Include a lot of code simplification/cleanup/confusion fix.

===================================================================

M	release/scripts/startup/bl_ui/properties_material.py
M	release/scripts/startup/bl_ui/space_userpref.py
M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/blenloader/intern/versioning_defaults.c
M	source/blender/blenloader/intern/versioning_userdef.c
M	source/blender/draw/engines/workbench/shaders/workbench_data_lib.glsl
M	source/blender/draw/engines/workbench/shaders/workbench_deferred_composite_frag.glsl
M	source/blender/draw/engines/workbench/shaders/workbench_forward_transparent_accum_frag.glsl
M	source/blender/draw/engines/workbench/shaders/workbench_world_light_lib.glsl
M	source/blender/draw/engines/workbench/workbench_data.c
M	source/blender/draw/engines/workbench/workbench_deferred.c
M	source/blender/draw/engines/workbench/workbench_forward.c
M	source/blender/draw/engines/workbench/workbench_materials.c
M	source/blender/draw/engines/workbench/workbench_private.h
M	source/blender/makesdna/DNA_userdef_types.h
M	source/blender/makesrna/intern/rna_userdef.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/properties_material.py b/release/scripts/startup/bl_ui/properties_material.py
index 5e57e267add..89c1f32ed2d 100644
--- a/release/scripts/startup/bl_ui/properties_material.py
+++ b/release/scripts/startup/bl_ui/properties_material.py
@@ -253,8 +253,8 @@ class MATERIAL_PT_viewport(MaterialButtonsPanel, Panel):
         layout.use_property_split = True
 
         col = layout.column()
-        col.prop(mat, "diffuse_color")
-        col.prop(mat, "specular_color")
+        col.prop(mat, "diffuse_color", text="Color")
+        col.prop(mat, "metallic")
         col.prop(mat, "roughness")
 
 
diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index 6add7bf32eb..8ace0b8164e 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -1531,8 +1531,8 @@ class USERPREF_PT_studiolight_camera(Panel, StudioLightPanelMixin):
     sl_orientation = 'CAMERA'
 
 
-class USERPREF_PT_studiolight_specular(Panel, StudioLightPanelMixin):
-    bl_label = "Specular Lights"
+class USERPREF_PT_studiolight_lights(Panel, StudioLightPanelMixin):
+    bl_label = "Studio Lights"
     sl_orientation = 'CAMERA'
 
     @classmethod
@@ -1548,7 +1548,9 @@ class USERPREF_PT_studiolight_specular(Panel, StudioLightPanelMixin):
 
         sub = col.column()
         sub.active = light.use
+        sub.prop(light, "diffuse_color")
         sub.prop(light, "specular_color")
+        sub.prop(light, "smooth")
 
         col = split.column()
         col.active = light.use
@@ -1561,6 +1563,8 @@ class USERPREF_PT_studiolight_specular(Panel, StudioLightPanelMixin):
         userpref = context.user_preferences
         system = userpref.system
 
+        layout.prop(system, "light_ambient")
+
         light = system.solid_lights[0]
         colsplit = column.split(factor=0.85)
         self.opengl_light_buttons(colsplit, light)
@@ -1572,7 +1576,6 @@ class USERPREF_PT_studiolight_specular(Panel, StudioLightPanelMixin):
         light = system.solid_lights[2]
         self.opengl_light_buttons(column, light)
 
-
 classes = (
     USERPREF_HT_header,
     USERPREF_PT_navigation,
@@ -1590,7 +1593,7 @@ classes = (
     USERPREF_PT_studiolight_matcaps,
     USERPREF_PT_studiolight_world,
     USERPREF_PT_studiolight_camera,
-    USERPREF_PT_studiolight_specular,
+    USERPREF_PT_studiolight_lights,
 )
 
 if __name__ == "__main__":  # only for live edit.
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 77f9c2332ac..8eac3cec976 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -4205,13 +4205,14 @@ class VIEW3D_PT_shading_lighting(Panel):
             sub.scale_y = 0.6  # smaller matcap/hdri preview
 
             if shading.light == 'STUDIO':
-                sub.template_icon_view(shading, "studio_light", scale=3)
+                # Not implemented right now
+                # sub.template_icon_view(shading, "studio_light", scale=3)
 
-                if shading.selected_studio_light.orientation == 'WORLD':
-                    col.prop(shading, "studiolight_rotate_z", text="Rotation")
+                # if shading.selected_studio_light.orientation == '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')
 
             elif shading.light == 'MATCAP':
                 sub.template_icon_view(shading, "studio_light", scale=3)
@@ -4355,8 +4356,8 @@ class VIEW3D_PT_shading_options(Panel):
         sub.prop(shading, "object_outline_color", text="")
 
         col = layout.column()
-        if (shading.light is not 'MATCAP') and (shading.type is not 'WIREFRAME'):
-            col.prop(shading, "show_specular_highlight")
+        if (shading.light == 'STUDIO') and (shading.type is not 'WIREFRAME'):
+            col.prop(shading, "show_specular_highlight", text="Specular Lighting")
 
 
 class VIEW3D_PT_shading_options_shadow(Panel):
diff --git a/source/blender/blenloader/intern/versioning_defaults.c b/source/blender/blenloader/intern/versioning_defaults.c
index f9f9905be3c..055e4b065a1 100644
--- a/source/blender/blenloader/intern/versioning_defaults.c
+++ b/source/blender/blenloader/intern/versioning_defaults.c
@@ -280,4 +280,15 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
 			}
 		}
 	}
+
+	for (bScreen *sc = bmain->screen.first; sc; sc = sc->id.next) {
+		for (ScrArea *sa = sc->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_SPECULAR_HIGHLIGHT;
+				}
+			}
+		}
+	}
 }
diff --git a/source/blender/blenloader/intern/versioning_userdef.c b/source/blender/blenloader/intern/versioning_userdef.c
index a65520c35fa..55c875e3412 100644
--- a/source/blender/blenloader/intern/versioning_userdef.c
+++ b/source/blender/blenloader/intern/versioning_userdef.c
@@ -421,6 +421,22 @@ void BLO_version_defaults_userpref_blend(Main *bmain, UserDef *userdef)
 	 */
 	{
 		/* (keep this block even if it becomes empty). */
+		copy_v4_fl4(userdef->light[0].vec, -0.580952, 0.228571, 0.781185, 0.0);
+		copy_v4_fl4(userdef->light[0].col, 0.900000, 0.900000, 0.900000, 1.000000);
+		copy_v4_fl4(userdef->light[0].spec, 0.318547, 0.318547, 0.318547, 1.000000);
+		userdef->light[0].smooth = 0.1;
+
+		copy_v4_fl4(userdef->light[1].vec, 0.788218, 0.593482, -0.162765, 0.0);
+		copy_v4_fl4(userdef->light[1].col, 0.267115, 0.269928, 0.358840, 1.000000);
+		copy_v4_fl4(userdef->light[1].spec, 0.090838, 0.090838, 0.090838, 1.000000);
+		userdef->light[1].smooth = 0.25;
+
+		copy_v4_fl4(userdef->light[2].vec, 0.696472, -0.696472, -0.172785, 0.0);
+		copy_v4_fl4(userdef->light[2].col, 0.293216, 0.304662, 0.401968, 1.000000);
+		copy_v4_fl4(userdef->light[2].spec, 0.069399, 0.020331, 0.020331, 1.000000);
+		userdef->light[2].smooth = 0.5;
+
+		copy_v4_fl4(userdef->light_ambient, 0.025000, 0.025000, 0.025000, 1.000000);
 	}
 
 	if (userdef->pixelsize == 0.0f)
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_data_lib.glsl b/source/blender/draw/engines/workbench/shaders/workbench_data_lib.glsl
index 3a538f4f2ac..fd058d45cf6 100644
--- a/source/blender/draw/engines/workbench/shaders/workbench_data_lib.glsl
+++ b/source/blender/draw/engines/workbench/shaders/workbench_data_lib.glsl
@@ -1,6 +1,7 @@
 struct LightData {
-	vec4 light_direction_vs;
+	vec4 direction;
 	vec4 specular_color;
+	vec4 diffuse_color_wrap; /* rgb: diffuse col a: wrapped lighting factor */
 };
 
 struct WorldData {
@@ -9,7 +10,8 @@ struct WorldData {
 	vec4 background_color_high;
 	vec4 object_outline_color;
 	vec4 shadow_direction_vs;
-	LightData lights[3];
+	LightData lights[4];
+	vec4 ambient_color;
 	int num_lights;
 	int matcap_orientation;
 	float background_alpha;
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_deferred_composite_frag.glsl b/source/blender/draw/engines/workbench/shaders/workbench_deferred_composite_frag.glsl
index f15e6b613a9..4aa471f70d8 100644
--- a/source/blender/draw/engines/workbench/shaders/workbench_deferred_composite_frag.glsl
+++ b/source/blender/draw/engines/workbench/shaders/workbench_deferred_composite_frag.glsl
@@ -1,6 +1,7 @@
 out vec4 fragColor;
 
 uniform mat4 ProjectionMatrix;
+uniform mat4 ViewMatrixInverse;
 
 uniform usampler2D objectId;
 uniform sampler2D colorBuffer;
@@ -14,7 +15,6 @@ uniform vec4 viewvecs[3];
 uniform float shadowMultiplier;
 uniform float lightMultiplier;
 uniform float shadowShift = 0.1;
-uniform mat3 normalWorldMatrix;
 
 #ifdef STUDIOLIGHT_ORIENTATION_VIEWNORMAL
 uniform sampler2D matcapImage;
@@ -70,39 +70,30 @@ void main()
 
 	vec3 I_vs = view_vector_from_screen_uv(uv_viewport, viewvecs, ProjectionMatrix);
 
-#ifdef STUDIOLIGHT_ORIENTATION_VIEWNORMAL
-	bool flipped = world_data.matcap_orientation != 0;
-	vec2 matcap_uv = matcap_uv_compute(I_vs, normal_viewport, flipped);
-	diffuse_color = textureLod(matcapImage, matcap_uv, 0.0);
-#endif
-
-#ifdef V3D_SHADING_SPECULAR_HIGHLIGHT
-	vec4 specular_data = texelFetch(specularBuffer, texel, 0);
-	vec3 specular_color = get_world_specular_lights(world_data, specular_data, normal_viewport, I_vs);
-#else
-	vec3 specular_color = vec3(0.0);
-#endif
-
+	/* -------- SHADING --------- */
 #ifdef V3D_LIGHTING_FLAT
-	vec3 diffuse_light = vec3(1.0);
-#endif
+	vec3 shaded_color = diffuse_color.rgb;
 
-#ifdef V3D_LIGHTING_MATCAP
-	vec3 diffuse_light = texelFetch(specularBuffer, texel, 0).rgb;
-#endif
+#elif defined(V3D_LIGHTING_MATCAP)
+	bool flipped = world_data.matcap_orientation != 0;
+	vec2 matcap_uv = matcap_uv_compute(I_vs, normal_viewport, flipped);
+	vec3 object_color = texelFetch(specularBuffer, texel, 0).rgb;
+	vec3 matcap = textureLod(matcapImage, matcap_uv, 0.0).rgb;
+	vec3 shaded_color = matcap * object_color;
 
-#ifdef V3D_LIGHTING_STUDIO
-#  ifdef STUDIOLIGHT_ORIENTATION_CAMERA
-	vec3 diffuse_light = get_camera_diffuse_light(world_data, normal_viewport);
-#  endif
+#elif defined(V3D_LIGHTING_STUDIO)
 
-#  ifdef STUDIOLIGHT_ORIENTATION_WORLD
-	vec3 normal_world = normalWorldMatrix * normal_viewport;
-	vec3 diffuse_light = get_world_diffuse_light(world_data, normal_world);
+#  ifdef V3D_SHADING_SPECULAR_HIGHLIGHT
+	vec4 specular_data = texelFetch(specularBuffer, texel, 0);
+#  else
+	vec4 specular_data = vec4(0.0);
 #  endif
+	vec3 shaded_color = get_world_lighting(world_data,
+	                                       diffuse_color.rgb, specular_data.rgb, specular_data.a,
+	                                       normal_viewport, I_vs);
 #endif
-	vec3 shaded_color = diffuse_light * diffuse_color.rgb + specular_color;
 
+	/* -------- POST EFFECTS --------- */
 #ifdef V3D_SHADING_SSAO
 	vec2 cavity = texelFetch(cavityBuffer, texel, 0).rg;
 	shaded_color *= 1.0 - cav

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list