Fix T62680 Mirrored objects have flipped binormal vectors in LookDev

Pass binormal sign via object info.
This commit is contained in:
Clément Foucault 2019-03-27 20:21:10 +01:00
parent 2add370096
commit afaa832a85
Notes: blender-bot 2023-02-14 03:20:16 +01:00
Referenced by issue #62680, Mirrored objects have flipped binormal vectors in LookDev
3 changed files with 8 additions and 7 deletions

View File

@ -823,10 +823,11 @@ static void draw_geometry_prepare(DRWShadingGroup *shgroup, DRWCall *call)
/* step 1 : bind object dependent matrices */
if (call != NULL) {
DRWCallState *state = call->state;
float objectinfo[3];
float objectinfo[4];
objectinfo[0] = state->objectinfo[0];
objectinfo[1] = call->single.ma_index; /* WATCH this is only valid for single drawcalls. */
objectinfo[2] = state->objectinfo[1];
objectinfo[3] = (state->flag & DRW_CALL_NEGSCALE) ? -1.0f : 1.0f;
GPU_shader_uniform_vector(shgroup->shader, shgroup->model, 16, 1, (float *)state->model);
GPU_shader_uniform_vector(shgroup->shader, shgroup->modelinverse, 16, 1, (float *)state->modelinverse);
@ -835,7 +836,7 @@ static void draw_geometry_prepare(DRWShadingGroup *shgroup, DRWCall *call)
GPU_shader_uniform_vector(shgroup->shader, shgroup->modelviewprojection, 16, 1, (float *)state->modelviewprojection);
GPU_shader_uniform_vector(shgroup->shader, shgroup->normalview, 9, 1, (float *)state->normalview);
GPU_shader_uniform_vector(shgroup->shader, shgroup->normalworld, 9, 1, (float *)state->normalworld);
GPU_shader_uniform_vector(shgroup->shader, shgroup->objectinfo, 3, 1, (float *)objectinfo);
GPU_shader_uniform_vector(shgroup->shader, shgroup->objectinfo, 4, 1, (float *)objectinfo);
GPU_shader_uniform_vector(shgroup->shader, shgroup->orcotexfac, 3, 2, (float *)state->orcotexfac);
GPU_shader_uniform_vector(shgroup->shader, shgroup->eye, 3, 1, (float *)state->eyevec);
}
@ -849,7 +850,7 @@ static void draw_geometry_prepare(DRWShadingGroup *shgroup, DRWCall *call)
GPU_shader_uniform_vector(shgroup->shader, shgroup->modelview, 16, 1, (float *)DST.view_data.matstate.mat[DRW_MAT_VIEW]);
GPU_shader_uniform_vector(shgroup->shader, shgroup->modelviewinverse, 16, 1, (float *)DST.view_data.matstate.mat[DRW_MAT_VIEWINV]);
GPU_shader_uniform_vector(shgroup->shader, shgroup->modelviewprojection, 16, 1, (float *)DST.view_data.matstate.mat[DRW_MAT_PERS]);
GPU_shader_uniform_vector(shgroup->shader, shgroup->objectinfo, 3, 1, (float *)unitmat);
GPU_shader_uniform_vector(shgroup->shader, shgroup->objectinfo, 4, 1, (float *)unitmat);
GPU_shader_uniform_vector(shgroup->shader, shgroup->orcotexfac, 3, 2, (float *)shgroup->instance_orcofac);
}
}

View File

@ -2977,7 +2977,7 @@ void node_light_falloff(float strength, float tsmooth, out float quadratic, out
constant = strength;
}
void node_object_info(mat4 obmat, vec3 info, out vec3 location, out float object_index, out float material_index, out float random)
void node_object_info(mat4 obmat, vec4 info, out vec3 location, out float object_index, out float material_index, out float random)
{
location = obmat[3].xyz;
object_index = info.x;
@ -2985,14 +2985,14 @@ void node_object_info(mat4 obmat, vec3 info, out vec3 location, out float object
random = info.z;
}
void node_normal_map(vec4 tangent, vec3 normal, vec3 texnormal, out vec3 outnormal)
void node_normal_map(vec4 info, vec4 tangent, vec3 normal, vec3 texnormal, out vec3 outnormal)
{
if (all(equal(tangent, vec4(0.0, 0.0, 0.0, 1.0)))) {
outnormal = normal;
return;
}
tangent *= (gl_FrontFacing ? 1.0 : -1.0);
vec3 B = tangent.w * cross(normal, tangent.xyz);
vec3 B = tangent.w * cross(normal, tangent.xyz) * info.w;
outnormal = texnormal.x * tangent.xyz + texnormal.y * B + texnormal.z * normal;
outnormal = normalize(outnormal);

View File

@ -82,7 +82,7 @@ static int gpu_shader_normal_map(GPUMaterial *mat, bNode *node, bNodeExecData *U
switch (nm->space) {
case SHD_SPACE_TANGENT:
GPU_link(mat, "color_to_normal_new_shading", realnorm, &realnorm);
GPU_link(mat, "node_normal_map", GPU_attribute(CD_TANGENT, nm->uv_map), negnorm, realnorm, &realnorm);
GPU_link(mat, "node_normal_map", GPU_builtin(GPU_OBJECT_INFO), GPU_attribute(CD_TANGENT, nm->uv_map), negnorm, realnorm, &realnorm);
GPU_link(mat, "vec_math_mix", strength, realnorm, GPU_builtin(GPU_VIEW_NORMAL), &out[0].link);
/* for uniform scale this is sufficient to match Cycles */
GPU_link(mat, "direction_transform_m4v3", out[0].link, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &out[0].link);