Eevee: Fix geometry node for environments and support true_normal
Also minor cleanup for the Bump node.
This commit is contained in:
parent
1250ace641
commit
9d12a5aa9e
|
@ -1759,23 +1759,37 @@ void node_geometry(
|
|||
out vec3 true_normal, out vec3 incoming, out vec3 parametric,
|
||||
out float backfacing, out float pointiness)
|
||||
{
|
||||
position = worldPosition;
|
||||
#ifndef VOLUMETRICS
|
||||
normal = normalize(worldNormal);
|
||||
#else
|
||||
normal = (toworld * vec4(N, 0.0)).xyz;
|
||||
#endif
|
||||
tangent_orco_z(orco, orco);
|
||||
node_tangent(N, orco, objmat, toworld, tangent);
|
||||
true_normal = normal;
|
||||
|
||||
/* handle perspective/orthographic */
|
||||
vec3 I_view = (ProjectionMatrix[3][3] == 0.0) ? normalize(I) : vec3(0.0, 0.0, -1.0);
|
||||
incoming = -(toworld * vec4(I_view, 0.0)).xyz;
|
||||
|
||||
#if defined(WORLD_BACKGROUND) || defined(PROBE_CAPTURE)
|
||||
position = -incoming;
|
||||
true_normal = normal = incoming;
|
||||
tangent = parametric = vec3(0.0);
|
||||
vec3(0.0);
|
||||
backfacing = 0.0;
|
||||
pointiness = 0.0;
|
||||
#else
|
||||
|
||||
position = worldPosition;
|
||||
# ifndef VOLUMETRICS
|
||||
normal = normalize(worldNormal);
|
||||
|
||||
vec3 B = dFdx(worldPosition);
|
||||
vec3 T = dFdy(worldPosition);
|
||||
true_normal = normalize(cross(B, T));
|
||||
# else
|
||||
normal = (toworld * vec4(N, 0.0)).xyz;
|
||||
true_normal = normal;
|
||||
# endif
|
||||
tangent_orco_z(orco, orco);
|
||||
node_tangent(N, orco, objmat, toworld, tangent);
|
||||
|
||||
parametric = vec3(barycentric, 0.0);
|
||||
backfacing = (gl_FrontFacing) ? 0.0 : 1.0;
|
||||
pointiness = 0.5;
|
||||
#endif
|
||||
}
|
||||
|
||||
void generated_texco(vec3 I, vec3 attr_orco, out vec3 generated)
|
||||
|
@ -2930,9 +2944,9 @@ void node_normal_map(vec4 tangent, vec3 normal, vec3 texnormal, out vec3 outnorm
|
|||
|
||||
void node_bump(float strength, float dist, float height, vec3 N, vec3 surf_pos, float invert, out vec3 result)
|
||||
{
|
||||
if (invert != 0.0) {
|
||||
dist *= -1.0;
|
||||
}
|
||||
N = mat3(ViewMatrix) * normalize(N);
|
||||
dist *= invert;
|
||||
|
||||
vec3 dPdx = dFdx(surf_pos);
|
||||
vec3 dPdy = dFdy(surf_pos);
|
||||
|
||||
|
@ -2942,7 +2956,6 @@ void node_bump(float strength, float dist, float height, vec3 N, vec3 surf_pos,
|
|||
|
||||
/* Compute surface gradient and determinant. */
|
||||
float det = dot(dPdx, Rx);
|
||||
float absdet = abs(det);
|
||||
|
||||
float dHdx = dFdx(height);
|
||||
float dHdy = dFdy(height);
|
||||
|
@ -2950,8 +2963,10 @@ void node_bump(float strength, float dist, float height, vec3 N, vec3 surf_pos,
|
|||
|
||||
strength = max(strength, 0.0);
|
||||
|
||||
result = normalize(absdet * N - dist * sign(det) * surfgrad);
|
||||
result = normalize(strength * result + (1.0 - strength) * N);
|
||||
result = normalize(abs(det) * N - dist * sign(det) * surfgrad);
|
||||
result = normalize(mix(N, result, strength));
|
||||
|
||||
result = mat3(ViewMatrixInverse) * result;
|
||||
}
|
||||
|
||||
void node_bevel(float radius, vec3 N, out vec3 result)
|
||||
|
|
|
@ -47,19 +47,13 @@ static bNodeSocketTemplate sh_node_bump_out[] = {
|
|||
|
||||
static int gpu_shader_bump(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
|
||||
{
|
||||
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);
|
||||
float invert = node->custom1;
|
||||
GPU_stack_link(mat, node, "node_bump", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_constant(&invert));
|
||||
/* Other nodes are applying view matrix if the input Normal has a link.
|
||||
* We don't want normal to have view matrix applied twice, so we cancel it here.
|
||||
*
|
||||
* TODO(sergey): This is an extra multiplication which cancels each other,
|
||||
* better avoid this but that requires bigger refactor.
|
||||
*/
|
||||
return GPU_link(mat, "direction_transform_m4v3", out[0].link, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &out[0].link);
|
||||
if (!in[3].link) {
|
||||
GPU_link(mat, "world_normals_get", &in[3].link);
|
||||
}
|
||||
|
||||
float invert = (node->custom1) ? -1.0 : 1.0;
|
||||
|
||||
return GPU_stack_link(mat, node, "node_bump", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_constant(&invert));
|
||||
}
|
||||
|
||||
/* node type definition */
|
||||
|
|
Loading…
Reference in New Issue