Fix T42184: Normal not displayed correctly in Material Viewport

There was a differences between how Cycles and BI treats Normal shader:

- Different normal direction assumption
- Different policy about vector normalization

Previous idea of trying to use single function and flip the output if
needed becomes more tricky, so i've just added new GLSL function which
corresponds to how Cycles deals with the Normal shader.
This commit is contained in:
Sergey Sharybin 2014-12-10 19:12:54 +05:00
parent d68521df7b
commit d9ddc99a27
2 changed files with 11 additions and 5 deletions

@ -357,6 +357,12 @@ void normal(vec3 dir, vec3 nor, out vec3 outnor, out float outdot)
outdot = -dot(dir, nor);
}
void normal_new_shading(vec3 dir, vec3 nor, out vec3 outnor, out float outdot)
{
outnor = normalize(nor);
outdot = dot(normalize(dir), nor);
}
void curves_vec(float fac, vec3 vec, sampler2D curvemap, out vec3 outvec)
{
outvec.x = texture2D(curvemap, vec2((vec.x + 1.0)*0.5, 0.0)).x;

@ -61,12 +61,12 @@ static void node_shader_exec_normal(void *UNUSED(data), int UNUSED(thread), bNod
static int gpu_shader_normal(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
GPUNodeLink *vec = GPU_uniform(out[0].vec);
int ret = GPU_stack_link(mat, "normal", in, out, vec);
if (ret && GPU_material_use_new_shading_nodes(mat)) {
float fac[3] = {-1.0f, -1.0f, -1.0f};
GPU_link(mat, "math_multiply", GPU_uniform(fac), out[1].link, &out[1].link);
if (GPU_material_use_new_shading_nodes(mat)) {
return GPU_stack_link(mat, "normal_new_shading", in, out, vec);
}
else {
return GPU_stack_link(mat, "normal", in, out, vec);
}
return ret;
}
void register_node_type_sh_normal(void)