diff options
Diffstat (limited to 'source/blender/draw/engines/workbench/workbench_data.c')
-rw-r--r-- | source/blender/draw/engines/workbench/workbench_data.c | 61 |
1 files changed, 40 insertions, 21 deletions
diff --git a/source/blender/draw/engines/workbench/workbench_data.c b/source/blender/draw/engines/workbench/workbench_data.c index 18f4ced6074..522b7d6e8c4 100644 --- a/source/blender/draw/engines/workbench/workbench_data.c +++ b/source/blender/draw/engines/workbench/workbench_data.c @@ -157,37 +157,56 @@ void workbench_private_data_get_light_direction(WORKBENCH_PrivateData *wpd, floa const DRWContextState *draw_ctx = DRW_context_state_get(); Scene *scene = draw_ctx->scene; WORKBENCH_UBO_World *wd = &wpd->world_data; - float view_matrix[4][4]; + float view_matrix[4][4], view_inv[4][4], rot_matrix[4][4]; DRW_viewport_matrix_get(view_matrix, DRW_MAT_VIEW); + DRW_viewport_matrix_get(view_inv, DRW_MAT_VIEWINV); copy_v3_v3(r_light_direction, scene->display.light_direction); negate_v3(r_light_direction); - { - WORKBENCH_UBO_Light *light = &wd->lights[0]; - mul_v3_mat3_m4v3(light->light_direction_vs, view_matrix, r_light_direction); - light->light_direction_vs[3] = 0.0f; - copy_v3_fl(light->specular_color, 1.0f); - light->energy = 1.0f; - copy_v4_v4(wd->shadow_direction_vs, light->light_direction_vs); - wd->num_lights = 1; + /* Shadow direction. */ + mul_v3_mat3_m4v3(wd->shadow_direction_vs, view_matrix, r_light_direction); + + /* TODO enable when we support studiolight presets. */ + if (STUDIOLIGHT_ORIENTATION_WORLD_ENABLED(wpd) && false) { + axis_angle_to_mat4_single(rot_matrix, 'Y', -wpd->shading.studiolight_rot_z); + mul_m4_m4m4(rot_matrix, rot_matrix, view_matrix); + swap_v3_v3(rot_matrix[2], rot_matrix[1]); + negate_v3(rot_matrix[2]); + } + else { + unit_m4(rot_matrix); } - if (!STUDIOLIGHT_ORIENTATION_WORLD_ENABLED(wpd)) { - int light_index = 0; - for (int index = 0 ; index < 3; index++) { - SolidLight *sl = &U.light[index]; - if (sl->flag) { - WORKBENCH_UBO_Light *light = &wd->lights[light_index++]; - copy_v4_v4(light->light_direction_vs, sl->vec); - negate_v3(light->light_direction_vs); - copy_v4_v4(light->specular_color, sl->spec); - light->energy = 1.0f; - } + /* 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 = &U.light[i]; + if (sl->flag) { + copy_v3_v3(light->light_direction, sl->vec); + mul_mat3_m4_v3(rot_matrix, light->light_direction); + /* We should predivide the power by PI but that makes the lights really dim. */ + copy_v3_v3(light->specular_color, sl->spec); + copy_v3_v3(light->diffuse_color, sl->col); + light->wrapped = sl->smooth; + } + else { + 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); } - wd->num_lights = light_index; } + copy_v4_v4(wd->ambient_color, U.light_ambient); + DRW_uniformbuffer_update(wpd->world_ubo, wd); } |