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>2019-08-19 21:33:17 +0300
committerClément Foucault <foucault.clem@gmail.com>2019-09-06 17:59:15 +0300
commitffd5e1e6acd296a187e7af016f9d7f8a9f209f87 (patch)
treef6dfa5af198009a7119aa90c5fb78feb0be49b0b /source/blender/gpu/shaders/material
parent83a7d98a325232bef85bd7c66dccf911248abf05 (diff)
Eevee: Use manual derivatives for better quality bump.
We basically duplicate the height map branch plugged into the bump node, and tag each node in each branch as dx/dy/ref using `branch_tag`. Then we add a one pixel offset on the texture coordinates if the node is tagged as dx or dy. The dx/dy branches are plugged into (new) hidden sockets on the bump node. This match cycles bump better but have a performance impact. Also, complex nodetrees can now become instruction limited and not compile anymore. Reviewers: brecht Differential Revision: https://developer.blender.org/D5531
Diffstat (limited to 'source/blender/gpu/shaders/material')
-rw-r--r--source/blender/gpu/shaders/material/gpu_shader_material_bump.glsl25
1 files changed, 21 insertions, 4 deletions
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_bump.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_bump.glsl
index 1137e5acdc6..fabc070b0bc 100644
--- a/source/blender/gpu/shaders/material/gpu_shader_material_bump.glsl
+++ b/source/blender/gpu/shaders/material/gpu_shader_material_bump.glsl
@@ -1,5 +1,22 @@
-void node_bump(
- float strength, float dist, float height, vec3 N, vec3 surf_pos, float invert, out vec3 result)
+void dfdx_v3(vec3 v, out vec3 dy)
+{
+ dy = v + abs(dFdx(v));
+}
+
+void dfdy_v3(vec3 v, out vec3 dy)
+{
+ dy = v + abs(dFdy(v));
+}
+
+void node_bump(float strength,
+ float dist,
+ float height,
+ float height_dx,
+ float height_dy,
+ vec3 N,
+ vec3 surf_pos,
+ float invert,
+ out vec3 result)
{
N = mat3(ViewMatrix) * normalize(N);
dist *= gl_FrontFacing ? invert : -invert;
@@ -14,8 +31,8 @@ void node_bump(
/* Compute surface gradient and determinant. */
float det = dot(dPdx, Rx);
- float dHdx = dFdx(height);
- float dHdy = dFdy(height);
+ float dHdx = height_dx - height;
+ float dHdy = height_dy - height;
vec3 surfgrad = dHdx * Rx + dHdy * Ry;
strength = max(strength, 0.0);