Eevee: Add Lamp Specular multiplier.
authorClément Foucault <foucault.clem@gmail.com>
Wed, 2 May 2018 16:39:17 +0000 (18:39 +0200)
committerClément Foucault <foucault.clem@gmail.com>
Wed, 2 May 2018 16:39:53 +0000 (18:39 +0200)
It's usefull in some scenario to tweak the specular intensity of a light
without modifying the diffuse contribution.

Cycles allows it via lamps material which we currently not support in Eevee.

This is a good workaround for now.

release/scripts/startup/bl_ui/properties_data_lamp.py
source/blender/blenloader/intern/versioning_280.c
source/blender/draw/engines/eevee/eevee_lights.c
source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
source/blender/makesdna/DNA_lamp_types.h
source/blender/makesrna/intern/rna_lamp.c

index 892ca26189de8210786b7d2658f3daa66d7eb27d..1d7e5807b347aabd0b2ba103ea66804ab5eafdbc 100644 (file)
@@ -143,7 +143,7 @@ class DATA_PT_EEVEE_lamp(DataButtonsPanel, Panel):
                 sub.prop(lamp, "size_y", text="Size Y")
 
         col = split.column()
-        col.label()
+        col.prop(lamp, "specular_factor", text="Specular")
 
 
 class DATA_PT_EEVEE_shadow(DataButtonsPanel, Panel):
index 7d473230a4e43ee1c05d63e1da5b0c74faf7d059..07f51dfbc2f1971b4222f7510dffe92e53c9cd90 100644 (file)
@@ -1072,4 +1072,12 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *main)
                        }
                }
        }
+
+       {
+               if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "spec_fac")) {
+                       for (Lamp *la = main->lamp.first; la; la = la->id.next) {
+                               la->spec_fac = 1.0f;
+                       }
+               }
+       }
 }
index 76e8fe83f0a4b32088ac94622d7b4af6394a34ba..3508a425eb09a2ec780885b3f388d81a2ccfc646 100644 (file)
@@ -546,6 +546,8 @@ static void eevee_light_setup(Object *ob, EEVEE_Light *evli)
        /* Color */
        copy_v3_v3(evli->color, &la->r);
 
+       evli->spec = la->spec_fac;
+
        /* Influence Radius */
        evli->dist = la->dist;
 
index cc66b477da0292455c587c6b156533f07c39314d..88fde8929cbc92cc412865049130bbd02892a6ee 100644 (file)
@@ -200,11 +200,11 @@ void CLOSURE_NAME(
        #endif
 
        #ifdef CLOSURE_GLOSSY
-               out_spec += l_color_vis * light_specular(ld, N, view_vec, l_vector, roughnessSquared, f0) * occlu;
+               out_spec += l_color_vis * light_specular(ld, N, view_vec, l_vector, roughnessSquared, f0) * occlu * ld.l_spec;
        #endif
 
        #ifdef CLOSURE_CLEARCOAT
-               out_spec += l_color_vis * light_specular(ld, C_N, view_vec, l_vector, C_roughnessSquared, f0) * C_intensity * occlu;
+               out_spec += l_color_vis * light_specular(ld, C_N, view_vec, l_vector, C_roughnessSquared, f0) * C_intensity * occlu * ld.l_spec;
        #endif
 
 #else /* HAIR_SHADER */
@@ -218,11 +218,11 @@ void CLOSURE_NAME(
        #endif
 
        #ifdef CLOSURE_GLOSSY
-               out_spec += l_color_vis * light_specular(ld, N, V, l_vector, roughnessSquared, f0);
+               out_spec += l_color_vis * light_specular(ld, N, V, l_vector, roughnessSquared, f0) * ld.l_spec;
        #endif
 
        #ifdef CLOSURE_CLEARCOAT
-               out_spec += l_color_vis * light_specular(ld, C_N, V, l_vector, C_roughnessSquared, f0) * C_intensity;
+               out_spec += l_color_vis * light_specular(ld, C_N, V, l_vector, C_roughnessSquared, f0) * C_intensity * ld.l_spec;
        #endif
 
 #endif /* HAIR_SHADER */
index b3c07543201a0952dfd191a85760655839f70852..43606cbcd9da4f15053eb50e8f1d72b9f64541d5 100644 (file)
@@ -89,6 +89,8 @@ typedef struct Lamp {
 
        float contact_dist, contact_bias, contact_spread, contact_thickness;
 
+       float spec_fac, pad;
+
        /* preview */
        struct PreviewImage *preview;
 
index 6f176ebe3316a5c0262ff9c175543c5eecdb99d8..5bb24f0270dbb98a976b002113ad15a1a12f29e4 100644 (file)
@@ -312,6 +312,13 @@ static void rna_def_lamp_shadow(StructRNA *srna, int sun)
                                                         "in shadow maps");
        RNA_def_property_update(prop, 0, "rna_Lamp_update");
 
+       prop = RNA_def_property(srna, "specular_factor", PROP_FLOAT, PROP_FACTOR);
+       RNA_def_property_float_sdna(prop, NULL, "spec_fac");
+       RNA_def_property_range(prop, 0.0f, 9999.0f);
+       RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.01, 2);
+       RNA_def_property_ui_text(prop, "Specular Factor", "Specular reflection multiplier");
+       RNA_def_property_update(prop, 0, "rna_Lamp_update");
+
        prop = RNA_def_property(srna, "contact_shadow_distance", PROP_FLOAT, PROP_DISTANCE);
        RNA_def_property_float_sdna(prop, NULL, "contact_dist");
        RNA_def_property_range(prop, 0.0f, 9999.0f);