diff options
author | Bartosz Moniewski <monio> | 2020-02-17 14:31:38 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2020-02-17 15:24:07 +0300 |
commit | 67d12bb5192d04a596e216f63cff2875fdd8cfbf (patch) | |
tree | c4d866f343ec9b87f713ebd004a8f343ab6f5307 /intern/cycles/kernel/shaders | |
parent | ae9bbb4d0360aea694b46ee698d24dbc1476ebf3 (diff) |
Shading: add direction modes and phase offset to wave texture node
* Direction mode X, Y and Z to align with axes rather than diagonal or
spherical as previously. X is the new default, existing files will
use diagonal or spherical for compatibility.
* Phase offset to offset the wave along its direction, for purposes like
animation and distortion.
https://developer.blender.org/D6382
Diffstat (limited to 'intern/cycles/kernel/shaders')
-rw-r--r-- | intern/cycles/kernel/shaders/node_wave_texture.osl | 67 |
1 files changed, 58 insertions, 9 deletions
diff --git a/intern/cycles/kernel/shaders/node_wave_texture.osl b/intern/cycles/kernel/shaders/node_wave_texture.osl index 5b27c570e42..5f97976e582 100644 --- a/intern/cycles/kernel/shaders/node_wave_texture.osl +++ b/intern/cycles/kernel/shaders/node_wave_texture.osl @@ -19,40 +19,81 @@ /* Wave */ -float wave(point p, string type, string profile, float detail, float distortion, float dscale) +float wave(point p, + string type, + string bands_direction, + string rings_direction, + string profile, + float detail, + float distortion, + float dscale, + float phase) { + /* Prevent precision issues on unit coordinates. */ + p = (p + 0.000001) * 0.999999; + float n = 0.0; if (type == "bands") { - n = (p[0] + p[1] + p[2]) * 10.0; + if (bands_direction == "x") { + n = p[0] * 20.0; + } + else if (bands_direction == "y") { + n = p[1] * 20.0; + } + else if (bands_direction == "z") { + n = p[2] * 20.0; + } + else { /* diagonal */ + n = (p[0] + p[1] + p[2]) * 10.0; + } } else if (type == "rings") { - n = length(p) * 20.0; + point rp = p; + if (rings_direction == "x") { + rp *= point(0.0, 1.0, 1.0); + } + else if (rings_direction == "y") { + rp *= point(1.0, 0.0, 1.0); + } + else if (rings_direction == "z") { + rp *= point(1.0, 1.0, 0.0); + } + /* else: "spherical" */ + + n = length(rp) * 20.0; } + n += phase; + if (distortion != 0.0) { n = n + (distortion * (fractal_noise(p * dscale, detail) * 2.0 - 1.0)); } if (profile == "sine") { - return 0.5 + 0.5 * sin(n); + return 0.5 + 0.5 * sin(n - M_PI_2); + } + else if (profile == "saw") { + n /= M_2PI; + return n - floor(n); } - else { - /* Saw profile */ + else { /* profile tri */ n /= M_2PI; - n -= (int)n; - return (n < 0.0) ? n + 1.0 : n; + return abs(n - floor(n + 0.5)) * 2.0; } } shader node_wave_texture(int use_mapping = 0, matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), string type = "bands", + string bands_direction = "x", + string rings_direction = "x", string profile = "sine", float Scale = 5.0, float Distortion = 0.0, float Detail = 2.0, float DetailScale = 1.0, + float PhaseOffset = 0.0, point Vector = P, output float Fac = 0.0, output color Color = 0.0) @@ -62,6 +103,14 @@ shader node_wave_texture(int use_mapping = 0, if (use_mapping) p = transform(mapping, p); - Fac = wave(p * Scale, type, profile, Detail, Distortion, DetailScale); + Fac = wave(p * Scale, + type, + bands_direction, + rings_direction, + profile, + Detail, + Distortion, + DetailScale, + PhaseOffset); Color = Fac; } |