diff options
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_material.glsl | 31 | ||||
-rw-r--r-- | source/blender/nodes/shader/nodes/node_shader_tex_wave.c | 10 |
2 files changed, 36 insertions, 5 deletions
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 */ diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_wave.c b/source/blender/nodes/shader/nodes/node_shader_tex_wave.c index 100510641e8..1194874e06c 100644 --- a/source/blender/nodes/shader/nodes/node_shader_tex_wave.c +++ b/source/blender/nodes/shader/nodes/node_shader_tex_wave.c @@ -56,12 +56,18 @@ static void node_shader_init_tex_wave(bNodeTree *UNUSED(ntree), bNode *node) static int node_shader_gpu_tex_wave(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) { - if (!in[0].link) + if (!in[0].link) { in[0].link = GPU_attribute(CD_ORCO, ""); + GPU_link(mat, "generated_from_orco", in[0].link, &in[0].link); + } node_shader_gpu_tex_mapping(mat, node, in, out); - return GPU_stack_link(mat, "node_tex_wave", in, out); + NodeTexWave *tex = (NodeTexWave *)node->storage; + float wave_type = tex->wave_type; + float wave_profile = tex->wave_profile; + + return GPU_stack_link(mat, "node_tex_wave", in, out, GPU_uniform(&wave_type), GPU_uniform(&wave_profile)); } /* node type definition */ |