Fix T47670: cycles GLSL incorrect layer weight / fresnel.
World space and view space normals were mixed up, we should only convert from world to view space if a custom normal is connected, otherwise it is already in view space.
This commit is contained in:
parent
40b748d40f
commit
002deb29cb
Notes:
blender-bot
2023-02-14 08:08:54 +01:00
Referenced by issue #47670, Layer weight gives incorrect result in GLSL Material mode
|
@ -2413,29 +2413,27 @@ void node_add_shader(vec4 shader1, vec4 shader2, out vec4 shader)
|
|||
|
||||
/* fresnel */
|
||||
|
||||
void node_fresnel(float ior, vec3 N, vec3 I, mat4 toworld, out float result)
|
||||
void node_fresnel(float ior, vec3 N, vec3 I, out float result)
|
||||
{
|
||||
/* handle perspective/orthographic */
|
||||
vec3 I_view = (gl_ProjectionMatrix[3][3] == 0.0)? normalize(I): vec3(0.0, 0.0, -1.0);
|
||||
vec3 normal = (toworld*vec4(N, 0.0)).xyz;
|
||||
|
||||
float eta = max(ior, 0.00001);
|
||||
result = fresnel_dielectric(I_view, normal, (gl_FrontFacing)? eta: 1.0/eta);
|
||||
result = fresnel_dielectric(I_view, N, (gl_FrontFacing)? eta: 1.0/eta);
|
||||
}
|
||||
|
||||
/* layer_weight */
|
||||
|
||||
void node_layer_weight(float blend, vec3 N, vec3 I, mat4 toworld, out float fresnel, out float facing)
|
||||
void node_layer_weight(float blend, vec3 N, vec3 I, out float fresnel, out float facing)
|
||||
{
|
||||
/* fresnel */
|
||||
float eta = max(1.0 - blend, 0.00001);
|
||||
vec3 I_view = (gl_ProjectionMatrix[3][3] == 0.0)? normalize(I): vec3(0.0, 0.0, -1.0);
|
||||
vec3 normal = (toworld*vec4(N, 0.0)).xyz;
|
||||
|
||||
fresnel = fresnel_dielectric(I_view, normal, (gl_FrontFacing)? 1.0/eta : eta );
|
||||
fresnel = fresnel_dielectric(I_view, N, (gl_FrontFacing)? 1.0/eta : eta );
|
||||
|
||||
/* facing */
|
||||
facing = abs(dot(I_view, normal));
|
||||
facing = abs(dot(I_view, N));
|
||||
if(blend != 0.5) {
|
||||
blend = clamp(blend, 0.0, 0.99999);
|
||||
blend = (blend < 0.5)? 2.0*blend: 0.5/(1.0 - blend);
|
||||
|
|
|
@ -53,6 +53,8 @@ static int node_shader_gpu_bsdf_anisotropic(GPUMaterial *mat, bNode *UNUSED(node
|
|||
{
|
||||
if (!in[4].link)
|
||||
in[4].link = GPU_builtin(GPU_VIEW_NORMAL);
|
||||
else
|
||||
GPU_link(mat, "direction_transform_m4v3", in[4].link, GPU_builtin(GPU_VIEW_MATRIX), &in[4].link);
|
||||
|
||||
return GPU_stack_link(mat, "node_bsdf_anisotropic", in, out);
|
||||
}
|
||||
|
|
|
@ -45,6 +45,8 @@ static int node_shader_gpu_bsdf_diffuse(GPUMaterial *mat, bNode *UNUSED(node), b
|
|||
{
|
||||
if (!in[2].link)
|
||||
in[2].link = GPU_builtin(GPU_VIEW_NORMAL);
|
||||
else
|
||||
GPU_link(mat, "direction_transform_m4v3", in[2].link, GPU_builtin(GPU_VIEW_MATRIX), &in[2].link);
|
||||
|
||||
return GPU_stack_link(mat, "node_bsdf_diffuse", in, out);
|
||||
}
|
||||
|
|
|
@ -51,6 +51,8 @@ static int node_shader_gpu_bsdf_glass(GPUMaterial *mat, bNode *UNUSED(node), bNo
|
|||
{
|
||||
if (!in[3].link)
|
||||
in[3].link = GPU_builtin(GPU_VIEW_NORMAL);
|
||||
else
|
||||
GPU_link(mat, "direction_transform_m4v3", in[3].link, GPU_builtin(GPU_VIEW_MATRIX), &in[3].link);
|
||||
|
||||
return GPU_stack_link(mat, "node_bsdf_glass", in, out);
|
||||
}
|
||||
|
|
|
@ -50,6 +50,8 @@ static int node_shader_gpu_bsdf_glossy(GPUMaterial *mat, bNode *UNUSED(node), bN
|
|||
{
|
||||
if (!in[2].link)
|
||||
in[2].link = GPU_builtin(GPU_VIEW_NORMAL);
|
||||
else
|
||||
GPU_link(mat, "direction_transform_m4v3", in[2].link, GPU_builtin(GPU_VIEW_MATRIX), &in[2].link);
|
||||
|
||||
return GPU_stack_link(mat, "node_bsdf_glossy", in, out);
|
||||
}
|
||||
|
|
|
@ -51,6 +51,8 @@ static int node_shader_gpu_bsdf_refraction(GPUMaterial *mat, bNode *UNUSED(node)
|
|||
{
|
||||
if (!in[3].link)
|
||||
in[3].link = GPU_builtin(GPU_VIEW_NORMAL);
|
||||
else
|
||||
GPU_link(mat, "direction_transform_m4v3", in[3].link, GPU_builtin(GPU_VIEW_MATRIX), &in[3].link);
|
||||
|
||||
return GPU_stack_link(mat, "node_bsdf_refraction", in, out);
|
||||
}
|
||||
|
|
|
@ -46,6 +46,8 @@ static int node_shader_gpu_bsdf_toon(GPUMaterial *mat, bNode *UNUSED(node), bNod
|
|||
{
|
||||
if (!in[3].link)
|
||||
in[3].link = GPU_builtin(GPU_VIEW_NORMAL);
|
||||
else
|
||||
GPU_link(mat, "direction_transform_m4v3", in[3].link, GPU_builtin(GPU_VIEW_MATRIX), &in[3].link);
|
||||
|
||||
return GPU_stack_link(mat, "node_bsdf_toon", in, out);
|
||||
}
|
||||
|
|
|
@ -44,6 +44,8 @@ static int node_shader_gpu_bsdf_translucent(GPUMaterial *mat, bNode *UNUSED(node
|
|||
{
|
||||
if (!in[1].link)
|
||||
in[1].link = GPU_builtin(GPU_VIEW_NORMAL);
|
||||
else
|
||||
GPU_link(mat, "direction_transform_m4v3", in[1].link, GPU_builtin(GPU_VIEW_MATRIX), &in[1].link);
|
||||
|
||||
return GPU_stack_link(mat, "node_bsdf_translucent", in, out);
|
||||
}
|
||||
|
|
|
@ -45,6 +45,8 @@ static int node_shader_gpu_bsdf_velvet(GPUMaterial *mat, bNode *UNUSED(node), bN
|
|||
{
|
||||
if (!in[2].link)
|
||||
in[2].link = GPU_builtin(GPU_VIEW_NORMAL);
|
||||
else
|
||||
GPU_link(mat, "direction_transform_m4v3", in[2].link, GPU_builtin(GPU_VIEW_MATRIX), &in[2].link);
|
||||
|
||||
return GPU_stack_link(mat, "node_bsdf_velvet", in, out);
|
||||
}
|
||||
|
|
|
@ -49,6 +49,8 @@ static int gpu_shader_bump(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData
|
|||
{
|
||||
if (!in[3].link)
|
||||
in[3].link = GPU_builtin(GPU_VIEW_NORMAL);
|
||||
else
|
||||
GPU_link(mat, "direction_transform_m4v3", in[3].link, GPU_builtin(GPU_VIEW_MATRIX), &in[3].link);
|
||||
|
||||
return GPU_stack_link(mat, "node_bump", in, out);
|
||||
}
|
||||
|
|
|
@ -43,8 +43,10 @@ static int node_shader_gpu_fresnel(GPUMaterial *mat, bNode *UNUSED(node), bNodeE
|
|||
{
|
||||
if (!in[1].link)
|
||||
in[1].link = GPU_builtin(GPU_VIEW_NORMAL);
|
||||
else
|
||||
GPU_link(mat, "direction_transform_m4v3", in[1].link, GPU_builtin(GPU_VIEW_MATRIX), &in[1].link);
|
||||
|
||||
return GPU_stack_link(mat, "node_fresnel", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_builtin(GPU_VIEW_MATRIX));
|
||||
return GPU_stack_link(mat, "node_fresnel", in, out, GPU_builtin(GPU_VIEW_POSITION));
|
||||
}
|
||||
|
||||
/* node type definition */
|
||||
|
|
|
@ -45,8 +45,10 @@ static int node_shader_gpu_layer_weight(GPUMaterial *mat, bNode *UNUSED(node), b
|
|||
{
|
||||
if (!in[1].link)
|
||||
in[1].link = GPU_builtin(GPU_VIEW_NORMAL);
|
||||
else
|
||||
GPU_link(mat, "direction_transform_m4v3", in[1].link, GPU_builtin(GPU_VIEW_MATRIX), &in[1].link);
|
||||
|
||||
return GPU_stack_link(mat, "node_layer_weight", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_builtin(GPU_VIEW_MATRIX));
|
||||
return GPU_stack_link(mat, "node_layer_weight", in, out, GPU_builtin(GPU_VIEW_POSITION));
|
||||
}
|
||||
|
||||
/* node type definition */
|
||||
|
|
|
@ -53,6 +53,8 @@ static int node_shader_gpu_subsurface_scattering(GPUMaterial *mat, bNode *UNUSED
|
|||
{
|
||||
if (!in[5].link)
|
||||
in[5].link = GPU_builtin(GPU_VIEW_NORMAL);
|
||||
else
|
||||
GPU_link(mat, "direction_transform_m4v3", in[5].link, GPU_builtin(GPU_VIEW_MATRIX), &in[5].link);
|
||||
|
||||
return GPU_stack_link(mat, "node_subsurface_scattering", in, out);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue