Workbench: Fix wrong shading shadoow direction.
This commit is contained in:
parent
e30f25ba22
commit
967b84534a
|
@ -8,7 +8,7 @@ struct WorldData {
|
|||
vec4 background_color_low;
|
||||
vec4 background_color_high;
|
||||
vec4 object_outline_color;
|
||||
vec4 light_direction_vs;
|
||||
vec4 shadow_direction_vs;
|
||||
LightData lights[3];
|
||||
int num_lights;
|
||||
int matcap_orientation;
|
||||
|
|
|
@ -106,12 +106,10 @@ void main()
|
|||
#endif
|
||||
|
||||
#ifdef V3D_SHADING_SHADOW
|
||||
float light_factor = -dot(normal_viewport, world_data.lights[0].light_direction_vs.xyz);
|
||||
float light_factor = -dot(normal_viewport, world_data.shadow_direction_vs.xyz);
|
||||
/* The step function might be ok for meshes but it's
|
||||
* clearly not the case for hairs. Do smoothstep in this case. */
|
||||
float shadow_mix = (diffuse_color.a == 1.0 || diffuse_color.a == 0.0)
|
||||
? step(-shadowShift, -light_factor)
|
||||
: smoothstep(1.0, shadowShift, light_factor);
|
||||
float shadow_mix = smoothstep(1.0, shadowShift, light_factor);
|
||||
float light_multiplier = mix(lightMultiplier, shadowMultiplier, shadow_mix);
|
||||
|
||||
#else /* V3D_SHADING_SHADOW */
|
||||
|
|
|
@ -89,7 +89,6 @@ vec3 get_world_specular_light(vec4 specular_data, LightData light_data, vec3 N,
|
|||
vec3 get_world_specular_lights(WorldData world_data, vec4 specular_data, vec3 N, vec3 I)
|
||||
{
|
||||
vec3 specular_light = vec3(0.0);
|
||||
specular_light += get_world_specular_light(specular_data, world_data.lights[0], N, I);
|
||||
for (int i = 0 ; i < world_data.num_lights ; i ++) {
|
||||
specular_light += get_world_specular_light(specular_data, world_data.lights[i], N, I);
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ void workbench_private_data_init(WORKBENCH_PrivateData *wpd)
|
|||
}
|
||||
}
|
||||
|
||||
void workbench_private_data_get_light_direction(WORKBENCH_PrivateData *wpd, float light_direction[3])
|
||||
void workbench_private_data_get_light_direction(WORKBENCH_PrivateData *wpd, float r_light_direction[3])
|
||||
{
|
||||
const DRWContextState *draw_ctx = DRW_context_state_get();
|
||||
Scene *scene = draw_ctx->scene;
|
||||
|
@ -129,13 +129,16 @@ void workbench_private_data_get_light_direction(WORKBENCH_PrivateData *wpd, floa
|
|||
float view_matrix[4][4];
|
||||
DRW_viewport_matrix_get(view_matrix, DRW_MAT_VIEW);
|
||||
|
||||
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, light_direction);
|
||||
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->light_direction_vs, light->light_direction_vs);
|
||||
copy_v4_v4(wd->shadow_direction_vs, light->light_direction_vs);
|
||||
wd->num_lights = 1;
|
||||
}
|
||||
|
||||
|
@ -154,8 +157,6 @@ void workbench_private_data_get_light_direction(WORKBENCH_PrivateData *wpd, floa
|
|||
wd->num_lights = light_index;
|
||||
}
|
||||
|
||||
copy_v3_v3(light_direction, scene->display.light_direction);
|
||||
negate_v3(light_direction);
|
||||
DRW_uniformbuffer_update(wpd->world_ubo, wd);
|
||||
}
|
||||
|
||||
|
|
|
@ -128,7 +128,7 @@ typedef struct WORKBENCH_UBO_World {
|
|||
float background_color_low[4];
|
||||
float background_color_high[4];
|
||||
float object_outline_color[4];
|
||||
float light_direction_vs[4];
|
||||
float shadow_direction_vs[4];
|
||||
WORKBENCH_UBO_Light lights[3];
|
||||
int num_lights;
|
||||
int matcap_orientation;
|
||||
|
@ -282,7 +282,7 @@ bool studiolight_camera_in_object_shadow(WORKBENCH_PrivateData *wpd, Object *ob,
|
|||
void workbench_effect_info_init(WORKBENCH_EffectInfo *effect_info);
|
||||
void workbench_private_data_init(WORKBENCH_PrivateData *wpd);
|
||||
void workbench_private_data_free(WORKBENCH_PrivateData *wpd);
|
||||
void workbench_private_data_get_light_direction(WORKBENCH_PrivateData *wpd, float light_direction[3]);
|
||||
void workbench_private_data_get_light_direction(WORKBENCH_PrivateData *wpd, float r_light_direction[3]);
|
||||
|
||||
extern DrawEngineType draw_engine_workbench_solid;
|
||||
extern DrawEngineType draw_engine_workbench_transparent;
|
||||
|
|
Loading…
Reference in New Issue