From ecf534e4c588254f6d8f8c9e5b1688f6556dec19 Mon Sep 17 00:00:00 2001 From: Thomas Dinges Date: Fri, 20 May 2016 21:21:57 +0200 Subject: Support Cycles wave texture in GLSL viewport. --- .../blender/gpu/shaders/gpu_shader_material.glsl | 31 +++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'source/blender/gpu') diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl index 7e815f1b5c5..6197b6fe7fb 100644 --- a/source/blender/gpu/shaders/gpu_shader_material.glsl +++ b/source/blender/gpu/shaders/gpu_shader_material.glsl @@ -3057,10 +3057,35 @@ void node_tex_voronoi(vec3 co, float scale, float coloring, out vec4 color, out } } -void node_tex_wave(vec3 co, float scale, float distortion, float detail, float detail_scale, out vec4 color, out float fac) +float calc_wave(vec3 p, float distortion, float detail, float detail_scale, int wave_type, int wave_profile) { - color = vec4(1.0); - fac = 1.0; + float n; + + if(wave_type == 0) /* type bands */ + n = (p.x + p.y + p.z) * 10.0; + else /* type rings */ + n = length(p) * 20.0; + + if(distortion != 0.0) + n += distortion * noise_turbulence(p*detail_scale, detail, 0); + + if(wave_profile == 0) { /* profile sin */ + return 0.5 + 0.5 * sin(n); + } + else { /* profile saw */ + n /= 2.0 * M_PI; + n -= int(n); + return (n < 0.0)? n + 1.0: n; + } +} + +void node_tex_wave(vec3 co, float scale, float distortion, float detail, float detail_scale, float wave_type, 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)); + + color = vec4(f, f, f, 1.0); + fac = f; } /* light path */ -- cgit v1.2.3