Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2018-11-08 15:16:06 +0300
committerClément Foucault <foucault.clem@gmail.com>2018-11-08 21:20:40 +0300
commit9d12a5aa9e20c33c49bd86e956d0b3d5fbf6fd46 (patch)
treefd18dfc5c3f9955ddb7eb39819c5e2721f527694
parent1250ace641814098ed8e6715f6e69c5cbd46f8dd (diff)
Eevee: Fix geometry node for environments and support true_normal
Also minor cleanup for the Bump node.
-rw-r--r--source/blender/gpu/shaders/gpu_shader_material.glsl43
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_bump.c20
2 files changed, 36 insertions, 27 deletions
diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl
index 0817a0311d4..24115dbd9c4 100644
--- a/source/blender/gpu/shaders/gpu_shader_material.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_material.glsl
@@ -1759,23 +1759,37 @@ void node_geometry(
out vec3 true_normal, out vec3 incoming, out vec3 parametric,
out float backfacing, out float pointiness)
{
+ /* 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
+# ifndef VOLUMETRICS
normal = normalize(worldNormal);
-#else
+
+ vec3 B = dFdx(worldPosition);
+ vec3 T = dFdy(worldPosition);
+ true_normal = normalize(cross(B, T));
+# else
normal = (toworld * vec4(N, 0.0)).xyz;
-#endif
+ true_normal = normal;
+# 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;
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)
diff --git a/source/blender/nodes/shader/nodes/node_shader_bump.c b/source/blender/nodes/shader/nodes/node_shader_bump.c
index b71a59d8c11..c806827b71d 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bump.c
+++ b/source/blender/nodes/shader/nodes/node_shader_bump.c
@@ -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 */