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 /source/blender/gpu/shaders/material | |
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 'source/blender/gpu/shaders/material')
-rw-r--r-- | source/blender/gpu/shaders/material/gpu_shader_material_tex_wave.glsl | 69 |
1 files changed, 59 insertions, 10 deletions
diff --git a/source/blender/gpu/shaders/material/gpu_shader_material_tex_wave.glsl b/source/blender/gpu/shaders/material/gpu_shader_material_tex_wave.glsl index 957aa606a79..c72f9717af3 100644 --- a/source/blender/gpu/shaders/material/gpu_shader_material_tex_wave.glsl +++ b/source/blender/gpu/shaders/material/gpu_shader_material_tex_wave.glsl @@ -1,26 +1,64 @@ -float calc_wave( - vec3 p, float distortion, float detail, float detail_scale, int wave_type, int wave_profile) +float calc_wave(vec3 p, + float distortion, + float detail, + float detail_scale, + float phase, + int wave_type, + int bands_dir, + int rings_dir, + int wave_profile) { + /* Prevent precision issues on unit coordinates. */ + p = (p + 0.000001) * 0.999999; + float n; - if (wave_type == 0) { /* type bands */ - n = (p.x + p.y + p.z) * 10.0; + if (wave_type == 0) { /* type bands */ + if (bands_dir == 0) { /* X axis */ + n = p.x * 20.0; + } + else if (bands_dir == 1) { /* Y axis */ + n = p.y * 20.0; + } + else if (bands_dir == 2) { /* Z axis */ + n = p.z * 20.0; + } + else { /* Diagonal axis */ + n = (p.x + p.y + p.z) * 10.0; + } } else { /* type rings */ - n = length(p) * 20.0; + vec3 rp = p; + if (rings_dir == 0) { /* X axis */ + rp *= vec3(0.0, 1.0, 1.0); + } + else if (rings_dir == 1) { /* Y axis */ + rp *= vec3(1.0, 0.0, 1.0); + } + else if (rings_dir == 2) { /* Z axis */ + rp *= vec3(1.0, 1.0, 0.0); + } + /* else: Spherical */ + + n = length(rp) * 20.0; } + n += phase; + if (distortion != 0.0) { n += distortion * (fractal_noise(p * detail_scale, detail) * 2.0 - 1.0); } if (wave_profile == 0) { /* profile sin */ - return 0.5 + 0.5 * sin(n); + return 0.5 + 0.5 * sin(n - M_PI_2); + } + else if (wave_profile == 1) { /* profile saw */ + n /= 2.0 * M_PI; + return n - floor(n); } - else { /* profile saw */ + else { /* profile tri */ n /= 2.0 * M_PI; - n -= int(n); - return (n < 0.0) ? n + 1.0 : n; + return abs(n - floor(n + 0.5)) * 2.0; } } @@ -29,13 +67,24 @@ void node_tex_wave(vec3 co, float distortion, float detail, float detail_scale, + float phase, float wave_type, + float bands_dir, + float rings_dir, float wave_profile, out vec4 color, out float fac) { float f; - f = calc_wave(co * scale, distortion, detail, detail_scale, int(wave_type), int(wave_profile)); + f = calc_wave(co * scale, + distortion, + detail, + detail_scale, + phase, + int(wave_type), + int(bands_dir), + int(rings_dir), + int(wave_profile)); color = vec4(f, f, f, 1.0); fac = f; |