StudioLight: Add a 4th light to adjust lighting

There was a bug due to non-aligned struct in the DNA that prevented us
to increase the size of the userdef light array.

Since the studio lights are now presets and stored in external files,
there is no need to keep backward compatibility with theses lights.

Remove the old array and create a new one.

Add blue tint light for specular.
This commit is contained in:
Clément Foucault
2018-11-30 13:58:27 +01:00
parent 856b858f88
commit 909fa08a76
7 changed files with 43 additions and 27 deletions

View File

@@ -1602,6 +1602,10 @@ class USERPREF_PT_studiolight_lights_editor(Panel):
self.opengl_light_buttons(colsplit, light)
light = system.solid_lights[2]
colsplit = column.split(factor=0.85)
self.opengl_light_buttons(colsplit, light)
light = system.solid_lights[3]
self.opengl_light_buttons(column, light)
layout.separator()

View File

@@ -307,8 +307,6 @@ void BKE_blender_userdef_app_template_data_swap(UserDef *userdef_a, UserDef *use
LIST_SWAP(addons);
LIST_SWAP(user_keymaps);
DATA_SWAP(light);
DATA_SWAP(font_path_ui);
DATA_SWAP(font_path_ui_mono);
DATA_SWAP(keyconfigstr);

View File

@@ -1210,6 +1210,12 @@ void BKE_studiolight_init(void)
sl->light[2].flag = 1;
sl->light[2].smooth = 0.5;
copy_v4_fl4(sl->light[3].vec, 0.021053, -0.989474, 0.143173, 0.0);
copy_v4_fl4(sl->light[3].col, 0.0, 0.0, 0.0, 1.0);
copy_v4_fl4(sl->light[3].spec, 0.072234, 0.082253, 0.162642, 1.000000);
sl->light[3].flag = 1;
sl->light[3].smooth = 0.7;
BLI_addtail(&studiolights, sl);
/* go over the preset folder and add a studiolight for every image with its path */
@@ -1360,7 +1366,7 @@ StudioLight *BKE_studiolight_create(const char *path, const SolidLight light[4],
BLI_snprintf(sl->path, FILE_MAXFILE, "%s%s", path, ".sl");
BLI_snprintf(sl->name, FILE_MAXFILE, "%s%s", filename, ".sl");
memcpy(sl->light, light, sizeof(*light) * 3);
memcpy(sl->light, light, sizeof(*light) * 4);
memcpy(sl->light_ambient, light_ambient, sizeof(*light_ambient) * 3);
studiolight_write_solid_light(sl);
@@ -1375,7 +1381,7 @@ StudioLight *BKE_studiolight_studio_edit_get(void)
static StudioLight sl = {0};
sl.flag = STUDIOLIGHT_TYPE_STUDIO;
memcpy(sl.light, U.light, sizeof(*sl.light) * 3);
memcpy(sl.light, U.light_param, sizeof(*sl.light) * 4);
memcpy(sl.light_ambient, U.light_ambient, sizeof(*sl.light_ambient) * 3);
return &sl;

View File

@@ -421,20 +421,29 @@ 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_param[0].vec, -0.580952, 0.228571, 0.781185, 0.0);
copy_v4_fl4(userdef->light_param[0].col, 0.900000, 0.900000, 0.900000, 1.000000);
copy_v4_fl4(userdef->light_param[0].spec, 0.318547, 0.318547, 0.318547, 1.000000);
userdef->light_param[0].flag = 1;
userdef->light_param[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_param[1].vec, 0.788218, 0.593482, -0.162765, 0.0);
copy_v4_fl4(userdef->light_param[1].col, 0.267115, 0.269928, 0.358840, 1.000000);
copy_v4_fl4(userdef->light_param[1].spec, 0.090838, 0.090838, 0.090838, 1.000000);
userdef->light_param[1].flag = 1;
userdef->light_param[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_param[2].vec, 0.696472, -0.696472, -0.172785, 0.0);
copy_v4_fl4(userdef->light_param[2].col, 0.293216, 0.304662, 0.401968, 1.000000);
copy_v4_fl4(userdef->light_param[2].spec, 0.069399, 0.020331, 0.020331, 1.000000);
userdef->light_param[2].flag = 1;
userdef->light_param[2].smooth = 0.4;
copy_v4_fl4(userdef->light_param[3].vec, 0.021053, -0.989474, 0.143173, 0.0);
copy_v4_fl4(userdef->light_param[3].col, 0.0, 0.0, 0.0, 1.0);
copy_v4_fl4(userdef->light_param[3].spec, 0.072234, 0.082253, 0.162642, 1.000000);
userdef->light_param[3].flag = 1;
userdef->light_param[3].smooth = 0.7;
copy_v4_fl4(userdef->light_ambient, 0.025000, 0.025000, 0.025000, 1.000000);
}

View File

@@ -54,13 +54,6 @@ void studiolight_update_world(WORKBENCH_PrivateData *wpd, StudioLight *studiolig
/* Studio Lights. */
for (int i = 0; i < 4; i++) {
WORKBENCH_UBO_Light *light = &wd->lights[i];
/* TODO use 4 lights in studiolights prefs. */
if (i > 2) {
copy_v3_fl3(light->light_direction, 1.0f, 0.0f, 0.0f);
copy_v3_fl(light->specular_color, 0.0f);
copy_v3_fl(light->diffuse_color, 0.0f);
continue;
}
SolidLight *sl = &studiolight->light[i];
if (sl->flag) {

View File

@@ -494,6 +494,7 @@ enum {
typedef struct SolidLight {
int flag;
float smooth;
float pad[2];
float col[4], spec[4], vec[4];
} SolidLight;
@@ -586,7 +587,8 @@ typedef struct UserDef {
short gp_manhattendist, gp_euclideandist, gp_eraser;
short gp_settings; /* eGP_UserdefSettings */
short tb_leftmouse, tb_rightmouse;
struct SolidLight light[3];
/* struct SolidLight light[3] DNA_DEPRECATED; */ /* Was using non-aligned struct! */
struct SolidLight light_param[4];
float light_ambient[3], pad7;
short gizmo_flag, gizmo_size;
short edit_solid_light;

View File

@@ -329,7 +329,11 @@ static void rna_UserDef_viewport_lights_update(Main *bmain, Scene *scene, Pointe
{
/* if all lights are off gpu_draw resets them all, [#27627]
* so disallow them all to be disabled */
if (U.light[0].flag == 0 && U.light[1].flag == 0 && U.light[2].flag == 0) {
if (U.light_param[0].flag == 0 &&
U.light_param[1].flag == 0 &&
U.light_param[2].flag == 0 &&
U.light_param[3].flag == 0)
{
SolidLight *light = ptr->data;
light->flag |= 1;
}
@@ -636,7 +640,7 @@ static StudioLight *rna_StudioLights_load(UserDef *UNUSED(userdef), const char *
/* TODO: Make it accept arguments. */
static StudioLight *rna_StudioLights_new(UserDef *userdef, const char *name)
{
return BKE_studiolight_create(name, userdef->light, userdef->light_ambient);
return BKE_studiolight_create(name, userdef->light_param, userdef->light_ambient);
}
/* StudioLight.name */
@@ -4300,7 +4304,7 @@ static void rna_def_userdef_system(BlenderRNA *brna)
/* System & OpenGL */
prop = RNA_def_property(srna, "solid_lights", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "light", "");
RNA_def_property_collection_sdna(prop, NULL, "light_param", "");
RNA_def_property_struct_type(prop, "UserSolidLight");
RNA_def_property_ui_text(prop, "Solid Lights", "Lights user to display objects in solid draw mode");