Support Cycles wave texture in GLSL viewport.

This commit is contained in:
Thomas Dinges 2016-05-20 21:21:57 +02:00
parent d5b843ba9d
commit ecf534e4c5
2 changed files with 36 additions and 5 deletions

View File

@ -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 */

View File

@ -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 */