diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2016-05-20 15:16:54 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2016-05-22 16:12:14 +0300 |
commit | 120492ace9150913f106f329942684c583a6f697 (patch) | |
tree | 117c2be4b67cfc5caa50b6a54f65ec3bf0387863 /source/blender/gpu/shaders | |
parent | 6115267a845a49bdf9a5d4c701fcf5b995fc499a (diff) |
Cycles: Support bump mapping in GLSL viewport
This commit implements Bump node in GLSL, making it possible to
see previews of bump mapping in viewport without need to render.
Nothing really fancy going on here, just uses internal dFdx/dFdy
functions to get derivatives of the surface and map itself.
Quite basic but seems to behave correct-ish.
This commit also makes Displacement material output to affect
viewport shading by re-linking unconnected Normal input to a
node which was used for displacement output (via Bump node).
Intention of all this is to make it really easy to do bump map
painting with Cycles as an active render engine.
Reviewers: campbellbarton, mont29, brecht, psy-fi
Reviewed By: brecht
Subscribers: Blendify, eyecandy
Differential Revision: https://developer.blender.org/D2014
Diffstat (limited to 'source/blender/gpu/shaders')
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_material.glsl | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl index dea5b994e74..28bf99b83dc 100644 --- a/source/blender/gpu/shaders/gpu_shader_material.glsl +++ b/source/blender/gpu/shaders/gpu_shader_material.glsl @@ -3160,9 +3160,27 @@ void node_normal_map(vec4 tangent, vec3 normal, vec3 texnormal, out vec3 outnorm outnormal = normalize(outnormal); } -void node_bump(float strength, float dist, float height, vec3 N, out vec3 result) +void node_bump(float strength, float dist, float height, vec3 N, vec3 surf_pos, out vec3 result) { - result = N; + vec3 dPdx = dFdx(surf_pos); + vec3 dPdy = dFdy(surf_pos); + + /* Get surface tangents from normal. */ + vec3 Rx = cross(dPdy, N); + vec3 Ry = cross(N, dPdx); + + /* Compute surface gradient and determinant. */ + float det = dot(dPdx, Rx); + float absdet = abs(det); + + float dHdx = dFdx(height); + float dHdy = dFdy(height); + vec3 surfgrad = dHdx*Rx + dHdy*Ry; + + strength = max(strength, 0.0); + + result = normalize(absdet*N - dist*sign(det)*surfgrad); + result = normalize(strength*result + (1.0 - strength)*N); } /* output */ |