Support gradient Cycles texture in GLSL viewport
This commit is contained in:
parent
b79214bbc5
commit
7ab55d8947
|
@ -2587,10 +2587,49 @@ void node_tex_coord_background(vec3 I, vec3 N, mat4 viewinvmat, mat4 obinvmat, v
|
|||
|
||||
/* textures */
|
||||
|
||||
void node_tex_gradient(vec3 co, out vec4 color, out float fac)
|
||||
float calc_gradient(vec3 p, int gradient_type)
|
||||
{
|
||||
color = vec4(1.0);
|
||||
fac = 1.0;
|
||||
float x, y, z;
|
||||
x = p.x;
|
||||
y = p.y;
|
||||
z = p.z;
|
||||
if(gradient_type == 0) { /* linear */
|
||||
return x;
|
||||
}
|
||||
else if(gradient_type == 1) { /* quadratic */
|
||||
float r = max(x, 0.0);
|
||||
return r*r;
|
||||
}
|
||||
else if(gradient_type == 2) { /* easing */
|
||||
float r = min(max(x, 0.0), 1.0);
|
||||
float t = r*r;
|
||||
return (3.0*t - 2.0*t*r);
|
||||
}
|
||||
else if(gradient_type == 3) { /* diagonal */
|
||||
return (x + y) * 0.5;
|
||||
}
|
||||
else if(gradient_type == 4) { /* radial */
|
||||
return atan(y, x) / (M_PI * 2) + 0.5;
|
||||
}
|
||||
else {
|
||||
float r = max(1.0 - sqrt(x*x + y*y + z*z), 0.0);
|
||||
if(gradient_type == 5) { /* quadratic sphere */
|
||||
return r*r;
|
||||
}
|
||||
else if(gradient_type == 6) { /* sphere */
|
||||
return r;
|
||||
}
|
||||
}
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
void node_tex_gradient(vec3 co, float gradient_type, out vec4 color, out float fac)
|
||||
{
|
||||
float f = calc_gradient(co, int(gradient_type));
|
||||
f = clamp(f, 0.0, 1.0);
|
||||
|
||||
color = vec4(f, f, f, 1.0);
|
||||
fac = f;
|
||||
}
|
||||
|
||||
void node_tex_checker(vec3 co, vec4 color1, vec4 color2, float scale, out vec4 color, out float fac)
|
||||
|
|
|
@ -52,12 +52,16 @@ static void node_shader_init_tex_gradient(bNodeTree *UNUSED(ntree), bNode *node)
|
|||
|
||||
static int node_shader_gpu_tex_gradient(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_gradient", in, out);
|
||||
NodeTexGradient *tex = (NodeTexGradient *)node->storage;
|
||||
float gradient_type = tex->gradient_type;
|
||||
return GPU_stack_link(mat, "node_tex_gradient", in, out, GPU_uniform(&gradient_type));
|
||||
}
|
||||
|
||||
/* node type definition */
|
||||
|
|
Loading…
Reference in New Issue